botan: Require botan2

It's already 2 years old, more than sensible to ask for uptodate crypto
stuff
This commit is contained in:
Albert Astals Cid 2020-01-20 23:32:04 +01:00
parent 156dd01575
commit 501a539c22
3 changed files with 6 additions and 84 deletions

View File

@ -1,31 +0,0 @@
# - Try to find the Gcrypt library
# Once run this will define
#
# BOTAN_FOUND - set if the system has the gcrypt library
# BOTAN_CFLAGS - the required gcrypt compilation flags
# BOTAN_LIBRARIES - the linker libraries needed to use the gcrypt library
#
# Copyright (c) 2006 Brad Hards <bradh@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#reset variables
set(BOTAN_LIBRARIES)
set(BOTAN_CFLAGS)
find_package(PkgConfig)
pkg_search_module(BOTAN botan>=1.10 botan-1.10 botan-2)
if (BOTAN_FOUND)
if (NOT Botan_FIND_QUIETLY)
message(STATUS "Found Botan: ${BOTAN_LIBRARIES}")
endif (NOT Botan_FIND_QUIETLY)
else (BOTAN_FOUND)
if (Botan_FIND_REQUIRED)
message(FATAL_ERROR "Could not find Botan libraries")
endif (Botan_FIND_REQUIRED)
endif (BOTAN_FOUND)

View File

@ -1,21 +1,21 @@
find_package(PkgConfig REQUIRED)
if(WITH_botan_PLUGIN STREQUAL "yes")
find_package(Botan REQUIRED)
else(WITH_botan_PLUGIN STREQUAL "yes")
find_package(Botan)
endif(WITH_botan_PLUGIN STREQUAL "yes")
pkg_check_modules(BOTAN REQUIRED IMPORTED_TARGET botan-2)
else()
pkg_check_modules(BOTAN IMPORTED_TARGET botan-2)
endif()
if(BOTAN_FOUND)
enable_plugin("botan")
set(QCA_BOTAN_SOURCES qca-botan.cpp)
add_definitions(${BOTAN_CFLAGS})
add_library(qca-botan ${PLUGIN_TYPE} ${QCA_BOTAN_SOURCES})
if(APPLE AND ${PLUGIN_TYPE} STREQUAL "MODULE")
set_property(TARGET qca-botan PROPERTY SUFFIX ".dylib")
endif()
target_link_libraries(qca-botan Qt5::Core ${QCA_LIB_NAME} ${BOTAN_LIBRARIES})
target_link_libraries(qca-botan Qt5::Core ${QCA_LIB_NAME} PkgConfig::BOTAN)
if(NOT DEVELOPER_MODE)
install(TARGETS qca-botan

View File

@ -25,20 +25,13 @@
#include <botan/hmac.h>
#include <botan/version.h>
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
#include <botan/botan.h>
#include <botan/algo_factory.h>
#else
#include <botan/auto_rng.h>
#include <botan/block_cipher.h>
#include <botan/filters.h>
#include <botan/hash.h>
#include <botan/pbkdf.h>
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0)
#include <botan/hkdf.h>
#endif
#include <botan/stream_cipher.h>
#endif
#include <stdlib.h>
#include <iostream>
@ -94,11 +87,7 @@ public:
BotanHashContext( QCA::Provider *p, const QString &type) : QCA::HashContext(p, type)
{
const QString hashName = qcaHashToBotanHash(type);
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
m_hashObj = Botan::get_hash(hashName.toStdString());
#else
m_hashObj = Botan::HashFunction::create(hashName.toStdString()).release();
#endif
}
~BotanHashContext()
@ -144,11 +133,7 @@ class BotanHMACContext : public QCA::MACContext
public:
BotanHMACContext( const QString &hashName, QCA::Provider *p, const QString &type) : QCA::MACContext(p, type)
{
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
m_hashObj = new Botan::HMAC(Botan::global_state().algorithm_factory().make_hash_function(hashName.toStdString()));
#else
m_hashObj = new Botan::HMAC(Botan::HashFunction::create_or_throw(hashName.toStdString()).release());
#endif
if (0 == m_hashObj) {
std::cout << "null context object" << std::endl;
}
@ -269,7 +254,6 @@ protected:
};
//-----------------------------------------------------------
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0)
class BotanHKDFContext: public QCA::HKDFContext
{
public:
@ -306,7 +290,6 @@ public:
protected:
Botan::HKDF* m_hkdf;
};
#endif
static void qcaCipherToBotanCipher(const QString &type, std::string *algoName, std::string *algoMode, std::string *algoPadding)
{
@ -462,14 +445,10 @@ public:
int blockSize() const override
{
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
return Botan::block_size_of(m_algoName);
#else
if(const std::unique_ptr<Botan::BlockCipher> bc = Botan::BlockCipher::create(m_algoName))
return bc->block_size();
throw Botan::Algorithm_Not_Found(m_algoName);
#endif
}
QCA::AuthTag tag() const override
@ -504,27 +483,12 @@ public:
QCA::KeyLength keyLength() const override
{
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
Botan::Algorithm_Factory &af = Botan::global_state().algorithm_factory();
#endif
Botan::Key_Length_Specification kls(0);
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
if(const Botan::BlockCipher *bc = af.prototype_block_cipher(m_algoName))
#else
if(const std::unique_ptr<Botan::BlockCipher> bc = Botan::BlockCipher::create(m_algoName))
#endif
kls = bc->key_spec();
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
else if(const Botan::StreamCipher *sc = af.prototype_stream_cipher(m_algoName))
#else
else if(const std::unique_ptr<Botan::StreamCipher> sc = Botan::StreamCipher::create(m_algoName))
#endif
kls = sc->key_spec();
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
else if(const Botan::MessageAuthenticationCode *mac = af.prototype_mac(m_algoName))
#else
else if(const std::unique_ptr<Botan::MessageAuthenticationCode> mac = Botan::MessageAuthenticationCode::create(m_algoName))
#endif
kls = mac->key_spec();
return QCA::KeyLength( kls.minimum_keylength(),
kls.maximum_keylength(),
@ -564,9 +528,6 @@ class botanProvider : public QCA::Provider
public:
void init() override
{
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
m_init = new Botan::LibraryInitializer;
#endif
}
~botanProvider()
@ -680,9 +641,7 @@ public:
// list += "hmac(sha512)";
list += "hmac(ripemd160)";
list += pbkdfTypes();
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0)
list += "hkdf(sha256)";
#endif
list += cipherTypes();
list += hashTypes();
}
@ -709,20 +668,14 @@ public:
return new BotanHMACContext( QString("RIPEMD-160"), this, type );
else if ( pbkdfTypes().contains(type) )
return new BotanPBKDFContext( qcaPbkdfToBotanPbkdf(type), this, type );
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0)
else if ( type == "hkdf(sha256)" )
return new BotanHKDFContext( QString("SHA-256"), this, type );
#endif
else if ( cipherTypes().contains( type ) )
return new BotanCipherContext( this, type );
else
return nullptr;
}
private:
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(2,0,0)
Botan::LibraryInitializer *m_init;
#endif
};
class botanPlugin : public QObject, public QCAPlugin