Commit fcc9ba4b authored by Christian Kandeler's avatar Christian Kandeler Committed by hjk
Browse files

Update botan library.



Old version was 1.8.8, new one is 1.10.2.
We now put all the code into one pair of files (via
a botan configure option) and move platform-specific
defines into the pro/qbs files. Besides drastically
reducing the number of files, this is expected to make
future updates less messy.

Change-Id: I004166b2ab15b6a699d69aebfcfd9999c5ccdb91
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent c6ac435d
This diff is collapsed.
This diff is collapsed.
INCLUDEPATH *= $$PWD/build
INCLUDEPATH *= $$PWD/..
LIBS *= -l$$qtLibraryName(Botan)
TEMPLATE = subdirs
CONFIG += ordered
TEMPLATE = lib
TARGET = Botan
SUBDIRS += src
\ No newline at end of file
PRECOMPILED_HEADER = ../precompiled_headers/botan_pch.h
include(../../../qtcreatorlibrary.pri)
CONFIG += exceptions
DEPENDPATH += .
INCLUDEPATH += .
unix:QMAKE_CXXFLAGS_DEBUG += -O2
unix:DEFINES+=BOTAN_TARGET_OS_HAS_GETTIMEOFDAY BOTAN_HAS_ALLOC_MMAP \
BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM BOTAN_HAS_ENTROPY_SRC_EGD BOTAN_HAS_ENTROPY_SRC_FTW \
BOTAN_HAS_ENTROPY_SRC_UNIX BOTAN_HAS_MUTEX_PTHREAD BOTAN_HAS_PIPE_UNIXFD_IO
*linux*:DEFINES+=BOTAN_TARGET_OS_IS_LINUX BOTAN_TARGET_OS_HAS_CLOCK_GETTIME \
BOTAN_TARGET_OS_HAS_DLOPEN BOTAN_TARGET_OS_HAS_GMTIME_R BOTAN_TARGET_OS_HAS_POSIX_MLOCK \
BOTAN_HAS_DYNAMICALLY_LOADED_ENGINE BOTAN_HAS_DYNAMIC_LOADER
macx:DEFINES+=BOTAN_TARGET_OS_IS_DARWIN
*g++*:DEFINES+=BOTAN_BUILD_COMPILER_IS_GCC
win32 {
DEFINES+=BOTAN_TARGET_OS_IS_WINDOWS BOTAN_TARGET_OS_HAS_GMTIME_S \
BOTAN_TARGET_OS_HAS_LOADLIBRARY BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME \
BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK BOTAN_HAS_DYNAMICALLY_LOADED_ENGINE \
BOTAN_HAS_DYNAMIC_LOADER BOTAN_HAS_ENTROPY_SRC_CAPI BOTAN_HAS_ENTROPY_SRC_WIN32 \
BOTAN_HAS_MUTEX_WIN32
win32-msvc* {
QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250
DEFINES += BOTAN_DLL=__declspec(dllexport) BOTAN_BUILD_COMPILER_IS_MSVC
} else {
QMAKE_CFLAGS += -fpermissive -finline-functions -Wno-long-long
QMAKE_CXXFLAGS += -fpermissive -finline-functions -Wno-long-long
}
LIBS += -ladvapi32 -luser32
}
unix:*-g++* {
QMAKE_CFLAGS += -fPIC -ansi -fpermissive -finline-functions -Wno-long-long
QMAKE_CXXFLAGS += -fPIC -ansi -fpermissive -finline-functions -Wno-long-long
QMAKE_CXXFLAGS_HIDESYMS -= -fvisibility-inlines-hidden # for ubuntu 7.04
}
HEADERS += botan.h
SOURCES += botan.cpp
linux*|freebsd* {
LIBS += -lrt
}
This diff is collapsed.
/*
* Adler32
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#ifndef BOTAN_ADLER32_H__
#define BOTAN_ADLER32_H__
#include <botan/hash.h>
namespace Botan {
/*
* Adler32
*/
class BOTAN_DLL Adler32 : public HashFunction
{
public:
void clear() throw() { S1 = 1; S2 = 0; }
std::string name() const { return "Adler32"; }
HashFunction* clone() const { return new Adler32; }
Adler32() : HashFunction(4) { clear(); }
~Adler32() { clear(); }
private:
void add_data(const byte[], u32bit);
void final_result(byte[]);
void hash(const byte[], u32bit);
u16bit S1, S2;
};
}
#endif
/**
* AES
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#ifndef BOTAN_AES_H__
#define BOTAN_AES_H__
#include <botan/block_cipher.h>
namespace Botan {
/**
* Rijndael aka AES
*/
class BOTAN_DLL AES : public BlockCipher
{
public:
void clear() throw();
std::string name() const { return "AES"; }
BlockCipher* clone() const { return new AES; }
AES() : BlockCipher(16, 16, 32, 8) { ROUNDS = 14; }
AES(u32bit);
private:
void enc(const byte[], byte[]) const;
void dec(const byte[], byte[]) const;
void key_schedule(const byte[], u32bit);
static u32bit S(u32bit);
static const byte SE[256];
static const byte SD[256];
static const u32bit TE[1024];
static const u32bit TD[1024];
u32bit ROUNDS;
SecureBuffer<u32bit, 56> EK;
SecureBuffer<byte, 16> ME;
SecureBuffer<u32bit, 56> DK;
SecureBuffer<byte, 16> MD;
};
/**
* AES-128
*/
class BOTAN_DLL AES_128 : public AES
{
public:
std::string name() const { return "AES-128"; }
BlockCipher* clone() const { return new AES_128; }
AES_128() : AES(16) {}
};
/**
* AES-192
*/
class BOTAN_DLL AES_192 : public AES
{
public:
std::string name() const { return "AES-192"; }
BlockCipher* clone() const { return new AES_192; }
AES_192() : AES(24) {}
};
/**
* AES-256
*/
class BOTAN_DLL AES_256 : public AES
{
public:
std::string name() const { return "AES-256"; }
BlockCipher* clone() const { return new AES_256; }
AES_256() : AES(32) {}
};
}
#endif
/*
* Algorithm Identifier
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#ifndef BOTAN_ALGORITHM_IDENTIFIER_H__
#define BOTAN_ALGORITHM_IDENTIFIER_H__
#include <botan/asn1_int.h>
#include <botan/asn1_oid.h>
#include <string>
namespace Botan {
/*
* Algorithm Identifier
*/
class BOTAN_DLL AlgorithmIdentifier : public ASN1_Object
{
public:
enum Encoding_Option { USE_NULL_PARAM };
void encode_into(class DER_Encoder&) const;
void decode_from(class BER_Decoder&);
AlgorithmIdentifier() {}
AlgorithmIdentifier(const OID&, Encoding_Option);
AlgorithmIdentifier(const std::string&, Encoding_Option);
AlgorithmIdentifier(const OID&, const MemoryRegion<byte>&);
AlgorithmIdentifier(const std::string&, const MemoryRegion<byte>&);
OID oid;
SecureVector<byte> parameters;
};
/*
* Comparison Operations
*/
bool BOTAN_DLL operator==(const AlgorithmIdentifier&,
const AlgorithmIdentifier&);
bool BOTAN_DLL operator!=(const AlgorithmIdentifier&,
const AlgorithmIdentifier&);
}
#endif
/**
* An algorithm cache (used by Algorithm_Factory)
*/
#ifndef BOTAN_ALGORITHM_CACHE_TEMPLATE_H__
#define BOTAN_ALGORITHM_CACHE_TEMPLATE_H__
#include <botan/mutex.h>
#include <botan/stl_util.h>
#include <string>
#include <vector>
#include <map>
namespace Botan {
/**
* @param prov_name a provider name
* @return weight for this provider
*/
u32bit static_provider_weight(const std::string& prov_name);
/**
* Algorithm_Cache (used by Algorithm_Factory)
*/
template<typename T>
class Algorithm_Cache
{
public:
const T* get(const std::string& algo_spec,
const std::string& pref_provider);
/**
* Add a new algorithm implementation to the cache
*/
void add(T* algo,
const std::string& requested_name,
const std::string& provider_name);
/**
* Set the preferred provider
*/
void set_preferred_provider(const std::string& algo_spec,
const std::string& provider);
/**
* Return the list of providers of this algorithm
*/
std::vector<std::string> providers_of(const std::string& algo_name);
Algorithm_Cache(Mutex* m) : mutex(m) {}
~Algorithm_Cache();
private:
typedef typename std::map<std::string, std::map<std::string, T*> >::iterator
algorithms_iterator;
typedef typename std::map<std::string, T*>::iterator provider_iterator;
algorithms_iterator find_algorithm(const std::string& algo_spec);
Mutex* mutex;
std::map<std::string, std::string> aliases;
std::map<std::string, std::string> pref_providers;
std::map<std::string, std::map<std::string, T*> > algorithms;
};
/**
* Look for an algorithm implementation in the cache, also checking aliases
* Assumes object lock is held
*/
template<typename T>
typename Algorithm_Cache<T>::algorithms_iterator
Algorithm_Cache<T>::find_algorithm(const std::string& algo_spec)
{
algorithms_iterator algo = algorithms.find(algo_spec);
// Not found? Check if a known alias
if(algo == algorithms.end())
{
std::map<std::string, std::string>::const_iterator alias =
aliases.find(algo_spec);
if(alias != aliases.end())
algo = algorithms.find(alias->second);
}
return algo;
}
/**
* Look for an algorithm implementation by a particular provider
*/
template<typename T>
const T* Algorithm_Cache<T>::get(const std::string& algo_spec,
const std::string& requested_provider)
{
Mutex_Holder lock(mutex);
algorithms_iterator algo = find_algorithm(algo_spec);
if(algo == algorithms.end()) // algo not found at all (no providers)
return 0;
// If a provider is requested specifically, return it or fail entirely
if(requested_provider != "")
{
provider_iterator prov = algo->second.find(requested_provider);
if(prov != algo->second.end())
return prov->second;
return 0;
}
const T* prototype = 0;
std::string prototype_provider;
u32bit prototype_prov_weight = 0;
const std::string pref_provider = search_map(pref_providers, algo_spec);
for(provider_iterator i = algo->second.begin(); i != algo->second.end(); ++i)
{
const std::string prov_name = i->first;
const u32bit prov_weight = static_provider_weight(prov_name);
// preferred prov exists, return immediately
if(prov_name == pref_provider)
return i->second;
if(prototype == 0 || prov_weight > prototype_prov_weight)
{
prototype = i->second;
prototype_provider = i->first;
prototype_prov_weight = prov_weight;
}
}
return prototype;
}
/**
* Add an implementation to the cache
*/
template<typename T>
void Algorithm_Cache<T>::add(T* algo,
const std::string& requested_name,
const std::string& provider)
{
if(!algo)
return;
Mutex_Holder lock(mutex);
delete algorithms[algo->name()][provider];
algorithms[algo->name()][provider] = algo;
if(algo->name() != requested_name &&
aliases.find(requested_name) == aliases.end())
{
aliases[requested_name] = algo->name();
}
}
/**
* Find the providers of this algo (if any)
*/
template<typename T> std::vector<std::string>
Algorithm_Cache<T>::providers_of(const std::string& algo_name)
{
Mutex_Holder lock(mutex);
std::vector<std::string> providers;
algorithms_iterator algo = find_algorithm(algo_name);
if(algo != algorithms.end())
{
provider_iterator provider = algo->second.begin();
while(provider != algo->second.end())
{
providers.push_back(provider->first);
++provider;
}
}
return providers;
}
/**
* Set the preferred provider for an algorithm
*/
template<typename T>
void Algorithm_Cache<T>::set_preferred_provider(const std::string& algo_spec,
const std::string& provider)
{
Mutex_Holder lock(mutex);
pref_providers[algo_spec] = provider;
}
/**
* Algorithm_Cache<T> Destructor
*/
template<typename T>
Algorithm_Cache<T>::~Algorithm_Cache()
{
algorithms_iterator algo = algorithms.begin();
while(algo != algorithms.end())
{
provider_iterator provider = algo->second.begin();
while(provider != algo->second.end())
{
delete provider->second;
++provider;
}
++algo;
}
delete mutex;
}
}
#endif
/**
* Algorithm Factory
* (C) 2008 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#ifndef BOTAN_ALGORITHM_FACTORY_H__
#define BOTAN_ALGORITHM_FACTORY_H__
#include <botan/mutex.h>
#include <string>
#include <vector>
namespace Botan {
/**
* Forward declarations (don't need full definitions here)
*/
class BlockCipher;
class StreamCipher;
class HashFunction;
class MessageAuthenticationCode;
template<typename T> class Algorithm_Cache;
class Engine;
/**
* Algorithm Factory
*/
class BOTAN_DLL Algorithm_Factory
{
public:
/**
* Constructor
* @param engines_in the list of engines to use
* @param mf a mutex factory
*/
Algorithm_Factory(const std::vector<Engine*>& engines_in,
Mutex_Factory& mf);
/**
* Destructor
*/
~Algorithm_Factory();
/*
* Provider management
*/
std::vector<std::string> providers_of(const std::string& algo_spec);
void set_preferred_provider(const std::string& algo_spec,
const std::string& provider);
/*
* Block cipher operations
*/
const BlockCipher*
prototype_block_cipher(const std::string& algo_spec,
const std::string& provider = "");
BlockCipher* make_block_cipher(const std::string& algo_spec,
const std::string& provider = "");
void add_block_cipher(BlockCipher* hash, const std::string& provider);
/*
* Stream cipher operations
*/
const StreamCipher*
prototype_stream_cipher(const std::string& algo_spec,
const std::string& provider = "");
StreamCipher* make_stream_cipher(const std::string& algo_spec,
const std::string& provider = "");
void add_stream_cipher(StreamCipher* hash, const std::string& provider);
/*
* Hash function operations
*/
const HashFunction*
prototype_hash_function(const std::string& algo_spec,
const std::string& provider = "");
HashFunction* make_hash_function(const std::string& algo_spec,
const std::string& provider = "");
void add_hash_function(HashFunction* hash, const std::string& provider);
/*
* MAC operations
*/
const MessageAuthenticationCode*
prototype_mac(const std::string& algo_spec,
const std::string& provider = "");
MessageAuthenticationCode* make_mac(const std::string& algo_spec,
const std::string& provider = "");
void add_mac(MessageAuthenticationCode* mac,
const std::string& provider);
/*
* Deprecated
*/
class BOTAN_DLL Engine_Iterator
{
public:
class Engine* next() { return af.get_engine_n(n++); }
Engine_Iterator(const Algorithm_Factory& a) : af(a) { n = 0; }
private:
const Algorithm_Factory& af;
u32bit n;
};
friend class Engine_Iterator;
private:
class Engine* get_engine_n(u32bit) const;
std::vector<class Engine*> engines;
Algorithm_Cache<BlockCipher>* block_cipher_cache;
Algorithm_Cache<StreamCipher>* stream_cipher_cache;
Algorithm_Cache<HashFunction>* hash_cache;
Algorithm_Cache<MessageAuthenticationCode>* mac_cache;
};
}
#endif
/*
* Allocator
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license