diff options
author | David Clark <david.a.clark@nokia.com> | 2010-11-18 16:20:48 +1000 |
---|---|---|
committer | David Clark <david.a.clark@nokia.com> | 2010-11-18 16:20:48 +1000 |
commit | c223232bc15106750da632598047a35ad3762723 (patch) | |
tree | 403f7aa2c3a5a912edce6feae869046c89d29178 /old/botan/build/botan | |
parent | b984b0b62076067f1f75db5a7eda5aaa2cdaad2a (diff) |
Diffstat (limited to 'old/botan/build/botan')
251 files changed, 19629 insertions, 0 deletions
diff --git a/old/botan/build/botan/adler32.h b/old/botan/build/botan/adler32.h new file mode 100644 index 0000000..98a28bc --- /dev/null +++ b/old/botan/build/botan/adler32.h @@ -0,0 +1,35 @@ +/* +* 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 diff --git a/old/botan/build/botan/aes.h b/old/botan/build/botan/aes.h new file mode 100644 index 0000000..05e2e31 --- /dev/null +++ b/old/botan/build/botan/aes.h @@ -0,0 +1,81 @@ +/** +* 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 diff --git a/old/botan/build/botan/alg_id.h b/old/botan/build/botan/alg_id.h new file mode 100644 index 0000000..4a1ad2f --- /dev/null +++ b/old/botan/build/botan/alg_id.h @@ -0,0 +1,49 @@ +/* +* 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 diff --git a/old/botan/build/botan/algo_cache.h b/old/botan/build/botan/algo_cache.h new file mode 100644 index 0000000..17ea996 --- /dev/null +++ b/old/botan/build/botan/algo_cache.h @@ -0,0 +1,224 @@ +/** +* 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 diff --git a/old/botan/build/botan/algo_factory.h b/old/botan/build/botan/algo_factory.h new file mode 100644 index 0000000..73e5920 --- /dev/null +++ b/old/botan/build/botan/algo_factory.h @@ -0,0 +1,132 @@ +/** +* 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 diff --git a/old/botan/build/botan/allocate.h b/old/botan/build/botan/allocate.h new file mode 100644 index 0000000..180f2c0 --- /dev/null +++ b/old/botan/build/botan/allocate.h @@ -0,0 +1,37 @@ +/* +* Allocator +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ALLOCATOR_H__ +#define BOTAN_ALLOCATOR_H__ + +#include <botan/types.h> +#include <string> + +namespace Botan { + +/* +* Allocator Interface +*/ +class BOTAN_DLL Allocator + { + public: + static Allocator* get(bool); + + virtual void* allocate(u32bit) = 0; + virtual void deallocate(void*, u32bit) = 0; + + virtual std::string type() const = 0; + + virtual void init() {} + virtual void destroy() {} + + virtual ~Allocator() {} + }; + +} + +#endif diff --git a/old/botan/build/botan/arc4.h b/old/botan/build/botan/arc4.h new file mode 100644 index 0000000..aa2cea7 --- /dev/null +++ b/old/botan/build/botan/arc4.h @@ -0,0 +1,41 @@ +/* +* ARC4 +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ARC4_H__ +#define BOTAN_ARC4_H__ + +#include <botan/stream_cipher.h> +#include <botan/types.h> + +namespace Botan { + +/* +* ARC4 +*/ +class BOTAN_DLL ARC4 : public StreamCipher + { + public: + void clear() throw(); + std::string name() const; + StreamCipher* clone() const { return new ARC4(SKIP); } + ARC4(u32bit = 0); + ~ARC4() { clear(); } + private: + void cipher(const byte[], byte[], u32bit); + void key_schedule(const byte[], u32bit); + void generate(); + + const u32bit SKIP; + + SecureBuffer<byte, DEFAULT_BUFFERSIZE> buffer; + SecureBuffer<u32bit, 256> state; + u32bit X, Y, position; + }; + +} + +#endif diff --git a/old/botan/build/botan/asn1_int.h b/old/botan/build/botan/asn1_int.h new file mode 100644 index 0000000..619f45b --- /dev/null +++ b/old/botan/build/botan/asn1_int.h @@ -0,0 +1,108 @@ +/* +* ASN.1 Internals +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ASN1_H__ +#define BOTAN_ASN1_H__ + +#include <botan/secmem.h> +#include <botan/exceptn.h> + +namespace Botan { + +/* +* ASN.1 Type and Class Tags +*/ +enum ASN1_Tag { + UNIVERSAL = 0x00, + APPLICATION = 0x40, + CONTEXT_SPECIFIC = 0x80, + PRIVATE = 0xC0, + + CONSTRUCTED = 0x20, + + EOC = 0x00, + BOOLEAN = 0x01, + INTEGER = 0x02, + BIT_STRING = 0x03, + OCTET_STRING = 0x04, + NULL_TAG = 0x05, + OBJECT_ID = 0x06, + ENUMERATED = 0x0A, + SEQUENCE = 0x10, + SET = 0x11, + + UTF8_STRING = 0x0C, + NUMERIC_STRING = 0x12, + PRINTABLE_STRING = 0x13, + T61_STRING = 0x14, + IA5_STRING = 0x16, + VISIBLE_STRING = 0x1A, + BMP_STRING = 0x1E, + + UTC_TIME = 0x17, + GENERALIZED_TIME = 0x18, + + NO_OBJECT = 0xFF00, + DIRECTORY_STRING = 0xFF01 +}; + +/* +* Basic ASN.1 Object Interface +*/ +class BOTAN_DLL ASN1_Object + { + public: + virtual void encode_into(class DER_Encoder&) const = 0; + virtual void decode_from(class BER_Decoder&) = 0; + virtual ~ASN1_Object() {} + }; + +/* +* BER Encoded Object +*/ +class BOTAN_DLL BER_Object + { + public: + void assert_is_a(ASN1_Tag, ASN1_Tag); + + ASN1_Tag type_tag, class_tag; + SecureVector<byte> value; + }; + +/* +* ASN.1 Utility Functions +*/ +class DataSource; + +namespace ASN1 { + +SecureVector<byte> put_in_sequence(const MemoryRegion<byte>&); +std::string to_string(const BER_Object&); +bool maybe_BER(DataSource&); + +} + +/* +* General BER Decoding Error Exception +*/ +struct BER_Decoding_Error : public Decoding_Error + { + BER_Decoding_Error(const std::string&); + }; + +/* +* Exception For Incorrect BER Taggings +*/ +struct BER_Bad_Tag : public BER_Decoding_Error + { + BER_Bad_Tag(const std::string&, ASN1_Tag); + BER_Bad_Tag(const std::string&, ASN1_Tag, ASN1_Tag); + }; + +} + +#endif diff --git a/old/botan/build/botan/asn1_obj.h b/old/botan/build/botan/asn1_obj.h new file mode 100644 index 0000000..ea21c47 --- /dev/null +++ b/old/botan/build/botan/asn1_obj.h @@ -0,0 +1,160 @@ +/* +* Common ASN.1 Objects +* (C) 1999-2007 Jack Lloyd +* 2007 Yves Jerschow +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ASN1_OBJ_H__ +#define BOTAN_ASN1_OBJ_H__ + +#include <botan/asn1_int.h> +#include <botan/asn1_oid.h> +#include <botan/alg_id.h> +#include <vector> +#include <map> + +namespace Botan { + +/* +* Attribute +*/ +class BOTAN_DLL Attribute : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + OID oid; + MemoryVector<byte> parameters; + + Attribute() {} + Attribute(const OID&, const MemoryRegion<byte>&); + Attribute(const std::string&, const MemoryRegion<byte>&); + }; + +/* +* X.509 Time +*/ +class BOTAN_DLL X509_Time : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + std::string as_string() const; + std::string readable_string() const; + bool time_is_set() const; + + s32bit cmp(const X509_Time&) const; + + void set_to(const std::string&); + void set_to(const std::string&, ASN1_Tag); + + X509_Time(u64bit); + X509_Time(const std::string& = ""); + X509_Time(const std::string&, ASN1_Tag); + private: + bool passes_sanity_check() const; + u32bit year, month, day, hour, minute, second; + ASN1_Tag tag; + }; + +/* +* Simple String +*/ +class BOTAN_DLL ASN1_String : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + std::string value() const; + std::string iso_8859() const; + + ASN1_Tag tagging() const; + + ASN1_String(const std::string& = ""); + ASN1_String(const std::string&, ASN1_Tag); + private: + std::string iso_8859_str; + ASN1_Tag tag; + }; + +/* +* Distinguished Name +*/ +class BOTAN_DLL X509_DN : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + std::multimap<OID, std::string> get_attributes() const; + std::vector<std::string> get_attribute(const std::string&) const; + + std::multimap<std::string, std::string> contents() const; + + void add_attribute(const std::string&, const std::string&); + void add_attribute(const OID&, const std::string&); + + static std::string deref_info_field(const std::string&); + + void do_decode(const MemoryRegion<byte>&); + MemoryVector<byte> get_bits() const; + + X509_DN(); + X509_DN(const std::multimap<OID, std::string>&); + X509_DN(const std::multimap<std::string, std::string>&); + private: + std::multimap<OID, ASN1_String> dn_info; + MemoryVector<byte> dn_bits; + }; + +/* +* Alternative Name +*/ +class BOTAN_DLL AlternativeName : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + std::multimap<std::string, std::string> contents() const; + + void add_attribute(const std::string&, const std::string&); + std::multimap<std::string, std::string> get_attributes() const; + + void add_othername(const OID&, const std::string&, ASN1_Tag); + std::multimap<OID, ASN1_String> get_othernames() const; + + bool has_items() const; + + AlternativeName(const std::string& = "", const std::string& = "", + const std::string& = "", const std::string& = ""); + private: + std::multimap<std::string, std::string> alt_info; + std::multimap<OID, ASN1_String> othernames; + }; + +/* +* Comparison Operations +*/ +bool BOTAN_DLL operator==(const X509_Time&, const X509_Time&); +bool BOTAN_DLL operator!=(const X509_Time&, const X509_Time&); +bool BOTAN_DLL operator<=(const X509_Time&, const X509_Time&); +bool BOTAN_DLL operator>=(const X509_Time&, const X509_Time&); + +bool BOTAN_DLL operator==(const X509_DN&, const X509_DN&); +bool BOTAN_DLL operator!=(const X509_DN&, const X509_DN&); +bool BOTAN_DLL operator<(const X509_DN&, const X509_DN&); + +/* +* Helper Functions +*/ +bool BOTAN_DLL is_string_type(ASN1_Tag); + +} + +#endif diff --git a/old/botan/build/botan/asn1_oid.h b/old/botan/build/botan/asn1_oid.h new file mode 100644 index 0000000..e6d077b --- /dev/null +++ b/old/botan/build/botan/asn1_oid.h @@ -0,0 +1,96 @@ +/* +* ASN.1 OID +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ASN1_OID_H__ +#define BOTAN_ASN1_OID_H__ + +#include <botan/asn1_int.h> +#include <string> +#include <vector> + +namespace Botan { + +/** +* This class represents ASN.1 object identifiers. +*/ +class BOTAN_DLL OID : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + /** + * Find out whether this OID is empty + * @return true is no OID value is set + */ + bool is_empty() const { return id.size() == 0; } + + /** + * Get this OID as list (vector) of its components. + * @return a vector representing this OID + */ + std::vector<u32bit> get_id() const { return id; } + + /** + * Get this OID as a string + * @return a string representing this OID + */ + std::string as_string() const; + + /** + * Compare two OIDs. + * @return true if they are equal, false otherwise + */ + bool operator==(const OID&) const; + + /** + * Reset this instance to an empty OID. + */ + void clear(); + + /** + * Add a component to this OID. + * @param new_comp the new component to add to the end of this OID + * @return a reference to *this + */ + OID& operator+=(u32bit new_comp); + + /** + * Construct an OID from a string. + * @param str a string in the form "a.b.c" etc., where a,b,c are numbers + */ + OID(const std::string& str = ""); + private: + std::vector<u32bit> id; + }; + +/** +* Append another component onto the OID. +* @param oid the OID to add the new component to +* @param new_comp the new component to add +*/ +OID operator+(const OID& oid, u32bit new_comp); + +/** +* Compare two OIDs. +* @param a the first OID +* @param b the second OID +* @return true if a is not equal to b +*/ +bool operator!=(const OID& a, const OID& b); + +/** +* Compare two OIDs. +* @param a the first OID +* @param b the second OID +* @return true if a is lexicographically smaller than b +*/ +bool operator<(const OID& a, const OID& b); + +} + +#endif diff --git a/old/botan/build/botan/auto_rng.h b/old/botan/build/botan/auto_rng.h new file mode 100644 index 0000000..f18f8e5 --- /dev/null +++ b/old/botan/build/botan/auto_rng.h @@ -0,0 +1,44 @@ +/* +* Auto Seeded RNG +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_AUTO_SEEDING_RNG_H__ +#define BOTAN_AUTO_SEEDING_RNG_H__ + +#include <botan/rng.h> +#include <string> + +namespace Botan { + +/** +* RNG that attempts to seed itself +*/ +class BOTAN_DLL AutoSeeded_RNG : public RandomNumberGenerator + { + public: + void randomize(byte out[], u32bit len) + { rng->randomize(out, len); } + bool is_seeded() const + { return rng->is_seeded(); } + void clear() throw() { rng->clear(); } + std::string name() const + { return "AutoSeeded(" + rng->name() + ")"; } + + void reseed(u32bit poll_bits = 256) { rng->reseed(poll_bits); } + void add_entropy_source(EntropySource* es) + { rng->add_entropy_source(es); } + void add_entropy(const byte in[], u32bit len) + { rng->add_entropy(in, len); } + + AutoSeeded_RNG(u32bit poll_bits = 256); + ~AutoSeeded_RNG() { delete rng; } + private: + RandomNumberGenerator* rng; + }; + +} + +#endif diff --git a/old/botan/build/botan/base64.h b/old/botan/build/botan/base64.h new file mode 100644 index 0000000..aca02da --- /dev/null +++ b/old/botan/build/botan/base64.h @@ -0,0 +1,94 @@ +/* +* Base64 Encoder/Decoder +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BASE64_H__ +#define BOTAN_BASE64_H__ + +#include <botan/filter.h> + +namespace Botan { + +/** +* This class represents a Base64 encoder. +*/ +class BOTAN_DLL Base64_Encoder : public Filter + { + public: + static void encode(const byte in[3], byte out[4]); + + /** + * Input a part of a message to the encoder. + * @param input the message to input as a byte array + * @param length the length of the byte array input + */ + void write(const byte input[], u32bit length); + + /** + * Inform the Encoder that the current message shall be closed. + */ + void end_msg(); + + /** + * Create a base64 encoder. + * @param breaks whether to use line breaks in the Streamcipheroutput + * @param length the length of the lines of the output + * @param t_n whether to use a trailing newline + */ + Base64_Encoder(bool breaks = false, u32bit length = 72, + bool t_n = false); + private: + void encode_and_send(const byte[], u32bit); + void do_output(const byte[], u32bit); + static const byte BIN_TO_BASE64[64]; + + const u32bit line_length; + const bool trailing_newline; + SecureVector<byte> in, out; + u32bit position, counter; + }; + +/** +* This object represents a Base64 decoder. +*/ +class BOTAN_DLL Base64_Decoder : public Filter + { + public: + static void decode(const byte input[4], byte output[3]); + + static bool is_valid(byte); + + /** + * Input a part of a message to the decoder. + * @param input the message to input as a byte array + * @param length the length of the byte array input + */ + void write(const byte input[], u32bit length); + + /** + * Inform the Encoder that the current message shall be closed. + */ + void end_msg(); + + /** + * Create a base64 encoder. + * @param checking the type of checking that shall be performed by + * the decoder + */ + Base64_Decoder(Decoder_Checking checking = NONE); + private: + void decode_and_send(const byte[], u32bit); + void handle_bad_char(byte); + static const byte BASE64_TO_BIN[256]; + + const Decoder_Checking checking; + SecureVector<byte> in, out; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/basefilt.h b/old/botan/build/botan/basefilt.h new file mode 100644 index 0000000..75625ab --- /dev/null +++ b/old/botan/build/botan/basefilt.h @@ -0,0 +1,99 @@ +/* +* Basic Filters +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BASEFILT_H__ +#define BOTAN_BASEFILT_H__ + +#include <botan/filter.h> +#include <botan/sym_algo.h> + +namespace Botan { + +/** +* This class represents Filter chains. A Filter chain is an ordered +* concatenation of Filters, the input to a Chain sequentially passes +* through all the Filters contained in the Chain. +*/ + +class BOTAN_DLL Chain : public Fanout_Filter + { + public: + void write(const byte input[], u32bit length) { send(input, length); } + + /** + * Construct a chain of up to four filters. The filters are set + * up in the same order as the arguments. + */ + Chain(Filter* = 0, Filter* = 0, Filter* = 0, Filter* = 0); + + /** + * Construct a chain from range of filters + * @param filter_arr the list of filters + * @param length how many filters + */ + Chain(Filter* filter_arr[], u32bit length); + }; + +/** +* This class represents a fork filter, whose purpose is to fork the +* flow of data. It causes an input message to result in n messages at +* the end of the filter, where n is the number of forks. +*/ +class BOTAN_DLL Fork : public Fanout_Filter + { + public: + void write(const byte input[], u32bit length) { send(input, length); } + void set_port(u32bit n) { Fanout_Filter::set_port(n); } + + /** + * Construct a Fork filter with up to four forks. + */ + Fork(Filter*, Filter*, Filter* = 0, Filter* = 0); + + /** + * Construct a Fork from range of filters + * @param filter_arr the list of filters + * @param length how many filters + */ + Fork(Filter* filter_arr[], u32bit length); + }; + +/** +* This class represents keyed filters, i.e. filters that have to be +* fed with a key in order to function. +*/ +class BOTAN_DLL Keyed_Filter : public Filter + { + public: + + /** + * Set the key of this filter. + * @param key the key to set + */ + virtual void set_key(const SymmetricKey& key); + + /** + * Set the initialization vector of this filter. + * @param iv the initialization vector to set + */ + virtual void set_iv(const InitializationVector&) {} + + /** + * Check whether a key length is valid for this filter. + * @param length the key length to be checked for validity + * @return true if the key length is valid, false otherwise + */ + virtual bool valid_keylength(u32bit length) const; + + Keyed_Filter() { base_ptr = 0; } + protected: + SymmetricAlgorithm* base_ptr; + }; + +} + +#endif diff --git a/old/botan/build/botan/benchmark.h b/old/botan/build/botan/benchmark.h new file mode 100644 index 0000000..272cfdf --- /dev/null +++ b/old/botan/build/botan/benchmark.h @@ -0,0 +1,59 @@ +/** +* Runtime benchmarking +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RUNTIME_BENCHMARK_H__ +#define BOTAN_RUNTIME_BENCHMARK_H__ + +#include <botan/algo_factory.h> +#include <botan/timer.h> +#include <botan/rng.h> +#include <map> +#include <string> + +/** +* Choose some sort of default timer implementation to use, since some +* (like hardware tick counters and current Win32 timer) are not +* reliable for benchmarking. +*/ +#if defined(BOTAN_HAS_TIMER_POSIX) + #include <botan/tm_posix.h> +#elif defined(BOTAN_HAS_TIMER_UNIX) + #include <botan/tm_unix.h> +#endif + +namespace Botan { + +#if defined(BOTAN_HAS_TIMER_POSIX) + typedef POSIX_Timer Default_Benchmark_Timer; +#elif defined(BOTAN_HAS_TIMER_UNIX) + typedef Unix_Timer Default_Benchmark_Timer; +#else + /* I have not had good success using clock(), the results seem + * pretty bogus, but as a last resort it works. + */ + typedef ANSI_Clock_Timer Default_Benchmark_Timer; +#endif + +/** +* Algorithm benchmark +* @param name the name of the algorithm to test (cipher, hash, or MAC) +* @param milliseconds total time for the benchmark to run +* @param timer the timer to use +* @param rng the rng to use to generate random inputs +* @param af the algorithm factory used to create objects +* @return results a map from provider to speed in mebibytes per second +*/ +std::map<std::string, double> +algorithm_benchmark(const std::string& name, + u32bit milliseconds, + Timer& timer, + RandomNumberGenerator& rng, + Algorithm_Factory& af); + +} + +#endif diff --git a/old/botan/build/botan/ber_dec.h b/old/botan/build/botan/ber_dec.h new file mode 100644 index 0000000..2e38af3 --- /dev/null +++ b/old/botan/build/botan/ber_dec.h @@ -0,0 +1,122 @@ +/* +* BER Decoder +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BER_DECODER_H__ +#define BOTAN_BER_DECODER_H__ + +#include <botan/asn1_oid.h> +#include <botan/data_src.h> + +namespace Botan { + +/* +* BER Decoding Object +*/ +class BOTAN_DLL BER_Decoder + { + public: + BER_Object get_next_object(); + void push_back(const BER_Object&); + + bool more_items() const; + BER_Decoder& verify_end(); + BER_Decoder& discard_remaining(); + + BER_Decoder start_cons(ASN1_Tag, ASN1_Tag = UNIVERSAL); + BER_Decoder& end_cons(); + + BER_Decoder& raw_bytes(MemoryRegion<byte>&); + + BER_Decoder& decode_null(); + BER_Decoder& decode(bool&); + BER_Decoder& decode(u32bit&); + BER_Decoder& decode(class BigInt&); + BER_Decoder& decode(MemoryRegion<byte>&, ASN1_Tag); + + BER_Decoder& decode(bool&, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + BER_Decoder& decode(u32bit&, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + BER_Decoder& decode(class BigInt&, + ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + BER_Decoder& decode(MemoryRegion<byte>&, ASN1_Tag, + ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + + BER_Decoder& decode(class ASN1_Object&); + + template<typename T> + BER_Decoder& decode_optional(T&, ASN1_Tag, ASN1_Tag, const T& = T()); + + template<typename T> + BER_Decoder& decode_list(std::vector<T>&, bool = true); + + BER_Decoder& decode_optional_string(MemoryRegion<byte>&, + ASN1_Tag, u16bit); + + BER_Decoder(DataSource&); + BER_Decoder(const byte[], u32bit); + BER_Decoder(const MemoryRegion<byte>&); + BER_Decoder(const BER_Decoder&); + ~BER_Decoder(); + private: + BER_Decoder& operator=(const BER_Decoder&) { return (*this); } + + BER_Decoder* parent; + DataSource* source; + BER_Object pushed; + mutable bool owns; + }; + +/* +* Decode an OPTIONAL or DEFAULT element +*/ +template<typename T> +BER_Decoder& BER_Decoder::decode_optional(T& out, + ASN1_Tag type_tag, + ASN1_Tag class_tag, + const T& default_value) + { + BER_Object obj = get_next_object(); + + if(obj.type_tag == type_tag && obj.class_tag == class_tag) + { + if(class_tag & CONSTRUCTED) + BER_Decoder(obj.value).decode(out).verify_end(); + else + { + push_back(obj); + decode(out, type_tag, class_tag); + } + } + else + { + out = default_value; + push_back(obj); + } + + return (*this); + } + +/* +* Decode a list of homogenously typed values +*/ +template<typename T> +BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec, bool clear_it) + { + if(clear_it) + vec.clear(); + + while(more_items()) + { + T value; + decode(value); + vec.push_back(value); + } + return (*this); + } + +} + +#endif diff --git a/old/botan/build/botan/bigint.h b/old/botan/build/botan/bigint.h new file mode 100644 index 0000000..16a1bba --- /dev/null +++ b/old/botan/build/botan/bigint.h @@ -0,0 +1,534 @@ +/* +* BigInt +* (C) 1999-2008 Jack Lloyd +* 2007 FlexSecure +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BIGINT_H__ +#define BOTAN_BIGINT_H__ + +#include <botan/rng.h> +#include <botan/secmem.h> +#include <botan/mp_types.h> +#include <iosfwd> + +namespace Botan { + +/** + * Big Integer representation. This class defines an integer type, + * that can be very big. Additionally some helper functions are + * defined to work more comfortably. + + */ +class BOTAN_DLL BigInt + { + public: + /** + * Base-Enumerator (currently 8,10,16 and 256 are defined) + */ + enum Base { Octal = 8, Decimal = 10, Hexadecimal = 16, Binary = 256 }; + + /** + * Sign symbol definitions for positive and negative numbers + */ + enum Sign { Negative = 0, Positive = 1 }; + + /** + * Number types (Powers of 2) + */ + enum NumberType { Power2 }; + + /** + * DivideByZero Exception + */ + struct DivideByZero : public Exception + { DivideByZero() : Exception("BigInt divide by zero") {} }; + + /************* + * operators + *************/ + + /** + * += Operator + * @param y the BigInt to add to the local value + */ + BigInt& operator+=(const BigInt& y); + + /** + * -= Operator + * @param y the BigInt to subtract from the local value + */ + BigInt& operator-=(const BigInt& y); + + /** + * *= Operator + * @param y the BigInt to multiply with the local value + */ + BigInt& operator*=(const BigInt& y); + + /** + * /= Operator + * @param y the BigInt to divide the local value by + */ + BigInt& operator/=(const BigInt& y); + + /** + * %= Operator, modulo operator. + * @param y the modulus to reduce the local value by + */ + BigInt& operator%=(const BigInt& y); + + /** + * %= Operator + * @param y the modulus (word) to reduce the local value by + */ + word operator%=(word y); + + /** + * <<= Operator + * @param y the amount of bits to shift the local value left + */ + BigInt& operator<<=(u32bit y); + + /** + * >>= Operator + * @param y the amount of bits to shift the local value right + */ + BigInt& operator>>=(u32bit y); + + /** + * ++ Operator + */ + BigInt& operator++() { return (*this += 1); } + + /** + * -- Operator + */ + BigInt& operator--() { return (*this -= 1); } + + /** + * ++ Operator (postfix) + */ + BigInt operator++(int) { BigInt x = (*this); ++(*this); return x; } + + /** + * -- Operator (postfix) + */ + BigInt operator--(int) { BigInt x = (*this); --(*this); return x; } + + /** + * - Operator + */ + BigInt operator-() const; + + /** + * ! Operator + */ + bool operator !() const { return (!is_nonzero()); } + + /** + * [] Operator (array access) + */ + word& operator[](u32bit i) { return reg[i]; } + + /** + * [] Operator (array access) + */ + word operator[](u32bit i) const { return reg[i]; } + + /** + * Zeroize the BigInt + */ + void clear() { get_reg().clear(); } + + /************* + * functions + ************/ + + /** + * Compare *this to another BigInt. + * @param n the BigInt value to compare to the local value. + * @param check_signs Include sign in comparison? + * @result if (this<n) return -1, if (this>n) return 1, if both + * values are identical return 0. + */ + s32bit cmp(const BigInt& n, bool check_signs = true) const; + + /** + * Test if the integer has an even value + * @result true, if the integer an even value, false otherwise + */ + bool is_even() const { return (get_bit(0) == 0); } + + /** + * Test if the integer has an odd value + * @result true, if the integer an odd value, false otherwise + */ + bool is_odd() const { return (get_bit(0) == 1); } + + /** + * Test if the integer is not zero. + * @result true, if the integer has a non-zero value, false otherwise + */ + bool is_nonzero() const { return (!is_zero()); } + + /** + * Test if the integer is zero. + * @result true, if the integer has the value zero, false otherwise + */ + bool is_zero() const + { + const u32bit sw = sig_words(); + + for(u32bit i = 0; i != sw; ++i) + if(reg[i]) + return false; + return true; + } + + /** + * Set bit at specified position + * @param n bit position to set + */ + void set_bit(u32bit n); + + /** + * Clear bit at specified position + * @param n bit position to clear + */ + void clear_bit(u32bit n); + + /** + * Clear all but the lowest n bits + * @param n amount of bits to keep + */ + void mask_bits(u32bit n); + + /** + * Return bit value at specified position + * @param n the bit offset to test + * @result true, if the bit at position n is set, false otherwise + */ + bool get_bit(u32bit n) const; + + /** + * Return (a maximum of) 32 bits of the complete value + * @param offset the offset to start extracting + * @param length amount of bits to extract (starting at offset) + * @result the integer extracted from the register starting at + * offset with specified length + */ + u32bit get_substring(u32bit offset, u32bit length) const; + + byte byte_at(u32bit) const; + + /** + * Return the word at a specified position of the internal register + * @param n position in the register + * @return the value at position n + */ + word word_at(u32bit n) const + { return ((n < size()) ? reg[n] : 0); } + + /** + * Return the integer as an unsigned 32bit-integer-value. If the + * value is negative OR to big to be stored in 32bits, this + * function will throw an exception. + * @result a 32bit-integer + */ + u32bit to_u32bit() const; + + /** + * Tests if the sign of the integer is negative. + * @result true, if the integer has a negative sign, + */ + bool is_negative() const { return (sign() == Negative); } + + /** + * Tests if the sign of the integer is positive. + * @result true, if the integer has a positive sign, + */ + bool is_positive() const { return (sign() == Positive); } + + /** + * Return the sign of the integer + * @result the sign of the integer + */ + Sign sign() const { return (signedness); } + + /** + * Return the opposite sign of the represented integer value + * @result the opposite sign of the represented integer value + */ + Sign reverse_sign() const; + + /** + * Flip (change!) the sign of the integer to its opposite value + */ + void flip_sign(); + + /** + * Set sign of the integer + * @param sign new Sign to set + */ + void set_sign(Sign sign); + + /** + * Give absolute (positive) value of the integer + * @result absolute (positive) value of the integer + */ + BigInt abs() const; + + /** + * Give size of internal register + * @result size of internal register in words + */ + u32bit size() const { return get_reg().size(); } + + /** + * Give significant words of the represented integer value + * @result significant words of the represented integer value + */ + u32bit sig_words() const + { + const word* x = reg.begin(); + u32bit sig = reg.size(); + + while(sig && (x[sig-1] == 0)) + sig--; + return sig; + } + + /** + * Give byte-length of the integer + * @result byte-length of the represented integer value + */ + u32bit bytes() const; + + /** + * Get the bit-length of the integer. + * @result bit-length of the represented integer value + */ + u32bit bits() const; + + /** + * Return a pointer to the big integer word register. + * @result a pointer to the start of the internal register of + * the integer value + */ + const word* data() const { return reg.begin(); } + + /** + * return a reference to the internal register containing the value + * @result a reference to the word-array (SecureVector<word>) + * with the internal register value (containing the integer + * value) + */ + SecureVector<word>& get_reg() { return reg; } + + /** + * return a const reference to the internal register containing the value + * @result a const reference to the word-array (SecureVector<word>) + * with the internal register value (containing the integer + * value) + */ + const SecureVector<word>& get_reg() const { return reg; } + + /** + * Increase internal register buffer by n words + * @param n increase by n words + */ + void grow_reg(u32bit n); + + void grow_to(u32bit n); + + /** + * Fill BigInt with a random number with size of bitsize + * @param rng the random number generator to use + * @param bitsize number of bits the created random value should have + */ + void randomize(RandomNumberGenerator& rng, u32bit bitsize = 0); + + /** + * Store BigInt-value in a given byte array + * @param buf destination byte array for the integer value + */ + void binary_encode(byte buf[]) const; + + /** + * Read integer value from a byte array with given size + * @param buf byte array buffer containing the integer + * @param length size of buf + */ + void binary_decode(const byte buf[], u32bit length); + + /** + * Read integer value from a byte array (MemoryRegion<byte>) + * @param buf the BigInt value to compare to the local value. + */ + void binary_decode(const MemoryRegion<byte>& buf); + + u32bit encoded_size(Base = Binary) const; + + /** + @param rng a random number generator + @result a random integer between min and max + */ + static BigInt random_integer(RandomNumberGenerator& rng, + const BigInt& min, const BigInt& max); + + /** + * Encode the integer value from a BigInt to a SecureVector of bytes + * @param n the BigInt to use as integer source + * @param base number-base of resulting byte array representation + * @result SecureVector of bytes containing the integer with given base + */ + static SecureVector<byte> encode(const BigInt& n, Base base = Binary); + + /** + * Encode the integer value from a BigInt to a byte array + * @param buf destination byte array for the encoded integer + * value with given base + * @param n the BigInt to use as integer source + * @param base number-base of resulting byte array representation + */ + static void encode(byte buf[], const BigInt& n, Base base = Binary); + + /** + * Create a BigInt from an integer in a byte array + * @param buf the BigInt value to compare to the local value. + * @param length size of buf + * @param base number-base of the integer in buf + * @result BigInt-representing the given integer read from the byte array + */ + static BigInt decode(const byte buf[], u32bit length, + Base base = Binary); + + static BigInt decode(const MemoryRegion<byte>&, Base = Binary); + + /** + * Encode a Big Integer to a byte array according to IEEE1363. + * @param n the Big Integer to encode + * @param bytes the length of the resulting SecureVector<byte> + * @result a SecureVector<byte> containing the encoded Big Integer + */ + static SecureVector<byte> encode_1363(const BigInt& n, u32bit bytes); + + /** + * Swap BigInt-value with given BigInt. + * @param bigint the BigInt to swap values with + */ + void swap(BigInt& bigint); + + /** + * constructors + */ + + /** + * Create empty BigInt + */ + BigInt() { signedness = Positive; } + + /** + * Create BigInt from 64bit-Integer value + * @param n 64bit-integer + */ + BigInt(u64bit n); + + /** + * Copy-Constructor: clone given BigInt + * @param bigint the BigInt to clone + */ + BigInt(const BigInt& bigint); + + /** + * Create BigInt from a string. + * If the string starts with 0x the rest of the string will be + * interpreted as hexadecimal digits. + * If the string starts with 0 and the second character is NOT + * an 'x' the string will be interpreted as octal digits. + * If the string starts with non-zero digit, it will be + * interpreted as a decimal number. + * @param str the string to parse for an integer value + */ + BigInt(const std::string& str); + + /** + * Create a BigInt from an integer in a byte array + * @param buf the BigInt value to compare to the local value. + * @param length size of buf + * @param base number-base of the integer in buf + */ + BigInt(const byte buf[], u32bit length, Base base = Binary); + + /** + * Create a random BigInt of the specified size + * @param rng random number generator + * @param bits size in bits + */ + BigInt(RandomNumberGenerator& rng, u32bit bits); + + /** + * Create BigInt from unsigned 32 bit integer value and an + * also specify the sign of the value + * @param n integer value + */ + BigInt(Sign, u32bit n); + + /** + * Create a number of the specified type and size + * @param type the type of number to create + * @param n the size + */ + BigInt(NumberType type, u32bit n); + + private: + SecureVector<word> reg; + Sign signedness; + }; + +/* +* Arithmetic Operators +*/ +BigInt BOTAN_DLL operator+(const BigInt&, const BigInt&); +BigInt BOTAN_DLL operator-(const BigInt&, const BigInt&); +BigInt BOTAN_DLL operator*(const BigInt&, const BigInt&); +BigInt BOTAN_DLL operator/(const BigInt&, const BigInt&); +BigInt BOTAN_DLL operator%(const BigInt&, const BigInt&); +word BOTAN_DLL operator%(const BigInt&, word); +BigInt BOTAN_DLL operator<<(const BigInt&, u32bit); +BigInt BOTAN_DLL operator>>(const BigInt&, u32bit); + +/* +* Comparison Operators +*/ +inline bool operator==(const BigInt& a, const BigInt& b) + { return (a.cmp(b) == 0); } +inline bool operator!=(const BigInt& a, const BigInt& b) + { return (a.cmp(b) != 0); } +inline bool operator<=(const BigInt& a, const BigInt& b) + { return (a.cmp(b) <= 0); } +inline bool operator>=(const BigInt& a, const BigInt& b) + { return (a.cmp(b) >= 0); } +inline bool operator<(const BigInt& a, const BigInt& b) + { return (a.cmp(b) < 0); } +inline bool operator>(const BigInt& a, const BigInt& b) + { return (a.cmp(b) > 0); } + +/* +* I/O Operators +*/ +BOTAN_DLL std::ostream& operator<<(std::ostream&, const BigInt&); +BOTAN_DLL std::istream& operator>>(std::istream&, BigInt&); + +} + +namespace std { + +inline void swap(Botan::BigInt& a, Botan::BigInt& b) { a.swap(b); } + +} + +#endif diff --git a/old/botan/build/botan/bit_ops.h b/old/botan/build/botan/bit_ops.h new file mode 100644 index 0000000..c02ec53 --- /dev/null +++ b/old/botan/build/botan/bit_ops.h @@ -0,0 +1,91 @@ +/* +* Bit/Word Operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BIT_OPS_H__ +#define BOTAN_BIT_OPS_H__ + +#include <botan/types.h> + +namespace Botan { + +/* +* Return true iff arg is 2**n for some n > 0 +* T should be an unsigned integer type +*/ +template<typename T> +inline bool power_of_2(T arg) + { + return ((arg != 0 && arg != 1) && ((arg & (arg-1)) == 0)); + } + +/* +* Return the index of the highest set bit +* T is an unsigned integer type +*/ +template<typename T> +inline u32bit high_bit(T n) + { + for(u32bit i = 8*sizeof(T); i > 0; --i) + if((n >> (i - 1)) & 0x01) + return i; + return 0; + } + +/* +* Return the index of the lowest set bit +*/ +template<typename T> +inline u32bit low_bit(T n) + { + for(u32bit i = 0; i != 8*sizeof(T); ++i) + if((n >> i) & 0x01) + return (i + 1); + return 0; + } + +/* +* Return the number of significant bytes in n +*/ +template<typename T> +inline u32bit significant_bytes(T n) + { + for(u32bit j = 0; j != sizeof(T); ++j) + if(get_byte(j, n)) + return sizeof(T)-j; + return 0; + } + +/* +* Return the Hamming weight of n +*/ +template<typename T> +inline u32bit hamming_weight(T n) + { + const byte NIBBLE_WEIGHTS[] = { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; + + u32bit weight = 0; + for(u32bit i = 0; i != 2*sizeof(T); ++i) + weight += NIBBLE_WEIGHTS[(n >> (4*i)) & 0x0F]; + return weight; + } + +/* +* Count the trailing zero bits in n +*/ +template<typename T> +inline u32bit ctz(T n) + { + for(u32bit i = 0; i != 8*sizeof(T); ++i) + if((n >> i) & 0x01) + return i; + return 8*sizeof(T); + } + +} + +#endif diff --git a/old/botan/build/botan/blinding.h b/old/botan/build/botan/blinding.h new file mode 100644 index 0000000..5f7f9e6 --- /dev/null +++ b/old/botan/build/botan/blinding.h @@ -0,0 +1,34 @@ +/* +* Blinder +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BLINDER_H__ +#define BOTAN_BLINDER_H__ + +#include <botan/bigint.h> +#include <botan/reducer.h> + +namespace Botan { + +/* +* Blinding Function Object +*/ +class BOTAN_DLL Blinder + { + public: + BigInt blind(const BigInt&) const; + BigInt unblind(const BigInt&) const; + + Blinder() {} + Blinder(const BigInt&, const BigInt&, const BigInt&); + private: + Modular_Reducer reducer; + mutable BigInt e, d; + }; + +} + +#endif diff --git a/old/botan/build/botan/block_cipher.h b/old/botan/build/botan/block_cipher.h new file mode 100644 index 0000000..01c45af --- /dev/null +++ b/old/botan/build/botan/block_cipher.h @@ -0,0 +1,100 @@ +/** +* Block Cipher Base Class +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BLOCK_CIPHER_H__ +#define BOTAN_BLOCK_CIPHER_H__ + +#include <botan/sym_algo.h> + +namespace Botan { + +/** +* This class represents a block cipher object. +* +* It would be very useful to extend this interface to support the +* encryption of multiple blocks at a time. This could help +* performance, wrt cache effects in the software implementations, and +* could be a big deal when supporting block ciphers implemented as +* hardware devices. It could be used by implementations of ECB, and +* more importantly counter mode (which most designs are moving to, due +* to the parallelism possible in counter mode which is not the case +* with feedback-based modes like CBC). +* +* Probable future API here: +* virtual void encrypt_n(const byte in[], byte out[], +* u32bit blocks) const = 0; +* virtual void decrypt_n(const byte in[], byte out[], +* u32bit blocks) const = 0; +*/ +class BOTAN_DLL BlockCipher : public SymmetricAlgorithm + { + public: + /** + * The block size of this algorithm. + */ + const u32bit BLOCK_SIZE; + + /** + * Encrypt a block. + * @param in The plaintext block to be encrypted as a byte array. + * Must be of length BLOCK_SIZE. + * @param out The byte array designated to hold the encrypted block. + * Must be of length BLOCK_SIZE. + */ + void encrypt(const byte in[], byte out[]) const { enc(in, out); } + + /** + * Decrypt a block. + * @param in The ciphertext block to be decypted as a byte array. + * Must be of length BLOCK_SIZE. + * @param out The byte array designated to hold the decrypted block. + * Must be of length BLOCK_SIZE. + */ + void decrypt(const byte in[], byte out[]) const { dec(in, out); } + + /** + * Encrypt a block. + * @param in The plaintext block to be encrypted as a byte array. + * Must be of length BLOCK_SIZE. Will hold the result when the function + * has finished. + */ + void encrypt(byte block[]) const { enc(block, block); } + + /** + * Decrypt a block. + * @param in The ciphertext block to be decrypted as a byte array. + * Must be of length BLOCK_SIZE. Will hold the result when the function + * has finished. + */ + void decrypt(byte block[]) const { dec(block, block); } + + /** + * Get a new object representing the same algorithm as *this + */ + virtual BlockCipher* clone() const = 0; + + /** + * Zeroize internal state + */ + virtual void clear() throw() = 0; + + BlockCipher(u32bit block_size, + u32bit key_min, + u32bit key_max = 0, + u32bit key_mod = 1) : + SymmetricAlgorithm(key_min, key_max, key_mod), + BLOCK_SIZE(block_size) {} + + virtual ~BlockCipher() {} + private: + virtual void enc(const byte[], byte[]) const = 0; + virtual void dec(const byte[], byte[]) const = 0; + }; + +} + +#endif diff --git a/old/botan/build/botan/blowfish.h b/old/botan/build/botan/blowfish.h new file mode 100644 index 0000000..f0f2641 --- /dev/null +++ b/old/botan/build/botan/blowfish.h @@ -0,0 +1,40 @@ +/* +* Blowfish +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BLOWFISH_H__ +#define BOTAN_BLOWFISH_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* Blowfish +*/ +class BOTAN_DLL Blowfish : public BlockCipher + { + public: + void clear() throw(); + std::string name() const { return "Blowfish"; } + BlockCipher* clone() const { return new Blowfish; } + Blowfish() : BlockCipher(8, 1, 56) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + void generate_sbox(u32bit[], u32bit, u32bit&, u32bit&) const; + + static const u32bit P_INIT[18]; + static const u32bit S_INIT[1024]; + + SecureBuffer<u32bit, 1024> S; + SecureBuffer<u32bit, 18> P; + }; + +} + +#endif diff --git a/old/botan/build/botan/botan.h b/old/botan/build/botan/botan.h new file mode 100644 index 0000000..3fa1312 --- /dev/null +++ b/old/botan/build/botan/botan.h @@ -0,0 +1,18 @@ +/** +* A vague catch all include file for Botan +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/init.h> +#include <botan/lookup.h> +#include <botan/libstate.h> +#include <botan/version.h> +#include <botan/parsing.h> + +#include <botan/rng.h> + +#if defined(BOTAN_HAS_AUTO_SEEDING_RNG) + #include <botan/auto_rng.h> +#endif diff --git a/old/botan/build/botan/bswap.h b/old/botan/build/botan/bswap.h new file mode 100644 index 0000000..ec1e814 --- /dev/null +++ b/old/botan/build/botan/bswap.h @@ -0,0 +1,62 @@ +/* +* Byte Swapping Operations +* (C) 1999-2008 Jack Lloyd +* (C) 2007 Yves Jerschow +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BYTE_SWAP_H__ +#define BOTAN_BYTE_SWAP_H__ + +#include <botan/types.h> +#include <botan/rotate.h> + +namespace Botan { + +/* +* Byte Swapping Functions +*/ +inline u16bit reverse_bytes(u16bit input) + { + return rotate_left(input, 8); + } + +inline u32bit reverse_bytes(u32bit input) + { +#if BOTAN_USE_GCC_INLINE_ASM && \ + (defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64)) + + /* GCC-style inline assembly for x86 or x86-64 */ + asm("bswapl %0" : "=r" (input) : "0" (input)); + return input; + +#elif defined(_MSC_VER) && defined(BOTAN_TARGET_ARCH_IS_IA32) + /* Visual C++ inline asm for 32-bit x86, by Yves Jerschow */ + __asm mov eax, input; + __asm bswap eax; + +#else + /* Generic implementation */ + input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8); + return rotate_left(input, 16); +#endif + } + +inline u64bit reverse_bytes(u64bit input) + { +#if BOTAN_USE_GCC_INLINE_ASM && defined(BOTAN_TARGET_ARCH_IS_AMD64) + asm("bswapq %0" : "=r" (input) : "0" (input)); + return input; +#else + u32bit hi = ((input >> 40) & 0x00FF00FF) | ((input >> 24) & 0xFF00FF00); + u32bit lo = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8); + hi = (hi << 16) | (hi >> 16); + lo = (lo << 16) | (lo >> 16); + return (static_cast<u64bit>(lo) << 32) | hi; +#endif + } + +} + +#endif diff --git a/old/botan/build/botan/buf_comp.h b/old/botan/build/botan/buf_comp.h new file mode 100644 index 0000000..3f1e90b --- /dev/null +++ b/old/botan/build/botan/buf_comp.h @@ -0,0 +1,126 @@ +/** +* BufferedComputation +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BUFFERED_COMPUTATION_H__ +#define BOTAN_BUFFERED_COMPUTATION_H__ + +#include <botan/secmem.h> + +namespace Botan { + +/** +* This class represents any kind of computation which +* uses an internal state, +* such as hash functions. +*/ +class BOTAN_DLL BufferedComputation + { + public: + + /** + * The length of the output of this function in bytes. + */ + const u32bit OUTPUT_LENGTH; + + /** + * Add new input to process. + * @param in the input to process as a byte array + * @param the length of the byte array + */ + void update(const byte in[], u32bit length) { add_data(in, length); } + + /** + * Add new input to process. + * @param in the input to process as a MemoryRegion + */ + void update(const MemoryRegion<byte>& in) { add_data(in, in.size()); } + + /** + * Add new input to process. + * @param str the input to process as a std::string. Will be interpreted + * as a byte array based on + * the strings encoding. + */ + void update(const std::string& str) + { + add_data(reinterpret_cast<const byte*>(str.data()), str.size()); + } + + /** + * Process a single byte. + * @param in the byte to process + */ + void update(byte in) { add_data(&in, 1); } + + /** + * Complete the computation and retrieve the + * final result. + * @param out The byte array to be filled with the result. + * Must be of length OUTPUT_LENGTH. + */ + void final(byte out[]) { final_result(out); } + + /** + * Complete the computation and retrieve the + * final result. + * @return a SecureVector holding the result + */ + SecureVector<byte> final() + { + SecureVector<byte> output(OUTPUT_LENGTH); + final_result(output); + return output; + } + + /** + * Update and finalize computation. Does the same as calling update() + * and final() consecutively. + * @param in the input to process as a byte array + * @param length the length of the byte array + * @result the result of the call to final() + */ + SecureVector<byte> process(const byte in[], u32bit length) + { + add_data(in, length); + return final(); + } + + /** + * Update and finalize computation. Does the same as calling update() + * and final() consecutively. + * @param in the input to process + * @result the result of the call to final() + */ + SecureVector<byte> process(const MemoryRegion<byte>& in) + { + add_data(in, in.size()); + return final(); + } + + /** + * Update and finalize computation. Does the same as calling update() + * and final() consecutively. + * @param in the input to process as a string + * @result the result of the call to final() + */ + SecureVector<byte> process(const std::string& in) + { + update(in); + return final(); + } + + BufferedComputation(u32bit out_len) : OUTPUT_LENGTH(out_len) {} + virtual ~BufferedComputation() {} + private: + BufferedComputation& operator=(const BufferedComputation&); + virtual void add_data(const byte[], u32bit) = 0; + virtual void final_result(byte[]) = 0; + }; + +} + +#endif diff --git a/old/botan/build/botan/buf_filt.h b/old/botan/build/botan/buf_filt.h new file mode 100644 index 0000000..ce3dbc9 --- /dev/null +++ b/old/botan/build/botan/buf_filt.h @@ -0,0 +1,39 @@ +/* +* Buffering Filter +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BUFFERING_FILTER_H__ +#define BOTAN_BUFFERING_FILTER_H__ + +#include <botan/filter.h> + +namespace Botan { + +/** +* Buffering_Filter: This class represents filters for operations that +* maintain an internal state. +*/ + +class BOTAN_DLL Buffering_Filter : public Filter + { + public: + void write(const byte[], u32bit); + virtual void end_msg(); + Buffering_Filter(u32bit, u32bit = 0); + virtual ~Buffering_Filter() {} + protected: + virtual void initial_block(const byte[]) {} + virtual void main_block(const byte[]) = 0; + virtual void final_block(const byte[], u32bit) = 0; + private: + const u32bit INITIAL_BLOCK_SIZE, BLOCK_SIZE; + SecureVector<byte> initial, block; + u32bit initial_block_pos, block_pos; + }; + +} + +#endif diff --git a/old/botan/build/botan/build.h b/old/botan/build/botan/build.h new file mode 100644 index 0000000..e23eb82 --- /dev/null +++ b/old/botan/build/botan/build.h @@ -0,0 +1,41 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef BOTAN_BUILD_CONFIG_H_QT +#define BOTAN_BUILD_CONFIG_H_QT + +#include <qglobal.h> + +#if defined(Q_OS_WIN) +# include "build_windows.h" +#elif defined(Q_OS_UNIX) +# include "build_unix.h" +#endif + +#endif diff --git a/old/botan/build/botan/build_unix.h b/old/botan/build/botan/build_unix.h new file mode 100644 index 0000000..a49de5d --- /dev/null +++ b/old/botan/build/botan/build_unix.h @@ -0,0 +1,353 @@ + +#ifndef BOTAN_BUILD_CONFIG_H__ +#define BOTAN_BUILD_CONFIG_H__ + +/* This file was automatically generated Tue Jan 12 09:38:57 2010 UTC */ + +#define BOTAN_VERSION_MAJOR 1 +#define BOTAN_VERSION_MINOR 8 +#define BOTAN_VERSION_PATCH 8 + +#ifndef BOTAN_DLL + #define BOTAN_DLL __attribute__ ((visibility("default"))) +#endif + +/* Chunk sizes */ +#define BOTAN_DEFAULT_BUFFER_SIZE 4096 +#define BOTAN_MEM_POOL_CHUNK_SIZE 64*1024 + +/* BigInt toggles */ +#define BOTAN_MP_WORD_BITS 32 +#define BOTAN_KARAT_MUL_THRESHOLD 32 +#define BOTAN_KARAT_SQR_THRESHOLD 32 +#define BOTAN_PRIVATE_KEY_OP_BLINDING_BITS 64 + +/* PK key consistency checking toggles */ +#define BOTAN_PUBLIC_KEY_STRONG_CHECKS_ON_LOAD 1 +#define BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_LOAD 1 +#define BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_GENERATE 1 + +/* Should we use GCC-style inline assembler? */ +#if !defined(BOTAN_USE_GCC_INLINE_ASM) && defined(__GNUG__) + #define BOTAN_USE_GCC_INLINE_ASM 1 +#endif + +#ifndef BOTAN_USE_GCC_INLINE_ASM + #define BOTAN_USE_GCC_INLINE_ASM 0 +#endif + + +#define BOTAN_USE_STD_TR1 + +/* Module definitions */ +#define BOTAN_HAS_ADLER32 +#define BOTAN_HAS_AES +#define BOTAN_HAS_ALGORITHM_FACTORY +#define BOTAN_HAS_ALLOC_MMAP +#define BOTAN_HAS_ANSI_X919_MAC +#define BOTAN_HAS_ARC4 +#define BOTAN_HAS_ASN1 +#define BOTAN_HAS_AUTO_SEEDING_RNG +#define BOTAN_HAS_BASE64_CODEC +#define BOTAN_HAS_BIGINT +#define BOTAN_HAS_BIGINT_GFP +#define BOTAN_HAS_BIGINT_MATH +#define BOTAN_HAS_BLOCK_CIPHER +#define BOTAN_HAS_BLOWFISH +#define BOTAN_HAS_CARD_VERIFIABLE_CERTIFICATES +#define BOTAN_HAS_CAST +#define BOTAN_HAS_CBC +#define BOTAN_HAS_CBC_MAC +#define BOTAN_HAS_CFB +#define BOTAN_HAS_CIPHER_MODEBASE +#define BOTAN_HAS_CIPHER_MODE_PADDING +#define BOTAN_HAS_CMAC +#define BOTAN_HAS_CMS +#define BOTAN_HAS_CRC24 +#define BOTAN_HAS_CRC32 +#define BOTAN_HAS_CRYPTO_BOX +#define BOTAN_HAS_CTR +#define BOTAN_HAS_CTS +#define BOTAN_HAS_DEFAULT_ENGINE +#define BOTAN_HAS_DES +#define BOTAN_HAS_DIFFIE_HELLMAN +#define BOTAN_HAS_DLIES +#define BOTAN_HAS_DL_GROUP +#define BOTAN_HAS_DL_PUBLIC_KEY_FAMILY +#define BOTAN_HAS_DSA +#define BOTAN_HAS_EAX +#define BOTAN_HAS_ECB +#define BOTAN_HAS_ECC_DOMAIN_PARAMATERS +#define BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO +#define BOTAN_HAS_ECDSA +#define BOTAN_HAS_ECKAEG +#define BOTAN_HAS_ELGAMAL +#define BOTAN_HAS_EME1 +#define BOTAN_HAS_EME_PKCS1v15 +#define BOTAN_HAS_EMSA1 +#define BOTAN_HAS_EMSA1_BSI +#define BOTAN_HAS_EMSA2 +#define BOTAN_HAS_EMSA3 +#define BOTAN_HAS_EMSA4 +#define BOTAN_HAS_EMSA_RAW +#define BOTAN_HAS_ENGINES +#define BOTAN_HAS_ENTROPY_SRC_DEVICE +#define BOTAN_HAS_ENTROPY_SRC_EGD +#define BOTAN_HAS_ENTROPY_SRC_FTW +#define BOTAN_HAS_ENTROPY_SRC_UNIX +#define BOTAN_HAS_FILTERS +#define BOTAN_HAS_FORK_256 +#define BOTAN_HAS_GOST_28147_89 +#define BOTAN_HAS_GOST_34_11 +#define BOTAN_HAS_HASH_ID +#define BOTAN_HAS_HAS_160 +#define BOTAN_HAS_HEX_CODEC +#define BOTAN_HAS_HMAC +#define BOTAN_HAS_HMAC_RNG +#define BOTAN_HAS_IDEA +#define BOTAN_HAS_IF_PUBLIC_KEY_FAMILY +#define BOTAN_HAS_KASUMI +#define BOTAN_HAS_KDF1 +#define BOTAN_HAS_KDF2 +#define BOTAN_HAS_KDF_BASE +#define BOTAN_HAS_KEYPAIR_TESTING +#define BOTAN_HAS_LIBSTATE_MODULE +#define BOTAN_HAS_LION +#define BOTAN_HAS_LUBY_RACKOFF +#define BOTAN_HAS_MARS +#define BOTAN_HAS_MD2 +#define BOTAN_HAS_MD4 +#define BOTAN_HAS_MD5 +#define BOTAN_HAS_MDX_HASH_FUNCTION +#define BOTAN_HAS_MGF1 +#define BOTAN_HAS_MISTY1 +#define BOTAN_HAS_MUTEX_NOOP +#define BOTAN_HAS_MUTEX_PTHREAD +#define BOTAN_HAS_MUTEX_WRAPPERS +#define BOTAN_HAS_NOEKEON +#define BOTAN_HAS_NYBERG_RUEPPEL +#define BOTAN_HAS_OFB +#define BOTAN_HAS_OID_LOOKUP +#define BOTAN_HAS_OPENPGP_CODEC +#define BOTAN_HAS_PARALLEL_HASH +#define BOTAN_HAS_PASSWORD_BASED_ENCRYPTION +#define BOTAN_HAS_PBE_PKCS_V15 +#define BOTAN_HAS_PBE_PKCS_V20 +#define BOTAN_HAS_PBKDF1 +#define BOTAN_HAS_PBKDF2 +#define BOTAN_HAS_PEM_CODEC +#define BOTAN_HAS_PGPS2K +#define BOTAN_HAS_PIPE_UNIXFD_IO +#define BOTAN_HAS_PK_PADDING +#define BOTAN_HAS_PUBLIC_KEY_CRYPTO +#define BOTAN_HAS_RANDPOOL +#define BOTAN_HAS_RC2 +#define BOTAN_HAS_RC5 +#define BOTAN_HAS_RC6 +#define BOTAN_HAS_RIPEMD_128 +#define BOTAN_HAS_RIPEMD_160 +#define BOTAN_HAS_RSA +#define BOTAN_HAS_RUNTIME_BENCHMARKING +#define BOTAN_HAS_RW +#define BOTAN_HAS_SAFER +#define BOTAN_HAS_SALSA20 +#define BOTAN_HAS_SEED +#define BOTAN_HAS_SELFTESTS +#define BOTAN_HAS_SERPENT +#define BOTAN_HAS_SHA1 +#define BOTAN_HAS_SHA2 +#define BOTAN_HAS_SKEIN_512 +#define BOTAN_HAS_SKIPJACK +#define BOTAN_HAS_SQUARE +#define BOTAN_HAS_SSL3_MAC +#define BOTAN_HAS_SSL_V3_PRF +#define BOTAN_HAS_STREAM_CIPHER +#define BOTAN_HAS_TEA +#define BOTAN_HAS_TIGER +#define BOTAN_HAS_TIMER +#ifndef Q_OS_MAC +#define BOTAN_HAS_TIMER_POSIX +#endif +#define BOTAN_HAS_TIMER_UNIX +#define BOTAN_HAS_TLS_V10_PRF +#define BOTAN_HAS_TURING +#define BOTAN_HAS_TWOFISH +#define BOTAN_HAS_UTIL_FUNCTIONS +#define BOTAN_HAS_WHIRLPOOL +#define BOTAN_HAS_WID_WAKE +#define BOTAN_HAS_X509 +#define BOTAN_HAS_X931_RNG +#define BOTAN_HAS_X942_PRF +#define BOTAN_HAS_XTEA +#define BOTAN_HAS_XTS + +/* Local configuration options */ + + +/* +christian@christian-linux ran 'configure.py --os=linux --cpu=ia32 --cc=gcc --disable-asm' + +Target +------- +Compiler: g++ -O2 -finline-functions +Arch: ia32/ia32 +OS: linux + +Modules +------- +adler32 (Adler32) +aes (AES) +algo_factory (Algorithm Factory) +alloc (Allocator) +alloc_mmap (Disk Based Allocation System) +arc4 (ARC4) +asn1 (ASN.1/BER/DER module) +auto_rng (Auto-seeded Random Number Generator) +base64 (Base64 Codec) +benchmark (Benchmarking) +bigint (BigInt) +block (Block Ciphers) +blowfish (Blowfish) +buf_comp (Buffered Computation) +cast (CAST) +cbc (CBC block cipher mode) +cbc_mac (CBC-MAC) +cfb (CFB block cipher mode) +cmac (CMAC) +cms (CMS) +crc24 (CRC-24) +crc32 (CRC-32) +cryptobox (Crypto Box) +ctr (CTR block cipher mode) +cts (CTS block cipher mode) +cvc (Card Verifiable Certificates) +datastor (Datastore) +def_engine (Default Engine) +des (DES) +dev_random (RNG Device Reader) +dh (Diffie-Hellman Key Agreement) +dl_algo (Discrete Logarithm PK Algorithms) +dl_group (DL Group) +dlies (DLIES) +dsa (DSA) +eax (EAX block cipher mode) +ec_dompar (ECC Domain Parameters) +ecb (ECB block cipher mode) +ecc_key (ECC Public Key) +ecdsa (ECDSA) +eckaeg (ECKAEG) +egd (EGD Entropy Source) +elgamal (ElGamal) +eme1 (EME1) +eme_pkcs (PKCSv1 v1.5 EME) +emsa1 (EMSA1) +emsa1_bsi (EMSA1 (BSI variant)) +emsa2 (EMSA2) +emsa3 (EMSA3) +emsa4 (EMSA4) +emsa_raw (EMSA-Raw) +engine (Engines) +entropy (Entropy Sources) +fd_unix (Unix I/O support for Pipe) +filters (Pipe/Filter) +fork256 (FORK-256) +gettimeofday (Unix Timer) +gfpmath (GF(p) Math) +gost_28147 (GOST 28147-89) +gost_3411 (GOST 34.11) +has160 (HAS-160) +hash (Hash Functions) +hash_id (Hash Function Identifiers) +hex (Hex Codec) +hmac (HMAC) +hmac_rng (HMAC RNG) +idea (IDEA) +if_algo (Integer Factorization Algorithms) +kasumi (Kasumi) +kdf (KDF Base Class) +kdf1 (KDF1) +kdf2 (KDF2) +keypair (Keypair Testing) +libstate (Botan Libstate Module) +lion (Lion) +lubyrack (Luby-Rackoff) +mac (Message Authentication Codes) +mars (MARS) +md2 (MD2) +md4 (MD4) +md5 (MD5) +mdx_hash (MDx Hash Base) +mem_pool (Memory Pool Allocator) +mgf1 (MGF1) +misty1 (MISTY-1) +mode_pad (Cipher Mode Padding Method) +modes (Cipher Mode Base Class) +monty_generic (Montgomery Reduction) +mp_generic (MPI Core (C++)) +mulop_generic (BigInt Multiply-Add) +mutex (Mutex Wrappers) +noekeon (Noekeon) +noop_mutex (No-Op Mutex) +nr (Nyberg-Rueppel) +numbertheory (Math Functions) +ofb (OFB block cipher mode) +oid_lookup (OID Lookup) +openpgp (OpenPGP Codec) +par_hash (Parallel Hash) +pbe (PBE Base) +pbes1 (PKCS5 v1.5 PBE) +pbes2 (PKCS5 v2.0 PBE) +pbkdf1 (Pbkdf1) +pbkdf2 (Pbkdf2) +pem (PEM Codec) +pgps2k (Pgps2k) +pk_codecs (PK codecs (PKCS8, X.509)) +pk_pad (Public Key EME/EMSA Padding Modes) +posix_rt (POSIX Timer) +proc_walk (File Tree Walking Entropy Source) +pthreads (Pthread Mutex) +pubkey (Public Key Base) +randpool (Randpool RNG) +rc2 (RC2) +rc5 (RC5) +rc6 (RC6) +rmd128 (RIPEMD-128) +rmd160 (RIPEMD-160) +rng (Random Number Generators) +rsa (RSA) +rw (Rabin-Williams) +s2k (String to Key Functions) +safer (SAFER) +salsa20 (Salsa20) +seed (SEED) +selftest (Selftests) +serpent (Serpent) +sha1 (SHA-1) +sha2 (SHA-2 (224, 256, 384, 512)) +skein (Skein) +skipjack (Skipjack) +square (Square) +ssl3mac (SSLv3 MAC) +ssl_prf (SSLv3 PRF) +stream (Stream Ciphers) +sym_algo (Symmetric Algorithms) +system_alloc (Default (Malloc) Allocators) +tea (TEA) +tiger (Tiger) +timer (Timer Base Class) +tls_prf (TLS v1.0 PRF) +turing (Turing) +twofish (Twofish) +unix_procs (Generic Unix Entropy Source) +utils (Utility Functions) +whirlpool (Whirlpool) +wid_wake (WiderWake) +x509 (X.509) +x919_mac (ANSI X9.19 MAC) +x931_rng (ANSI X9.31 PRNG) +x942_prf (X942 PRF) +xtea (XTEA) +xts (XTS block cipher mode) +*/ + +#endif diff --git a/old/botan/build/botan/build_windows.h b/old/botan/build/botan/build_windows.h new file mode 100644 index 0000000..8e9bc03 --- /dev/null +++ b/old/botan/build/botan/build_windows.h @@ -0,0 +1,335 @@ + +#ifndef BOTAN_BUILD_CONFIG_H__ +#define BOTAN_BUILD_CONFIG_H__ + +/* This file was automatically generated Mon Jan 11 14:51:24 2010 UTC */ + +#define BOTAN_VERSION_MAJOR 1 +#define BOTAN_VERSION_MINOR 8 +#define BOTAN_VERSION_PATCH 8 + +#ifndef BOTAN_DLL +# if !defined(Q_CC_MINGW) +# define BOTAN_DLL __declspec(dllexport) +# else +# define BOTAN_DLL +# endif +#endif + +/* Chunk sizes */ +#define BOTAN_DEFAULT_BUFFER_SIZE 4096 +#define BOTAN_MEM_POOL_CHUNK_SIZE 64*1024 + +/* BigInt toggles */ +#define BOTAN_MP_WORD_BITS 32 +#define BOTAN_KARAT_MUL_THRESHOLD 32 +#define BOTAN_KARAT_SQR_THRESHOLD 32 +#define BOTAN_PRIVATE_KEY_OP_BLINDING_BITS 64 + +/* PK key consistency checking toggles */ +#define BOTAN_PUBLIC_KEY_STRONG_CHECKS_ON_LOAD 1 +#define BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_LOAD 1 +#define BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_GENERATE 1 + +/* Should we use GCC-style inline assembler? */ +#if !defined(BOTAN_USE_GCC_INLINE_ASM) && defined(__GNUG__) + #define BOTAN_USE_GCC_INLINE_ASM 1 +#endif + +#ifndef BOTAN_USE_GCC_INLINE_ASM + #define BOTAN_USE_GCC_INLINE_ASM 0 +#endif + +/* Target identification and feature test macros */ +#define BOTAN_TARGET_OS_IS_WINDOWS +#define BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK + +/* Module definitions */ +#if defined(Q_CC_MINGW) +# define BOTAN_USE_STD_TR1 +# define BOTAN_HAS_BIGINT_GFP +# define BOTAN_HAS_CARD_VERIFIABLE_CERTIFICATES +# define BOTAN_HAS_ECC_DOMAIN_PARAMATERS +# define BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO +#endif + +#define BOTAN_HAS_ADLER32 +#define BOTAN_HAS_AES +#define BOTAN_HAS_ALGORITHM_FACTORY +#define BOTAN_HAS_ANSI_X919_MAC +#define BOTAN_HAS_ARC4 +#define BOTAN_HAS_ASN1 +#define BOTAN_HAS_AUTO_SEEDING_RNG +#define BOTAN_HAS_BASE64_CODEC +#define BOTAN_HAS_BIGINT +#define BOTAN_HAS_BIGINT_MATH +#define BOTAN_HAS_BLOCK_CIPHER +#define BOTAN_HAS_BLOWFISH +#define BOTAN_HAS_CAST +#define BOTAN_HAS_CBC +#define BOTAN_HAS_CBC_MAC +#define BOTAN_HAS_CFB +#define BOTAN_HAS_CIPHER_MODEBASE +#define BOTAN_HAS_CIPHER_MODE_PADDING +#define BOTAN_HAS_CMAC +#define BOTAN_HAS_CMS +#define BOTAN_HAS_CRC24 +#define BOTAN_HAS_CRC32 +#define BOTAN_HAS_CRYPTO_BOX +#define BOTAN_HAS_CTR +#define BOTAN_HAS_CTS +#define BOTAN_HAS_DEFAULT_ENGINE +#define BOTAN_HAS_DES +#define BOTAN_HAS_DIFFIE_HELLMAN +#define BOTAN_HAS_DLIES +#define BOTAN_HAS_DL_GROUP +#define BOTAN_HAS_DL_PUBLIC_KEY_FAMILY +#define BOTAN_HAS_DSA +#define BOTAN_HAS_EAX +#define BOTAN_HAS_ECB +#define BOTAN_HAS_ELGAMAL +#define BOTAN_HAS_EME1 +#define BOTAN_HAS_EME_PKCS1v15 +#define BOTAN_HAS_EMSA1 +#define BOTAN_HAS_EMSA1_BSI +#define BOTAN_HAS_EMSA2 +#define BOTAN_HAS_EMSA3 +#define BOTAN_HAS_EMSA4 +#define BOTAN_HAS_EMSA_RAW +#define BOTAN_HAS_ENGINES +#define BOTAN_HAS_ENTROPY_SRC_CAPI +#define BOTAN_HAS_ENTROPY_SRC_WIN32 +#define BOTAN_HAS_FILTERS +#define BOTAN_HAS_FORK_256 +#define BOTAN_HAS_GOST_28147_89 +#define BOTAN_HAS_GOST_34_11 +#define BOTAN_HAS_HASH_ID +#define BOTAN_HAS_HAS_160 +#define BOTAN_HAS_HEX_CODEC +#define BOTAN_HAS_HMAC +#define BOTAN_HAS_HMAC_RNG +#define BOTAN_HAS_IDEA +#define BOTAN_HAS_IF_PUBLIC_KEY_FAMILY +#define BOTAN_HAS_KASUMI +#define BOTAN_HAS_KDF1 +#define BOTAN_HAS_KDF2 +#define BOTAN_HAS_KDF_BASE +#define BOTAN_HAS_KEYPAIR_TESTING +#define BOTAN_HAS_LIBSTATE_MODULE +#define BOTAN_HAS_LION +#define BOTAN_HAS_LUBY_RACKOFF +#define BOTAN_HAS_MARS +#define BOTAN_HAS_MD2 +#define BOTAN_HAS_MD4 +#define BOTAN_HAS_MD5 +#define BOTAN_HAS_MDX_HASH_FUNCTION +#define BOTAN_HAS_MGF1 +#define BOTAN_HAS_MISTY1 +#define BOTAN_HAS_MUTEX_NOOP +#define BOTAN_HAS_MUTEX_WIN32 +#define BOTAN_HAS_MUTEX_WRAPPERS +#define BOTAN_HAS_NOEKEON +#define BOTAN_HAS_NYBERG_RUEPPEL +#define BOTAN_HAS_OFB +#define BOTAN_HAS_OID_LOOKUP +#define BOTAN_HAS_OPENPGP_CODEC +#define BOTAN_HAS_PARALLEL_HASH +#define BOTAN_HAS_PASSWORD_BASED_ENCRYPTION +#define BOTAN_HAS_PBE_PKCS_V15 +#define BOTAN_HAS_PBE_PKCS_V20 +#define BOTAN_HAS_PBKDF1 +#define BOTAN_HAS_PBKDF2 +#define BOTAN_HAS_PEM_CODEC +#define BOTAN_HAS_PGPS2K +#define BOTAN_HAS_PK_PADDING +#define BOTAN_HAS_PUBLIC_KEY_CRYPTO +#define BOTAN_HAS_RANDPOOL +#define BOTAN_HAS_RC2 +#define BOTAN_HAS_RC5 +#define BOTAN_HAS_RC6 +#define BOTAN_HAS_RIPEMD_128 +#define BOTAN_HAS_RIPEMD_160 +#define BOTAN_HAS_RSA +#define BOTAN_HAS_RUNTIME_BENCHMARKING +#define BOTAN_HAS_RW +#define BOTAN_HAS_SAFER +#define BOTAN_HAS_SALSA20 +#define BOTAN_HAS_SEED +#define BOTAN_HAS_SELFTESTS +#define BOTAN_HAS_SERPENT +#define BOTAN_HAS_SHA1 +#define BOTAN_HAS_SHA2 +#define BOTAN_HAS_SKEIN_512 +#define BOTAN_HAS_SKIPJACK +#define BOTAN_HAS_SQUARE +#define BOTAN_HAS_SSL3_MAC +#define BOTAN_HAS_SSL_V3_PRF +#define BOTAN_HAS_STREAM_CIPHER +#define BOTAN_HAS_TEA +#define BOTAN_HAS_TIGER +#define BOTAN_HAS_TIMER +#define BOTAN_HAS_TIMER_WIN32 +#define BOTAN_HAS_TLS_V10_PRF +#define BOTAN_HAS_TURING +#define BOTAN_HAS_TWOFISH +#define BOTAN_HAS_UTIL_FUNCTIONS +#define BOTAN_HAS_WHIRLPOOL +#define BOTAN_HAS_WID_WAKE +#define BOTAN_HAS_X509 +#define BOTAN_HAS_X931_RNG +#define BOTAN_HAS_X942_PRF +#define BOTAN_HAS_XTEA +#define BOTAN_HAS_XTS + + +/* Local configuration options */ + + +/* +Modules +------- +adler32 (Adler32) +aes (AES) +algo_factory (Algorithm Factory) +alloc (Allocator) +arc4 (ARC4) +asn1 (ASN.1/BER/DER module) +auto_rng (Auto-seeded Random Number Generator) +base64 (Base64 Codec) +benchmark (Benchmarking) +bigint (BigInt) +block (Block Ciphers) +blowfish (Blowfish) +buf_comp (Buffered Computation) +cast (CAST) +cbc (CBC block cipher mode) +cbc_mac (CBC-MAC) +cfb (CFB block cipher mode) +cmac (CMAC) +cms (CMS) +crc24 (CRC-24) +crc32 (CRC-32) +cryptoapi_rng (Win32 CryptoAPI Entropy Source) +cryptobox (Crypto Box) +ctr (CTR block cipher mode) +cts (CTS block cipher mode) +datastor (Datastore) +def_engine (Default Engine) +des (DES) +dh (Diffie-Hellman Key Agreement) +dl_algo (Discrete Logarithm PK Algorithms) +dl_group (DL Group) +dlies (DLIES) +dsa (DSA) +eax (EAX block cipher mode) +ecb (ECB block cipher mode) +elgamal (ElGamal) +eme1 (EME1) +eme_pkcs (PKCSv1 v1.5 EME) +emsa1 (EMSA1) +emsa1_bsi (EMSA1 (BSI variant)) +emsa2 (EMSA2) +emsa3 (EMSA3) +emsa4 (EMSA4) +emsa_raw (EMSA-Raw) +engine (Engines) +entropy (Entropy Sources) +filters (Pipe/Filter) +fork256 (FORK-256) +gost_28147 (GOST 28147-89) +gost_3411 (GOST 34.11) +has160 (HAS-160) +hash (Hash Functions) +hash_id (Hash Function Identifiers) +hex (Hex Codec) +hmac (HMAC) +hmac_rng (HMAC RNG) +idea (IDEA) +if_algo (Integer Factorization Algorithms) +kasumi (Kasumi) +kdf (KDF Base Class) +kdf1 (KDF1) +kdf2 (KDF2) +keypair (Keypair Testing) +libstate (Botan Libstate Module) +lion (Lion) +lubyrack (Luby-Rackoff) +mac (Message Authentication Codes) +mars (MARS) +md2 (MD2) +md4 (MD4) +md5 (MD5) +mdx_hash (MDx Hash Base) +mem_pool (Memory Pool Allocator) +mgf1 (MGF1) +misty1 (MISTY-1) +mode_pad (Cipher Mode Padding Method) +modes (Cipher Mode Base Class) +monty_generic (Montgomery Reduction) +mp_generic (MPI Core (C++)) +mulop_generic (BigInt Multiply-Add) +mutex (Mutex Wrappers) +noekeon (Noekeon) +noop_mutex (No-Op Mutex) +nr (Nyberg-Rueppel) +numbertheory (Math Functions) +ofb (OFB block cipher mode) +oid_lookup (OID Lookup) +openpgp (OpenPGP Codec) +par_hash (Parallel Hash) +pbe (PBE Base) +pbes1 (PKCS5 v1.5 PBE) +pbes2 (PKCS5 v2.0 PBE) +pbkdf1 (Pbkdf1) +pbkdf2 (Pbkdf2) +pem (PEM Codec) +pgps2k (Pgps2k) +pk_codecs (PK codecs (PKCS8, X.509)) +pk_pad (Public Key EME/EMSA Padding Modes) +pubkey (Public Key Base) +randpool (Randpool RNG) +rc2 (RC2) +rc5 (RC5) +rc6 (RC6) +rmd128 (RIPEMD-128) +rmd160 (RIPEMD-160) +rng (Random Number Generators) +rsa (RSA) +rw (Rabin-Williams) +s2k (String to Key Functions) +safer (SAFER) +salsa20 (Salsa20) +seed (SEED) +selftest (Selftests) +serpent (Serpent) +sha1 (SHA-1) +sha2 (SHA-2 (224, 256, 384, 512)) +skein (Skein) +skipjack (Skipjack) +square (Square) +ssl3mac (SSLv3 MAC) +ssl_prf (SSLv3 PRF) +stream (Stream Ciphers) +sym_algo (Symmetric Algorithms) +system_alloc (Default (Malloc) Allocators) +tea (TEA) +tiger (Tiger) +timer (Timer Base Class) +tls_prf (TLS v1.0 PRF) +turing (Turing) +twofish (Twofish) +utils (Utility Functions) +whirlpool (Whirlpool) +wid_wake (WiderWake) +win32_crit_section (Win32 Mutex) +win32_query_perf_ctr (Win32 Timer) +win32_stats (Win32 Entropy Source) +x509 (X.509) +x919_mac (ANSI X9.19 MAC) +x931_rng (ANSI X9.31 PRNG) +x942_prf (X942 PRF) +xtea (XTEA) +xts (XTS block cipher mode) +*/ + +#endif diff --git a/old/botan/build/botan/cast128.h b/old/botan/build/botan/cast128.h new file mode 100644 index 0000000..6804814 --- /dev/null +++ b/old/botan/build/botan/cast128.h @@ -0,0 +1,47 @@ +/* +* CAST-128 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CAST128_H__ +#define BOTAN_CAST128_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* CAST-128 +*/ +class BOTAN_DLL CAST_128 : public BlockCipher + { + public: + void clear() throw() { MK.clear(); RK.clear(); } + std::string name() const { return "CAST-128"; } + BlockCipher* clone() const { return new CAST_128; } + CAST_128() : BlockCipher(8, 11, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + static void key_schedule(u32bit[16], u32bit[4]); + + static const u32bit S5[256]; + static const u32bit S6[256]; + static const u32bit S7[256]; + static const u32bit S8[256]; + + SecureBuffer<u32bit, 16> MK, RK; + }; + +extern const u32bit CAST_SBOX1[256]; +extern const u32bit CAST_SBOX2[256]; +extern const u32bit CAST_SBOX3[256]; +extern const u32bit CAST_SBOX4[256]; + +} + +#endif diff --git a/old/botan/build/botan/cast256.h b/old/botan/build/botan/cast256.h new file mode 100644 index 0000000..cd48edd --- /dev/null +++ b/old/botan/build/botan/cast256.h @@ -0,0 +1,44 @@ +/* +* CAST-256 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CAST256_H__ +#define BOTAN_CAST256_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* CAST-256 +*/ +class BOTAN_DLL CAST_256 : public BlockCipher + { + public: + void clear() throw() { MK.clear(); RK.clear(); } + std::string name() const { return "CAST-256"; } + BlockCipher* clone() const { return new CAST_256; } + CAST_256() : BlockCipher(16, 4, 32, 4) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + static const u32bit KEY_MASK[192]; + static const byte KEY_ROT[32]; + + SecureBuffer<u32bit, 48> MK; + SecureBuffer<byte, 48> RK; + }; + +extern const u32bit CAST_SBOX1[256]; +extern const u32bit CAST_SBOX2[256]; +extern const u32bit CAST_SBOX3[256]; +extern const u32bit CAST_SBOX4[256]; + +} + +#endif diff --git a/old/botan/build/botan/cbc.h b/old/botan/build/botan/cbc.h new file mode 100644 index 0000000..a926ac1 --- /dev/null +++ b/old/botan/build/botan/cbc.h @@ -0,0 +1,55 @@ +/* +* CBC Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CBC_H__ +#define BOTAN_CBC_H__ + +#include <botan/modebase.h> +#include <botan/mode_pad.h> + +namespace Botan { + +/* +* CBC Encryption +*/ +class BOTAN_DLL CBC_Encryption : public BlockCipherMode + { + public: + CBC_Encryption(BlockCipher*, BlockCipherModePaddingMethod*); + CBC_Encryption(BlockCipher*, BlockCipherModePaddingMethod*, + const SymmetricKey&, const InitializationVector&); + + ~CBC_Encryption() { delete padder; } + private: + std::string name() const; + void write(const byte[], u32bit); + void end_msg(); + const BlockCipherModePaddingMethod* padder; + }; + +/* +* CBC Decryption +*/ +class BOTAN_DLL CBC_Decryption : public BlockCipherMode + { + public: + CBC_Decryption(BlockCipher*, BlockCipherModePaddingMethod*); + CBC_Decryption(BlockCipher*, BlockCipherModePaddingMethod*, + const SymmetricKey&, const InitializationVector&); + + ~CBC_Decryption() { delete padder; } + private: + std::string name() const; + void write(const byte[], u32bit); + void end_msg(); + const BlockCipherModePaddingMethod* padder; + SecureVector<byte> temp; + }; + +} + +#endif diff --git a/old/botan/build/botan/cbc_mac.h b/old/botan/build/botan/cbc_mac.h new file mode 100644 index 0000000..d17d792 --- /dev/null +++ b/old/botan/build/botan/cbc_mac.h @@ -0,0 +1,40 @@ +/* +* CBC-MAC +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CBC_MAC_H__ +#define BOTAN_CBC_MAC_H__ + +#include <botan/mac.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* CBC-MAC +*/ +class BOTAN_DLL CBC_MAC : public MessageAuthenticationCode + { + public: + void clear() throw(); + std::string name() const; + MessageAuthenticationCode* clone() const; + + CBC_MAC(BlockCipher* e); + ~CBC_MAC(); + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + void key_schedule(const byte[], u32bit); + + BlockCipher* e; + SecureVector<byte> state; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/certstor.h b/old/botan/build/botan/certstor.h new file mode 100644 index 0000000..d5004e3 --- /dev/null +++ b/old/botan/build/botan/certstor.h @@ -0,0 +1,39 @@ +/* +* Certificate Store +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CERT_STORE_H__ +#define BOTAN_CERT_STORE_H__ + +#include <botan/x509cert.h> +#include <botan/x509_crl.h> + +namespace Botan { + +/* +* Certificate Store Interface +*/ +class BOTAN_DLL Certificate_Store + { + public: + virtual std::vector<X509_Certificate> + by_SKID(const MemoryRegion<byte>&) const = 0; + + virtual std::vector<X509_Certificate> by_name(const std::string&) const; + virtual std::vector<X509_Certificate> by_email(const std::string&) const; + virtual std::vector<X509_Certificate> by_dn(const X509_DN&) const; + + virtual std::vector<X509_CRL> + get_crls_for(const X509_Certificate&) const; + + virtual Certificate_Store* clone() const = 0; + + virtual ~Certificate_Store() {} + }; + +} + +#endif diff --git a/old/botan/build/botan/cfb.h b/old/botan/build/botan/cfb.h new file mode 100644 index 0000000..7810c00 --- /dev/null +++ b/old/botan/build/botan/cfb.h @@ -0,0 +1,47 @@ +/* +* CFB Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CFB_H__ +#define BOTAN_CFB_H__ + +#include <botan/modebase.h> + +namespace Botan { + +/* +* CFB Encryption +*/ +class BOTAN_DLL CFB_Encryption : public BlockCipherMode + { + public: + CFB_Encryption(BlockCipher*, u32bit = 0); + CFB_Encryption(BlockCipher*, const SymmetricKey&, + const InitializationVector&, u32bit = 0); + private: + void write(const byte[], u32bit); + void feedback(); + const u32bit FEEDBACK_SIZE; + }; + +/* +* CFB Decryption +*/ +class BOTAN_DLL CFB_Decryption : public BlockCipherMode + { + public: + CFB_Decryption(BlockCipher*, u32bit = 0); + CFB_Decryption(BlockCipher*, const SymmetricKey&, + const InitializationVector&, u32bit = 0); + private: + void write(const byte[], u32bit); + void feedback(); + const u32bit FEEDBACK_SIZE; + }; + +} + +#endif diff --git a/old/botan/build/botan/charset.h b/old/botan/build/botan/charset.h new file mode 100644 index 0000000..eebb199 --- /dev/null +++ b/old/botan/build/botan/charset.h @@ -0,0 +1,44 @@ +/* +* Character Set Handling +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CHARSET_H__ +#define BOTAN_CHARSET_H__ + +#include <botan/types.h> +#include <string> + +namespace Botan { + +/** +* The different charsets (nominally) supported by Botan. +*/ +enum Character_Set { + LOCAL_CHARSET, + UCS2_CHARSET, + UTF8_CHARSET, + LATIN1_CHARSET +}; + +namespace Charset { + +/* +* Character Set Handling +*/ +std::string transcode(const std::string&, Character_Set, Character_Set); + +bool is_digit(char); +bool is_space(char); +bool caseless_cmp(char, char); + +byte char2digit(char); +char digit2char(byte); + +} + +} + +#endif diff --git a/old/botan/build/botan/cmac.h b/old/botan/build/botan/cmac.h new file mode 100644 index 0000000..5a6deb7 --- /dev/null +++ b/old/botan/build/botan/cmac.h @@ -0,0 +1,44 @@ +/* +* CMAC +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CMAC_H__ +#define BOTAN_CMAC_H__ + +#include <botan/mac.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* CMAC +*/ +class BOTAN_DLL CMAC : public MessageAuthenticationCode + { + public: + void clear() throw(); + std::string name() const; + MessageAuthenticationCode* clone() const; + + static SecureVector<byte> poly_double(const MemoryRegion<byte>& in, + byte polynomial); + + CMAC(BlockCipher* e); + ~CMAC(); + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + void key_schedule(const byte[], u32bit); + + BlockCipher* e; + SecureVector<byte> buffer, state, B, P; + u32bit position; + byte polynomial; + }; + +} + +#endif diff --git a/old/botan/build/botan/cms_dec.h b/old/botan/build/botan/cms_dec.h new file mode 100644 index 0000000..75b61c9 --- /dev/null +++ b/old/botan/build/botan/cms_dec.h @@ -0,0 +1,65 @@ +/* +* CMS Decoding +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CMS_DECODER_H__ +#define BOTAN_CMS_DECODER_H__ + +#include <botan/x509cert.h> +#include <botan/x509stor.h> +#include <botan/pkcs8.h> +#include <botan/ber_dec.h> +#include <botan/ui.h> + +namespace Botan { + +/* +* CMS Decoding Operation +*/ +class BOTAN_DLL CMS_Decoder + { + public: + enum Status { GOOD, BAD, NO_KEY, FAILURE }; + + enum Content_Type { DATA, UNKNOWN, COMPRESSED, ENVELOPED, SIGNED, + AUTHENTICATED, DIGESTED }; + + Status layer_status() const; + Content_Type layer_type() const; + std::string layer_info() const; + std::string layer_algo() const; + std::string get_data() const; + std::vector<X509_Certificate> get_certs() const; + std::vector<X509_CRL> get_crls() const; + + void next_layer() { decode_layer(); } + + void add_key(PKCS8_PrivateKey*); + + CMS_Decoder(DataSource&, const X509_Store&, User_Interface&, + PKCS8_PrivateKey* = 0); + private: + std::string get_passphrase(const std::string&); + void read_econtent(BER_Decoder&); + void initial_read(DataSource&); + void decode_layer(); + void decompress(BER_Decoder&); + + User_Interface& ui; + + X509_Store store; + std::vector<std::string> passphrases; + std::vector<PKCS8_PrivateKey*> keys; + + OID type, next_type; + SecureVector<byte> data; + Status status; + std::string info; + }; + +} + +#endif diff --git a/old/botan/build/botan/cms_enc.h b/old/botan/build/botan/cms_enc.h new file mode 100644 index 0000000..6fdd2b7 --- /dev/null +++ b/old/botan/build/botan/cms_enc.h @@ -0,0 +1,92 @@ +/* +* CMS Encoding +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CMS_ENCODER_H__ +#define BOTAN_CMS_ENCODER_H__ + +#include <botan/x509cert.h> +#include <botan/x509stor.h> +#include <botan/pkcs8.h> +#include <botan/symkey.h> + +namespace Botan { + +/* +* CMS Encoding Operation +*/ +class BOTAN_DLL CMS_Encoder + { + public: + + void encrypt(RandomNumberGenerator&, + const X509_Certificate&, const std::string = ""); + + void encrypt(RandomNumberGenerator& rng, + const std::string&, const std::string& = ""); + + void encrypt(RandomNumberGenerator& rng, + const SymmetricKey&, const std::string& = ""); + + void authenticate(const X509_Certificate&, const std::string& = ""); + void authenticate(const std::string&, const std::string& = ""); + void authenticate(const SymmetricKey&, const std::string& = ""); + + void sign(const X509_Certificate& cert, + const PKCS8_PrivateKey& key, + RandomNumberGenerator& rng, + const std::vector<X509_Certificate>& cert_chain, + const std::string& hash, + const std::string& padding); + + void digest(const std::string& = ""); + + void compress(const std::string&); + static bool can_compress_with(const std::string&); + + SecureVector<byte> get_contents(); + std::string PEM_contents(); + + void set_data(const std::string&); + void set_data(const byte[], u32bit); + + CMS_Encoder(const std::string& str) { set_data(str); } + CMS_Encoder(const byte buf[], u32bit length) { set_data(buf, length); } + private: + void add_layer(const std::string&, DER_Encoder&); + + void encrypt_ktri(RandomNumberGenerator&, + const X509_Certificate&, PK_Encrypting_Key*, + const std::string&); + void encrypt_kari(RandomNumberGenerator&, + const X509_Certificate&, X509_PublicKey*, + const std::string&); + + SecureVector<byte> do_encrypt(RandomNumberGenerator& rng, + const SymmetricKey&, const std::string&); + + static SecureVector<byte> make_econtent(const SecureVector<byte>&, + const std::string&); + + static SymmetricKey setup_key(RandomNumberGenerator& rng, + const std::string&); + + static SecureVector<byte> wrap_key(RandomNumberGenerator& rng, + const std::string&, + const SymmetricKey&, + const SymmetricKey&); + + static SecureVector<byte> encode_params(const std::string&, + const SymmetricKey&, + const InitializationVector&); + + SecureVector<byte> data; + std::string type; + }; + +} + +#endif diff --git a/old/botan/build/botan/crc24.h b/old/botan/build/botan/crc24.h new file mode 100644 index 0000000..bca4d0e --- /dev/null +++ b/old/botan/build/botan/crc24.h @@ -0,0 +1,34 @@ +/* +* CRC24 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CRC24_H__ +#define BOTAN_CRC24_H__ + +#include <botan/hash.h> + +namespace Botan { + +/* +* CRC24 +*/ +class BOTAN_DLL CRC24 : public HashFunction + { + public: + void clear() throw() { crc = 0xB704CE; } + std::string name() const { return "CRC24"; } + HashFunction* clone() const { return new CRC24; } + CRC24() : HashFunction(3) { clear(); } + ~CRC24() { clear(); } + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + u32bit crc; + }; + +} + +#endif diff --git a/old/botan/build/botan/crc32.h b/old/botan/build/botan/crc32.h new file mode 100644 index 0000000..390fb10 --- /dev/null +++ b/old/botan/build/botan/crc32.h @@ -0,0 +1,34 @@ +/* +* CRC32 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CRC32_H__ +#define BOTAN_CRC32_H__ + +#include <botan/hash.h> + +namespace Botan { + +/* +* CRC32 +*/ +class BOTAN_DLL CRC32 : public HashFunction + { + public: + void clear() throw() { crc = 0xFFFFFFFF; } + std::string name() const { return "CRC32"; } + HashFunction* clone() const { return new CRC32; } + CRC32() : HashFunction(4) { clear(); } + ~CRC32() { clear(); } + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + u32bit crc; + }; + +} + +#endif diff --git a/old/botan/build/botan/crl_ent.h b/old/botan/build/botan/crl_ent.h new file mode 100644 index 0000000..050356c --- /dev/null +++ b/old/botan/build/botan/crl_ent.h @@ -0,0 +1,78 @@ +/* +* CRL Entry +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CRL_ENTRY_H__ +#define BOTAN_CRL_ENTRY_H__ + +#include <botan/x509cert.h> + +namespace Botan { + +/** +* This class represents CRL entries +*/ +class BOTAN_DLL CRL_Entry : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + /** + * Get the serial number of the certificate associated with this entry. + * @return the certificate's serial number + */ + MemoryVector<byte> serial_number() const { return serial; } + + /** + * Get the revocation date of the certificate associated with this entry + * @return the certificate's revocation date + */ + X509_Time expire_time() const { return time; } + + /** + * Get the entries reason code + * @return the reason code + */ + CRL_Code reason_code() const { return reason; } + + /** + * Construct an empty CRL entry. + */ + CRL_Entry(bool throw_on_unknown_critical_extension = false); + + /** + * Construct an CRL entry. + * @param cert the certificate to revoke + * @param reason the reason code to set in the entry + */ + CRL_Entry(const X509_Certificate&, CRL_Code = UNSPECIFIED); + + private: + bool throw_on_unknown_critical; + MemoryVector<byte> serial; + X509_Time time; + CRL_Code reason; + }; + +/** +* Test two CRL entries for equality in all fields. +*/ +BOTAN_DLL bool operator==(const CRL_Entry&, const CRL_Entry&); + +/** +* Test two CRL entries for inequality in at least one field. +*/ +BOTAN_DLL bool operator!=(const CRL_Entry&, const CRL_Entry&); + +/** +* Order two entries based on the revocation date. +*/ +BOTAN_DLL bool operator<(const CRL_Entry&, const CRL_Entry&); + +} + +#endif diff --git a/old/botan/build/botan/cryptobox.h b/old/botan/build/botan/cryptobox.h new file mode 100644 index 0000000..a30cb24 --- /dev/null +++ b/old/botan/build/botan/cryptobox.h @@ -0,0 +1,42 @@ +/* +* Cryptobox Message Routines +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CRYPTOBOX_H__ +#define BOTAN_CRYPTOBOX_H__ + +#include <string> +#include <botan/rng.h> + +namespace Botan { + +namespace CryptoBox { + +/** +* Encrypt a message +* @param input the input data +* @param input_len the length of input in bytes +* @param passphrase the passphrase used to encrypt the message +* @param rng a ref to a random number generator, such as AutoSeeded_RNG +*/ +BOTAN_DLL std::string encrypt(const byte input[], u32bit input_len, + const std::string& passphrase, + RandomNumberGenerator& rng); + +/** +* Decrypt a message encrypted with CryptoBox::encrypt +* @param input the input data +* @param input_len the length of input in bytes +* @param passphrase the passphrase used to encrypt the message +*/ +BOTAN_DLL std::string decrypt(const byte input[], u32bit input_len, + const std::string& passphrase); + +} + +} + +#endif diff --git a/old/botan/build/botan/ctr.h b/old/botan/build/botan/ctr.h new file mode 100644 index 0000000..aa0db57 --- /dev/null +++ b/old/botan/build/botan/ctr.h @@ -0,0 +1,31 @@ +/* +* CTR Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_COUNTER_MODE_H__ +#define BOTAN_COUNTER_MODE_H__ + +#include <botan/modebase.h> +#include <botan/modebase.h> + +namespace Botan { + +/* +* CTR-BE Mode +*/ +class BOTAN_DLL CTR_BE : public BlockCipherMode + { + public: + CTR_BE(BlockCipher*); + CTR_BE(BlockCipher*, const SymmetricKey&, const InitializationVector&); + private: + void write(const byte[], u32bit); + void increment_counter(); + }; + +} + +#endif diff --git a/old/botan/build/botan/cts.h b/old/botan/build/botan/cts.h new file mode 100644 index 0000000..9b17203 --- /dev/null +++ b/old/botan/build/botan/cts.h @@ -0,0 +1,60 @@ +/* +* CTS Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CTS_H__ +#define BOTAN_CTS_H__ + +#include <botan/modebase.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* CTS Encryption +*/ +class BOTAN_DLL CTS_Encryption : public BlockCipherMode + { + public: + CTS_Encryption(BlockCipher* ciph) : + BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2) {} + + CTS_Encryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv) : + BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2) + { set_key(key); set_iv(iv); } + private: + void write(const byte[], u32bit); + void end_msg(); + void encrypt(const byte[]); + }; + +/* +* CTS Decryption +*/ +class BOTAN_DLL CTS_Decryption : public BlockCipherMode + { + public: + CTS_Decryption(BlockCipher* ciph) : + BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2) + { temp.create(BLOCK_SIZE); } + + CTS_Decryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv) : + BlockCipherMode(ciph, "CTS", ciph->BLOCK_SIZE, 0, 2) + { set_key(key); set_iv(iv); temp.create(BLOCK_SIZE); } + private: + void write(const byte[], u32bit); + void end_msg(); + void decrypt(const byte[]); + SecureVector<byte> temp; + }; + +} + +#endif diff --git a/old/botan/build/botan/curve_gfp.h b/old/botan/build/botan/curve_gfp.h new file mode 100644 index 0000000..81cf6ce --- /dev/null +++ b/old/botan/build/botan/curve_gfp.h @@ -0,0 +1,177 @@ +/****** + * Elliptic curves over GF(p) (header file) + * + * (C) 2007 Martin Doering + * doering@cdc.informatik.tu-darmstadt.de + * Christoph Ludwig + * ludwig@fh-worms.de + * Falko Strenzke + * strenzke@flexsecure.de + ******/ + +#ifndef BOTAN_GFP_CURVE_H__ +#define BOTAN_GFP_CURVE_H__ + +#include <botan/bigint.h> +#include <botan/gfp_element.h> +#include <iosfwd> + +namespace Botan { + +/** +* This class represents an elliptic curve over GF(p) +* +* Distributed under the terms of the Botan license +*/ +class BOTAN_DLL CurveGFp + { + public: + + /** + * Construct the elliptic curve E: y^2 = x^3 + ax + b over GF(p) + * @param a first coefficient + * @param b second coefficient + * @param p prime number of the field + */ + CurveGFp(const GFpElement& a, const GFpElement& b, + const BigInt& p); + + /** + * Copy constructor + * @param other The curve to clone + */ + CurveGFp(const CurveGFp& other); + + /** + * Assignment operator + * @param other The curve to use as source for the assignment + */ + const CurveGFp& operator=(const CurveGFp& other); + + /** + * Set the shared GFpModulus object. + * Warning: do not use this function unless you know in detail how + * the sharing of values + * in the various EC related objects works. + * Do NOT spread pointers to a GFpModulus over different threads! + * @param mod a shared pointer to a GFpModulus object suitable for + * *this. + */ + void set_shrd_mod(const std::tr1::shared_ptr<GFpModulus> mod); + + // getters + + /** + * Get coefficient a + * @result coefficient a + */ + const GFpElement& get_a() const; + + /** + * Get coefficient b + * @result coefficient b + */ + const GFpElement& get_b() const; + + /** + * Get the GFpElement coefficient a transformed + * to its m-residue. This can be used for efficency reasons: the curve + * stores the transformed version after the first invocation of this + * function. + * @result the coefficient a, transformed to its m-residue + */ + GFpElement const get_mres_a() const; + + /** + * Get the GFpElement coefficient b transformed + * to its m-residue. This can be used for efficency reasons: the curve + * stores the transformed version after the first invocation of this + * function. + * @result the coefficient b, transformed to its m-residue + */ + GFpElement const get_mres_b() const; + + + /** + * Get the GFpElement 1 transformed + * to its m-residue. This can be used for efficency reasons: the curve + * stores the transformed version after the first invocation of this + * function. + * @result the GFpElement 1, transformed to its m-residue + */ + std::tr1::shared_ptr<GFpElement const> const get_mres_one() const; + + /** + * Get prime modulus of the field of the curve + * @result prime modulus of the field of the curve + */ + BigInt const get_p() const; + /*inline std::tr1::shared_ptr<BigInt> const get_ptr_p() const + { + return mp_p; + }*/ + + /** + * Retrieve a shared pointer to the curves GFpModulus object for efficient storage + * and computation of montgomery multiplication related data members and functions. + * Warning: do not use this function unless you know in detail how the sharing of values + * in the various EC related objects works. + * Do NOT spread pointers to a GFpModulus over different threads! + * @result a shared pointer to a GFpModulus object + */ + inline std::tr1::shared_ptr<GFpModulus> const get_ptr_mod() const + { + return mp_mod; + } + + /** + * swaps the states of *this and other, does not throw + * @param other The curve to swap values with + */ + void swap(CurveGFp& other); + + private: + std::tr1::shared_ptr<GFpModulus> mp_mod; + GFpElement mA; + GFpElement mB; + mutable std::tr1::shared_ptr<GFpElement> mp_mres_a; + mutable std::tr1::shared_ptr<GFpElement> mp_mres_b; + mutable std::tr1::shared_ptr<GFpElement> mp_mres_one; + }; + +// relational operators +bool operator==(const CurveGFp& lhs, const CurveGFp& rhs); + +inline bool operator!=(const CurveGFp& lhs, const CurveGFp& rhs) + { + return !(lhs == rhs); + } + +// io operators +std::ostream& operator<<(std::ostream& output, const CurveGFp& elem); + +// swaps the states of curve1 and curve2, does not throw! +// cf. Meyers, Item 25 +inline +void swap(CurveGFp& curve1, CurveGFp& curve2) + { + curve1.swap(curve2); + } + +} // namespace Botan + + +namespace std { + +// swaps the states of curve1 and curve2, does not throw! +// cf. Meyers, Item 25 +template<> inline +void swap<Botan::CurveGFp>(Botan::CurveGFp& curve1, + Botan::CurveGFp& curve2) + { + curve1.swap(curve2); + } + +} // namespace std + +#endif diff --git a/old/botan/build/botan/cvc_ado.h b/old/botan/build/botan/cvc_ado.h new file mode 100644 index 0000000..2c4f3ce --- /dev/null +++ b/old/botan/build/botan/cvc_ado.h @@ -0,0 +1,101 @@ +/* +* EAC1_1 CVC ADO +* (C) 2008 Falko Strenzke +* strenzke@flexsecure.de +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAC_CVC_ADO_H__ +#define BOTAN_EAC_CVC_ADO_H__ + +#include <botan/x509_key.h> +#include <botan/pubkey_enums.h> +#include <botan/pubkey.h> +#include <botan/ecdsa.h> +#include <botan/eac_obj.h> +#include <botan/cvc_req.h> +#include <string> + +namespace Botan { + +/** +* This class represents a TR03110 (EAC) v1.1 CVC ADO request +*/ + + // CRTP continuation from EAC1_1_obj +class BOTAN_DLL EAC1_1_ADO : public EAC1_1_obj<EAC1_1_ADO> + { + public: + friend class EAC1_1_obj<EAC1_1_ADO>; + + /** + * Construct a CVC ADO request from a DER encoded CVC ADO request file. + * @param str the path to the DER encoded file + */ + EAC1_1_ADO(const std::string& str); + + /** + * Construct a CVC ADO request from a data source + * @param source the data source + */ + EAC1_1_ADO(std::tr1::shared_ptr<DataSource> source); + + /** + * Create a signed CVC ADO request from to be signed (TBS) data + * @param signer the signer used to sign the CVC ADO request + * @param tbs_bits the TBS data to sign + */ + static MemoryVector<byte> make_signed( + std::auto_ptr<PK_Signer> signer, + const MemoryRegion<byte>& tbs_bits, + RandomNumberGenerator& rng); + + /** + * Get the CAR of this CVC ADO request + * @result the CAR of this CVC ADO request + */ + ASN1_Car get_car() const; + + /** + * Get the CVC request contained in this object. + * @result the CVC request inside this CVC ADO request + */ + EAC1_1_Req get_request() const; + + /** + * Encode this object into a pipe. Only DER is supported. + * @param out the pipe to encode this object into + * @param encoding the encoding type to use, must be DER + */ + void encode(Pipe& out, X509_Encoding encoding) const; + + bool operator==(EAC1_1_ADO const& rhs) const; + + /** + * Get the TBS data of this CVC ADO request. + * @result the TBS data + */ + SecureVector<byte> tbs_data() const; + + virtual ~EAC1_1_ADO() {} + private: + ASN1_Car m_car; + EAC1_1_Req m_req; + + void force_decode(); + static void decode_info(SharedPtrConverter<DataSource> source, + SecureVector<byte> & res_tbs_bits, + ECDSA_Signature & res_sig); + }; + +inline bool operator!=(EAC1_1_ADO const& lhs, EAC1_1_ADO const& rhs) + { + return (!(lhs == rhs)); + } + +} + +#endif + + diff --git a/old/botan/build/botan/cvc_ca.h b/old/botan/build/botan/cvc_ca.h new file mode 100644 index 0000000..3ec307b --- /dev/null +++ b/old/botan/build/botan/cvc_ca.h @@ -0,0 +1,51 @@ +/* +* EAC1.1 CVC Certificate Authority +* (C) 2007 FlexSecure GmbH +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CVC_CA_H__ +#define BOTAN_CVC_CA_H__ + +#include <botan/pkcs8.h> +#include <botan/pkcs10.h> +#include <botan/pubkey.h> +#include <botan/cvc_cert.h> + +namespace Botan { + +/** +* This class represents a CVC CA. +*/ +class BOTAN_DLL EAC1_1_CVC_CA + { + public: + + /** + * Create an arbitrary EAC 1.1 CVC. + * The desired key encoding must be set within the key (if applicable). + * @param signer the signer used to sign the certificate + * @param public_key the DER encoded public key to appear in + * the certificate + * @param car the CAR of the certificate + * @param chr the CHR of the certificate + * @param holder_auth_templ the holder authorization value byte to + * appear in the CHAT of the certificate + * @param ced the CED to appear in the certificate + * @param ced the CEX to appear in the certificate + */ + static EAC1_1_CVC make_cert(std::auto_ptr<PK_Signer> signer, + MemoryRegion<byte> const& public_key, + ASN1_Car const& car, + ASN1_Chr const& chr, + byte holder_auth_templ, + ASN1_Ced ced, + ASN1_Cex cex, + RandomNumberGenerator& rng); + }; + +} + +#endif diff --git a/old/botan/build/botan/cvc_cert.h b/old/botan/build/botan/cvc_cert.h new file mode 100644 index 0000000..17671d3 --- /dev/null +++ b/old/botan/build/botan/cvc_cert.h @@ -0,0 +1,94 @@ +/* +* EAC1_1 CVC +* (C) 2008 Falko Strenzke +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CVC_EAC_H__ +#define BOTAN_CVC_EAC_H__ + +#include <botan/x509_key.h> +#include <botan/pubkey_enums.h> +#include <botan/signed_obj.h> +#include <botan/pubkey.h> +#include <botan/ecdsa.h> +#include <botan/ecdsa_sig.h> +#include <botan/eac_obj.h> +#include <botan/cvc_gen_cert.h> +#include <string> + +namespace Botan { + +/** +* This class represents TR03110 (EAC) v1.1 CV Certificates +*/ +class BOTAN_DLL EAC1_1_CVC : public EAC1_1_gen_CVC<EAC1_1_CVC>//Signed_Object + { + public: + friend class EAC1_1_obj<EAC1_1_CVC>; + + /** + * Get the CAR of the certificate. + * @result the CAR of the certificate + */ + ASN1_Car get_car() const; + + /** + * Get the CED of this certificate. + * @result the CED this certificate + */ + ASN1_Ced get_ced() const; + + /** + * Get the CEX of this certificate. + * @result the CEX this certificate + */ + ASN1_Cex get_cex() const; + + /** + * Get the CHAT value. + * @result the CHAT value + */ + u32bit get_chat_value() const; + + bool operator==(const EAC1_1_CVC&) const; + + /** + * Construct a CVC from a data source + * @param source the data source + */ + EAC1_1_CVC(std::tr1::shared_ptr<DataSource>& source); + + /** + * Construct a CVC from a file + * @param str the path to the certificate file + */ + EAC1_1_CVC(const std::string& str); + + virtual ~EAC1_1_CVC() {} + private: + void force_decode(); + friend class EAC1_1_CVC_CA; + EAC1_1_CVC() {} + + ASN1_Car m_car; + ASN1_Ced m_ced; + ASN1_Cex m_cex; + byte m_chat_val; + OID m_chat_oid; + }; + +/* +* Comparison +*/ +inline bool operator!=(EAC1_1_CVC const& lhs, EAC1_1_CVC const& rhs) + { + return !(lhs == rhs); + } + +} + +#endif + diff --git a/old/botan/build/botan/cvc_gen_cert.h b/old/botan/build/botan/cvc_gen_cert.h new file mode 100644 index 0000000..4a78802 --- /dev/null +++ b/old/botan/build/botan/cvc_gen_cert.h @@ -0,0 +1,177 @@ +/* +* EAC1_1 general CVC +* (C) 2008 Falko Strenzke +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAC_CVC_GEN_CERT_H__ +#define BOTAN_EAC_CVC_GEN_CERT_H__ + +#include <botan/x509_key.h> +#include <botan/eac_asn_obj.h> +#include <botan/pubkey_enums.h> +#include <botan/pubkey.h> +#include <botan/ecdsa_sig.h> +#include <string> +#include <assert.h> + +namespace Botan { + +/** +* This class represents TR03110 (EAC) v1.1 generalized CV Certificates +*/ +template<typename Derived> +class BOTAN_DLL EAC1_1_gen_CVC : public EAC1_1_obj<Derived> // CRTP continuation from EAC1_1_obj + { + friend class EAC1_1_obj<EAC1_1_gen_CVC>; + + public: + + /** + * Get this certificates public key. + * @result this certificates public key + */ + std::auto_ptr<Public_Key> subject_public_key() const; + + /** + * Find out whether this object is self signed. + * @result true if this object is self signed + */ + bool is_self_signed() const; + + /** + * Get the CHR of the certificate. + * @result the CHR of the certificate + */ + ASN1_Chr get_chr() const; + + /** + * Put the DER encoded version of this object into a pipe. PEM + * is not supported. + * @param out the pipe to push the DER encoded version into + * @param encoding the encoding to use. Must be DER. + */ + void encode(Pipe& out, X509_Encoding encoding) const; + + /** + * Get the to-be-signed (TBS) data of this object. + * @result the TBS data of this object + */ + SecureVector<byte> tbs_data() const; + + /** + * Build the DER encoded certifcate body of an object + * @param tbs the data to be signed + * @result the correctly encoded body of the object + */ + static SecureVector<byte> build_cert_body(MemoryRegion<byte> const& tbs); + + /** + * Create a signed generalized CVC object. + * @param signer the signer used to sign this object + * @param tbs_bits the body the generalized CVC object to be signed + * @result the DER encoded signed generalized CVC object + */ + static MemoryVector<byte> make_signed( + std::auto_ptr<PK_Signer> signer, + const MemoryRegion<byte>& tbs_bits, + RandomNumberGenerator& rng); + virtual ~EAC1_1_gen_CVC<Derived>() + {} + + protected: + ECDSA_PublicKey m_pk; // public key + ASN1_Chr m_chr; + bool self_signed; + + static void decode_info(SharedPtrConverter<DataSource> source, + SecureVector<byte> & res_tbs_bits, + ECDSA_Signature & res_sig); + + }; + +template<typename Derived> ASN1_Chr EAC1_1_gen_CVC<Derived>::get_chr() const + { + return m_chr; + } + +template<typename Derived> bool EAC1_1_gen_CVC<Derived>::is_self_signed() const + { + return self_signed; + } + +template<typename Derived> MemoryVector<byte> EAC1_1_gen_CVC<Derived>::make_signed( + std::auto_ptr<PK_Signer> signer, + const MemoryRegion<byte>& tbs_bits, + RandomNumberGenerator& rng) // static + { + SecureVector<byte> concat_sig = EAC1_1_obj<Derived>::make_signature(signer.get(), tbs_bits, rng); + assert(concat_sig.size() % 2 == 0); + return DER_Encoder() + .start_cons(ASN1_Tag(33), APPLICATION) + .raw_bytes(tbs_bits) + .encode(concat_sig, OCTET_STRING, ASN1_Tag(55), APPLICATION) + .end_cons() + .get_contents(); + } + +template<typename Derived> std::auto_ptr<Public_Key> EAC1_1_gen_CVC<Derived>::subject_public_key() const + { + return std::auto_ptr<Public_Key>(new ECDSA_PublicKey(m_pk)); + } + +template<typename Derived> SecureVector<byte> EAC1_1_gen_CVC<Derived>::build_cert_body(MemoryRegion<byte> const& tbs) + { + return DER_Encoder() + .start_cons(ASN1_Tag(78), APPLICATION) + .raw_bytes(tbs) + .end_cons().get_contents(); + } + +template<typename Derived> SecureVector<byte> EAC1_1_gen_CVC<Derived>::tbs_data() const + { + return build_cert_body(EAC1_1_obj<Derived>::tbs_bits); + } + +template<typename Derived> void EAC1_1_gen_CVC<Derived>::encode(Pipe& out, X509_Encoding encoding) const + { + SecureVector<byte> concat_sig(EAC1_1_obj<Derived>::m_sig.get_concatenation()); + SecureVector<byte> der = DER_Encoder() + .start_cons(ASN1_Tag(33), APPLICATION) + .start_cons(ASN1_Tag(78), APPLICATION) + .raw_bytes(EAC1_1_obj<Derived>::tbs_bits) + .end_cons() + .encode(concat_sig, OCTET_STRING, ASN1_Tag(55), APPLICATION) + .end_cons() + .get_contents(); + + if (encoding == PEM) + throw Invalid_Argument("EAC1_1_gen_CVC::encode() cannot PEM encode an EAC object"); + else + out.write(der); + } + +template<typename Derived> +void EAC1_1_gen_CVC<Derived>::decode_info( + SharedPtrConverter<DataSource> source, + SecureVector<byte> & res_tbs_bits, + ECDSA_Signature & res_sig) + { + SecureVector<byte> concat_sig; + BER_Decoder(*source.get_shared().get()) + .start_cons(ASN1_Tag(33)) + .start_cons(ASN1_Tag(78)) + .raw_bytes(res_tbs_bits) + .end_cons() + .decode(concat_sig, OCTET_STRING, ASN1_Tag(55), APPLICATION) + .end_cons(); + res_sig = decode_concatenation(concat_sig); + } + +} + +#endif + + diff --git a/old/botan/build/botan/cvc_key.h b/old/botan/build/botan/cvc_key.h new file mode 100644 index 0000000..67b6cef --- /dev/null +++ b/old/botan/build/botan/cvc_key.h @@ -0,0 +1,54 @@ +/* +* EAC CVC Public Key +* (C) 2008 FlexSecure Gmbh +* Falko Strenzke +* strenzke@flexsecure.de +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAC1_1_CVC_PUBLIC_KEY_H__ +#define BOTAN_EAC1_1_CVC_PUBLIC_KEY_H__ + +#include <botan/pipe.h> +#include <botan/pk_keys.h> +#include <botan/alg_id.h> + +namespace Botan { + +/** +* This class represents EAC 1.1 CVC public key encoders. +*/ +class BOTAN_DLL EAC1_1_CVC_Encoder + { + public: + /** + * Get the DER encoded CVC public key. + * @param alg_id the algorithm identifier to use in the encoding + * @return the DER encoded public key + */ + virtual MemoryVector<byte> + public_key(const AlgorithmIdentifier& enc) const = 0; + + virtual ~EAC1_1_CVC_Encoder() {} + }; + +/** +* This class represents EAC 1.1 CVC public key decoders. +*/ +class BOTAN_DLL EAC1_1_CVC_Decoder + { + public: + /** + * Decode a CVC public key. + * @param enc the DER encoded public key to decode + * @return the algorithm identifier found in the encoded public key + */ + virtual AlgorithmIdentifier const + public_key(const MemoryRegion<byte>& enc) = 0; + + virtual ~EAC1_1_CVC_Decoder() {} + }; +} + +#endif diff --git a/old/botan/build/botan/cvc_req.h b/old/botan/build/botan/cvc_req.h new file mode 100644 index 0000000..8599f53 --- /dev/null +++ b/old/botan/build/botan/cvc_req.h @@ -0,0 +1,63 @@ +/* +* EAC1_1 CVC Request +* (C) 2008 Falko Strenzke +* strenzke@flexsecure.de +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAC_CVC_REQ_H__ +#define BOTAN_EAC_CVC_REQ_H__ + +#include <botan/x509_key.h> +#include <botan/pubkey_enums.h> +#include <botan/cvc_gen_cert.h> +#include <botan/cvc_req.h> + +namespace Botan { + +/** +* This class represents TR03110 v1.1 EAC CV Certificate Requests. +*/ +class BOTAN_DLL EAC1_1_Req : public EAC1_1_gen_CVC<EAC1_1_Req> + { + public: + friend class EAC1_1_Req_CA; + friend class EAC1_1_ADO; + friend class EAC1_1_obj<EAC1_1_Req>; + + /** + * Compare for equality with other + * @param other compare for equality with this object + */ + bool operator==(const EAC1_1_Req& other) const; + + /** + * Construct a CVC request from a data source. + * @param source the data source + */ + EAC1_1_Req(std::tr1::shared_ptr<DataSource> source); + + /** + * Construct a CVC request from a DER encoded CVC reqeust file. + * @param str the path to the DER encoded file + */ + EAC1_1_Req(const std::string& str); + + virtual ~EAC1_1_Req(){} + private: + void force_decode(); + EAC1_1_Req() {} + }; + +/* +* Comparison Operator +*/ +inline bool operator!=(EAC1_1_Req const& lhs, EAC1_1_Req const& rhs) + { + return !(lhs == rhs); + } + +} + +#endif diff --git a/old/botan/build/botan/cvc_self.h b/old/botan/build/botan/cvc_self.h new file mode 100644 index 0000000..db23547 --- /dev/null +++ b/old/botan/build/botan/cvc_self.h @@ -0,0 +1,167 @@ +/* +* CVC Self-Signed Certificate +* (C) 2007 FlexSecure GmbH +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CVC_EAC_SELF_H__ +#define BOTAN_CVC_EAC_SELF_H__ + +#include <botan/pkcs8.h> +#include <botan/pkcs10.h> +#include <botan/cvc_cert.h> +#include <botan/ecdsa.h> +#include <botan/asn1_obj.h> +#include <botan/cvc_req.h> +#include <botan/cvc_ado.h> + +namespace Botan { + +/** +* This class represents a set of options used for the creation of CVC certificates +*/ +class BOTAN_DLL EAC1_1_CVC_Options + { + public: + + ASN1_Car car; + ASN1_Chr chr; + byte holder_auth_templ; + ASN1_Ced ced; + ASN1_Cex cex; + std::string hash_alg; + }; + +/** +* This namespace represents general EAC 1.1 convenience functions. +*/ +namespace CVC_EAC { + +/** +* Create a selfsigned CVCA +* @param rng the rng to use +* @param key the ECDSA private key to be used to sign the certificate +* @param opts used to set several parameters. Necessary are: +* car, holder_auth_templ, hash_alg, ced, cex and hash_alg +* @result the self signed certificate +*/ + +EAC1_1_CVC create_self_signed_cert(Private_Key const& key, + EAC1_1_CVC_Options const& opts, + RandomNumberGenerator& rng); +/** +* Create a CVC request. The key encoding will be according to the provided private key. +* @param priv_key the private key associated with the requesting entity +* @param chr the chr to appear in the certificate (to be provided without +* sequence number) +* @param hash_alg the string defining the hash algorithm to be used for the creation +* of the signature +* @param rng the rng to use +* @result the new request +*/ +EAC1_1_Req create_cvc_req(Private_Key const& priv_key, + ASN1_Chr const& chr, + std::string const& hash_alg, + RandomNumberGenerator& rng); + +/** +* Create an ADO from a request object. +* @param priv_key the private key used to sign the ADO +* @param req the request forming the body of the ADO +* @param car the CAR forming the body of the ADO, i.e. the +* CHR of the entity associated with the provided private key +* @param rng the rng to use +*/ +EAC1_1_ADO create_ado_req(Private_Key const& priv_key, + EAC1_1_Req const& req, + ASN1_Car const& car, + RandomNumberGenerator& rng); +} +/** +* This namespace represents EAC 1.1 CVC convenience functions following the specific german +* requirements. +*/ +namespace DE_EAC { + +/** +* Create a CVCA certificate. +* @param priv_key the private key associated with the CVCA certificate +* to be created +* @param hash the string identifying the hash algorithm to be used +* for signing the certificate to be created +* @param car the CAR of the certificate to be created +* @param iris indicates whether the entity associated with the certificate +* shall be entitled to read the biometrical iris image +* @param fingerpr indicates whether the entity associated with the certificate +* shall be entitled to read the biometrical fingerprint image +* @param rng the rng to use +* @result the CVCA certificate created +*/ +EAC1_1_CVC create_cvca(Private_Key const& priv_key, + std::string const& hash, + ASN1_Car const& car, + bool iris, + bool fingerpr, + u32bit cvca_validity_months, + RandomNumberGenerator& rng); + +/** +* Create a link certificate between two CVCA certificates. The key +* encoding will be implicitCA. +* @param signer the cvca certificate associated with the signing +* entity +* @param priv_key the private key associated with the signer +* @param to_be_signed the certificate which whose CAR/CHR will be +* the holder of the link certificate +* @param rng a random number generator +*/ +EAC1_1_CVC link_cvca(EAC1_1_CVC const& signer, + Private_Key const& priv_key, + EAC1_1_CVC const& to_be_signed, + RandomNumberGenerator& rng); + +/** +* Create a CVC request. The key encoding will be implicitCA. +* @param priv_key the private key associated with the requesting entity +* @param chr the chr to appear in the certificate (to be provided without +* sequence number) +* @param hash_alg the string defining the hash algorithm to be used for the creation +* of the signature +* @param rng a random number generator +* @result the new request +*/ +EAC1_1_Req create_cvc_req(Private_Key const& priv_key, + ASN1_Chr const& chr, + std::string const& hash_alg, + RandomNumberGenerator& rng); + +/** +* Sign a CVC request. +* @param signer_cert the certificate of the signing entity +* @param priv_key the private key of the signing entity +* @param req the request to be signed +* @param seqnr the sequence number of the certificate to be created +* @param seqnr_len the number of digits the sequence number will be +* encoded in +* @param domestic indicates whether to sign a domestic or a foreign certificate: +* set to true for domestic +* @param rng a random number generator +* @result the new certificate +* +**/ +EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert, + Private_Key const& priv_key, + EAC1_1_Req const& req, + u32bit seqnr, + u32bit seqnr_len, + bool domestic, + u32bit dvca_validity_months, + u32bit ca_is_validity_months, + RandomNumberGenerator& rng); +} + +} + +#endif diff --git a/old/botan/build/botan/data_snk.h b/old/botan/build/botan/data_snk.h new file mode 100644 index 0000000..61ddf6e --- /dev/null +++ b/old/botan/build/botan/data_snk.h @@ -0,0 +1,65 @@ +/* +* DataSink +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DATA_SINK_H__ +#define BOTAN_DATA_SINK_H__ + +#include <botan/filter.h> +#include <iosfwd> + +namespace Botan { + +/** +* This class represents abstract data sink objects. +*/ +class BOTAN_DLL DataSink : public Filter + { + public: + bool attachable() { return false; } + DataSink() {} + virtual ~DataSink() {} + private: + DataSink& operator=(const DataSink&) { return (*this); } + DataSink(const DataSink&); + }; + +/** +* This class represents a data sink which writes its output to a stream. +*/ +class BOTAN_DLL DataSink_Stream : public DataSink + { + public: + void write(const byte[], u32bit); + + /** + * Construct a DataSink_Stream from a stream. + * @param stream the stream to write to + * @param name identifier + */ + DataSink_Stream(std::ostream& stream, + const std::string& name = ""); + + /** + * Construct a DataSink_Stream from a stream. + * @param file the name of the file to open a stream to + * @param use_binary indicates whether to treat the file + * as a binary file or not + */ + DataSink_Stream(const std::string& filename, + bool use_binary = false); + + ~DataSink_Stream(); + private: + const std::string identifier; + const bool owner; + + std::ostream* sink; + }; + +} + +#endif diff --git a/old/botan/build/botan/data_src.h b/old/botan/build/botan/data_src.h new file mode 100644 index 0000000..e16217e --- /dev/null +++ b/old/botan/build/botan/data_src.h @@ -0,0 +1,150 @@ +/* +* DataSource +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DATA_SRC_H__ +#define BOTAN_DATA_SRC_H__ + +#include <botan/secmem.h> +#include <string> +#include <iosfwd> + +namespace Botan { + +/** +* This class represents an abstract data source object. +*/ +class BOTAN_DLL DataSource + { + public: + /** + * Read from the source. Moves the internal offset so that + * every call to read will return a new portion of the source. + * @param out the byte array to write the result to + * @param length the length of the byte array out + * @return the length in bytes that was actually read and put + * into out + */ + virtual u32bit read(byte out[], u32bit length) = 0; + + /** + * Read from the source but do not modify the internal offset. Consecutive + * calls to peek() will return portions of the source starting at the same + * position. + * @param out the byte array to write the output to + * @param length the length of the byte array out + * @return the length in bytes that was actually read and put + * into out + */ + virtual u32bit peek(byte out[], u32bit length, + u32bit peek_offset) const = 0; + + /** + * Test whether the source still has data that can be read. + * @return true if there is still data to read, false otherwise + */ + virtual bool end_of_data() const = 0; + /** + * return the id of this data source + * @return the std::string representing the id of this data source + */ + virtual std::string id() const { return ""; } + + /** + * Read one byte. + * @param the byte to read to + * @return the length in bytes that was actually read and put + * into out + */ + u32bit read_byte(byte& out); + + /** + * Peek at one byte. + * @param the byte to read to + * @return the length in bytes that was actually read and put + * into out + */ + u32bit peek_byte(byte& out) const; + + /** + * Discard the next N bytes of the data + * @param N the number of bytes to discard + * @return the number of bytes actually discarded + */ + u32bit discard_next(u32bit N); + + DataSource() {} + virtual ~DataSource() {} + private: + DataSource& operator=(const DataSource&) { return (*this); } + DataSource(const DataSource&); + }; + +/** +* This class represents a Memory-Based DataSource +*/ +class BOTAN_DLL DataSource_Memory : public DataSource + { + public: + u32bit read(byte[], u32bit); + u32bit peek(byte[], u32bit, u32bit) const; + bool end_of_data() const; + + /** + * Construct a memory source that reads from a string + * @param in the string to read from + */ + DataSource_Memory(const std::string& in); + + /** + * Construct a memory source that reads from a byte array + * @param in the byte array to read from + * @param length the length of the byte array + */ + DataSource_Memory(const byte in[], u32bit length); + + /** + * Construct a memory source that reads from a MemoryRegion + * @param in the MemoryRegion to read from + */ + DataSource_Memory(const MemoryRegion<byte>& in); + private: + SecureVector<byte> source; + u32bit offset; + }; + +/** +* This class represents a Stream-Based DataSource. +*/ +class BOTAN_DLL DataSource_Stream : public DataSource + { + public: + u32bit read(byte[], u32bit); + u32bit peek(byte[], u32bit, u32bit) const; + bool end_of_data() const; + std::string id() const; + + DataSource_Stream(std::istream&, const std::string& id = ""); + + /** + * Construct a Stream-Based DataSource from file + * @param file the name of the file + * @param use_binary whether to treat the file as binary or not + */ + DataSource_Stream(const std::string& file, bool use_binary = false); + + ~DataSource_Stream(); + private: + const std::string identifier; + const bool owner; + + std::istream* source; + u32bit total_read; + }; + +} + +#endif diff --git a/old/botan/build/botan/datastor.h b/old/botan/build/botan/datastor.h new file mode 100644 index 0000000..7ee626f --- /dev/null +++ b/old/botan/build/botan/datastor.h @@ -0,0 +1,61 @@ +/* +* Data Store +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DATA_STORE_H__ +#define BOTAN_DATA_STORE_H__ + +#include <botan/secmem.h> +#include <utility> +#include <string> +#include <vector> +#include <map> + +namespace Botan { + +/** +* Data Store +*/ +class BOTAN_DLL Data_Store + { + public: + class BOTAN_DLL Matcher + { + public: + virtual bool operator()(const std::string&, + const std::string&) const = 0; + + virtual std::pair<std::string, std::string> + transform(const std::string&, const std::string&) const; + + virtual ~Matcher() {} + }; + + bool operator==(const Data_Store&) const; + + std::multimap<std::string, std::string> + search_with(const Matcher&) const; + + std::vector<std::string> get(const std::string&) const; + + std::string get1(const std::string&) const; + + MemoryVector<byte> get1_memvec(const std::string&) const; + u32bit get1_u32bit(const std::string&, u32bit = 0) const; + + bool has_value(const std::string&) const; + + void add(const std::multimap<std::string, std::string>&); + void add(const std::string&, const std::string&); + void add(const std::string&, u32bit); + void add(const std::string&, const MemoryRegion<byte>&); + private: + std::multimap<std::string, std::string> contents; + }; + +} + +#endif diff --git a/old/botan/build/botan/def_eng.h b/old/botan/build/botan/def_eng.h new file mode 100644 index 0000000..2d71454 --- /dev/null +++ b/old/botan/build/botan/def_eng.h @@ -0,0 +1,83 @@ +/* +* Default Engine +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DEFAULT_ENGINE_H__ +#define BOTAN_DEFAULT_ENGINE_H__ + +#include <botan/engine.h> + +namespace Botan { + +/* +* Default Engine +*/ +class BOTAN_DLL Default_Engine : public Engine + { + public: + std::string provider_name() const { return "core"; } + +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) + IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_DSA) + DSA_Operation* dsa_op(const DL_Group&, const BigInt&, + const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) + NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_ELGAMAL) + ELG_Operation* elg_op(const DL_Group&, const BigInt&, + const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) + DH_Operation* dh_op(const DL_Group&, const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_ECDSA) + virtual ECDSA_Operation* ecdsa_op(const EC_Domain_Params&, + const BigInt&, + const PointGFp&) const; +#endif + +#if defined(BOTAN_HAS_ECKAEG) + virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&, + const BigInt&, + const PointGFp&) const; +#endif + + Modular_Exponentiator* mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const; + + virtual bool can_add_algorithms() { return true; } + + Keyed_Filter* get_cipher(const std::string&, Cipher_Dir, + Algorithm_Factory&); + + private: + BlockCipher* find_block_cipher(const SCAN_Name&, + Algorithm_Factory&) const; + + StreamCipher* find_stream_cipher(const SCAN_Name&, + Algorithm_Factory&) const; + + HashFunction* find_hash(const SCAN_Name& reqeust, + Algorithm_Factory&) const; + + MessageAuthenticationCode* find_mac(const SCAN_Name& reqeust, + Algorithm_Factory&) const; + }; + +} + +#endif diff --git a/old/botan/build/botan/def_powm.h b/old/botan/build/botan/def_powm.h new file mode 100644 index 0000000..472c865 --- /dev/null +++ b/old/botan/build/botan/def_powm.h @@ -0,0 +1,64 @@ +/* +* Modular Exponentiation +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DEFAULT_MODEXP_H__ +#define BOTAN_DEFAULT_MODEXP_H__ + +#include <botan/pow_mod.h> +#include <botan/reducer.h> +#include <vector> + +namespace Botan { + +/* +* Fixed Window Exponentiator +*/ +class BOTAN_DLL Fixed_Window_Exponentiator : public Modular_Exponentiator + { + public: + void set_exponent(const BigInt&); + void set_base(const BigInt&); + BigInt execute() const; + + Modular_Exponentiator* copy() const + { return new Fixed_Window_Exponentiator(*this); } + + Fixed_Window_Exponentiator(const BigInt&, Power_Mod::Usage_Hints); + private: + Modular_Reducer reducer; + BigInt exp; + u32bit window_bits; + std::vector<BigInt> g; + Power_Mod::Usage_Hints hints; + }; + +/* +* Montgomery Exponentiator +*/ +class BOTAN_DLL Montgomery_Exponentiator : public Modular_Exponentiator + { + public: + void set_exponent(const BigInt&); + void set_base(const BigInt&); + BigInt execute() const; + + Modular_Exponentiator* copy() const + { return new Montgomery_Exponentiator(*this); } + + Montgomery_Exponentiator(const BigInt&, Power_Mod::Usage_Hints); + private: + BigInt exp, modulus; + BigInt R2, R_mod; + std::vector<BigInt> g; + word mod_prime; + u32bit mod_words, exp_bits, window_bits; + Power_Mod::Usage_Hints hints; + }; + +} + +#endif diff --git a/old/botan/build/botan/defalloc.h b/old/botan/build/botan/defalloc.h new file mode 100644 index 0000000..627e8df --- /dev/null +++ b/old/botan/build/botan/defalloc.h @@ -0,0 +1,43 @@ +/* +* Basic Allocators +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BASIC_ALLOC_H__ +#define BOTAN_BASIC_ALLOC_H__ + +#include <botan/mem_pool.h> + +namespace Botan { + +/* +* Malloc Allocator +*/ +class BOTAN_DLL Malloc_Allocator : public Allocator + { + public: + void* allocate(u32bit); + void deallocate(void*, u32bit); + + std::string type() const { return "malloc"; } + }; + +/* +* Locking Allocator +*/ +class BOTAN_DLL Locking_Allocator : public Pooling_Allocator + { + public: + Locking_Allocator(Mutex* m) : Pooling_Allocator(m) {} + + std::string type() const { return "locking"; } + private: + void* alloc_block(u32bit); + void dealloc_block(void*, u32bit); + }; + +} + +#endif diff --git a/old/botan/build/botan/der_enc.h b/old/botan/build/botan/der_enc.h new file mode 100644 index 0000000..23b5297 --- /dev/null +++ b/old/botan/build/botan/der_enc.h @@ -0,0 +1,91 @@ +/* +* DER Encoder +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DER_ENCODER_H__ +#define BOTAN_DER_ENCODER_H__ + +#include <botan/asn1_int.h> +#include <vector> + +namespace Botan { + +/* +* General DER Encoding Object +*/ +class BOTAN_DLL DER_Encoder + { + public: + SecureVector<byte> get_contents(); + + DER_Encoder& start_cons(ASN1_Tag, ASN1_Tag = UNIVERSAL); + DER_Encoder& end_cons(); + + DER_Encoder& start_explicit(u16bit); + DER_Encoder& end_explicit(); + + DER_Encoder& raw_bytes(const byte[], u32bit); + DER_Encoder& raw_bytes(const MemoryRegion<byte>&); + + DER_Encoder& encode_null(); + DER_Encoder& encode(bool); + DER_Encoder& encode(u32bit); + DER_Encoder& encode(const class BigInt&); + DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag); + DER_Encoder& encode(const byte[], u32bit, ASN1_Tag); + + DER_Encoder& encode(bool, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& encode(u32bit, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& encode(const class BigInt&, ASN1_Tag, + ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag, + ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + DER_Encoder& encode(const byte[], u32bit, ASN1_Tag, + ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); + + template<typename T> + DER_Encoder& encode_optional(const T& value, const T& default_value) + { + if(value != default_value) + encode(value); + return (*this); + } + + template<typename T> + DER_Encoder& encode_list(const std::vector<T>& values) + { + for(u32bit j = 0; j != values.size(); ++j) + encode(values[j]); + return (*this); + } + + DER_Encoder& encode(const class ASN1_Object&); + DER_Encoder& encode_if(bool, DER_Encoder&); + + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], u32bit); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const MemoryRegion<byte>&); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const std::string&); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, byte); + private: + class DER_Sequence + { + public: + ASN1_Tag tag_of() const; + SecureVector<byte> get_contents(); + void add_bytes(const byte[], u32bit); + DER_Sequence(ASN1_Tag, ASN1_Tag); + private: + ASN1_Tag type_tag, class_tag; + SecureVector<byte> contents; + std::vector< SecureVector<byte> > set_contents; + }; + SecureVector<byte> contents; + std::vector<DER_Sequence> subsequences; + }; + +} + +#endif diff --git a/old/botan/build/botan/des.h b/old/botan/build/botan/des.h new file mode 100644 index 0000000..6fa59de --- /dev/null +++ b/old/botan/build/botan/des.h @@ -0,0 +1,70 @@ +/* +* DES +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DES_H__ +#define BOTAN_DES_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* DES +*/ +class BOTAN_DLL DES : public BlockCipher + { + public: + void clear() throw() { round_key.clear(); } + std::string name() const { return "DES"; } + BlockCipher* clone() const { return new DES; } + DES() : BlockCipher(8, 8) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u32bit, 32> round_key; + }; + +/* +* Triple DES +*/ +class BOTAN_DLL TripleDES : public BlockCipher + { + public: + void clear() throw() { round_key.clear(); } + std::string name() const { return "TripleDES"; } + BlockCipher* clone() const { return new TripleDES; } + TripleDES() : BlockCipher(8, 16, 24, 8) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u32bit, 96> round_key; + }; + +/* +* DES Tables +*/ +extern const u32bit DES_SPBOX1[256]; +extern const u32bit DES_SPBOX2[256]; +extern const u32bit DES_SPBOX3[256]; +extern const u32bit DES_SPBOX4[256]; +extern const u32bit DES_SPBOX5[256]; +extern const u32bit DES_SPBOX6[256]; +extern const u32bit DES_SPBOX7[256]; +extern const u32bit DES_SPBOX8[256]; + +extern const u64bit DES_IPTAB1[256]; +extern const u64bit DES_IPTAB2[256]; +extern const u64bit DES_FPTAB1[256]; +extern const u64bit DES_FPTAB2[256]; + +} + +#endif diff --git a/old/botan/build/botan/desx.h b/old/botan/build/botan/desx.h new file mode 100644 index 0000000..49ecc24 --- /dev/null +++ b/old/botan/build/botan/desx.h @@ -0,0 +1,35 @@ +/* +* DESX +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DESX_H__ +#define BOTAN_DESX_H__ + +#include <botan/des.h> + +namespace Botan { + +/* +* DESX +*/ +class BOTAN_DLL DESX : public BlockCipher + { + public: + void clear() throw() { des.clear(); K1.clear(); K2.clear(); } + std::string name() const { return "DESX"; } + BlockCipher* clone() const { return new DESX; } + DESX() : BlockCipher(8, 24) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + SecureBuffer<byte, 8> K1, K2; + DES des; + }; + +} + +#endif diff --git a/old/botan/build/botan/dh.h b/old/botan/build/botan/dh.h new file mode 100644 index 0000000..fa558bc --- /dev/null +++ b/old/botan/build/botan/dh.h @@ -0,0 +1,80 @@ +/* +* Diffie-Hellman +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DIFFIE_HELLMAN_H__ +#define BOTAN_DIFFIE_HELLMAN_H__ + +#include <botan/dl_algo.h> +#include <botan/dh_core.h> + +namespace Botan { + +/** +* This class represents Diffie-Hellman public keys. +*/ +class BOTAN_DLL DH_PublicKey : public virtual DL_Scheme_PublicKey + { + public: + std::string algo_name() const { return "DH"; } + + MemoryVector<byte> public_value() const; + u32bit max_input_bits() const; + + DL_Group::Format group_format() const { return DL_Group::ANSI_X9_42; } + + /** + * Construct an uninitialized key. Use this constructor if you wish + * to decode an encoded key into the new instance. + */ + DH_PublicKey() {} + + /** + * Construct a public key with the specified parameters. + * @param grp the DL group to use in the key + * @param y the public value y + */ + DH_PublicKey(const DL_Group& grp, const BigInt& y); + private: + void X509_load_hook(); + }; + +/** +* This class represents Diffie-Hellman private keys. +*/ +class BOTAN_DLL DH_PrivateKey : public DH_PublicKey, + public PK_Key_Agreement_Key, + public virtual DL_Scheme_PrivateKey + { + public: + SecureVector<byte> derive_key(const byte other[], u32bit length) const; + SecureVector<byte> derive_key(const DH_PublicKey& other) const; + SecureVector<byte> derive_key(const BigInt& other) const; + + MemoryVector<byte> public_value() const; + + /** + * Construct an uninitialized key. Use this constructor if you wish + * to decode an encoded key into the new instance. + */ + DH_PrivateKey() {} + + /** + * Construct a private key with predetermined value. + * @param rng random number generator to use + * @param grp the group to be used in the key + * @param x the key's secret value (or if zero, generate a new key) + */ + DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& grp, + const BigInt& x = 0); + private: + void PKCS8_load_hook(RandomNumberGenerator& rng, bool = false); + DH_Core core; + }; + +} + +#endif diff --git a/old/botan/build/botan/dh_core.h b/old/botan/build/botan/dh_core.h new file mode 100644 index 0000000..91b50a2 --- /dev/null +++ b/old/botan/build/botan/dh_core.h @@ -0,0 +1,38 @@ +/* +* DH Core +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DH_CORE_H__ +#define BOTAN_DH_CORE_H__ + +#include <botan/dh_op.h> +#include <botan/blinding.h> + +namespace Botan { + +/* +* DH Core +*/ +class BOTAN_DLL DH_Core + { + public: + BigInt agree(const BigInt&) const; + + DH_Core& operator=(const DH_Core&); + + DH_Core() { op = 0; } + DH_Core(const DH_Core&); + DH_Core(RandomNumberGenerator& rng, + const DL_Group&, const BigInt&); + ~DH_Core() { delete op; } + private: + DH_Operation* op; + Blinder blinder; + }; + +} + +#endif diff --git a/old/botan/build/botan/dh_op.h b/old/botan/build/botan/dh_op.h new file mode 100644 index 0000000..50f3d78 --- /dev/null +++ b/old/botan/build/botan/dh_op.h @@ -0,0 +1,45 @@ +/* +* DH Operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DH_OPS_H__ +#define BOTAN_DH_OPS_H__ + +#include <botan/dl_group.h> +#include <botan/reducer.h> +#include <botan/pow_mod.h> + +namespace Botan { + +/* +* DH Operation Interface +*/ +class BOTAN_DLL DH_Operation + { + public: + virtual BigInt agree(const BigInt&) const = 0; + virtual DH_Operation* clone() const = 0; + virtual ~DH_Operation() {} + }; + +/* +* Botan's Default DH Operation +*/ +class BOTAN_DLL Default_DH_Op : public DH_Operation + { + public: + BigInt agree(const BigInt& i) const { return powermod_x_p(i); } + DH_Operation* clone() const { return new Default_DH_Op(*this); } + + Default_DH_Op(const DL_Group& group, const BigInt& x) : + powermod_x_p(x, group.get_p()) {} + private: + Fixed_Exponent_Power_Mod powermod_x_p; + }; + +} + +#endif diff --git a/old/botan/build/botan/divide.h b/old/botan/build/botan/divide.h new file mode 100644 index 0000000..9445b13 --- /dev/null +++ b/old/botan/build/botan/divide.h @@ -0,0 +1,19 @@ +/* +* Division +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DIVISON_ALGORITHM_H__ +#define BOTAN_DIVISON_ALGORITHM_H__ + +#include <botan/bigint.h> + +namespace Botan { + +void BOTAN_DLL divide(const BigInt&, const BigInt&, BigInt&, BigInt&); + +} + +#endif diff --git a/old/botan/build/botan/dl_algo.h b/old/botan/build/botan/dl_algo.h new file mode 100644 index 0000000..256ce96 --- /dev/null +++ b/old/botan/build/botan/dl_algo.h @@ -0,0 +1,116 @@ +/* +* DL Scheme +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DL_ALGO_H__ +#define BOTAN_DL_ALGO_H__ + +#include <botan/dl_group.h> +#include <botan/x509_key.h> +#include <botan/pkcs8.h> +#include <botan/rng.h> + +namespace Botan { + +/** +* This class represents discrete logarithm (DL) public keys. +*/ +class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key + { + public: + bool check_key(RandomNumberGenerator& rng, bool) const; + + /** + * Get the DL domain parameters of this key. + * @return the DL domain parameters of this key + */ + const DL_Group& get_domain() const { return group; } + + /** + * Get the public value y with y = g^x mod p where x is the secret key. + */ + const BigInt& get_y() const { return y; } + + /** + * Get the prime p of the underlying DL group. + * @return the prime p + */ + const BigInt& group_p() const { return group.get_p(); } + + /** + * Get the prime q of the underlying DL group. + * @return the prime q + */ + const BigInt& group_q() const { return group.get_q(); } + + /** + * Get the generator g of the underlying DL group. + * @return the generator g + */ + const BigInt& group_g() const { return group.get_g(); } + + /** + * Get the underlying groups encoding format. + * @return the encoding format + */ + virtual DL_Group::Format group_format() const = 0; + + /** + * Get an X509 encoder for this key. + * @return an encoder usable to encode this key. + */ + X509_Encoder* x509_encoder() const; + + /** + * Get an X509 decoder for this key. + * @return an decoder usable to decode a DL key and store the + * values in this instance. + */ + X509_Decoder* x509_decoder(); + protected: + BigInt y; + DL_Group group; + private: + virtual void X509_load_hook() {} + }; + +/** +* This class represents discrete logarithm (DL) private keys. +*/ +class BOTAN_DLL DL_Scheme_PrivateKey : public virtual DL_Scheme_PublicKey, + public virtual Private_Key + { + public: + bool check_key(RandomNumberGenerator& rng, bool) const; + + /** + * Get the secret key x. + * @return the secret key + */ + const BigInt& get_x() const { return x; } + + /** + * Get an PKCS#8 encoder for this key. + * @return an encoder usable to encode this key. + */ + PKCS8_Encoder* pkcs8_encoder() const; + + /** + * Get an PKCS#8 decoder for this key. + * @param rng the rng to use + * @return an decoder usable to decode a DL key and store the + * values in this instance. + */ + PKCS8_Decoder* pkcs8_decoder(RandomNumberGenerator& rng); + protected: + BigInt x; + private: + virtual void PKCS8_load_hook(RandomNumberGenerator&, bool = false) {} + }; + +} + +#endif diff --git a/old/botan/build/botan/dl_group.h b/old/botan/build/botan/dl_group.h new file mode 100644 index 0000000..a84a85f --- /dev/null +++ b/old/botan/build/botan/dl_group.h @@ -0,0 +1,162 @@ +/* +* Discrete Logarithm Group +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DL_PARAM_H__ +#define BOTAN_DL_PARAM_H__ + +#include <botan/bigint.h> +#include <botan/data_src.h> + +namespace Botan { + +/** +* This class represents discrete logarithm groups. It holds a prime p, +* a prime q = (p-1)/2 and g = x^((p-1)/q) mod p. +*/ +class BOTAN_DLL DL_Group + { + public: + /** + * Get the prime p. + * @return the prime p + */ + const BigInt& get_p() const; + + /** + * Get the prime q. + * @return the prime q + */ + const BigInt& get_q() const; + + /** + * Get the base g. + * @return the base g + */ + const BigInt& get_g() const; + + /** + * The DL group encoding format variants. + */ + enum Format { + ANSI_X9_42, + ANSI_X9_57, + PKCS_3, + + DSA_PARAMETERS = ANSI_X9_57, + DH_PARAMETERS = ANSI_X9_42, + X942_DH_PARAMETERS = ANSI_X9_42, + PKCS3_DH_PARAMETERS = PKCS_3 + }; + + /** + * Determine the prime creation for DL groups. + */ + enum PrimeType { Strong, Prime_Subgroup, DSA_Kosherizer }; + + /** + * Perform validity checks on the group. + * @param rng the rng to use + * @param strong whether to perform stronger by lengthier tests + * @return true if the object is consistent, false otherwise + */ + bool verify_group(RandomNumberGenerator& rng, bool strong) const; + + /** + * Encode this group into a string using PEM encoding. + * @param format the encoding format + * @return the string holding the PEM encoded group + */ + std::string PEM_encode(Format format) const; + + /** + * Encode this group into a string using DER encoding. + * @param format the encoding format + * @return the string holding the DER encoded group + */ + SecureVector<byte> DER_encode(Format format) const; + + /** + * Decode a DER/BER encoded group into this instance. + * @param src a DataSource providing the encoded group + * @param format the format of the encoded group + */ + void BER_decode(DataSource& src, Format format); + + /** + * Decode a PEM encoded group into this instance. + * @param src a DataSource providing the encoded group + */ + void PEM_decode(DataSource& src); + + /** + * Construct a DL group with uninitialized internal value. + * Use this constructor is you wish to set the groups values + * from a DER or PEM encoded group. + */ + DL_Group(); + + /** + * Construct a DL group that is registered in the configuration. + * @param name the name that is configured in the global configuration + * for the desired group. If no configuration file is specified, + * the default values from the file policy.cpp will be used. For instance, + * use "modp/ietf/768" as name. + */ + DL_Group(const std::string& name); + + /** + * Create a new group randomly. + * @param rng the random number generator to use + * @param type specifies how the creation of primes p and q shall + * be performed. If type=Strong, then p will be determined as a + * safe prime, and q will be chosen as (p-1)/2. If + * type=Prime_Subgroup and qbits = 0, then the size of q will be + * determined according to the estimated difficulty of the DL + * problem. If type=DSA_Kosherizer, DSA primes will be created. + * @param pbits the number of bits of p + * @param qbits the number of bits of q. Leave it as 0 to have + * the value determined according to pbits. + */ + DL_Group(RandomNumberGenerator& rng, PrimeType type, + u32bit pbits, u32bit qbits = 0); + + /** + * Create a DSA group with a given seed. + * @param rng the random number generator to use + * @param seed the seed to use to create the random primes + * @param pbits the desired bit size of the prime p + * @param qbits the desired bit size of the prime q. + */ + DL_Group(RandomNumberGenerator& rng, const MemoryRegion<byte>& seed, + u32bit pbits = 1024, u32bit qbits = 0); + + /** + * Create a DL group. The prime q will be determined according to p. + * @param p the prime p + * @param g the base g + */ + DL_Group(const BigInt& p, const BigInt& g); + + /** + * Create a DL group. + * @param p the prime p + * @param q the prime q + * @param g the base g + */ + DL_Group(const BigInt& p, const BigInt& q, const BigInt& g); + private: + static BigInt make_dsa_generator(const BigInt&, const BigInt&); + + void init_check() const; + void initialize(const BigInt&, const BigInt&, const BigInt&); + bool initialized; + BigInt p, q, g; + }; + +} + +#endif diff --git a/old/botan/build/botan/dlies.h b/old/botan/build/botan/dlies.h new file mode 100644 index 0000000..88a22b9 --- /dev/null +++ b/old/botan/build/botan/dlies.h @@ -0,0 +1,69 @@ +/* +* DLIES +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DLIES_H__ +#define BOTAN_DLIES_H__ + +#include <botan/pubkey.h> +#include <botan/mac.h> +#include <botan/kdf.h> + +namespace Botan { + +/* +* DLIES Encryption +*/ +class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor + { + public: + DLIES_Encryptor(const PK_Key_Agreement_Key&, + KDF* kdf, + MessageAuthenticationCode* mac, + u32bit mac_key_len = 20); + + ~DLIES_Encryptor(); + + void set_other_key(const MemoryRegion<byte>&); + private: + SecureVector<byte> enc(const byte[], u32bit, + RandomNumberGenerator&) const; + u32bit maximum_input_size() const; + + const PK_Key_Agreement_Key& key; + SecureVector<byte> other_key; + + KDF* kdf; + MessageAuthenticationCode* mac; + u32bit mac_keylen; + }; + +/* +* DLIES Decryption +*/ +class BOTAN_DLL DLIES_Decryptor : public PK_Decryptor + { + public: + DLIES_Decryptor(const PK_Key_Agreement_Key&, + KDF* kdf, + MessageAuthenticationCode* mac, + u32bit mac_key_len = 20); + + ~DLIES_Decryptor(); + + private: + SecureVector<byte> dec(const byte[], u32bit) const; + + const PK_Key_Agreement_Key& key; + + KDF* kdf; + MessageAuthenticationCode* mac; + u32bit mac_keylen; + }; + +} + +#endif diff --git a/old/botan/build/botan/dsa.h b/old/botan/build/botan/dsa.h new file mode 100644 index 0000000..4c9b708 --- /dev/null +++ b/old/botan/build/botan/dsa.h @@ -0,0 +1,62 @@ +/* +* DSA +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DSA_H__ +#define BOTAN_DSA_H__ + +#include <botan/dl_algo.h> +#include <botan/dsa_core.h> + +namespace Botan { + +/* +* DSA Public Key +*/ +class BOTAN_DLL DSA_PublicKey : public PK_Verifying_wo_MR_Key, + public virtual DL_Scheme_PublicKey + { + public: + std::string algo_name() const { return "DSA"; } + + DL_Group::Format group_format() const { return DL_Group::ANSI_X9_57; } + u32bit message_parts() const { return 2; } + u32bit message_part_size() const; + + bool verify(const byte[], u32bit, const byte[], u32bit) const; + u32bit max_input_bits() const; + + DSA_PublicKey() {} + DSA_PublicKey(const DL_Group&, const BigInt&); + protected: + DSA_Core core; + private: + void X509_load_hook(); + }; + +/* +* DSA Private Key +*/ +class BOTAN_DLL DSA_PrivateKey : public DSA_PublicKey, + public PK_Signing_Key, + public virtual DL_Scheme_PrivateKey + { + public: + SecureVector<byte> sign(const byte[], u32bit, + RandomNumberGenerator& rng) const; + + bool check_key(RandomNumberGenerator& rng, bool) const; + + DSA_PrivateKey() {} + DSA_PrivateKey(RandomNumberGenerator&, const DL_Group&, + const BigInt& = 0); + private: + void PKCS8_load_hook(RandomNumberGenerator& rng, bool = false); + }; + +} + +#endif diff --git a/old/botan/build/botan/dsa_core.h b/old/botan/build/botan/dsa_core.h new file mode 100644 index 0000000..8bb1621 --- /dev/null +++ b/old/botan/build/botan/dsa_core.h @@ -0,0 +1,37 @@ +/* +* DSA Core +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DSA_CORE_H__ +#define BOTAN_DSA_CORE_H__ + +#include <botan/dsa_op.h> +#include <botan/dl_group.h> + +namespace Botan { + +/* +* DSA Core +*/ +class BOTAN_DLL DSA_Core + { + public: + SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const; + bool verify(const byte[], u32bit, const byte[], u32bit) const; + + DSA_Core& operator=(const DSA_Core&); + + DSA_Core() { op = 0; } + DSA_Core(const DSA_Core&); + DSA_Core(const DL_Group&, const BigInt&, const BigInt& = 0); + ~DSA_Core() { delete op; } + private: + DSA_Operation* op; + }; + +} + +#endif diff --git a/old/botan/build/botan/dsa_op.h b/old/botan/build/botan/dsa_op.h new file mode 100644 index 0000000..0b112c6 --- /dev/null +++ b/old/botan/build/botan/dsa_op.h @@ -0,0 +1,53 @@ +/* +* DSA Operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_DSA_OPS_H__ +#define BOTAN_DSA_OPS_H__ + +#include <botan/numthry.h> +#include <botan/pow_mod.h> +#include <botan/reducer.h> +#include <botan/dl_group.h> + +namespace Botan { + +/* +* DSA Operation +*/ +class BOTAN_DLL DSA_Operation + { + public: + virtual bool verify(const byte[], u32bit, + const byte[], u32bit) const = 0; + virtual SecureVector<byte> sign(const byte[], u32bit, + const BigInt&) const = 0; + virtual DSA_Operation* clone() const = 0; + virtual ~DSA_Operation() {} + }; + +/* +* Botan's Default DSA Operation +*/ +class BOTAN_DLL Default_DSA_Op : public DSA_Operation + { + public: + bool verify(const byte[], u32bit, const byte[], u32bit) const; + SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const; + + DSA_Operation* clone() const { return new Default_DSA_Op(*this); } + + Default_DSA_Op(const DL_Group&, const BigInt&, const BigInt&); + private: + const BigInt x, y; + const DL_Group group; + Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; + Modular_Reducer mod_p, mod_q; + }; + +} + +#endif diff --git a/old/botan/build/botan/eac_asn_obj.h b/old/botan/build/botan/eac_asn_obj.h new file mode 100644 index 0000000..3e70f6b --- /dev/null +++ b/old/botan/build/botan/eac_asn_obj.h @@ -0,0 +1,244 @@ +/* +* EAC ASN.1 Objects +* (C) 2007-2008 FlexSecure GmbH +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAC_ASN1_OBJ_H__ +#define BOTAN_EAC_ASN1_OBJ_H__ + +#include <botan/asn1_obj.h> +#include <vector> +#include <map> + +namespace Botan { + +/** +* This class represents CVC EAC Time objects. +* It only models year, month and day. Only limited sanity checks of +* the inputted date value are performed. +*/ +class BOTAN_DLL EAC_Time : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + /** + * Get a this objects value as a string. + * @return the date string + */ + std::string as_string() const; + + /** + * Get a this objects value as a readable formatted string. + * @return the date string + */ + std::string readable_string() const; + + /** + * Find out whether this object's values have been set. + * @return true if this object's internal values are set + */ + bool time_is_set() const; + + /** + * Compare this to another EAC_Time object. + * @return -1 if this object's date is earlier than + * other, +1 in the opposite case, and 0 if both dates are + * equal. + */ + s32bit cmp(const EAC_Time& other) const; + + /** + * Set this' value by a string value. + * @param str a string in the format "yyyy mm dd", + * e.g. "2007 08 01" + */ + void set_to(const std::string& str); + //void set_to(const std::string&, ASN1_Tag); + + /** + * Add the specified number of years to this. + * @param years the number of years to add + */ + void add_years(u32bit years); + + /** + * Add the specified number of months to this. + * @param months the number of months to add + */ + void add_months(u32bit months); + + /** + * Get the year value of this objects. + * @return the year value + */ + u32bit get_year() const; + + /** + * Get the month value of this objects. + * @return the month value + */ + u32bit get_month() const; + + /** + * Get the day value of this objects. + * @return the day value + */ + u32bit get_day() const; + + EAC_Time(u64bit, ASN1_Tag t = ASN1_Tag(0)); + //EAC_Time(const std::string& = ""); + EAC_Time(const std::string&, ASN1_Tag = ASN1_Tag(0)); + EAC_Time(u32bit year, u32bit month, u32bit day, ASN1_Tag = ASN1_Tag(0)); + + virtual ~EAC_Time() {} + private: + SecureVector<byte> encoded_eac_time() const; + bool passes_sanity_check() const; + u32bit year, month, day; + ASN1_Tag tag; + }; + +/** +* This class represents CVC CEDs. Only limited sanity checks of +* the inputted date value are performed. +*/ +class BOTAN_DLL ASN1_Ced : public EAC_Time + { + public: + /** + * Construct a CED from a string value. + * @param str a string in the format "yyyy mm dd", + * e.g. "2007 08 01" + */ + ASN1_Ced(std::string const& str = ""); + + /** + * Construct a CED from a timer value. + * @param time the number of seconds elapsed midnight, 1st + * January 1970 GMT (or 7pm, 31st December 1969 EST) up to the + * desired date + */ + ASN1_Ced(u64bit time); + + /** + * Copy constructor (for general EAC_Time objects). + * @param other the object to copy from + */ + ASN1_Ced(EAC_Time const& other); + //ASN1_Ced(ASN1_Cex const& cex); + }; + + +/** +* This class represents CVC CEXs. Only limited sanity checks of +* the inputted date value are performed. +*/ +class BOTAN_DLL ASN1_Cex : public EAC_Time + { + public: + /** + * Construct a CED from a string value. + * @param str a string in the format "yyyy mm dd", + * e.g. "2007 08 01" + */ + ASN1_Cex(std::string const& str=""); + + /** + * Construct a CED from a timer value. + * @param time the number of seconds elapsed + * midnight, 1st + * January 1970 GMT (or 7pm, 31st December 1969 EST) + * up to the desired date + */ + ASN1_Cex(u64bit time); + + /** + * Copy constructor (for general EAC_Time objects). + * @param other the object to copy from + */ + ASN1_Cex(EAC_Time const& other); + //ASN1_Cex(ASN1_Ced const& ced); + }; + +/** +* Base class for car/chr of cv certificates. +*/ +class BOTAN_DLL ASN1_EAC_String: public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + /** + * Get this objects string value. + * @return the string value + */ + std::string value() const; + + /** + * Get this objects string value. + * @return the string value in iso8859 encoding + */ + std::string iso_8859() const; + + ASN1_Tag tagging() const; + ASN1_EAC_String(const std::string& str, ASN1_Tag the_tag); + + virtual ~ASN1_EAC_String() {} + protected: + bool sanity_check() const; + private: + std::string iso_8859_str; + ASN1_Tag tag; + }; + +/** +* This class represents CARs of CVCs. (String tagged with 2) +*/ +class BOTAN_DLL ASN1_Car : public ASN1_EAC_String + { + public: + /** + * Create a CAR with the specified content. + * @param str the CAR value + */ + ASN1_Car(std::string const& str = ""); + }; + +/** +* This class represents CHRs of CVCs (tag 32) +*/ +class BOTAN_DLL ASN1_Chr : public ASN1_EAC_String + { + public: + /** + * Create a CHR with the specified content. + * @param str the CHR value + */ + ASN1_Chr(std::string const& str = ""); + }; + +/* +* Comparison Operations +*/ +bool operator==(const EAC_Time&, const EAC_Time&); +bool operator!=(const EAC_Time&, const EAC_Time&); +bool operator<=(const EAC_Time&, const EAC_Time&); +bool operator>=(const EAC_Time&, const EAC_Time&); +bool operator>(const EAC_Time&, const EAC_Time&); +bool operator<(const EAC_Time&, const EAC_Time&); + +bool operator==(const ASN1_EAC_String&, const ASN1_EAC_String&); +inline bool operator!=(const ASN1_EAC_String& lhs, const ASN1_EAC_String& rhs) + { + return !(lhs == rhs); + } + +} + +#endif diff --git a/old/botan/build/botan/eac_obj.h b/old/botan/build/botan/eac_obj.h new file mode 100644 index 0000000..04afd7e --- /dev/null +++ b/old/botan/build/botan/eac_obj.h @@ -0,0 +1,131 @@ +/* +* EAC1_1 objects +* (C) 2008 Falko Strenzke +* strenzke@flexsecure.de +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAC_OBJ_H__ +#define BOTAN_EAC_OBJ_H__ + +#include <botan/pubkey.h> +#include <botan/x509_key.h> +#include <botan/signed_obj.h> +#include <botan/pubkey_enums.h> +#include <botan/pubkey.h> +#include <botan/parsing.h> +#include <botan/pem.h> +#include <botan/oids.h> +#include <botan/look_pk.h> +#include <botan/ecdsa_sig.h> +#include <string> + +namespace Botan { + +const std::string eac_cvc_emsa("EMSA1_BSI"); + +/* +* TR03110 v1.1 EAC CV Certificate +*/ +template<typename Derived> // CRTP is used enable the call sequence: +class BOTAN_DLL EAC1_1_obj : public EAC_Signed_Object + { + // data members first: + protected: + + ECDSA_Signature m_sig; + + // member functions here: + public: + /** + * Return the signature as a concatenation of the encoded parts. + * @result the concatenated signature + */ + SecureVector<byte> get_concat_sig() const; + + /** + * Verify the signature of this objects. + * @param pub_key the public key to verify the signature with + * @result true if the verification succeeded + */ + virtual bool check_signature(Public_Key& pub_key) const; + + protected: + void init(SharedPtrConverter<DataSource> in); + + static SecureVector<byte> make_signature(PK_Signer* signer, + const MemoryRegion<byte>& tbs_bits, + RandomNumberGenerator& rng); + + virtual ~EAC1_1_obj<Derived>(){} + + }; + +template<typename Derived> SecureVector<byte> EAC1_1_obj<Derived>::get_concat_sig() const + { + return m_sig.get_concatenation(); + } + +template<typename Derived> SecureVector<byte> +EAC1_1_obj<Derived>::make_signature(PK_Signer* signer, + const MemoryRegion<byte>& tbs_bits, + RandomNumberGenerator& rng) + { + // this is the signature as a der sequence + SecureVector<byte> seq_sig = signer->sign_message(tbs_bits, rng); + + ECDSA_Signature sig(decode_seq(seq_sig)); + SecureVector<byte> concat_sig(sig.get_concatenation()); + return concat_sig; + } + +template<typename Derived> void EAC1_1_obj<Derived>::init(SharedPtrConverter<DataSource> in) + { + try + { + Derived::decode_info(in.get_shared(), tbs_bits, m_sig); + } + catch(Decoding_Error) + { + throw Decoding_Error(PEM_label_pref + " decoding failed"); + } + } + +template<typename Derived> +bool EAC1_1_obj<Derived>::check_signature(Public_Key& pub_key) const + { + try + { + std::vector<std::string> sig_info = + split_on(OIDS::lookup(sig_algo.oid), '/'); + + if(sig_info.size() != 2 || sig_info[0] != pub_key.algo_name()) + { + return false; + } + + std::string padding = sig_info[1]; + Signature_Format format = + (pub_key.message_parts() >= 2) ? DER_SEQUENCE : IEEE_1363; + + if(!dynamic_cast<PK_Verifying_wo_MR_Key*>(&pub_key)) + return false; + + std::auto_ptr<ECDSA_Signature_Encoder> enc(new ECDSA_Signature_Encoder(&m_sig)); + SecureVector<byte> seq_sig = enc->signature_bits(); + SecureVector<byte> to_sign = tbs_data(); + + PK_Verifying_wo_MR_Key& sig_key = dynamic_cast<PK_Verifying_wo_MR_Key&>(pub_key); + std::auto_ptr<PK_Verifier> verifier(get_pk_verifier(sig_key, padding, format)); + return verifier->verify_message(to_sign, seq_sig); + } + catch(...) + { + return false; + } + } + +} + +#endif diff --git a/old/botan/build/botan/eax.h b/old/botan/build/botan/eax.h new file mode 100644 index 0000000..1bb2e51 --- /dev/null +++ b/old/botan/build/botan/eax.h @@ -0,0 +1,85 @@ +/* +* EAX Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAX_H__ +#define BOTAN_EAX_H__ + +#include <botan/basefilt.h> +#include <botan/block_cipher.h> +#include <botan/mac.h> + +namespace Botan { + +/* +* EAX Base Class +*/ +class BOTAN_DLL EAX_Base : public Keyed_Filter + { + public: + void set_key(const SymmetricKey&); + void set_iv(const InitializationVector&); + void set_header(const byte[], u32bit); + std::string name() const; + + bool valid_keylength(u32bit) const; + + ~EAX_Base() { delete cipher; delete mac; } + protected: + EAX_Base(BlockCipher*, u32bit); + void start_msg(); + void increment_counter(); + + const u32bit TAG_SIZE, BLOCK_SIZE; + BlockCipher* cipher; + MessageAuthenticationCode* mac; + SecureVector<byte> nonce_mac, header_mac, state, buffer; + u32bit position; + }; + +/* +* EAX Encryption +*/ +class BOTAN_DLL EAX_Encryption : public EAX_Base + { + public: + EAX_Encryption(BlockCipher* ciph, u32bit tag_size = 0) : + EAX_Base(ciph, tag_size) {} + + EAX_Encryption(BlockCipher* ciph, const SymmetricKey& key, + const InitializationVector& iv, + u32bit tag_size) : EAX_Base(ciph, tag_size) + { + set_key(key); + set_iv(iv); + } + private: + void write(const byte[], u32bit); + void end_msg(); + }; + +/* +* EAX Decryption +*/ +class BOTAN_DLL EAX_Decryption : public EAX_Base + { + public: + EAX_Decryption(BlockCipher* ciph, u32bit tag_size = 0); + + EAX_Decryption(BlockCipher* ciph, const SymmetricKey& key, + const InitializationVector& iv, + u32bit tag_size = 0); + private: + void write(const byte[], u32bit); + void do_write(const byte[], u32bit); + void end_msg(); + SecureVector<byte> queue; + u32bit queue_start, queue_end; + }; + +} + +#endif diff --git a/old/botan/build/botan/ec_dompar.h b/old/botan/build/botan/ec_dompar.h new file mode 100644 index 0000000..47971d8 --- /dev/null +++ b/old/botan/build/botan/ec_dompar.h @@ -0,0 +1,121 @@ +/* +* ECDSA Domain Parameters +* (C) 2007 Falko Strenzke, FlexSecure GmbH +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECC_DOMAIN_PARAMETERS_H__ +#define BOTAN_ECC_DOMAIN_PARAMETERS_H__ + +#include <botan/point_gfp.h> +#include <botan/gfp_element.h> +#include <botan/curve_gfp.h> +#include <botan/bigint.h> +#include <botan/der_enc.h> +#include <botan/ber_dec.h> +#include <botan/alg_id.h> +#include <botan/pubkey_enums.h> + +namespace Botan { + +/** +* This class represents elliptic curce domain parameters +*/ +class BOTAN_DLL EC_Domain_Params + { + public: + + /** + * Construct Domain paramers from specified parameters + * @param curve elliptic curve + * @param base_point a base point + * @param order the order of the base point + * @param cofactor the cofactor + */ + EC_Domain_Params(const CurveGFp& curve, + const PointGFp& base_point, + const BigInt& order, + const BigInt& cofactor); + + /** + * Return domain parameter curve + * @result domain parameter curve + */ + const CurveGFp& get_curve() const + { + return m_curve; + } + + /** + * Return domain parameter curve + * @result domain parameter curve + */ + const PointGFp& get_base_point() const + { + return m_base_point; + } + + /** + * Return the order of the base point + * @result order of the base point + */ + const BigInt& get_order() const + { + return m_order; + } + + /** + * Return the cofactor + * @result the cofactor + */ + const BigInt& get_cofactor() const + { + return m_cofactor; + } + + /** + * Return the OID of these domain parameters + * @result the OID + */ + std::string get_oid() const { return m_oid; } + + private: + friend EC_Domain_Params get_EC_Dom_Pars_by_oid(std::string oid); + + CurveGFp m_curve; + PointGFp m_base_point; + BigInt m_order; + BigInt m_cofactor; + std::string m_oid; + }; + +bool operator==(EC_Domain_Params const& lhs, EC_Domain_Params const& rhs); + +inline bool operator!=(const EC_Domain_Params& lhs, + const EC_Domain_Params& rhs) + { + return !(lhs == rhs); + } + +enum EC_dompar_enc { ENC_EXPLICIT = 0, ENC_IMPLICITCA = 1, ENC_OID = 2 }; + +SecureVector<byte> encode_der_ec_dompar(EC_Domain_Params const& dom_pars, + EC_dompar_enc enc_type); + +EC_Domain_Params decode_ber_ec_dompar(SecureVector<byte> const& encoded); + +/** +* Factory function, the only way to obtain EC domain parameters with +* an OID. The demanded OID has to be registered in the InSiTo +* configuration. Consult the file ec_dompar.cpp for the default +* configuration. +* @param oid the oid of the demanded EC domain parameters +* @result the EC domain parameters associated with the OID +*/ +EC_Domain_Params get_EC_Dom_Pars_by_oid(std::string oid); + +} + +#endif diff --git a/old/botan/build/botan/ecb.h b/old/botan/build/botan/ecb.h new file mode 100644 index 0000000..5230f9b --- /dev/null +++ b/old/botan/build/botan/ecb.h @@ -0,0 +1,73 @@ +/* +* ECB Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECB_H__ +#define BOTAN_ECB_H__ + +#include <botan/modebase.h> +#include <botan/mode_pad.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* ECB +*/ +class BOTAN_DLL ECB : public BlockCipherMode + { + protected: + ECB(BlockCipher* ciph, BlockCipherModePaddingMethod* pad) : + BlockCipherMode(ciph, "ECB", 0), padder(pad) {} + ~ECB() { delete padder; } + + std::string name() const; + BlockCipherModePaddingMethod* padder; + private: + bool valid_iv_size(u32bit) const; + }; + +/* +* ECB Encryption +*/ +class BOTAN_DLL ECB_Encryption : public ECB + { + public: + ECB_Encryption(BlockCipher* ciph, + BlockCipherModePaddingMethod* pad) : + ECB(ciph, pad) {} + + ECB_Encryption(BlockCipher* ciph, + BlockCipherModePaddingMethod* pad, + const SymmetricKey& key) : + ECB(ciph, pad) { set_key(key); } + private: + void write(const byte[], u32bit); + void end_msg(); + }; + +/* +* ECB Decryption +*/ +class BOTAN_DLL ECB_Decryption : public ECB + { + public: + ECB_Decryption(BlockCipher* ciph, + BlockCipherModePaddingMethod* pad) : + ECB(ciph, pad) {} + + ECB_Decryption(BlockCipher* ciph, + BlockCipherModePaddingMethod* pad, + const SymmetricKey& key) : + ECB(ciph, pad) { set_key(key); } + private: + void write(const byte[], u32bit); + void end_msg(); + }; + +} + +#endif diff --git a/old/botan/build/botan/ecc_key.h b/old/botan/build/botan/ecc_key.h new file mode 100644 index 0000000..0ca9a0e --- /dev/null +++ b/old/botan/build/botan/ecc_key.h @@ -0,0 +1,154 @@ +/* +* ECDSA +* (C) 2007 Falko Strenzke, FlexSecure GmbH +* Manuel Hartl, FlexSecure GmbH +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECC_PUBLIC_KEY_BASE_H__ +#define BOTAN_ECC_PUBLIC_KEY_BASE_H__ + +#include <botan/bigint.h> +#include <botan/curve_gfp.h> +#include <botan/pk_keys.h> +#include <botan/ec_dompar.h> +#include <botan/x509_key.h> +#include <botan/pkcs8.h> + +namespace Botan { + +/** +* This class represents abstract EC Public Keys. When encoding a key +* via an encoder that can be accessed via the corresponding member +* functions, the key will decide upon its internally stored encoding +* information whether to encode itself with or without domain +* parameters, or using the domain parameter oid. Furthermore, a public +* key without domain parameters can be decoded. In that case, it +* cannot be used for verification until its domain parameters are set +* by calling the corresponding member function. +*/ +class BOTAN_DLL EC_PublicKey : public virtual Public_Key + { + public: + + /** + * Tells whether this key knows his own domain parameters. + * @result true if the domain parameters are set, false otherwise + */ + bool domain_parameters_set(); + + /** + * Get the public point of this key. + * @throw Invalid_State is thrown if the + * domain parameters of this point are not set + * @result the public point of this key + */ + const PointGFp& public_point() const; + + /** + * Get the domain parameters of this key. + * @throw Invalid_State is thrown if the + * domain parameters of this point are not set + * @result the domain parameters of this key + */ + const EC_Domain_Params& domain_parameters() const; + + /** + * Set the domain parameter encoding to be used when encoding this key. + * @param enc the encoding to use + */ + void set_parameter_encoding(EC_dompar_enc enc); + + /** + * Get the domain parameter encoding to be used when encoding this key. + * @result the encoding to use + */ + inline int get_parameter_encoding() const + { + return m_param_enc; + } + + //ctors + EC_PublicKey() + : m_param_enc(ENC_EXPLICIT) + { + //assert(mp_dom_pars.get() == 0); + //assert(mp_public_point.get() == 0); + } + + /** + * Get an x509_encoder that can be used to encode this key. + * @result an x509_encoder for this key + */ + X509_Encoder* x509_encoder() const; + + /** + * Get an x509_decoder that can be used to decode a stored key into + * this key. + * @result an x509_decoder for this key + */ + X509_Decoder* x509_decoder(); + + /** + * Make sure that the public point and domain parameters of this key are set. + * @throw Invalid_State if either of the two data members is not set + */ + virtual void affirm_init() const; + + virtual ~EC_PublicKey() {} + protected: + virtual void X509_load_hook(); + + SecureVector<byte> m_enc_public_point; // stores the public point + + std::auto_ptr<EC_Domain_Params> mp_dom_pars; + std::auto_ptr<PointGFp> mp_public_point; + EC_dompar_enc m_param_enc; + }; + +/** +* This abstract class represents general EC Private Keys +*/ +class BOTAN_DLL EC_PrivateKey : public virtual EC_PublicKey, public virtual Private_Key + { + public: + + /** + * Get an PKCS#8 encoder that can be used to encoded this key. + * @result an PKCS#8 encoder for this key + */ + PKCS8_Encoder* pkcs8_encoder() const; + + /** + * Get an PKCS#8 decoder that can be used to decoded a stored key into + * this key. + * @result an PKCS#8 decoder for this key + */ + PKCS8_Decoder* pkcs8_decoder(RandomNumberGenerator&); + + /** + * Get the private key value of this key object. + * @result the private key value of this key object + */ + const BigInt& private_value() const; + + /** + * Make sure that the public key parts of this object are set + * (calls EC_PublicKey::affirm_init()) as well as the private key + * value. + * @throw Invalid_State if the above conditions are not satisfied + */ + virtual void affirm_init() const; + + virtual ~EC_PrivateKey() {} + protected: + virtual void PKCS8_load_hook(bool = false); + void generate_private_key(RandomNumberGenerator&); + BigInt m_private_value; + }; + +} + +#endif diff --git a/old/botan/build/botan/ecdsa.h b/old/botan/build/botan/ecdsa.h new file mode 100644 index 0000000..3794457 --- /dev/null +++ b/old/botan/build/botan/ecdsa.h @@ -0,0 +1,145 @@ +/* +* ECDSA +* (C) 2007 Falko Strenzke, FlexSecure GmbH +* Manuel Hartl, FlexSecure GmbH +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECDSA_KEY_H__ +#define BOTAN_ECDSA_KEY_H__ + +#include <botan/ecc_key.h> +#include <botan/ecdsa_core.h> + +namespace Botan { + +/** +* This class represents ECDSA Public Keys. +*/ +class BOTAN_DLL ECDSA_PublicKey : public virtual EC_PublicKey, + public PK_Verifying_wo_MR_Key + { + public: + + /** + * Get this keys algorithm name. + * @result this keys algorithm name ("ECDSA") + */ + std::string algo_name() const { return "ECDSA"; } + + /** + * Get the maximum number of bits allowed to be fed to this key. + * This is the bitlength of the order of the base point. + + * @result the maximum number of input bits + */ + u32bit max_input_bits() const; + + /** + * Verify a message with this key. + * @param message the byte array containing the message + * @param mess_len the number of bytes in the message byte array + * @param signature the byte array containing the signature + * @param sig_len the number of bytes in the signature byte array + */ + bool verify(const byte message[], u32bit mess_len, + const byte signature[], u32bit sig_len) const; + + /** + * Default constructor. Use this one if you want to later fill + * this object with data from an encoded key. + */ + ECDSA_PublicKey() {} + + /** + * Construct a public key from a given public point. + * @param dom_par the domain parameters associated with this key + * @param public_point the public point defining this key + */ + ECDSA_PublicKey(const EC_Domain_Params& dom_par, + const PointGFp& public_point); // sets core + + ECDSA_PublicKey const& operator=(const ECDSA_PublicKey& rhs); + + ECDSA_PublicKey(const ECDSA_PublicKey& other); + + /** + * Set the domain parameters of this key. This function has to be + * used when a key encoded without domain parameters was decoded into + * this key. Otherwise it will not be able to verify a signature. + * @param dom_pars the domain_parameters associated with this key + * @throw Invalid_Argument if the point was found not to be satisfying the + * curve equation of the provided domain parameters + * or if this key already has domain parameters set + * and these are differing from those given as the parameter + */ + void set_domain_parameters(const EC_Domain_Params& dom_pars); + + /** + * Ensure that the public point and domain parameters of this key are set. + * @throw Invalid_State if either of the two data members is not set + */ + virtual void affirm_init() const; + + protected: + void X509_load_hook(); + virtual void set_all_values(const ECDSA_PublicKey& other); + + ECDSA_Core m_ecdsa_core; + }; + +/** +* This class represents ECDSA Private Keys +*/ +class BOTAN_DLL ECDSA_PrivateKey : public ECDSA_PublicKey, + public EC_PrivateKey, + public PK_Signing_Key + { + public: + //ctors + + /** + * Default constructor. Use this one if you want to later fill + * this object with data from an encoded key. + */ + ECDSA_PrivateKey() {} + + /** + * Generate a new private key + * @param the domain parameters to used for this key + */ + ECDSA_PrivateKey(RandomNumberGenerator& rng, + const EC_Domain_Params& domain); + + ECDSA_PrivateKey(const ECDSA_PrivateKey& other); + ECDSA_PrivateKey const& operator=(const ECDSA_PrivateKey& rhs); + + /** + * Sign a message with this key. + * @param message the byte array representing the message to be signed + * @param mess_len the length of the message byte array + * @result the signature + */ + + SecureVector<byte> sign(const byte message[], u32bit mess_len, + RandomNumberGenerator& rng) const; + + /** + * Make sure that the public key parts of this object are set + * (calls EC_PublicKey::affirm_init()) as well as the private key + * value. + * @throw Invalid_State if the above conditions are not satisfied + */ + virtual void affirm_init() const; + + protected: + virtual void set_all_values(const ECDSA_PrivateKey& other); + private: + void PKCS8_load_hook(bool = false); + }; + +} + +#endif diff --git a/old/botan/build/botan/ecdsa_core.h b/old/botan/build/botan/ecdsa_core.h new file mode 100644 index 0000000..ceccc94 --- /dev/null +++ b/old/botan/build/botan/ecdsa_core.h @@ -0,0 +1,47 @@ +/* +* ECDSA Core +* (C) 1999-2007 Jack Lloyd +* (C) 2007 FlexSecure GmbH +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECDSA_CORE_H__ +#define BOTAN_ECDSA_CORE_H__ + +#include <botan/ecdsa_op.h> +#include <botan/blinding.h> +#include <botan/ec_dompar.h> + +namespace Botan { + +/* +* ECDSA Core +*/ +class BOTAN_DLL ECDSA_Core + { + public: + bool verify(const byte signature[], u32bit sig_len, + const byte message[], u32bit mess_len) const; + + SecureVector<byte> sign(const byte message[], u32bit mess_len, + RandomNumberGenerator& rng) const; + + ECDSA_Core& operator=(const ECDSA_Core&); + + ECDSA_Core() { op = 0; } + + ECDSA_Core(const ECDSA_Core&); + + ECDSA_Core(const EC_Domain_Params& dom_pars, + const BigInt& priv_key, + const PointGFp& pub_key); + + ~ECDSA_Core() { delete op; } + private: + ECDSA_Operation* op; + }; + +} + +#endif diff --git a/old/botan/build/botan/ecdsa_op.h b/old/botan/build/botan/ecdsa_op.h new file mode 100644 index 0000000..25831a9 --- /dev/null +++ b/old/botan/build/botan/ecdsa_op.h @@ -0,0 +1,64 @@ +/* +* ECDSA Operations +* (C) 1999-2008 Jack Lloyd +* (C) 2007 FlexSecure GmbH +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECDSA_OPERATIONS_H__ +#define BOTAN_ECDSA_OPERATIONS_H__ + +#include <botan/ec_dompar.h> +#include <botan/rng.h> + +namespace Botan { + +/* +* ECDSA Operation +*/ +class BOTAN_DLL ECDSA_Operation + { + public: + virtual bool verify(const byte sig[], u32bit sig_len, + const byte msg[], u32bit msg_len) const = 0; + + virtual SecureVector<byte> sign(const byte message[], + u32bit mess_len, + RandomNumberGenerator&) const = 0; + + virtual ECDSA_Operation* clone() const = 0; + + virtual ~ECDSA_Operation() {} + }; + + +/* +* Default ECDSA operation +*/ +class BOTAN_DLL Default_ECDSA_Op : public ECDSA_Operation + { + public: + bool verify(const byte signature[], u32bit sig_len, + const byte message[], u32bit mess_len) const; + + SecureVector<byte> sign(const byte message[], u32bit mess_len, + RandomNumberGenerator& rng) const; + + ECDSA_Operation* clone() const + { + return new Default_ECDSA_Op(*this); + } + + Default_ECDSA_Op(const EC_Domain_Params& dom_pars, + const BigInt& priv_key, + const PointGFp& pub_key); + private: + EC_Domain_Params m_dom_pars; + PointGFp m_pub_key; + BigInt m_priv_key; + }; + +} + +#endif diff --git a/old/botan/build/botan/ecdsa_sig.h b/old/botan/build/botan/ecdsa_sig.h new file mode 100644 index 0000000..15015c7 --- /dev/null +++ b/old/botan/build/botan/ecdsa_sig.h @@ -0,0 +1,88 @@ +/* +* ECDSA +* (C) 2007 Falko Strenzke, FlexSecure GmbH +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECDSA_SIGNATURE_H__ +#define BOTAN_ECDSA_SIGNATURE_H__ + +#include <botan/bigint.h> +#include <botan/der_enc.h> +#include <botan/ber_dec.h> + +namespace Botan { + +class BOTAN_DLL ECDSA_Signature + { + public: + friend class ECDSA_Signature_Decoder; + + ECDSA_Signature() {} + ECDSA_Signature(const BigInt& r, const BigInt& s); + ECDSA_Signature(ECDSA_Signature const& other); + ECDSA_Signature const& operator=(ECDSA_Signature const& other); + + const BigInt& get_r() const { return m_r; } + const BigInt& get_s() const { return m_s; } + + /** + * return the r||s + */ + SecureVector<byte> const get_concatenation() const; + private: + BigInt m_r; + BigInt m_s; + }; + +/* Equality of ECDSA_Signature */ +bool operator==(const ECDSA_Signature& lhs, const ECDSA_Signature& rhs); +inline bool operator!=(const ECDSA_Signature& lhs, const ECDSA_Signature& rhs) + { + return !(lhs == rhs); + } + +class BOTAN_DLL ECDSA_Signature_Decoder + { + public: + void signature_bits(const MemoryRegion<byte>& bits) + { + BER_Decoder(bits) + .start_cons(SEQUENCE) + .decode(m_signature->m_r) + .decode(m_signature->m_s) + .verify_end() + .end_cons(); + } + ECDSA_Signature_Decoder(ECDSA_Signature* signature) : m_signature(signature) + {} + private: + ECDSA_Signature* m_signature; + }; + +class BOTAN_DLL ECDSA_Signature_Encoder + { + public: + MemoryVector<byte> signature_bits() const + { + return DER_Encoder() + .start_cons(SEQUENCE) + .encode(m_signature->get_r()) + .encode(m_signature->get_s()) + .end_cons() + .get_contents(); + } + ECDSA_Signature_Encoder(const ECDSA_Signature* signature) : m_signature(signature) + {} + private: + const ECDSA_Signature* m_signature; + }; + +ECDSA_Signature const decode_seq(MemoryRegion<byte> const& seq); +ECDSA_Signature const decode_concatenation(MemoryRegion<byte> const& concatenation); + +} + +#endif diff --git a/old/botan/build/botan/eckaeg.h b/old/botan/build/botan/eckaeg.h new file mode 100644 index 0000000..31b6574 --- /dev/null +++ b/old/botan/build/botan/eckaeg.h @@ -0,0 +1,137 @@ +/* +* ECKAEG +* (C) 2007 Falko Strenzke, FlexSecure GmbH +* Manuel Hartl, FlexSecure GmbH +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECKAEG_KEY_H__ +#define BOTAN_ECKAEG_KEY_H__ + +#include <botan/ecc_key.h> +#include <botan/eckaeg_core.h> + +namespace Botan { + +/** +* This class represents ECKAEG Public Keys. +*/ +class BOTAN_DLL ECKAEG_PublicKey : public virtual EC_PublicKey + { + public: + + /** + * Default constructor. Use this one if you want to later fill + * this object with data from an encoded key. + */ + ECKAEG_PublicKey() {} + + /** + * Construct a public key from a given public point. + * @param dom_par the domain parameters associated with this key + * @param public_point the public point defining this key + */ + ECKAEG_PublicKey(const EC_Domain_Params& dom_par, + const PointGFp& public_point); + + /** + * Get this keys algorithm name. + * @result this keys algorithm name + */ + std::string algo_name() const { return "ECKAEG"; } + + /** + * Get the maximum number of bits allowed to be fed to this key. + * This is the bitlength of the order of the base point. + + * @result the maximum number of input bits + */ + u32bit max_input_bits() const + { + if(!mp_dom_pars.get()) + throw Invalid_State("ECKAEG_PublicKey::max_input_bits(): domain parameters not set"); + + return mp_dom_pars->get_order().bits(); + } + + ECKAEG_PublicKey(ECKAEG_PublicKey const& other); + ECKAEG_PublicKey const& operator= (ECKAEG_PublicKey const& rhs); + + /** + * Make sure that the public point and domain parameters of this + * key are set. + * @throw Invalid_State if either of the two data members is not set + */ + virtual void affirm_init() const; + + protected: + void X509_load_hook(); + virtual void set_all_values(const ECKAEG_PublicKey& other); + + ECKAEG_Core m_eckaeg_core; + }; + +/** +* This class represents ECKAEG Private Keys. +*/ +class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey, + public EC_PrivateKey, + public PK_Key_Agreement_Key + { + public: + + /** + * Generate a new private key + * @param the domain parameters to used for this key + */ + ECKAEG_PrivateKey(RandomNumberGenerator& rng, + const EC_Domain_Params& dom_pars) + { + mp_dom_pars = std::auto_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_pars)); + generate_private_key(rng); + mp_public_point->check_invariants(); + m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, m_private_value, *mp_public_point); + } + + /** + * Default constructor. Use this one if you want to later fill this object with data + * from an encoded key. + */ + ECKAEG_PrivateKey() {} + ECKAEG_PrivateKey(ECKAEG_PrivateKey const& other); + ECKAEG_PrivateKey const& operator=(ECKAEG_PrivateKey const& rhs); + + MemoryVector<byte> public_value() const; + + void PKCS8_load_hook(bool = false); + + /** + * Derive a shared key with the other partys public key. + * @param key the other partys public key + * @param key_len the other partys public key + */ + SecureVector<byte> derive_key(const byte key[], u32bit key_len) const; + + /** + * Derive a shared key with the other partys public key. + * @param other the other partys public key + */ + SecureVector<byte> derive_key(const ECKAEG_PublicKey& other) const; + + /** + * Make sure that the public key parts of this object are set + * (calls EC_PublicKey::affirm_init()) as well as the private key + * value. + * @throw Invalid_State if the above conditions are not satisfied + */ + virtual void affirm_init() const; + + protected: + virtual void set_all_values(const ECKAEG_PrivateKey& other); + }; + +} + +#endif diff --git a/old/botan/build/botan/eckaeg_core.h b/old/botan/build/botan/eckaeg_core.h new file mode 100644 index 0000000..d632c94 --- /dev/null +++ b/old/botan/build/botan/eckaeg_core.h @@ -0,0 +1,44 @@ +/* +* ECKAEG Core +* (C) 1999-2007 Jack Lloyd +* (C) 2007 FlexSecure GmbH +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECKAEG_CORE_H__ +#define BOTAN_ECKAEG_CORE_H__ + +#include <botan/eckaeg_op.h> +#include <botan/blinding.h> +#include <botan/ec_dompar.h> + +namespace Botan { + +/* +* ECKAEG Core +*/ +class BOTAN_DLL ECKAEG_Core + { + public: + SecureVector<byte> agree(const PointGFp&) const; + + ECKAEG_Core& operator=(const ECKAEG_Core&); + + ECKAEG_Core() { op = 0; } + + ECKAEG_Core(const ECKAEG_Core&); + + ECKAEG_Core(const EC_Domain_Params& dom_pars, + const BigInt& priv_key, + PointGFp const& pub_key); + + ~ECKAEG_Core() { delete op; } + private: + ECKAEG_Operation* op; + Blinder blinder; + }; + +} + +#endif diff --git a/old/botan/build/botan/eckaeg_op.h b/old/botan/build/botan/eckaeg_op.h new file mode 100644 index 0000000..27cf4f3 --- /dev/null +++ b/old/botan/build/botan/eckaeg_op.h @@ -0,0 +1,49 @@ +/* +* ECKAEG Operations +* (C) 1999-2008 Jack Lloyd +* 2007 FlexSecure GmbH +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECKAEG_OPERATIONS_H__ +#define BOTAN_ECKAEG_OPERATIONS_H__ + +#include <botan/ec_dompar.h> + +namespace Botan { + +/* +* ECKAEG Operation +*/ +class BOTAN_DLL ECKAEG_Operation + { + public: + virtual SecureVector<byte> agree(const PointGFp&) const = 0; + virtual ECKAEG_Operation* clone() const = 0; + virtual ~ECKAEG_Operation() {} + }; + +/* +* Default ECKAEG operation +*/ +class BOTAN_DLL Default_ECKAEG_Op : public ECKAEG_Operation + { + public: + SecureVector<byte> agree(const PointGFp& i) const; + + ECKAEG_Operation* clone() const { return new Default_ECKAEG_Op(*this); } + + Default_ECKAEG_Op(const EC_Domain_Params& dom_pars, + const BigInt& priv_key, + const PointGFp& pub_key); + private: + EC_Domain_Params m_dom_pars; + PointGFp m_pub_key; + BigInt m_priv_key; + }; + + +} + +#endif diff --git a/old/botan/build/botan/elg_core.h b/old/botan/build/botan/elg_core.h new file mode 100644 index 0000000..a7768a6 --- /dev/null +++ b/old/botan/build/botan/elg_core.h @@ -0,0 +1,44 @@ +/* +* ElGamal Core +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ELGAMAL_CORE_H__ +#define BOTAN_ELGAMAL_CORE_H__ + +#include <botan/elg_op.h> +#include <botan/blinding.h> +#include <botan/dl_group.h> + +namespace Botan { + +/* +* ElGamal Core +*/ +class BOTAN_DLL ELG_Core + { + public: + SecureVector<byte> encrypt(const byte[], u32bit, const BigInt&) const; + SecureVector<byte> decrypt(const byte[], u32bit) const; + + ELG_Core& operator=(const ELG_Core&); + + ELG_Core() { op = 0; } + ELG_Core(const ELG_Core&); + + ELG_Core(const DL_Group&, const BigInt&); + ELG_Core(RandomNumberGenerator&, const DL_Group&, + const BigInt&, const BigInt&); + + ~ELG_Core() { delete op; } + private: + ELG_Operation* op; + Blinder blinder; + u32bit p_bytes; + }; + +} + +#endif diff --git a/old/botan/build/botan/elg_op.h b/old/botan/build/botan/elg_op.h new file mode 100644 index 0000000..39ed897 --- /dev/null +++ b/old/botan/build/botan/elg_op.h @@ -0,0 +1,52 @@ +/* +* ElGamal Operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ELGAMAL_OPS_H__ +#define BOTAN_ELGAMAL_OPS_H__ + +#include <botan/pow_mod.h> +#include <botan/numthry.h> +#include <botan/reducer.h> +#include <botan/dl_group.h> + +namespace Botan { + +/* +* ElGamal Operation +*/ +class BOTAN_DLL ELG_Operation + { + public: + virtual SecureVector<byte> encrypt(const byte[], u32bit, + const BigInt&) const = 0; + virtual BigInt decrypt(const BigInt&, const BigInt&) const = 0; + virtual ELG_Operation* clone() const = 0; + virtual ~ELG_Operation() {} + }; + +/* +* Botan's Default ElGamal Operation +*/ +class BOTAN_DLL Default_ELG_Op : public ELG_Operation + { + public: + SecureVector<byte> encrypt(const byte[], u32bit, const BigInt&) const; + BigInt decrypt(const BigInt&, const BigInt&) const; + + ELG_Operation* clone() const { return new Default_ELG_Op(*this); } + + Default_ELG_Op(const DL_Group&, const BigInt&, const BigInt&); + private: + const BigInt p; + Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; + Fixed_Exponent_Power_Mod powermod_x_p; + Modular_Reducer mod_p; + }; + +} + +#endif diff --git a/old/botan/build/botan/elgamal.h b/old/botan/build/botan/elgamal.h new file mode 100644 index 0000000..93e640f --- /dev/null +++ b/old/botan/build/botan/elgamal.h @@ -0,0 +1,59 @@ +/* +* ElGamal +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ELGAMAL_H__ +#define BOTAN_ELGAMAL_H__ + +#include <botan/dl_algo.h> +#include <botan/elg_core.h> + +namespace Botan { + +/* +* ElGamal Public Key +*/ +class BOTAN_DLL ElGamal_PublicKey : public PK_Encrypting_Key, + public virtual DL_Scheme_PublicKey + { + public: + std::string algo_name() const { return "ElGamal"; } + DL_Group::Format group_format() const { return DL_Group::ANSI_X9_42; } + + SecureVector<byte> encrypt(const byte[], u32bit, + RandomNumberGenerator& rng) const; + u32bit max_input_bits() const; + + ElGamal_PublicKey() {} + ElGamal_PublicKey(const DL_Group&, const BigInt&); + protected: + ELG_Core core; + private: + void X509_load_hook(); + }; + +/* +* ElGamal Private Key +*/ +class BOTAN_DLL ElGamal_PrivateKey : public ElGamal_PublicKey, + public PK_Decrypting_Key, + public virtual DL_Scheme_PrivateKey + { + public: + SecureVector<byte> decrypt(const byte[], u32bit) const; + + bool check_key(RandomNumberGenerator& rng, bool) const; + + ElGamal_PrivateKey() {} + ElGamal_PrivateKey(RandomNumberGenerator&, const DL_Group&, + const BigInt& = 0); + private: + void PKCS8_load_hook(RandomNumberGenerator&, bool = false); + }; + +} + +#endif diff --git a/old/botan/build/botan/eme.h b/old/botan/build/botan/eme.h new file mode 100644 index 0000000..321c1d0 --- /dev/null +++ b/old/botan/build/botan/eme.h @@ -0,0 +1,42 @@ +/* +* EME Classes +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PUBKEY_EME_ENCRYPTION_PAD_H__ +#define BOTAN_PUBKEY_EME_ENCRYPTION_PAD_H__ + +#include <botan/secmem.h> +#include <botan/rng.h> + +namespace Botan { + +/* +* Encoding Method for Encryption +*/ +class BOTAN_DLL EME + { + public: + virtual u32bit maximum_input_size(u32bit) const = 0; + + SecureVector<byte> encode(const byte[], u32bit, u32bit, + RandomNumberGenerator&) const; + SecureVector<byte> encode(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator&) const; + + SecureVector<byte> decode(const byte[], u32bit, u32bit) const; + SecureVector<byte> decode(const MemoryRegion<byte>&, u32bit) const; + + virtual ~EME() {} + private: + virtual SecureVector<byte> pad(const byte[], u32bit, u32bit, + RandomNumberGenerator&) const = 0; + + virtual SecureVector<byte> unpad(const byte[], u32bit, u32bit) const = 0; + }; + +} + +#endif diff --git a/old/botan/build/botan/eme1.h b/old/botan/build/botan/eme1.h new file mode 100644 index 0000000..4df5c5f --- /dev/null +++ b/old/botan/build/botan/eme1.h @@ -0,0 +1,45 @@ +/* +* EME1 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EME1_H__ +#define BOTAN_EME1_H__ + +#include <botan/eme.h> +#include <botan/kdf.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* EME1 +*/ +class BOTAN_DLL EME1 : public EME + { + public: + u32bit maximum_input_size(u32bit) const; + + /** + EME1 constructor. Hash will be deleted by ~EME1 (when mgf is deleted) + + P is an optional label. Normally empty. + */ + EME1(HashFunction* hash, const std::string& P = ""); + + ~EME1() { delete mgf; } + private: + SecureVector<byte> pad(const byte[], u32bit, u32bit, + RandomNumberGenerator&) const; + SecureVector<byte> unpad(const byte[], u32bit, u32bit) const; + + const u32bit HASH_LENGTH; + SecureVector<byte> Phash; + MGF* mgf; + }; + +} + +#endif diff --git a/old/botan/build/botan/eme_pkcs.h b/old/botan/build/botan/eme_pkcs.h new file mode 100644 index 0000000..1aeedf5 --- /dev/null +++ b/old/botan/build/botan/eme_pkcs.h @@ -0,0 +1,30 @@ +/* +* EME PKCS#1 v1.5 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EME_PKCS1_H__ +#define BOTAN_EME_PKCS1_H__ + +#include <botan/eme.h> + +namespace Botan { + +/* +* EME_PKCS1v15 +*/ +class BOTAN_DLL EME_PKCS1v15 : public EME + { + public: + u32bit maximum_input_size(u32bit) const; + private: + SecureVector<byte> pad(const byte[], u32bit, u32bit, + RandomNumberGenerator&) const; + SecureVector<byte> unpad(const byte[], u32bit, u32bit) const; + }; + +} + +#endif diff --git a/old/botan/build/botan/emsa.h b/old/botan/build/botan/emsa.h new file mode 100644 index 0000000..e2491e4 --- /dev/null +++ b/old/botan/build/botan/emsa.h @@ -0,0 +1,36 @@ +/* +* EMSA Classes +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PUBKEY_EMSA_H__ +#define BOTAN_PUBKEY_EMSA_H__ + +#include <botan/secmem.h> +#include <botan/rng.h> + +namespace Botan { + +/* +* Encoding Method for Signatures, Appendix +*/ +class BOTAN_DLL EMSA + { + public: + virtual void update(const byte[], u32bit) = 0; + virtual SecureVector<byte> raw_data() = 0; + + virtual SecureVector<byte> encoding_of(const MemoryRegion<byte>&, + u32bit, + RandomNumberGenerator& rng) = 0; + + virtual bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, + u32bit) throw() = 0; + virtual ~EMSA() {} + }; + +} + +#endif diff --git a/old/botan/build/botan/emsa1.h b/old/botan/build/botan/emsa1.h new file mode 100644 index 0000000..a5dac07 --- /dev/null +++ b/old/botan/build/botan/emsa1.h @@ -0,0 +1,41 @@ +/* +* EMSA1 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EMSA1_H__ +#define BOTAN_EMSA1_H__ + +#include <botan/emsa.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* EMSA1 +*/ +class BOTAN_DLL EMSA1 : public EMSA + { + public: + EMSA1(HashFunction* h) : hash(h) {} + ~EMSA1() { delete hash; } + protected: + const HashFunction* hash_ptr() const { return hash; } + private: + void update(const byte[], u32bit); + SecureVector<byte> raw_data(); + + SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator& rng); + + bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, + u32bit) throw(); + + HashFunction* hash; + }; + +} + +#endif diff --git a/old/botan/build/botan/emsa1_bsi.h b/old/botan/build/botan/emsa1_bsi.h new file mode 100644 index 0000000..ec86d40 --- /dev/null +++ b/old/botan/build/botan/emsa1_bsi.h @@ -0,0 +1,32 @@ +/* +* EMSA1 BSI Variant +* (C) 1999-2008 Jack Lloyd +* 2007 FlexSecure GmbH +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EMSA1_BSI_H__ +#define BOTAN_EMSA1_BSI_H__ + +#include <botan/emsa1.h> + +namespace Botan { + +/** +EMSA1_BSI is a variant of EMSA1 specified by the BSI. It accepts only +hash values which are less or equal than the maximum key length. The +implementation comes from InSiTo +*/ +class BOTAN_DLL EMSA1_BSI : public EMSA1 + { + public: + EMSA1_BSI(HashFunction* hash) : EMSA1(hash) {} + private: + SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator& rng); + }; + +} + +#endif diff --git a/old/botan/build/botan/emsa2.h b/old/botan/build/botan/emsa2.h new file mode 100644 index 0000000..76888d1 --- /dev/null +++ b/old/botan/build/botan/emsa2.h @@ -0,0 +1,41 @@ +/* +* EMSA2 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EMSA2_H__ +#define BOTAN_EMSA2_H__ + +#include <botan/emsa.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* EMSA2 +*/ +class BOTAN_DLL EMSA2 : public EMSA + { + public: + EMSA2(HashFunction* hash); + ~EMSA2() { delete hash; } + private: + void update(const byte[], u32bit); + SecureVector<byte> raw_data(); + + SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator& rng); + + bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, + u32bit) throw(); + + SecureVector<byte> empty_hash; + HashFunction* hash; + byte hash_id; + }; + +} + +#endif diff --git a/old/botan/build/botan/emsa3.h b/old/botan/build/botan/emsa3.h new file mode 100644 index 0000000..301f214 --- /dev/null +++ b/old/botan/build/botan/emsa3.h @@ -0,0 +1,65 @@ +/* +* EMSA3 and EMSA3_Raw +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EMSA3_H__ +#define BOTAN_EMSA3_H__ + +#include <botan/emsa.h> +#include <botan/hash.h> + +namespace Botan { + +/** +* EMSA3 +* aka PKCS #1 v1.5 signature padding +* aka PKCS #1 block type 1 +*/ +class BOTAN_DLL EMSA3 : public EMSA + { + public: + EMSA3(HashFunction*); + ~EMSA3(); + + void update(const byte[], u32bit); + + SecureVector<byte> raw_data(); + + SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator& rng); + + bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, + u32bit) throw(); + private: + HashFunction* hash; + SecureVector<byte> hash_id; + }; + +/** +* EMSA3_Raw which is EMSA3 without a hash or digest id (which +* according to QCA docs is "identical to PKCS#11's CKM_RSA_PKCS +* mechanism", something I have not confirmed) +*/ +class BOTAN_DLL EMSA3_Raw : public EMSA + { + public: + void update(const byte[], u32bit); + + SecureVector<byte> raw_data(); + + SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator& rng); + + bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, + u32bit) throw(); + + private: + SecureVector<byte> message; + }; + +} + +#endif diff --git a/old/botan/build/botan/emsa4.h b/old/botan/build/botan/emsa4.h new file mode 100644 index 0000000..b716178 --- /dev/null +++ b/old/botan/build/botan/emsa4.h @@ -0,0 +1,43 @@ +/* +* EMSA4 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EMSA4_H__ +#define BOTAN_EMSA4_H__ + +#include <botan/emsa.h> +#include <botan/hash.h> +#include <botan/kdf.h> + +namespace Botan { + +/* +* EMSA4 +*/ +class BOTAN_DLL EMSA4 : public EMSA + { + public: + EMSA4(HashFunction*); + EMSA4(HashFunction*, u32bit); + + ~EMSA4() { delete hash; delete mgf; } + private: + void update(const byte[], u32bit); + SecureVector<byte> raw_data(); + + SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator& rng); + bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, + u32bit) throw(); + + u32bit SALT_SIZE; + HashFunction* hash; + const MGF* mgf; + }; + +} + +#endif diff --git a/old/botan/build/botan/emsa_raw.h b/old/botan/build/botan/emsa_raw.h new file mode 100644 index 0000000..1b0ad51 --- /dev/null +++ b/old/botan/build/botan/emsa_raw.h @@ -0,0 +1,34 @@ +/* +* EMSA-Raw +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EMSA_RAW_H__ +#define BOTAN_EMSA_RAW_H__ + +#include <botan/emsa.h> + +namespace Botan { + +/* +* EMSA-Raw +*/ +class BOTAN_DLL EMSA_Raw : public EMSA + { + private: + void update(const byte[], u32bit); + SecureVector<byte> raw_data(); + + SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, + RandomNumberGenerator&); + bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, + u32bit) throw(); + + SecureVector<byte> message; + }; + +} + +#endif diff --git a/old/botan/build/botan/engine.h b/old/botan/build/botan/engine.h new file mode 100644 index 0000000..66a159e --- /dev/null +++ b/old/botan/build/botan/engine.h @@ -0,0 +1,140 @@ +/* +* Engine +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENGINE_H__ +#define BOTAN_ENGINE_H__ + +#include <botan/scan_name.h> + +#include <botan/block_cipher.h> +#include <botan/stream_cipher.h> +#include <botan/hash.h> +#include <botan/mac.h> +#include <botan/pow_mod.h> + +#include <utility> +#include <map> + +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) + #include <botan/if_op.h> +#endif + +#if defined(BOTAN_HAS_DSA) + #include <botan/dsa_op.h> +#endif + +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) + #include <botan/dh_op.h> +#endif + +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) + #include <botan/nr_op.h> +#endif + +#if defined(BOTAN_HAS_ELGAMAL) + #include <botan/elg_op.h> +#endif + +#if defined(BOTAN_HAS_ECDSA) + #include <botan/ecdsa_op.h> + #include <botan/ec_dompar.h> +#endif + +#if defined(BOTAN_HAS_ECKAEG) + #include <botan/eckaeg_op.h> + #include <botan/ec_dompar.h> +#endif + +namespace Botan { + +class Algorithm_Factory; +class Keyed_Filter; + +/* +* Engine Base Class +*/ +class BOTAN_DLL Engine + { + public: + virtual ~Engine() {} + + virtual std::string provider_name() const = 0; + + // Lookup functions + virtual BlockCipher* + find_block_cipher(const SCAN_Name&, Algorithm_Factory&) const + { return 0; } + + virtual StreamCipher* + find_stream_cipher(const SCAN_Name&, Algorithm_Factory&) const + { return 0; } + + virtual HashFunction* + find_hash(const SCAN_Name&, Algorithm_Factory&) const + { return 0; } + + virtual MessageAuthenticationCode* + find_mac(const SCAN_Name&, Algorithm_Factory&) const + { return 0; } + + virtual Modular_Exponentiator* + mod_exp(const BigInt&, Power_Mod::Usage_Hints) const + { return 0; } + + virtual Keyed_Filter* get_cipher(const std::string&, + Cipher_Dir, + Algorithm_Factory&) + { return 0; } + +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) + virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&) const + { return 0; } +#endif + +#if defined(BOTAN_HAS_DSA) + virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&, + const BigInt&) const + { return 0; } +#endif + +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) + virtual NR_Operation* nr_op(const DL_Group&, const BigInt&, + const BigInt&) const + { return 0; } +#endif + +#if defined(BOTAN_HAS_ELGAMAL) + virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, + const BigInt&) const + { return 0; } +#endif + +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) + virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const + { return 0; } +#endif + +#if defined(BOTAN_HAS_ECDSA) + virtual ECDSA_Operation* ecdsa_op(const EC_Domain_Params&, + const BigInt&, + const PointGFp&) const + { return 0; } +#endif + +#if defined(BOTAN_HAS_ECKAEG) + virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&, + const BigInt&, + const PointGFp&) const + { return 0; } +#endif + }; + +} + +#endif diff --git a/old/botan/build/botan/entropy_src.h b/old/botan/build/botan/entropy_src.h new file mode 100644 index 0000000..a1a53fa --- /dev/null +++ b/old/botan/build/botan/entropy_src.h @@ -0,0 +1,95 @@ +/** +* EntropySource +* (C) 2008-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENTROPY_SOURCE_BASE_H__ +#define BOTAN_ENTROPY_SOURCE_BASE_H__ + +#include <botan/buf_comp.h> +#include <string> +#include <utility> + +namespace Botan { + +/** +* Class used to accumulate the poll results of EntropySources +*/ +class Entropy_Accumulator + { + public: + Entropy_Accumulator(u32bit goal) : + entropy_goal(goal), collected_bits(0) {} + + virtual ~Entropy_Accumulator() {} + + /** + @return cached I/O buffer for repeated polls + */ + MemoryRegion<byte>& get_io_buffer(u32bit size) + { io_buffer.create(size); return io_buffer; } + + u32bit bits_collected() const + { return static_cast<u32bit>(collected_bits); } + + bool polling_goal_achieved() const + { return (collected_bits >= entropy_goal); } + + u32bit desired_remaining_bits() const + { + if(collected_bits >= entropy_goal) + return 0; + return static_cast<u32bit>(entropy_goal - collected_bits); + } + + void add(const void* bytes, u32bit length, double entropy_bits_per_byte) + { + add_bytes(reinterpret_cast<const byte*>(bytes), length); + collected_bits += entropy_bits_per_byte * length; + } + + template<typename T> + void add(const T& v, double entropy_bits_per_byte) + { + add(&v, sizeof(T), entropy_bits_per_byte); + } + private: + virtual void add_bytes(const byte bytes[], u32bit length) = 0; + + SecureVector<byte> io_buffer; + u32bit entropy_goal; + double collected_bits; + }; + +class Entropy_Accumulator_BufferedComputation : public Entropy_Accumulator + { + public: + Entropy_Accumulator_BufferedComputation(BufferedComputation& sink, + u32bit goal) : + Entropy_Accumulator(goal), entropy_sink(sink) {} + + private: + virtual void add_bytes(const byte bytes[], u32bit length) + { + entropy_sink.update(bytes, length); + } + + BufferedComputation& entropy_sink; + }; + +/** +* Abstract interface to a source of (hopefully unpredictable) system entropy +*/ +class BOTAN_DLL EntropySource + { + public: + virtual std::string name() const = 0; + virtual void poll(Entropy_Accumulator& accum) = 0; + virtual ~EntropySource() {} + }; + +} + +#endif diff --git a/old/botan/build/botan/es_capi.h b/old/botan/build/botan/es_capi.h new file mode 100644 index 0000000..55966d7 --- /dev/null +++ b/old/botan/build/botan/es_capi.h @@ -0,0 +1,33 @@ +/* +* Win32 CAPI EntropySource +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENTROPY_SRC_WIN32_CAPI_H__ +#define BOTAN_ENTROPY_SRC_WIN32_CAPI_H__ + +#include <botan/entropy_src.h> +#include <vector> + +namespace Botan { + +/** +* Win32 CAPI Entropy Source +*/ +class BOTAN_DLL Win32_CAPI_EntropySource : public EntropySource + { + public: + std::string name() const { return "Win32 CryptoGenRandom"; } + + void poll(Entropy_Accumulator& accum); + + Win32_CAPI_EntropySource(const std::string& = ""); + private: + std::vector<u64bit> prov_types; + }; + +} + +#endif diff --git a/old/botan/build/botan/es_dev.h b/old/botan/build/botan/es_dev.h new file mode 100644 index 0000000..df9dbe1 --- /dev/null +++ b/old/botan/build/botan/es_dev.h @@ -0,0 +1,53 @@ +/* +* /dev/random EntropySource +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENTROPY_SRC_DEVICE_H__ +#define BOTAN_ENTROPY_SRC_DEVICE_H__ + +#include <botan/entropy_src.h> +#include <vector> +#include <string> + +namespace Botan { + +class BOTAN_DLL Device_EntropySource : public EntropySource + { + public: + std::string name() const { return "RNG Device Reader"; } + + void poll(Entropy_Accumulator& accum); + + Device_EntropySource(const std::vector<std::string>& fsnames); + ~Device_EntropySource(); + private: + + /** + A class handling reading from a Unix character device + */ + class Device_Reader + { + public: + typedef int fd_type; + + // Does not own fd, a transient class + Device_Reader(fd_type device_fd) : fd(device_fd) {} + + void close(); + + u32bit get(byte out[], u32bit length, u32bit ms_wait_time); + + static fd_type open(const std::string& pathname); + private: + fd_type fd; + }; + + std::vector<Device_Reader> devices; + }; + +} + +#endif diff --git a/old/botan/build/botan/es_egd.h b/old/botan/build/botan/es_egd.h new file mode 100644 index 0000000..5db6565 --- /dev/null +++ b/old/botan/build/botan/es_egd.h @@ -0,0 +1,49 @@ +/** +* EGD EntropySource +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENTROPY_SRC_EGD_H__ +#define BOTAN_ENTROPY_SRC_EGD_H__ + +#include <botan/entropy_src.h> +#include <string> +#include <vector> + +namespace Botan { + +/** +* EGD Entropy Source +*/ +class BOTAN_DLL EGD_EntropySource : public EntropySource + { + public: + std::string name() const { return "EGD/PRNGD"; } + + void poll(Entropy_Accumulator& accum); + + EGD_EntropySource(const std::vector<std::string>&); + ~EGD_EntropySource(); + private: + class EGD_Socket + { + public: + EGD_Socket(const std::string& path); + + void close(); + u32bit read(byte outbuf[], u32bit length); + private: + static int open_socket(const std::string& path); + + std::string socket_path; + int m_fd; // cached fd + }; + + std::vector<EGD_Socket> sockets; + }; + +} + +#endif diff --git a/old/botan/build/botan/es_ftw.h b/old/botan/build/botan/es_ftw.h new file mode 100644 index 0000000..928a7b1 --- /dev/null +++ b/old/botan/build/botan/es_ftw.h @@ -0,0 +1,42 @@ +/* +* File Tree Walking EntropySource +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENTROPY_SRC_FTW_H__ +#define BOTAN_ENTROPY_SRC_FTW_H__ + +#include <botan/entropy_src.h> + +namespace Botan { + +/** +* File Tree Walking Entropy Source +*/ +class BOTAN_DLL FTW_EntropySource : public EntropySource + { + public: + std::string name() const { return "Proc Walker"; } + + void poll(Entropy_Accumulator& accum); + + FTW_EntropySource(const std::string& root_dir); + ~FTW_EntropySource(); + + class File_Descriptor_Source + { + public: + virtual int next_fd() = 0; + virtual ~File_Descriptor_Source() {} + }; + private: + + std::string path; + File_Descriptor_Source* dir; + }; + +} + +#endif diff --git a/old/botan/build/botan/es_unix.h b/old/botan/build/botan/es_unix.h new file mode 100644 index 0000000..1f8abb7 --- /dev/null +++ b/old/botan/build/botan/es_unix.h @@ -0,0 +1,39 @@ +/* +* Unix EntropySource +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENTROPY_SRC_UNIX_H__ +#define BOTAN_ENTROPY_SRC_UNIX_H__ + +#include <botan/entropy_src.h> +#include <botan/unix_cmd.h> +#include <vector> + +namespace Botan { + +/** +* Unix Entropy Source +*/ +class BOTAN_DLL Unix_EntropySource : public EntropySource + { + public: + std::string name() const { return "Unix Entropy Source"; } + + void poll(Entropy_Accumulator& accum); + + void add_sources(const Unix_Program[], u32bit); + Unix_EntropySource(const std::vector<std::string>& path); + private: + static void add_default_sources(std::vector<Unix_Program>&); + void fast_poll(Entropy_Accumulator& accum); + + const std::vector<std::string> PATH; + std::vector<Unix_Program> sources; + }; + +} + +#endif diff --git a/old/botan/build/botan/es_win32.h b/old/botan/build/botan/es_win32.h new file mode 100644 index 0000000..0aa9054 --- /dev/null +++ b/old/botan/build/botan/es_win32.h @@ -0,0 +1,27 @@ +/** +* Win32 EntropySource +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENTROPY_SRC_WIN32_H__ +#define BOTAN_ENTROPY_SRC_WIN32_H__ + +#include <botan/entropy_src.h> + +namespace Botan { + +/** +* Win32 Entropy Source +*/ +class BOTAN_DLL Win32_EntropySource : public EntropySource + { + public: + std::string name() const { return "Win32 Statistics"; } + void poll(Entropy_Accumulator& accum); + }; + +} + +#endif diff --git a/old/botan/build/botan/exceptn.h b/old/botan/build/botan/exceptn.h new file mode 100644 index 0000000..a55d842 --- /dev/null +++ b/old/botan/build/botan/exceptn.h @@ -0,0 +1,197 @@ +/* +* Exceptions +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EXCEPTION_H__ +#define BOTAN_EXCEPTION_H__ + +#include <botan/types.h> +#include <exception> +#include <string> + +namespace Botan { + +/* +* Exception Base Class +*/ +class BOTAN_DLL Exception : public std::exception + { + public: + const char* what() const throw() { return msg.c_str(); } + Exception(const std::string& m = "Unknown error") { set_msg(m); } + virtual ~Exception() throw() {} + protected: + void set_msg(const std::string& m) { msg = "Botan: " + m; } + private: + std::string msg; + }; + +/* +* Invalid_Argument Exception +*/ +struct BOTAN_DLL Invalid_Argument : public Exception + { + Invalid_Argument(const std::string& err = "") : Exception(err) {} + }; + +/* +* Invalid_Key_Length Exception +*/ +struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument + { + Invalid_Key_Length(const std::string&, u32bit); + }; + +/* +* Invalid_Block_Size Exception +*/ +struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument + { + Invalid_Block_Size(const std::string&, const std::string&); + }; + +/* +* Invalid_IV_Length Exception +*/ +struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument + { + Invalid_IV_Length(const std::string&, u32bit); + }; + +/* +* Invalid_State Exception +*/ +struct BOTAN_DLL Invalid_State : public Exception + { + Invalid_State(const std::string& err) : Exception(err) {} + }; + +/* +* PRNG_Unseeded Exception +*/ +struct BOTAN_DLL PRNG_Unseeded : public Invalid_State + { + PRNG_Unseeded(const std::string& algo) : + Invalid_State("PRNG not seeded: " + algo) {} + }; + +/* +* Policy_Violation Exception +*/ +struct BOTAN_DLL Policy_Violation : public Invalid_State + { + Policy_Violation(const std::string& err) : + Invalid_State("Policy violation: " + err) {} + }; + +/* +* Lookup_Error Exception +*/ +struct BOTAN_DLL Lookup_Error : public Exception + { + Lookup_Error(const std::string& err) : Exception(err) {} + }; + +/* +* Algorithm_Not_Found Exception +*/ +struct BOTAN_DLL Algorithm_Not_Found : public Exception + { + Algorithm_Not_Found(const std::string&); + }; + +/* +* Format_Error Exception +*/ +struct BOTAN_DLL Format_Error : public Exception + { + Format_Error(const std::string& err = "") : Exception(err) {} + }; + +/* +* Invalid_Algorithm_Name Exception +*/ +struct BOTAN_DLL Invalid_Algorithm_Name : public Format_Error + { + Invalid_Algorithm_Name(const std::string&); + }; + +/* +* Encoding_Error Exception +*/ +struct BOTAN_DLL Encoding_Error : public Format_Error + { + Encoding_Error(const std::string& name) : + Format_Error("Encoding error: " + name) {} + }; + +/* +* Decoding_Error Exception +*/ +struct BOTAN_DLL Decoding_Error : public Format_Error + { + Decoding_Error(const std::string& name) : + Format_Error("Decoding error: " + name) {} + }; + +/* +* Invalid_OID Exception +*/ +struct BOTAN_DLL Invalid_OID : public Decoding_Error + { + Invalid_OID(const std::string& oid) : + Decoding_Error("Invalid ASN.1 OID: " + oid) {} + }; + +/* +* Stream_IO_Error Exception +*/ +struct BOTAN_DLL Stream_IO_Error : public Exception + { + Stream_IO_Error(const std::string& err) : + Exception("I/O error: " + err) {} + }; + +/* +* Configuration Error Exception +*/ +struct BOTAN_DLL Config_Error : public Format_Error + { + Config_Error(const std::string& err) : + Format_Error("Config error: " + err) {} + Config_Error(const std::string&, u32bit); + }; + +/* +* Integrity Failure Exception +*/ +struct BOTAN_DLL Integrity_Failure : public Exception + { + Integrity_Failure(const std::string& err) : + Exception("Integrity failure: " + err) {} + }; + +/* +* Internal_Error Exception +*/ +struct BOTAN_DLL Internal_Error : public Exception + { + Internal_Error(const std::string& err) : + Exception("Internal error: " + err) {} + }; + +/* +* Self Test Failure Exception +*/ +struct BOTAN_DLL Self_Test_Failure : public Internal_Error + { + Self_Test_Failure(const std::string& err) : + Internal_Error("Self test failed: " + err) {} + }; + +} + +#endif diff --git a/old/botan/build/botan/fd_unix.h b/old/botan/build/botan/fd_unix.h new file mode 100644 index 0000000..0aed009 --- /dev/null +++ b/old/botan/build/botan/fd_unix.h @@ -0,0 +1,23 @@ +/* +* Pipe I/O for Unix +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PIPE_UNIXFD_H__ +#define BOTAN_PIPE_UNIXFD_H__ + +#include <botan/pipe.h> + +namespace Botan { + +/* +* Unix I/O Operators for Pipe +*/ +int operator<<(int, Pipe&); +int operator>>(int, Pipe&); + +} + +#endif diff --git a/old/botan/build/botan/filter.h b/old/botan/build/botan/filter.h new file mode 100644 index 0000000..b13a366 --- /dev/null +++ b/old/botan/build/botan/filter.h @@ -0,0 +1,113 @@ +/* +* Filter +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_FILTER_H__ +#define BOTAN_FILTER_H__ + +#include <botan/secmem.h> +#include <vector> + +namespace Botan { + +/** +* This class represents general abstract filter objects. +*/ +class BOTAN_DLL Filter + { + public: + + /** + * Write a portion of a message to this filter. + * @param input the input as a byte array + * @param length the length of the byte array input + */ + virtual void write(const byte input[], u32bit length) = 0; + + /** + * Start a new message. Must be closed by end_msg() before another + * message can be startet. + */ + virtual void start_msg() {} + + /** + * Tell the Filter that the current message shall be ended. + */ + virtual void end_msg() {} + + /** + * Check whether this filter is an attachable filter. + * @return true if this filter is attachable, false otherwise + */ + virtual bool attachable() { return true; } + + /** + * Start a new message in *this and all following filters. Only for + * internal use, not intended for use in client applications. + */ + void new_msg(); + + /** + * End a new message in *this and all following filters. Only for + * internal use, not intended for use in client applications. + */ + void finish_msg(); + + virtual ~Filter() {} + protected: + void send(const byte[], u32bit); + void send(byte input) { send(&input, 1); } + void send(const MemoryRegion<byte>& in) { send(in.begin(), in.size()); } + Filter(); + private: + Filter(const Filter&) {} + Filter& operator=(const Filter&) { return (*this); } + + friend class Pipe; + friend class Fanout_Filter; + + u32bit total_ports() const; + u32bit current_port() const { return port_num; } + void set_port(u32bit); + + u32bit owns() const { return filter_owns; } + + void attach(Filter*); + void set_next(Filter*[], u32bit); + Filter* get_next() const; + + SecureVector<byte> write_queue; + std::vector<Filter*> next; + u32bit port_num, filter_owns; + + // true if filter belongs to a pipe --> prohibit filter sharing! + bool owned; + }; + +/** +* This is the abstract Fanout_Filter base class. +**/ +class BOTAN_DLL Fanout_Filter : public Filter + { + protected: + void incr_owns() { ++filter_owns; } + + void set_port(u32bit n) { Filter::set_port(n); } + void set_next(Filter* f[], u32bit n) { Filter::set_next(f, n); } + void attach(Filter* f) { Filter::attach(f); } + }; + +/** +* The type of checking to be performed by decoders: +* NONE - no checks, IGNORE_WS - perform checks, but ignore +* whitespaces, FULL_CHECK - perform checks, also complain +* about white spaces. +*/ +enum Decoder_Checking { NONE, IGNORE_WS, FULL_CHECK }; + +} + +#endif diff --git a/old/botan/build/botan/filters.h b/old/botan/build/botan/filters.h new file mode 100644 index 0000000..725651f --- /dev/null +++ b/old/botan/build/botan/filters.h @@ -0,0 +1,189 @@ +/* +* Filters +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_FILTERS_H__ +#define BOTAN_FILTERS_H__ + +#include <botan/block_cipher.h> +#include <botan/stream_cipher.h> +#include <botan/hash.h> +#include <botan/mac.h> + +#include <botan/pipe.h> +#include <botan/basefilt.h> +#include <botan/data_snk.h> +#include <botan/scan_name.h> + +#if defined(BOTAN_HAS_BASE64_CODEC) + #include <botan/base64.h> +#endif + +#if defined(BOTAN_HAS_HEX_CODEC) + #include <botan/hex.h> +#endif + +namespace Botan { + +/** +* Stream Cipher Filter. +*/ +class BOTAN_DLL StreamCipher_Filter : public Keyed_Filter + { + public: + + /** + * Seek in the stream. + * @param position the position to seek ahead + */ + void seek(u32bit position) { cipher->seek(position); } + + /** + * Find out whether the cipher underlying this filter supports + * resyncing. + * @return true if the cipher supports resyncing + */ + bool supports_resync() const { return (cipher->IV_LENGTH != 0); } + + /** + * Set the initialization vector for this filter. + * @param iv the initialization vector to set + */ + void set_iv(const InitializationVector& iv); + void write(const byte[], u32bit); + + /** + * Construct a stream cipher filter. + * @param cipher_obj a cipher object to use + */ + StreamCipher_Filter(StreamCipher* cipher_obj); + + /** + * Construct a stream cipher filter. + * @param cipher the name of the desired cipher + */ + StreamCipher_Filter(const std::string& cipher); + + /** + * Construct a stream cipher filter. + * @param cipher the name of the desired cipher + * @param key the key to use inside this filter + */ + StreamCipher_Filter(const std::string& cipher, const SymmetricKey& key); + + ~StreamCipher_Filter() { delete cipher; } + private: + SecureVector<byte> buffer; + StreamCipher* cipher; + }; + +/** +* Hash Filter. +*/ +class BOTAN_DLL Hash_Filter : public Filter + { + public: + void write(const byte input[], u32bit len) { hash->update(input, len); } + void end_msg(); + + /** + * Construct a hash filter. + * @param hash_fun the hash function to use + * @param len the output length of this filter. Leave the default + * value 0 if you want to use the full output of the hashfunction + * hash. Otherwise, specify a smaller value here so that the + * output of the hash algorithm will be cut off. + */ + Hash_Filter(HashFunction* hash_fun, u32bit len = 0) : + OUTPUT_LENGTH(len), hash(hash_fun) {} + + /** + * Construct a hash filter. + * @param request the name of the hash algorithm to use + * @param len the output length of this filter. Leave the default + * value 0 if you want to use the full output of the hashfunction + * hash. Otherwise, specify a smaller value here so that the + * output of the hash algorithm will be cut off. + */ + Hash_Filter(const std::string& request, u32bit len = 0); + + ~Hash_Filter() { delete hash; } + private: + const u32bit OUTPUT_LENGTH; + HashFunction* hash; + }; + +/** +* MessageAuthenticationCode Filter. +*/ +class BOTAN_DLL MAC_Filter : public Keyed_Filter + { + public: + void write(const byte input[], u32bit len) { mac->update(input, len); } + void end_msg(); + + /** + * Construct a MAC filter. The MAC key will be left empty. + * @param mac the MAC to use + * @param len the output length of this filter. Leave the default + * value 0 if you want to use the full output of the + * MAC. Otherwise, specify a smaller value here so that the + * output of the MAC will be cut off. + */ + MAC_Filter(MessageAuthenticationCode* mac_obj, + u32bit out_len = 0) : OUTPUT_LENGTH(out_len) + { + base_ptr = mac = mac_obj; + } + + /** + * Construct a MAC filter. + * @param mac the MAC to use + * @param key the MAC key to use + * @param len the output length of this filter. Leave the default + * value 0 if you want to use the full output of the + * MAC. Otherwise, specify a smaller value here so that the + * output of the MAC will be cut off. + */ + MAC_Filter(MessageAuthenticationCode* mac_obj, + const SymmetricKey& key, + u32bit out_len = 0) : OUTPUT_LENGTH(out_len) + { + base_ptr = mac = mac_obj; + mac->set_key(key); + } + + /** + * Construct a MAC filter. The MAC key will be left empty. + * @param mac the name of the MAC to use + * @param len the output length of this filter. Leave the default + * value 0 if you want to use the full output of the + * MAC. Otherwise, specify a smaller value here so that the + * output of the MAC will be cut off. + */ + MAC_Filter(const std::string& mac, u32bit len = 0); + + /** + * Construct a MAC filter. + * @param mac the name of the MAC to use + * @param key the MAC key to use + * @param len the output length of this filter. Leave the default + * value 0 if you want to use the full output of the + * MAC. Otherwise, specify a smaller value here so that the + * output of the MAC will be cut off. + */ + MAC_Filter(const std::string& mac, const SymmetricKey& key, + u32bit len = 0); + + ~MAC_Filter() { delete mac; } + private: + const u32bit OUTPUT_LENGTH; + MessageAuthenticationCode* mac; + }; + +} + +#endif diff --git a/old/botan/build/botan/fork256.h b/old/botan/build/botan/fork256.h new file mode 100644 index 0000000..70d336c --- /dev/null +++ b/old/botan/build/botan/fork256.h @@ -0,0 +1,35 @@ +/* +* FORK-256 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_FORK_256_H__ +#define BOTAN_FORK_256_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* FORK-256 +*/ +class BOTAN_DLL FORK_256 : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "FORK-256"; } + HashFunction* clone() const { return new FORK_256; } + FORK_256() : MDx_HashFunction(32, 64, true, true) { clear(); } + private: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + SecureBuffer<u32bit, 8> digest; + SecureBuffer<u32bit, 16> M; + }; + +} + +#endif diff --git a/old/botan/build/botan/freestore.h b/old/botan/build/botan/freestore.h new file mode 100644 index 0000000..f95afa8 --- /dev/null +++ b/old/botan/build/botan/freestore.h @@ -0,0 +1,85 @@ +/** +* (C) 2007 Christoph Ludwig +* ludwig@fh-worms.de +**/ + +#ifndef BOTAN_FREESTORE_H__ +#define BOTAN_FREESTORE_H__ + +#include <botan/build.h> + +#if defined(BOTAN_USE_STD_TR1) + #include <tr1/memory> +#elif defined(BOTAN_USE_BOOST_TR1) + #include <boost/tr1/memory.hpp> +#else + #error "Please choose a TR1 implementation in build.h" +#endif + +namespace Botan { + +/** +* This class is intended as an function call parameter type and +* enables convenient automatic conversions between plain and smart +* pointer types. It internally stores a SharedPointer which can be +* accessed. +* +* Distributed under the terms of the Botan license +*/ +template<typename T> +class BOTAN_DLL SharedPtrConverter + { + public: + typedef std::tr1::shared_ptr<T> SharedPtr; + + /** + * Construct a null pointer equivalent object. + */ + SharedPtrConverter() : ptr() {} + + /** + * Copy constructor. + */ + SharedPtrConverter(SharedPtrConverter const& other) : + ptr(other.ptr) {} + + /** + * Construct a converter object from another pointer type. + * @param p the pointer which shall be set as the internally stored + * pointer value of this converter. + */ + template<typename Ptr> + SharedPtrConverter(Ptr p) + : ptr(p) {} + + /** + * Get the internally stored shared pointer. + * @return the internally stored shared pointer + */ + SharedPtr const& get_ptr() const { return this->ptr; } + + /** + * Get the internally stored shared pointer. + * @return the internally stored shared pointer + */ + SharedPtr get_ptr() { return this->ptr; } + + /** + * Get the internally stored shared pointer. + * @return the internally stored shared pointer + */ + SharedPtr const& get_shared() const { return this->ptr; } + + /** + * Get the internally stored shared pointer. + * @return the internally stored shared pointer + */ + SharedPtr get_shared() { return this->ptr; } + + private: + SharedPtr ptr; + }; + +} + +#endif diff --git a/old/botan/build/botan/get_pbe.h b/old/botan/build/botan/get_pbe.h new file mode 100644 index 0000000..04eda66 --- /dev/null +++ b/old/botan/build/botan/get_pbe.h @@ -0,0 +1,33 @@ +/* +* PBE Lookup +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_LOOKUP_PBE_H__ +#define BOTAN_LOOKUP_PBE_H__ + +#include <botan/pbe.h> +#include <string> + +namespace Botan { + +/** +* Factory function for PBEs. +* @param algo_spec the name of the PBE algorithm to retrieve +* @return a pointer to a PBE with randomly created parameters +*/ +BOTAN_DLL PBE* get_pbe(const std::string&); + +/** +* Factory function for PBEs. +* @param pbe_oid the oid of the desired PBE +* @param params a DataSource providing the DER encoded parameters to use +* @return a pointer to the PBE with the specified parameters +*/ +BOTAN_DLL PBE* get_pbe(const OID&, DataSource&); + +} + +#endif diff --git a/old/botan/build/botan/gfp_element.h b/old/botan/build/botan/gfp_element.h new file mode 100644 index 0000000..4e0ee98 --- /dev/null +++ b/old/botan/build/botan/gfp_element.h @@ -0,0 +1,311 @@ +/****** + * Arithmetic for prime fields GF(p) (header file) + * + * (C) 2007 Martin Doering + * doering@cdc.informatik.tu-darmstadt.de + * Christoph Ludwig + * ludwig@fh-worms.de + * Falko Strenzke + * strenzke@flexsecure.de + ******/ + +#ifndef BOTAN_GFP_ELEMENT_H__ +#define BOTAN_GFP_ELEMENT_H__ + +#include <botan/bigint.h> +#include <botan/gfp_modulus.h> +#include <iosfwd> + +#if defined(BOTAN_USE_STD_TR1) + #include <tr1/memory> +#elif defined(BOTAN_USE_BOOST_TR1) + #include <boost/tr1/memory.hpp> +#else + #error "Please choose a TR1 implementation in build.h" +#endif + +namespace Botan { + +struct Illegal_Transformation : public Exception + { + Illegal_Transformation(const std::string& err = + "Requested transformation is not possible") + : Exception(err) {} + }; + +/** + * This class represents one element in GF(p). Enables the convenient, + * transparent use of the montgomery multiplication. + */ +class BOTAN_DLL GFpElement + { + private: + std::tr1::shared_ptr<GFpModulus> mp_mod; + mutable BigInt m_value; // ordinary residue or m-residue respectively + mutable BigInt workspace; + + // ***************************************** + // data members for montgomery multiplication + mutable bool m_use_montgm; + //mutable BigInt m_mres; + // this bool tells use whether the m_mres carries + // the actual value (in this case mValue doesn´t) + mutable bool m_is_trf; + + void ensure_montgm_precomp() const; + void trf_to_mres() const; + void trf_to_ordres() const; + + public: + + /** construct an element of GF(p) with the given value. + * use_montg defaults to false and determines wether Montgomery + * multiplications will be use when applying operators *, *= + * @param p the prime number of the field + * @param value the element value + * @param use_montgm whether this object will use Montgomery multiplication + */ + explicit GFpElement (const BigInt& p, const BigInt& value, bool use_montgm = false); + + + /** construct an element of GF(p) with the given value (defaults + * to 0). use_montg defaults to false and determines wether + * montgomery multiplications will be use when applying operators + * '*' , '*='. Use this constructor for efficient use of + * Montgomery multiplication in a context with a fixed a modulus. + * Warning: do not use this function unless you know in detail + * about the implications of using the shared GFpModulus objects! + * @param mod shared pointer to the GFpModulus to be shared + * @param value the element value + * @param use_montgm whether this object will use Montgomery multiplication + */ + explicit GFpElement(std::tr1::shared_ptr<GFpModulus> const mod, + const BigInt& value, bool use_mongm = false); + + /** + * Copy constructor + * @param other The element to clone + */ + GFpElement(const GFpElement& other); + + /** + * Assignment operator. + * makes *this a totally independent object + * (gives *this independent modulus specific values). + + * @param other The element to assign to our object + */ + const GFpElement& operator=(const GFpElement& other); + + /** + * Works like the assignment operator, but lets + * *this share the modulus dependend value with other. + * Warning: do not use this function unless you know in detail about + * the implications of using + * the shared GFpModulus objects! + * @param other The element to assign to our object + */ + void share_assign(const GFpElement& other); + + /** + * Switch Montgomery multiplcation optimizations ON + */ + void turn_on_sp_red_mul() const; + + /** + * Switch Montgomery multiplcation optimizations OFF + */ + void turn_off_sp_red_mul() const; + + /** + * += Operator + * @param rhs the GFpElement to add to the local value + * @result *this + */ + GFpElement& operator+=(const GFpElement& rhs); + + /** + * -= Operator + * @param rhs the GFpElement to subtract from the local value + * @result *this + */ + GFpElement& operator-=(const GFpElement& rhs); + + /** + * *= Operator + * @param rhs the GFpElement to multiply with the local value + * @result *this + */ + GFpElement& operator*=(const GFpElement& rhs); + /** + * /= Operator + * @param rhs the GFpElement to divide the local value by + * @result *this + */ + GFpElement& operator/=(const GFpElement& rhs); + + /** + * *= Operator + * @param rhs the value to multiply with the local value + * @result *this + */ + GFpElement& operator*= (u32bit rhs); + + /** + * Negate internal value(*this *= -1 ) + * @return *this + */ + GFpElement& negate(); + + /** + * Assigns the inverse of *this to *this, i.e. + * *this = (*this)^(-1) + * @result *this + */ + GFpElement& inverse_in_place(); + + /** + * checks whether the value is zero (without provoking + * a backtransformation to the ordinary-residue) + * @result true, if the value is zero, false otherwise. + */ + bool is_zero(); + + /** + * return prime number of GF(p) + * @result a prime number + */ + const BigInt& get_p() const; + + /** + * Return the represented value in GF(p) + * @result The value in GF(p) + */ + const BigInt& get_value() const; + + /** + * Returns the shared pointer to the GFpModulus of *this. + * Warning: do not use this function unless you know in detail about + * the implications of using + * the shared GFpModulus objects! + * @result the shared pointer to the GFpModulus of *this + */ + inline std::tr1::shared_ptr<GFpModulus> const get_ptr_mod() const + { + return mp_mod; + } + + + /** + * Sets the shared pointer to the GFpModulus of *this. + * Warning: do not use this function unless you know in detail about + * the implications of using + * the shared GFpModulus objects! + * @param mod a shared pointer to a GFpModulus that will be held in *this + */ + void set_shrd_mod(std::tr1::shared_ptr<GFpModulus> const mod); + + /** + * Tells whether this GFpElement is currently transformed to it´ m-residue, + * i.e. in the form x_bar = x * r mod m. + * @result true if it is currently transformed to it´s m-residue. + */ + bool is_trf_to_mres() const; + + /** + * Transforms this to x_bar = x * r mod m + * @result return the value x_bar. + */ + const BigInt& get_mres() const; + + /** + * Check, if montgomery multiplication is used. + * @result true, if montgomery multiplication is used, false otherwise + */ + bool is_use_montgm() const + { + return m_use_montgm; + } + + /** + * Transforms the arguments in such way that either both + * are in m-residue representation (returns true) or both are + * in ordinary residue representation (returns false). + * m-residue is prefered in case of ambiguity. + * does not toggle m_use_montgm of the arguments. + * Don´t be confused about the constness of the arguments: + * the transformation between normal residue and m-residue is + * considered as leaving the object const. + * @param lhs the first operand to be aligned + * @param rhs the second operand to be aligned + * @result true if both are transformed to their m-residue, + * false it both are transformed to their normal residue. + */ + static bool align_operands_res(const GFpElement& lhs, const GFpElement& rhs); + + //friend declarations for non-member functions + + /** + * write a GFpElement to an output stream. + * @param output the output stream to write to + * @param elem the object to write + * @result the output stream + */ + friend std::ostream& operator<<(std::ostream& output, const GFpElement& elem); + + friend class Point_Coords_GFp; + + /** + * swaps the states of *this and other, does not throw! + * @param other The value to swap with + */ + void swap(GFpElement& other); + + }; + +// relational operators +bool operator==(const GFpElement& lhs, const GFpElement& rhs); +inline bool operator!=(const GFpElement& lhs, const GFpElement& rhs ) + { + return !operator==(lhs, rhs); + } + +// arithmetic operators +GFpElement operator+(const GFpElement& lhs, const GFpElement& rhs); +GFpElement operator-(const GFpElement& lhs, const GFpElement& rhs); +GFpElement operator-(const GFpElement& lhs); + +GFpElement operator*(const GFpElement& lhs, const GFpElement& rhs); +GFpElement operator/(const GFpElement& lhs, const GFpElement& rhs); +GFpElement operator* (const GFpElement& lhs, u32bit rhs); +GFpElement operator* (u32bit rhs, const GFpElement& lhs); + +// io operators +std::ostream& operator<<(std::ostream& output, const GFpElement& elem); + +// return (*this)^(-1) +GFpElement inverse(const GFpElement& elem); + +// encoding and decoding +SecureVector<byte> FE2OSP(const GFpElement& elem); +GFpElement OS2FEP(MemoryRegion<byte> const& os, BigInt p); + +inline void swap(GFpElement& x, GFpElement& y) + { + x.swap(y); + } + +} + +namespace std { + +template<> inline +void swap<Botan::GFpElement>(Botan::GFpElement& x, + Botan::GFpElement& y) + { + x.swap(y); + } + +} + +#endif diff --git a/old/botan/build/botan/gfp_modulus.h b/old/botan/build/botan/gfp_modulus.h new file mode 100644 index 0000000..b5c0857 --- /dev/null +++ b/old/botan/build/botan/gfp_modulus.h @@ -0,0 +1,127 @@ +/****** + * Modulus and related data for a specific + * implementation of GF(p) (header file) + * + * (C) 2008 Martin Döring + * doering@cdc.informatik.tu-darmstadt.de + * Christoph Ludwig + * ludwig@fh-worms.de + * Falko Strenzke + * strenzke@flexsecure.de + ******/ + +#ifndef BOTAN_GFP_MODULUS_H__ +#define BOTAN_GFP_MODULUS_H__ + +#include <botan/bigint.h> + +namespace Botan +{ + +class BOTAN_DLL GFpElement; +/** +* This class represents a GFpElement modulus including the modulus related +* values necessary for the montgomery multiplication. +* +* Distributed under the terms of the Botan license +*/ +class BOTAN_DLL GFpModulus + { + friend class GFpElement; + private: + BigInt m_p; // the modulus itself + mutable BigInt m_p_dash; + mutable BigInt m_r; + mutable BigInt m_r_inv; + public: + + /** + * Construct a GF(P)-Modulus from a BigInt + */ + GFpModulus(BigInt p) + : m_p(p), + m_p_dash(), + m_r(), + m_r_inv() + {} + + /** + * Tells whether the precomputations necessary for the use of the + * montgomery multiplication have yet been established. + * @result true if the precomputated value are already available. + */ + inline bool has_precomputations() const + { + return(!m_p_dash.is_zero() && !m_r.is_zero() && !m_r_inv.is_zero()); + } + + /** + * Swaps this with another GFpModulus, does not throw. + * @param other the GFpModulus to swap *this with. + */ + inline void swap(GFpModulus& other) + { + m_p.swap(other.m_p); + m_p_dash.swap(other.m_p_dash); + m_r.swap(other.m_r); + m_r_inv.swap(other.m_r_inv); + } + + /** + * Tells whether the modulus of *this is equal to the argument. + * @param mod the modulus to compare this with + * @result true if the modulus of *this and the argument are equal. + */ + inline bool p_equal_to(const BigInt& mod) const + { + return (m_p == mod); + } + + /** + * Return the modulus of this GFpModulus. + * @result the modulus of *this. + */ + inline const BigInt& get_p() const + { + return m_p; + } + + /** + * returns the montgomery multiplication related value r. + * Warning: will be zero if precomputations have not yet been + * performed! + * @result r + */ + inline const BigInt& get_r() const + { + return m_r; + } + + /** + * returns the montgomery multiplication related value r^{-1}. + * Warning: will be zero if precomputations have not yet been + * performed! + * @result r^{-1} + */ + inline const BigInt& get_r_inv() const + { + return m_r_inv; + } + + /** + * returns the montgomery multiplication related value p'. + * Warning: will be zero if precomputations have not yet been + * performed! + * @result p' + */ + inline const BigInt& get_p_dash() const + { + return m_p_dash; + } + // default cp-ctor, op= are fine + }; + +} + +#endif + diff --git a/old/botan/build/botan/gost_28147.h b/old/botan/build/botan/gost_28147.h new file mode 100644 index 0000000..96d24c6 --- /dev/null +++ b/old/botan/build/botan/gost_28147.h @@ -0,0 +1,67 @@ +/* +* GOST 28147-89 +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_GOST_28147_89_H__ +#define BOTAN_GOST_28147_89_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +class GOST_28147_89_Params; + +/** +* The GOST 28147-89 block cipher uses a set of 4 bit Sboxes, however +* the standard does not actually define these Sboxes; they are +* considered a local configuration issue. Several different sets are +* used. +*/ +class GOST_28147_89_Params + { + public: + byte sbox_entry(u32bit row, u32bit col) const; + + std::string param_name() const { return name; } + + /** + * Default GOST parameters are the ones given in GOST R 34.11 for + * testing purposes; these sboxes are also used by Crypto++, and, + * at least according to Wikipedia, the Central Bank of Russian Federation + */ + GOST_28147_89_Params(const std::string& name = "R3411_94_TestParam"); + private: + const byte* sboxes; + std::string name; + }; + +/** +* GOST 28147-89 +*/ +class BOTAN_DLL GOST_28147_89 : public BlockCipher + { + public: + void clear() throw() { EK.clear(); } + + std::string name() const { return "GOST-28147-89"; } + BlockCipher* clone() const { return new GOST_28147_89(SBOX); } + + GOST_28147_89(const GOST_28147_89_Params& params); + private: + GOST_28147_89(const SecureBuffer<u32bit, 1024>& other_SBOX) : + BlockCipher(8, 32), SBOX(other_SBOX) {} + + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u32bit, 1024> SBOX; + SecureBuffer<u32bit, 8> EK; + }; + +} + +#endif diff --git a/old/botan/build/botan/gost_3411.h b/old/botan/build/botan/gost_3411.h new file mode 100644 index 0000000..c695550 --- /dev/null +++ b/old/botan/build/botan/gost_3411.h @@ -0,0 +1,41 @@ +/** +* GOST 34.11 +* (C) 2009 Jack Lloyd +*/ + +#ifndef BOTAN_GOST_3411_H__ +#define BOTAN_GOST_3411_H__ + +#include <botan/hash.h> +#include <botan/gost_28147.h> + +namespace Botan { + +/** +* GOST 34.11 +*/ +class BOTAN_DLL GOST_34_11 : public HashFunction + { + public: + void clear() throw(); + std::string name() const { return "GOST-R-34.11-94" ; } + HashFunction* clone() const { return new GOST_34_11; } + + GOST_34_11(); + protected: + void compress_n(const byte input[], u32bit blocks); + + void add_data(const byte[], u32bit); + void final_result(byte[]); + + GOST_28147_89 cipher; + SecureBuffer<byte, 32> buffer; + SecureBuffer<byte, 32> sum; + SecureBuffer<byte, 32> hash; + u64bit count; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/has160.h b/old/botan/build/botan/has160.h new file mode 100644 index 0000000..44bb63b --- /dev/null +++ b/old/botan/build/botan/has160.h @@ -0,0 +1,35 @@ +/* +* HAS-160 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_HAS_160_H__ +#define BOTAN_HAS_160_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* HAS-160 +*/ +class BOTAN_DLL HAS_160 : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "HAS-160"; } + HashFunction* clone() const { return new HAS_160; } + HAS_160() : MDx_HashFunction(20, 64, false, true) { clear(); } + private: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + SecureBuffer<u32bit, 20> X; + SecureBuffer<u32bit, 5> digest; + }; + +} + +#endif diff --git a/old/botan/build/botan/hash.h b/old/botan/build/botan/hash.h new file mode 100644 index 0000000..a30234b --- /dev/null +++ b/old/botan/build/botan/hash.h @@ -0,0 +1,52 @@ +/** +* Hash Function Base Class +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_HASH_FUNCTION_BASE_CLASS_H__ +#define BOTAN_HASH_FUNCTION_BASE_CLASS_H__ + +#include <botan/buf_comp.h> +#include <string> + +namespace Botan { + +/** +* This class represents hash function (message digest) objects. +*/ +class BOTAN_DLL HashFunction : public BufferedComputation + { + public: + /** + * The hash block size as defined for this algorithm. + */ + const u32bit HASH_BLOCK_SIZE; + + /** + * Get a new object representing the same algorithm as *this + */ + virtual HashFunction* clone() const = 0; + + /** + * Get the name of this algorithm. + * @return the name of this algorithm + */ + virtual std::string name() const = 0; + + /** + * Reset the internal state of this object. + */ + virtual void clear() throw() = 0; + + HashFunction(u32bit hash_len, u32bit block_len = 0) : + BufferedComputation(hash_len), HASH_BLOCK_SIZE(block_len) {} + virtual ~HashFunction() {} + private: + HashFunction& operator=(const HashFunction&); + }; + +} + +#endif diff --git a/old/botan/build/botan/hash_id.h b/old/botan/build/botan/hash_id.h new file mode 100644 index 0000000..847d910 --- /dev/null +++ b/old/botan/build/botan/hash_id.h @@ -0,0 +1,24 @@ +/* +* Hash Function Identification +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_HASHID_H__ +#define BOTAN_HASHID_H__ + +#include <botan/secmem.h> +#include <string> + +namespace Botan { + +/* +* Return the values of various defined HashIDs +*/ +BOTAN_DLL MemoryVector<byte> pkcs_hash_id(const std::string&); +BOTAN_DLL byte ieee1363_hash_id(const std::string&); + +} + +#endif diff --git a/old/botan/build/botan/hex.h b/old/botan/build/botan/hex.h new file mode 100644 index 0000000..035bf4e --- /dev/null +++ b/old/botan/build/botan/hex.h @@ -0,0 +1,90 @@ +/* +* Hex Encoder/Decoder +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_HEX_H__ +#define BOTAN_HEX_H__ + +#include <botan/filter.h> + +namespace Botan { + +/** +* This class represents a hex encoder. It encodes byte arrays to hex strings. +*/ +class BOTAN_DLL Hex_Encoder : public Filter + { + public: + /** + * Whether to use uppercase or lowercase letters for the encoded string. + */ + enum Case { Uppercase, Lowercase }; + + /** + Encode a single byte into two hex characters + */ + static void encode(byte in, byte out[2], Case the_case = Uppercase); + + void write(const byte in[], u32bit length); + void end_msg(); + + /** + * Create a hex encoder. + * @param the_case the case to use in the encoded strings. + */ + Hex_Encoder(Case the_case); + + /** + * Create a hex encoder. + * @param newlines should newlines be used + * @param line_length if newlines are used, how long are lines + * @param the_case the case to use in the encoded strings + */ + Hex_Encoder(bool newlines = false, + u32bit line_length = 72, + Case the_case = Uppercase); + private: + void encode_and_send(const byte[], u32bit); + static const byte BIN_TO_HEX_UPPER[16]; + static const byte BIN_TO_HEX_LOWER[16]; + + const Case casing; + const u32bit line_length; + SecureVector<byte> in, out; + u32bit position, counter; + }; + +/** +* This class represents a hex decoder. It converts hex strings to byte arrays. +*/ +class BOTAN_DLL Hex_Decoder : public Filter + { + public: + static byte decode(const byte[2]); + static bool is_valid(byte); + + void write(const byte[], u32bit); + void end_msg(); + + /** + * Construct a Hex Decoder using the specified + * character checking. + * @param checking the checking to use during decoding. + */ + Hex_Decoder(Decoder_Checking checking = NONE); + private: + void decode_and_send(const byte[], u32bit); + void handle_bad_char(byte); + static const byte HEX_TO_BIN[256]; + + const Decoder_Checking checking; + SecureVector<byte> in, out; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/hmac.h b/old/botan/build/botan/hmac.h new file mode 100644 index 0000000..932af71 --- /dev/null +++ b/old/botan/build/botan/hmac.h @@ -0,0 +1,38 @@ +/* +* HMAC +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_HMAC_H__ +#define BOTAN_HMAC_H__ + +#include <botan/mac.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* HMAC +*/ +class BOTAN_DLL HMAC : public MessageAuthenticationCode + { + public: + void clear() throw(); + std::string name() const; + MessageAuthenticationCode* clone() const; + + HMAC(HashFunction* hash); + ~HMAC() { delete hash; } + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + void key_schedule(const byte[], u32bit); + HashFunction* hash; + SecureVector<byte> i_key, o_key; + }; + +} + +#endif diff --git a/old/botan/build/botan/hmac_rng.h b/old/botan/build/botan/hmac_rng.h new file mode 100644 index 0000000..318e2a9 --- /dev/null +++ b/old/botan/build/botan/hmac_rng.h @@ -0,0 +1,59 @@ +/* +* HMAC RNG +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_HMAC_RNG_H__ +#define BOTAN_HMAC_RNG_H__ + +#include <botan/mac.h> +#include <botan/rng.h> +#include <vector> + +namespace Botan { + +/** +HMAC_RNG - based on the design described in "On Extract-then-Expand +Key Derivation Functions and an HMAC-based KDF" by Hugo Krawczyk +(henceforce, 'E-t-E') + +However it actually can be parameterized with any two MAC functions, +not restricted to HMAC (this variation is also described in Krawczyk's +paper), for instance one could use HMAC(SHA-512) as the extractor +and CMAC(AES-256) as the PRF. +*/ +class BOTAN_DLL HMAC_RNG : public RandomNumberGenerator + { + public: + void randomize(byte buf[], u32bit len); + bool is_seeded() const { return seeded; } + void clear() throw(); + std::string name() const; + + void reseed(u32bit poll_bits); + void add_entropy_source(EntropySource* es); + void add_entropy(const byte[], u32bit); + + HMAC_RNG(MessageAuthenticationCode* extractor, + MessageAuthenticationCode* prf); + + ~HMAC_RNG(); + private: + void reseed_with_input(u32bit poll_bits, + const byte input[], u32bit length); + + MessageAuthenticationCode* extractor; + MessageAuthenticationCode* prf; + + std::vector<EntropySource*> entropy_sources; + bool seeded; + + SecureVector<byte> K, io_buffer; + u32bit counter, source_index; + }; + +} + +#endif diff --git a/old/botan/build/botan/idea.h b/old/botan/build/botan/idea.h new file mode 100644 index 0000000..2c53cd0 --- /dev/null +++ b/old/botan/build/botan/idea.h @@ -0,0 +1,34 @@ +/* +* IDEA +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_IDEA_H__ +#define BOTAN_IDEA_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* IDEA +*/ +class BOTAN_DLL IDEA : public BlockCipher + { + public: + void clear() throw() { EK.clear(); DK.clear(); } + std::string name() const { return "IDEA"; } + BlockCipher* clone() const { return new IDEA; } + IDEA() : BlockCipher(8, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + SecureBuffer<u16bit, 52> EK, DK; + }; + +} + +#endif diff --git a/old/botan/build/botan/if_algo.h b/old/botan/build/botan/if_algo.h new file mode 100644 index 0000000..32a29be --- /dev/null +++ b/old/botan/build/botan/if_algo.h @@ -0,0 +1,85 @@ +/* +* IF Scheme +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_IF_ALGO_H__ +#define BOTAN_IF_ALGO_H__ + +#include <botan/if_core.h> +#include <botan/x509_key.h> +#include <botan/pkcs8.h> + +namespace Botan { + +/** +* This class represents public keys +* of integer factorization based (IF) public key schemes. +*/ +class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key + { + public: + bool check_key(RandomNumberGenerator& rng, bool) const; + + /** + * Get n = p * q. + * @return n + */ + const BigInt& get_n() const { return n; } + + /** + * Get the public exponent used by the key. + * @return the public exponent + */ + const BigInt& get_e() const { return e; } + + u32bit max_input_bits() const { return (n.bits() - 1); } + + X509_Encoder* x509_encoder() const; + X509_Decoder* x509_decoder(); + protected: + virtual void X509_load_hook(); + BigInt n, e; + IF_Core core; + }; + +/** +* This class represents public keys +* of integer factorization based (IF) public key schemes. +*/ +class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey, + public virtual Private_Key + { + public: + bool check_key(RandomNumberGenerator& rng, bool) const; + + /** + * Get the first prime p. + * @return the prime p + */ + const BigInt& get_p() const { return p; } + + /** + * Get the second prime q. + * @return the prime q + */ + const BigInt& get_q() const { return q; } + + /** + * Get d with exp * d = 1 mod (p - 1, q - 1). + * @return d + */ + const BigInt& get_d() const { return d; } + + PKCS8_Encoder* pkcs8_encoder() const; + PKCS8_Decoder* pkcs8_decoder(RandomNumberGenerator&); + protected: + virtual void PKCS8_load_hook(RandomNumberGenerator&, bool = false); + BigInt d, p, q, d1, d2, c; + }; + +} + +#endif diff --git a/old/botan/build/botan/if_core.h b/old/botan/build/botan/if_core.h new file mode 100644 index 0000000..b7f4877 --- /dev/null +++ b/old/botan/build/botan/if_core.h @@ -0,0 +1,45 @@ +/* +* IF Algorithm Core +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_IF_CORE_H__ +#define BOTAN_IF_CORE_H__ + +#include <botan/if_op.h> +#include <botan/blinding.h> + +namespace Botan { + +/* +* IF Core +*/ +class BOTAN_DLL IF_Core + { + public: + BigInt public_op(const BigInt&) const; + BigInt private_op(const BigInt&) const; + + IF_Core& operator=(const IF_Core&); + + IF_Core() { op = 0; } + IF_Core(const IF_Core&); + + IF_Core(const BigInt&, const BigInt&); + + IF_Core(RandomNumberGenerator& rng, + const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&); + + ~IF_Core() { delete op; } + private: + IF_Operation* op; + Blinder blinder; + }; + +} + +#endif diff --git a/old/botan/build/botan/if_op.h b/old/botan/build/botan/if_op.h new file mode 100644 index 0000000..516902f --- /dev/null +++ b/old/botan/build/botan/if_op.h @@ -0,0 +1,52 @@ +/* +* IF Operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_IF_OP_H__ +#define BOTAN_IF_OP_H__ + +#include <botan/bigint.h> +#include <botan/pow_mod.h> +#include <botan/reducer.h> + +namespace Botan { + +/* +* IF Operation +*/ +class BOTAN_DLL IF_Operation + { + public: + virtual BigInt public_op(const BigInt&) const = 0; + virtual BigInt private_op(const BigInt&) const = 0; + virtual IF_Operation* clone() const = 0; + virtual ~IF_Operation() {} + }; + +/* +* Default IF Operation +*/ +class BOTAN_DLL Default_IF_Op : public IF_Operation + { + public: + BigInt public_op(const BigInt& i) const + { return powermod_e_n(i); } + BigInt private_op(const BigInt&) const; + + IF_Operation* clone() const { return new Default_IF_Op(*this); } + + Default_IF_Op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&); + private: + Fixed_Exponent_Power_Mod powermod_e_n, powermod_d1_p, powermod_d2_q; + Modular_Reducer reducer; + BigInt c, q; + }; + +} + +#endif diff --git a/old/botan/build/botan/init.h b/old/botan/build/botan/init.h new file mode 100644 index 0000000..254f945 --- /dev/null +++ b/old/botan/build/botan/init.h @@ -0,0 +1,41 @@ +/** +* Library Initialization +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_LIBRARY_INITIALIZER_H__ +#define BOTAN_LIBRARY_INITIALIZER_H__ + +#include <botan/build.h> +#include <string> + +namespace Botan { + +/** +* This class represents the Library Initialization/Shutdown Object. It +* has to exceed the lifetime of any Botan object used in an +* application. You can call initialize/deinitialize or use +* LibraryInitializer in the RAII style. +*/ +class BOTAN_DLL LibraryInitializer + { + public: + static void initialize(const std::string& options = ""); + + static void deinitialize(); + + /** + * Initialize the library + * @param thread_safe if the library should use a thread-safe mutex + */ + LibraryInitializer(const std::string& options = "") + { LibraryInitializer::initialize(options); } + + ~LibraryInitializer() { LibraryInitializer::deinitialize(); } + }; + +} + +#endif diff --git a/old/botan/build/botan/kasumi.h b/old/botan/build/botan/kasumi.h new file mode 100644 index 0000000..df49fa9 --- /dev/null +++ b/old/botan/build/botan/kasumi.h @@ -0,0 +1,36 @@ +/* +* KASUMI +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_KASUMI_H__ +#define BOTAN_KASUMI_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* KASUMI +*/ +class BOTAN_DLL KASUMI : public BlockCipher + { + public: + void clear() throw() { EK.clear(); } + std::string name() const { return "KASUMI"; } + BlockCipher* clone() const { return new KASUMI; } + + KASUMI() : BlockCipher(8, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u16bit, 64> EK; + }; + +} + +#endif diff --git a/old/botan/build/botan/kdf.h b/old/botan/build/botan/kdf.h new file mode 100644 index 0000000..70f636b --- /dev/null +++ b/old/botan/build/botan/kdf.h @@ -0,0 +1,60 @@ +/* +* KDF/MGF +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_KDF_BASE_H__ +#define BOTAN_KDF_BASE_H__ + +#include <botan/secmem.h> +#include <botan/types.h> + +namespace Botan { + +/* +* Key Derivation Function +*/ +class BOTAN_DLL KDF + { + public: + SecureVector<byte> derive_key(u32bit key_len, + const MemoryRegion<byte>& secret, + const std::string& salt = "") const; + SecureVector<byte> derive_key(u32bit key_len, + const MemoryRegion<byte>& secret, + const MemoryRegion<byte>& salt) const; + + SecureVector<byte> derive_key(u32bit key_len, + const MemoryRegion<byte>& secret, + const byte salt[], u32bit salt_len) const; + + SecureVector<byte> derive_key(u32bit key_len, + const byte secret[], u32bit secret_len, + const std::string& salt = "") const; + SecureVector<byte> derive_key(u32bit key_len, + const byte secret[], u32bit secret_len, + const byte salt[], u32bit salt_len) const; + + virtual ~KDF() {} + private: + virtual SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const = 0; + }; + +/* +* Mask Generation Function +*/ +class BOTAN_DLL MGF + { + public: + virtual void mask(const byte in[], u32bit in_len, + byte out[], u32bit out_len) const = 0; + + virtual ~MGF() {} + }; + +} + +#endif diff --git a/old/botan/build/botan/kdf1.h b/old/botan/build/botan/kdf1.h new file mode 100644 index 0000000..d657ccc --- /dev/null +++ b/old/botan/build/botan/kdf1.h @@ -0,0 +1,36 @@ +/* +* KDF1 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_KDF1_H__ +#define BOTAN_KDF1_H__ + +#include <botan/kdf.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* KDF1 +*/ +class BOTAN_DLL KDF1 : public KDF + { + public: + SecureVector<byte> derive(u32bit, + const byte secret[], u32bit secret_len, + const byte P[], u32bit P_len) const; + + KDF1(HashFunction* h) : hash(h) {} + KDF1(const KDF1& other) : KDF(), hash(other.hash->clone()) {} + + ~KDF1() { delete hash; } + private: + HashFunction* hash; + }; + +} + +#endif diff --git a/old/botan/build/botan/kdf2.h b/old/botan/build/botan/kdf2.h new file mode 100644 index 0000000..f748bed --- /dev/null +++ b/old/botan/build/botan/kdf2.h @@ -0,0 +1,34 @@ +/* +* KDF2 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_KDF2_H__ +#define BOTAN_KDF2_H__ + +#include <botan/kdf.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* KDF2 +*/ +class BOTAN_DLL KDF2 : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + KDF2(HashFunction* h) : hash(h) {} + KDF2(const KDF2& other) : KDF(), hash(other.hash->clone()) {} + ~KDF2() { delete hash; } + private: + HashFunction* hash; + }; + +} + +#endif diff --git a/old/botan/build/botan/keypair.h b/old/botan/build/botan/keypair.h new file mode 100644 index 0000000..b1d5c2d --- /dev/null +++ b/old/botan/build/botan/keypair.h @@ -0,0 +1,47 @@ +/* +* Keypair Checks +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_KEYPAIR_H__ +#define BOTAN_KEYPAIR_H__ + +#include <botan/pubkey.h> + +namespace Botan { + +namespace KeyPair { + +/** +* Tests whether the specified encryptor and decryptor are related to each other, +* i.e. whether encrypting with the encryptor and consecutive decryption leads to +* the original plaintext. +* @param rng the rng to use +* @param enc the encryptor to test +* @param dec the decryptor to test +* @throw Self_Test_Failure if the arguments are not related to each other +*/ +BOTAN_DLL void check_key(RandomNumberGenerator& rng, + PK_Encryptor* enc, + PK_Decryptor* dec); + +/** +* Tests whether the specified signer and verifier are related to each other, +* i.e. whether a signature created with the signer and can be +* successfully verified with the verifier. +* @param rng the rng to use +* @param sig the signer to test +* @param ver the verifier to test +* @throw Self_Test_Failure if the arguments are not related to each other +*/ +BOTAN_DLL void check_key(RandomNumberGenerator& rng, + PK_Signer* sig, + PK_Verifier* ver); + +} + +} + +#endif diff --git a/old/botan/build/botan/libstate.h b/old/botan/build/botan/libstate.h new file mode 100644 index 0000000..2493863 --- /dev/null +++ b/old/botan/build/botan/libstate.h @@ -0,0 +1,125 @@ +/* +* Library Internal/Global State +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_LIB_STATE_H__ +#define BOTAN_LIB_STATE_H__ + +#include <botan/types.h> +#include <botan/allocate.h> +#include <botan/algo_factory.h> + +#include <string> +#include <vector> +#include <map> + +namespace Botan { + +/* +* Global State Container Base +*/ +class BOTAN_DLL Library_State + { + public: + Library_State(); + ~Library_State(); + + void initialize(bool thread_safe); + + Algorithm_Factory& algorithm_factory(); + + Allocator* get_allocator(const std::string& = "") const; + void add_allocator(Allocator*); + void set_default_allocator(const std::string&); + + /** + * Get a parameter value as std::string. + * @param section the section of the desired key + * @param key the desired keys name + * @result the value of the parameter + */ + std::string get(const std::string& section, + const std::string& key) const; + + /** + * Check whether a certain parameter is set + * or not. + * @param section the section of the desired key + * @param key the desired keys name + * @result true if the parameters value is set, + * false otherwise + */ + bool is_set(const std::string& section, const std::string& key) const; + + /** + * Set a configuration parameter. + * @param section the section of the desired key + * @param key the desired keys name + * @param overwrite if set to true, the parameters value + * will be overwritten even if it is already set, otherwise + * no existing values will be overwritten. + */ + void set(const std::string& section, const std::string& key, + const std::string& value, bool overwrite = true); + + /** + * Get a parameters value out of the "conf" section ( + * referred to as option). + * @param key the desired keys name + */ + std::string option(const std::string& key) const; + + /** + * Set an option. + * @param key the key of the option to set + * @param value the value to set + */ + void set_option(const std::string key, const std::string& value); + + /** + * Add a parameter value to the "alias" section. + * @param key the name of the parameter which shall have a new alias + * @param value the new alias + */ + void add_alias(const std::string&, const std::string&); + + /** + * Resolve an alias. + * @param alias the alias to resolve. + * @return what the alias stands for + */ + std::string deref_alias(const std::string&) const; + + class Mutex* get_mutex() const; + private: + void load_default_config(); + + Library_State(const Library_State&) {} + Library_State& operator=(const Library_State&) { return (*this); } + + class Mutex_Factory* mutex_factory; + + std::map<std::string, std::string> config; + class Mutex* config_lock; + + class Mutex* allocator_lock; + std::map<std::string, Allocator*> alloc_factory; + mutable Allocator* cached_default_allocator; + std::vector<Allocator*> allocators; + + Algorithm_Factory* m_algorithm_factory; + }; + +/* +* Global State +*/ +BOTAN_DLL Library_State& global_state(); +BOTAN_DLL void set_global_state(Library_State*); +BOTAN_DLL Library_State* swap_global_state(Library_State*); + +} + +#endif diff --git a/old/botan/build/botan/lion.h b/old/botan/build/botan/lion.h new file mode 100644 index 0000000..5bc4e72 --- /dev/null +++ b/old/botan/build/botan/lion.h @@ -0,0 +1,43 @@ +/* +* Lion +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_LION_H__ +#define BOTAN_LION_H__ + +#include <botan/block_cipher.h> +#include <botan/stream_cipher.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* Lion +*/ +class BOTAN_DLL Lion : public BlockCipher + { + public: + void clear() throw(); + std::string name() const; + BlockCipher* clone() const; + + Lion(HashFunction*, StreamCipher*, u32bit); + ~Lion() { delete hash; delete cipher; } + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + const u32bit LEFT_SIZE, RIGHT_SIZE; + + HashFunction* hash; + StreamCipher* cipher; + SecureVector<byte> key1, key2; + }; + +} + +#endif diff --git a/old/botan/build/botan/loadstor.h b/old/botan/build/botan/loadstor.h new file mode 100644 index 0000000..77ed155 --- /dev/null +++ b/old/botan/build/botan/loadstor.h @@ -0,0 +1,281 @@ +/* +* Load/Store Operators +* (C) 1999-2007 Jack Lloyd +* 2007 Yves Jerschow +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_LOAD_STORE_H__ +#define BOTAN_LOAD_STORE_H__ + +#include <botan/types.h> +#include <botan/bswap.h> +#include <botan/rotate.h> + +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + +#if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) + +#define BOTAN_ENDIAN_N2B(x) (x) +#define BOTAN_ENDIAN_B2N(x) (x) + +#define BOTAN_ENDIAN_N2L(x) reverse_bytes(x) +#define BOTAN_ENDIAN_L2N(x) reverse_bytes(x) + +#elif defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) + +#define BOTAN_ENDIAN_N2L(x) (x) +#define BOTAN_ENDIAN_L2N(x) (x) + +#define BOTAN_ENDIAN_N2B(x) reverse_bytes(x) +#define BOTAN_ENDIAN_B2N(x) reverse_bytes(x) + +#endif + +#endif + +namespace Botan { + +/* +* Byte Extraction Function +*/ +template<typename T> inline byte get_byte(u32bit byte_num, T input) + { + return (input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)); + } + +/* +* Byte to Word Conversions +*/ +inline u16bit make_u16bit(byte i0, byte i1) + { + return ((static_cast<u16bit>(i0) << 8) | i1); + } + +inline u32bit make_u32bit(byte i0, byte i1, byte i2, byte i3) + { + return ((static_cast<u32bit>(i0) << 24) | + (static_cast<u32bit>(i1) << 16) | + (static_cast<u32bit>(i2) << 8) | + (static_cast<u32bit>(i3))); + } + +inline u64bit make_u64bit(byte i0, byte i1, byte i2, byte i3, + byte i4, byte i5, byte i6, byte i7) + { + return ((static_cast<u64bit>(i0) << 56) | + (static_cast<u64bit>(i1) << 48) | + (static_cast<u64bit>(i2) << 40) | + (static_cast<u64bit>(i3) << 32) | + (static_cast<u64bit>(i4) << 24) | + (static_cast<u64bit>(i5) << 16) | + (static_cast<u64bit>(i6) << 8) | + (static_cast<u64bit>(i7))); + } + +/* +* Endian-Specific Word Loading Operations +*/ +template<typename T> +inline T load_be(const byte in[], u32bit off) + { + in += off * sizeof(T); + T out = 0; + for(u32bit j = 0; j != sizeof(T); j++) + out = (out << 8) | in[j]; + return out; + } + +template<typename T> +inline T load_le(const byte in[], u32bit off) + { + in += off * sizeof(T); + T out = 0; + for(u32bit j = 0; j != sizeof(T); j++) + out = (out << 8) | in[sizeof(T)-1-j]; + return out; + } + +template<> +inline u16bit load_be<u16bit>(const byte in[], u32bit off) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + return BOTAN_ENDIAN_N2B(*(reinterpret_cast<const u16bit*>(in) + off)); +#else + in += off * sizeof(u16bit); + return make_u16bit(in[0], in[1]); +#endif + } + +template<> +inline u16bit load_le<u16bit>(const byte in[], u32bit off) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + return BOTAN_ENDIAN_N2L(*(reinterpret_cast<const u16bit*>(in) + off)); +#else + in += off * sizeof(u16bit); + return make_u16bit(in[1], in[0]); +#endif + } + +template<> +inline u32bit load_be<u32bit>(const byte in[], u32bit off) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + return BOTAN_ENDIAN_N2B(*(reinterpret_cast<const u32bit*>(in) + off)); +#else + in += off * sizeof(u32bit); + return make_u32bit(in[0], in[1], in[2], in[3]); +#endif + } + +template<> +inline u32bit load_le<u32bit>(const byte in[], u32bit off) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + return BOTAN_ENDIAN_N2L(*(reinterpret_cast<const u32bit*>(in) + off)); +#else + in += off * sizeof(u32bit); + return make_u32bit(in[3], in[2], in[1], in[0]); +#endif + } + +template<> +inline u64bit load_be<u64bit>(const byte in[], u32bit off) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + return BOTAN_ENDIAN_N2B(*(reinterpret_cast<const u64bit*>(in) + off)); +#else + in += off * sizeof(u64bit); + return make_u64bit(in[0], in[1], in[2], in[3], + in[4], in[5], in[6], in[7]); +#endif + } + +template<> +inline u64bit load_le<u64bit>(const byte in[], u32bit off) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + return BOTAN_ENDIAN_N2L(*(reinterpret_cast<const u64bit*>(in) + off)); +#else + in += off * sizeof(u64bit); + return make_u64bit(in[7], in[6], in[5], in[4], + in[3], in[2], in[1], in[0]); +#endif + } + +/* +* Endian-Specific Word Storing Operations +*/ +inline void store_be(u16bit in, byte out[2]) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u16bit*>(out) = BOTAN_ENDIAN_B2N(in); +#else + out[0] = get_byte(0, in); + out[1] = get_byte(1, in); +#endif + } + +inline void store_le(u16bit in, byte out[2]) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u16bit*>(out) = BOTAN_ENDIAN_L2N(in); +#else + out[0] = get_byte(1, in); + out[1] = get_byte(0, in); +#endif + } + +inline void store_be(u32bit in, byte out[4]) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u32bit*>(out) = BOTAN_ENDIAN_B2N(in); +#else + out[0] = get_byte(0, in); + out[1] = get_byte(1, in); + out[2] = get_byte(2, in); + out[3] = get_byte(3, in); +#endif + } + +inline void store_le(u32bit in, byte out[4]) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u32bit*>(out) = BOTAN_ENDIAN_L2N(in); +#else + out[0] = get_byte(3, in); + out[1] = get_byte(2, in); + out[2] = get_byte(1, in); + out[3] = get_byte(0, in); +#endif + } + +inline void store_be(u64bit in, byte out[8]) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u64bit*>(out) = BOTAN_ENDIAN_B2N(in); +#else + out[0] = get_byte(0, in); + out[1] = get_byte(1, in); + out[2] = get_byte(2, in); + out[3] = get_byte(3, in); + out[4] = get_byte(4, in); + out[5] = get_byte(5, in); + out[6] = get_byte(6, in); + out[7] = get_byte(7, in); +#endif + } + +inline void store_le(u64bit in, byte out[8]) + { +#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u64bit*>(out) = BOTAN_ENDIAN_L2N(in); +#else + out[0] = get_byte(7, in); + out[1] = get_byte(6, in); + out[2] = get_byte(5, in); + out[3] = get_byte(4, in); + out[4] = get_byte(3, in); + out[5] = get_byte(2, in); + out[6] = get_byte(1, in); + out[7] = get_byte(0, in); +#endif + } + +template<typename T> +inline void store_le(byte out[], T a, T b) + { + store_le(a, out + (0 * sizeof(T))); + store_le(b, out + (1 * sizeof(T))); + } + +template<typename T> +inline void store_be(byte out[], T a, T b) + { + store_be(a, out + (0 * sizeof(T))); + store_be(b, out + (1 * sizeof(T))); + } + +template<typename T> +inline void store_le(byte out[], T a, T b, T c, T d) + { + store_le(a, out + (0 * sizeof(T))); + store_le(b, out + (1 * sizeof(T))); + store_le(c, out + (2 * sizeof(T))); + store_le(d, out + (3 * sizeof(T))); + } + +template<typename T> +inline void store_be(byte out[], T a, T b, T c, T d) + { + store_be(a, out + (0 * sizeof(T))); + store_be(b, out + (1 * sizeof(T))); + store_be(c, out + (2 * sizeof(T))); + store_be(d, out + (3 * sizeof(T))); + } + +} + +#endif diff --git a/old/botan/build/botan/look_pk.h b/old/botan/build/botan/look_pk.h new file mode 100644 index 0000000..27b67dc --- /dev/null +++ b/old/botan/build/botan/look_pk.h @@ -0,0 +1,78 @@ +/* +* PK Algorithm Lookup +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PK_LOOKUP_H__ +#define BOTAN_PK_LOOKUP_H__ + +#include <botan/build.h> +#include <botan/pubkey.h> + +namespace Botan { + +/** +* Public key encryptor factory method. +* @param key the key that will work inside the encryptor +* @param pad determines the algorithm and encoding +* @return the public key encryptor object +*/ +BOTAN_DLL PK_Encryptor* get_pk_encryptor(const PK_Encrypting_Key& key, + const std::string& pad); + +/** +* Public key decryptor factory method. +* @param key the key that will work inside the decryptor +* @param pad determines the algorithm and encoding +* @return the public key decryptor object +*/ +BOTAN_DLL PK_Decryptor* get_pk_decryptor(const PK_Decrypting_Key& key, + const std::string& pad); + +/** +* Public key signer factory method. +* @param key the key that will work inside the signer +* @param pad determines the algorithm, encoding and hash algorithm +* @param sig_format the signature format to be used +* @return the public key signer object +*/ +BOTAN_DLL PK_Signer* get_pk_signer(const PK_Signing_Key& key, + const std::string& pad, + Signature_Format = IEEE_1363); + +/** +* Public key verifier factory method. +* @param key the key that will work inside the verifier +* @param pad determines the algorithm, encoding and hash algorithm +* @param sig_format the signature format to be used +* @return the public key verifier object +*/ +BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_with_MR_Key& key, + const std::string& pad, + Signature_Format = IEEE_1363); + +/** +* Public key verifier factory method. +* @param key the key that will work inside the verifier +* @param pad determines the algorithm, encoding and hash algorithm +* @param sig_form the signature format to be used +* @return the public key verifier object +*/ +BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_wo_MR_Key& key, + const std::string& pad, + Signature_Format sig_form = IEEE_1363); + +/** +* Public key key agreement factory method. +* @param key the key that will work inside the key agreement +* @param pad determines the algorithm, encoding and hash algorithm +* @return the public key verifier object +*/ +BOTAN_DLL PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key& key, + const std::string& pad); + +} + +#endif diff --git a/old/botan/build/botan/lookup.h b/old/botan/build/botan/lookup.h new file mode 100644 index 0000000..0f48ddd --- /dev/null +++ b/old/botan/build/botan/lookup.h @@ -0,0 +1,239 @@ +/* +* Algorithm Lookup +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_LOOKUP_H__ +#define BOTAN_LOOKUP_H__ + +#include <botan/block_cipher.h> +#include <botan/stream_cipher.h> +#include <botan/hash.h> +#include <botan/mac.h> +#include <botan/s2k.h> + +#include <botan/filters.h> +#include <botan/mode_pad.h> +#include <botan/kdf.h> +#include <botan/eme.h> +#include <botan/emsa.h> + +namespace Botan { + +/* +* Retrieve an object from the lookup table +*/ +// NOTE: these functions return internally stored objects, library +// retains ownership + +BOTAN_DLL const BlockCipher* +retrieve_block_cipher(const std::string&); + +BOTAN_DLL const StreamCipher* +retrieve_stream_cipher(const std::string&); + +BOTAN_DLL const HashFunction* +retrieve_hash(const std::string&); + +BOTAN_DLL const MessageAuthenticationCode* +retrieve_mac(const std::string&); + +/* +* Get an algorithm object +*/ +// NOTE: these functions create and return new objects, letting the +// caller assume ownership of them + +/** +* Block cipher factory method. +* @param algo_spec the name of the desired block cipher +* @return a pointer to the block cipher object +*/ +BOTAN_DLL BlockCipher* get_block_cipher(const std::string& name); + + +/** +* Stream cipher factory method. +* @param algo_spec the name of the desired stream cipher +* @return a pointer to the stream cipher object +*/ +BOTAN_DLL StreamCipher* get_stream_cipher(const std::string& name); + +/** +* Hash function factory method. +* @param algo_spec the name of the desired hash function +* @return a pointer to the hash function object +*/ +BOTAN_DLL HashFunction* get_hash(const std::string& name); + +/** +* MAC factory method. +* @param algo_spec the name of the desired MAC +* @return a pointer to the MAC object +*/ +BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string& name); + +/** +* String to key algorithm factory method. +* @param name the name of the desired string to key (S2K) algorithm +* @return a pointer to the string to key algorithm object +*/ +BOTAN_DLL S2K* get_s2k(const std::string& name); + +/* +* Get an EMSA/EME/KDF/MGF function +*/ +// NOTE: these functions create and return new objects, letting the +// caller assume ownership of them + +/** +* Factory method for EME (message-encoding methods for encryption) objects +* @param name the name of the EME to create +* @return a pointer to the desired EME object +*/ +BOTAN_DLL EME* get_eme(const std::string& name); + +/** +* Factory method for EMSA (message-encoding methods for signatures +* with appendix) objects +* @param name the name of the EME to create +* @return a pointer to the desired EME object +*/ +BOTAN_DLL EMSA* get_emsa(const std::string& name); + +/** +* Factory method for KDF (key derivation function) +* @param name the name of the KDF to create +* @return a pointer to the desired KDF object +*/ +BOTAN_DLL KDF* get_kdf(const std::string& name); + +/* +* Get a cipher object +*/ + +/** +* Factory method for general symmetric cipher filters. +* @param algo_spec the name of the desired cipher +* @param key the key to be used for encryption/decryption performed by +* the filter +* @param iv the initialization vector to be used +* @param direction determines whether the filter will be an encrypting or decrypting +* filter +* @return a pointer to the encryption or decryption filter +*/ +BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, + const SymmetricKey& key, + const InitializationVector& iv, + Cipher_Dir dir); +/** +* Factory method for general symmetric cipher filters. +* @param algo_spec the name of the desired cipher +* @param key the key to be used for encryption/decryption performed by +* the filter +* @param direction determines whether the filter will be an encrypting or decrypting +* filter +* @return a pointer to the encryption or decryption filter +*/ +BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, + const SymmetricKey& key, + Cipher_Dir dir); + +/** Factory method for general symmetric cipher filters. No key will +* be set in the filter. +* @param algo_spec the name of the desired cipher + +* @param direction determines whether the filter will be an encrypting or +* decrypting filter +* @return a pointer to the encryption or decryption filter +*/ +BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, Cipher_Dir dir); + +/** +* Check if an algorithm exists. +* @param name the name of the algorithm to check for +* @return true if the algorithm exists, false otherwise +*/ +BOTAN_DLL bool have_algorithm(const std::string& name); + +/** +* Check if a block cipher algorithm exists. +* @param name the name of the algorithm to check for +* @return true if the algorithm exists, false otherwise +*/ +BOTAN_DLL bool have_block_cipher(const std::string& name); + +/** +* Check if a stream cipher algorithm exists. +* @param name the name of the algorithm to check for +* @return true if the algorithm exists, false otherwise +*/ +BOTAN_DLL bool have_stream_cipher(const std::string& name); + +/** +* Check if a hash algorithm exists. +* @param algo_spec the name of the algorithm to check for +* @return true if the algorithm exists, false otherwise +*/ +BOTAN_DLL bool have_hash(const std::string& name); + +/** +* Check if a MAC algorithm exists. +* @param algo_spec the name of the algorithm to check for +* @return true if the algorithm exists, false otherwise +*/ +BOTAN_DLL bool have_mac(const std::string& name); + +/* +* Query information about an algorithm +*/ + +/** +* Find out the block size of a certain symmetric algorithm. +* @param name the name of the algorithm +* @return the block size of the specified algorithm +*/ +BOTAN_DLL u32bit block_size_of(const std::string& name); + +/** +* Find out the output length of a certain symmetric algorithm. +* @param name the name of the algorithm +* @return the output length of the specified algorithm +*/ +BOTAN_DLL u32bit output_length_of(const std::string& name); + +/** +* Find out the whether a certain key length is allowd for a given +* symmetric algorithm. +* @param key_len the key length in question +* @param name the name of the algorithm +* @return true if the key length is valid for that algorithm, false otherwise +*/ +BOTAN_DLL bool valid_keylength_for(u32bit keylen, const std::string& name); + +/** +* Find out the minimum key size of a certain symmetric algorithm. +* @param name the name of the algorithm +* @return the minimum key length of the specified algorithm +*/ +BOTAN_DLL u32bit min_keylength_of(const std::string& name); + +/** +* Find out the maximum key size of a certain symmetric algorithm. +* @param name the name of the algorithm +* @return the maximum key length of the specified algorithm +*/ +BOTAN_DLL u32bit max_keylength_of(const std::string& name); + +/** +* Find out the size any valid key is a multiple of for a certain algorithm. +* @param name the name of the algorithm +* @return the size any valid key is a multiple of +*/ +BOTAN_DLL u32bit keylength_multiple_of(const std::string& name); + +} + +#endif diff --git a/old/botan/build/botan/lubyrack.h b/old/botan/build/botan/lubyrack.h new file mode 100644 index 0000000..ebde313 --- /dev/null +++ b/old/botan/build/botan/lubyrack.h @@ -0,0 +1,38 @@ +/* +* Luby-Rackoff +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_LUBY_RACKOFF_H__ +#define BOTAN_LUBY_RACKOFF_H__ + +#include <botan/block_cipher.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* Luby-Rackoff +*/ +class BOTAN_DLL LubyRackoff : public BlockCipher + { + public: + void clear() throw(); + std::string name() const; + BlockCipher* clone() const; + + LubyRackoff(HashFunction* hash); + ~LubyRackoff() { delete hash; } + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + HashFunction* hash; + SecureVector<byte> K1, K2; + }; + +} + +#endif diff --git a/old/botan/build/botan/mac.h b/old/botan/build/botan/mac.h new file mode 100644 index 0000000..3ec5fff --- /dev/null +++ b/old/botan/build/botan/mac.h @@ -0,0 +1,60 @@ +/** +* Base class for message authentiction codes +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MESSAGE_AUTH_CODE_BASE_H__ +#define BOTAN_MESSAGE_AUTH_CODE_BASE_H__ + +#include <botan/buf_comp.h> +#include <botan/sym_algo.h> +#include <string> + +namespace Botan { + +/** +* This class represents Message Authentication Code (MAC) objects. +*/ +class BOTAN_DLL MessageAuthenticationCode : public BufferedComputation, + public SymmetricAlgorithm + { + public: + /** + * Verify a MAC. + * @param in the MAC to verify as a byte array + * @param length the length of the byte array + * @return true if the MAC is valid, false otherwise + */ + virtual bool verify_mac(const byte[], u32bit); + + /** + * Get a new object representing the same algorithm as *this + */ + virtual MessageAuthenticationCode* clone() const = 0; + + /** + * Get the name of this algorithm. + * @return the name of this algorithm + */ + virtual std::string name() const = 0; + + /** + * Reset the internal state of this object. + */ + virtual void clear() throw() = 0; + + MessageAuthenticationCode(u32bit mac_len, + u32bit key_min, + u32bit key_max = 0, + u32bit key_mod = 1) : + BufferedComputation(mac_len), + SymmetricAlgorithm(key_min, key_max, key_mod) {} + + virtual ~MessageAuthenticationCode() {} + }; + +} + +#endif diff --git a/old/botan/build/botan/mars.h b/old/botan/build/botan/mars.h new file mode 100644 index 0000000..ca49695 --- /dev/null +++ b/old/botan/build/botan/mars.h @@ -0,0 +1,38 @@ +/* +* MARS +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MARS_H__ +#define BOTAN_MARS_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +class BOTAN_DLL MARS : public BlockCipher + { + public: + void clear() throw() { EK.clear(); } + std::string name() const { return "MARS"; } + BlockCipher* clone() const { return new MARS; } + MARS() : BlockCipher(16, 16, 32, 4) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + void encrypt_round(u32bit&, u32bit&, u32bit&, u32bit&, u32bit) const; + void decrypt_round(u32bit&, u32bit&, u32bit&, u32bit&, u32bit) const; + static void forward_mix(u32bit&, u32bit&, u32bit&, u32bit&); + static void reverse_mix(u32bit&, u32bit&, u32bit&, u32bit&); + + static const u32bit SBOX[512]; + SecureBuffer<u32bit, 40> EK; + }; + +} + +#endif diff --git a/old/botan/build/botan/md2.h b/old/botan/build/botan/md2.h new file mode 100644 index 0000000..9337c43 --- /dev/null +++ b/old/botan/build/botan/md2.h @@ -0,0 +1,37 @@ +/* +* MD2 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MD2_H__ +#define BOTAN_MD2_H__ + +#include <botan/hash.h> + +namespace Botan { + +/* +* MD2 +*/ +class BOTAN_DLL MD2 : public HashFunction + { + public: + void clear() throw(); + std::string name() const { return "MD2"; } + HashFunction* clone() const { return new MD2; } + MD2() : HashFunction(16, 16) { clear(); } + private: + void add_data(const byte[], u32bit); + void hash(const byte[]); + void final_result(byte[]); + + SecureBuffer<byte, 48> X; + SecureBuffer<byte, 16> checksum, buffer; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/md4.h b/old/botan/build/botan/md4.h new file mode 100644 index 0000000..df6f229 --- /dev/null +++ b/old/botan/build/botan/md4.h @@ -0,0 +1,36 @@ +/* +* MD4 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MD4_H__ +#define BOTAN_MD4_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* MD4 +*/ +class BOTAN_DLL MD4 : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "MD4"; } + HashFunction* clone() const { return new MD4; } + MD4() : MDx_HashFunction(16, 64, false, true) { clear(); } + protected: + void compress_n(const byte input[], u32bit blocks); + void hash_old(const byte[]); + void copy_out(byte[]); + + SecureBuffer<u32bit, 48> M; + SecureBuffer<u32bit, 4> digest; + }; + +} + +#endif diff --git a/old/botan/build/botan/md5.h b/old/botan/build/botan/md5.h new file mode 100644 index 0000000..85f684d --- /dev/null +++ b/old/botan/build/botan/md5.h @@ -0,0 +1,35 @@ +/** +* MD5 +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MD5_H__ +#define BOTAN_MD5_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/** +* MD5 +*/ +class BOTAN_DLL MD5 : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "MD5"; } + HashFunction* clone() const { return new MD5; } + MD5() : MDx_HashFunction(16, 64, false, true) { clear(); } + protected: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + SecureBuffer<u32bit, 16> M; + SecureBuffer<u32bit, 4> digest; + }; + +} + +#endif diff --git a/old/botan/build/botan/mdx_hash.h b/old/botan/build/botan/mdx_hash.h new file mode 100644 index 0000000..0c3aa78 --- /dev/null +++ b/old/botan/build/botan/mdx_hash.h @@ -0,0 +1,42 @@ +/** +* MDx Hash Function +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MDX_BASE_H__ +#define BOTAN_MDX_BASE_H__ + +#include <botan/hash.h> + +namespace Botan { + +/** +* MDx Hash Function Base Class +*/ +class BOTAN_DLL MDx_HashFunction : public HashFunction + { + public: + MDx_HashFunction(u32bit, u32bit, bool, bool, u32bit = 8); + virtual ~MDx_HashFunction() {} + protected: + void add_data(const byte[], u32bit); + void final_result(byte output[]); + virtual void compress_n(const byte block[], u32bit block_n) = 0; + + void clear() throw(); + virtual void copy_out(byte[]) = 0; + virtual void write_count(byte[]); + private: + SecureVector<byte> buffer; + u64bit count; + u32bit position; + + const bool BIG_BYTE_ENDIAN, BIG_BIT_ENDIAN; + const u32bit COUNT_SIZE; + }; + +} + +#endif diff --git a/old/botan/build/botan/mem_ops.h b/old/botan/build/botan/mem_ops.h new file mode 100644 index 0000000..0fcf34b --- /dev/null +++ b/old/botan/build/botan/mem_ops.h @@ -0,0 +1,40 @@ +/* +* Memory Operations +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MEMORY_OPS_H__ +#define BOTAN_MEMORY_OPS_H__ + +#include <botan/types.h> +#include <cstring> + +namespace Botan { + +/* +* Memory Manipulation Functions +*/ +template<typename T> inline void copy_mem(T* out, const T* in, u32bit n) + { std::memmove(out, in, sizeof(T)*n); } + +template<typename T> inline void clear_mem(T* ptr, u32bit n) + { if(n) std::memset(ptr, 0, sizeof(T)*n); } + +template<typename T> inline void set_mem(T* ptr, u32bit n, byte val) + { std::memset(ptr, val, sizeof(T)*n); } + +template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n) + { + bool is_same = true; + + for(u32bit i = 0; i != n; ++i) + is_same &= (p1[i] == p2[i]); + + return is_same; + } + +} + +#endif diff --git a/old/botan/build/botan/mem_pool.h b/old/botan/build/botan/mem_pool.h new file mode 100644 index 0000000..a578009 --- /dev/null +++ b/old/botan/build/botan/mem_pool.h @@ -0,0 +1,74 @@ +/* +* Pooling Allocator +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_POOLING_ALLOCATOR_H__ +#define BOTAN_POOLING_ALLOCATOR_H__ + +#include <botan/allocate.h> +#include <botan/exceptn.h> +#include <botan/mutex.h> +#include <utility> +#include <vector> + +namespace Botan { + +/* +* Pooling Allocator +*/ +class BOTAN_DLL Pooling_Allocator : public Allocator + { + public: + void* allocate(u32bit); + void deallocate(void*, u32bit); + + void destroy(); + + Pooling_Allocator(Mutex*); + ~Pooling_Allocator(); + private: + void get_more_core(u32bit); + byte* allocate_blocks(u32bit); + + virtual void* alloc_block(u32bit) = 0; + virtual void dealloc_block(void*, u32bit) = 0; + + class BOTAN_DLL Memory_Block + { + public: + Memory_Block(void*); + + static u32bit bitmap_size() { return BITMAP_SIZE; } + static u32bit block_size() { return BLOCK_SIZE; } + + bool contains(void*, u32bit) const throw(); + byte* alloc(u32bit) throw(); + void free(void*, u32bit) throw(); + + bool operator<(const Memory_Block& other) const + { + if(buffer < other.buffer && other.buffer < buffer_end) + return false; + return (buffer < other.buffer); + } + private: + typedef u64bit bitmap_type; + static const u32bit BITMAP_SIZE = 8 * sizeof(bitmap_type); + static const u32bit BLOCK_SIZE = 64; + + bitmap_type bitmap; + byte* buffer, *buffer_end; + }; + + std::vector<Memory_Block> blocks; + std::vector<Memory_Block>::iterator last_used; + std::vector<std::pair<void*, u32bit> > allocated; + Mutex* mutex; + }; + +} + +#endif diff --git a/old/botan/build/botan/mgf1.h b/old/botan/build/botan/mgf1.h new file mode 100644 index 0000000..799ba7e --- /dev/null +++ b/old/botan/build/botan/mgf1.h @@ -0,0 +1,36 @@ +/* +* MGF1 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MGF1_H__ +#define BOTAN_MGF1_H__ + +#include <botan/kdf.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* MGF1 (Mask Generation Function) +*/ +class BOTAN_DLL MGF1 : public MGF + { + public: + void mask(const byte[], u32bit, byte[], u32bit) const; + + /** + MGF1 constructor: takes ownership of hash + */ + MGF1(HashFunction* hash); + + ~MGF1(); + private: + HashFunction* hash; + }; + +} + +#endif diff --git a/old/botan/build/botan/misty1.h b/old/botan/build/botan/misty1.h new file mode 100644 index 0000000..62d4f85 --- /dev/null +++ b/old/botan/build/botan/misty1.h @@ -0,0 +1,35 @@ +/** +* MISTY1 +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MISTY1_H__ +#define BOTAN_MISTY1_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/** +* MISTY1 +*/ +class BOTAN_DLL MISTY1 : public BlockCipher + { + public: + void clear() throw() { EK.clear(); DK.clear(); } + std::string name() const { return "MISTY1"; } + BlockCipher* clone() const { return new MISTY1; } + MISTY1(u32bit = 8); + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u16bit, 100> EK, DK; + }; + +} + +#endif diff --git a/old/botan/build/botan/mmap_mem.h b/old/botan/build/botan/mmap_mem.h new file mode 100644 index 0000000..bef166a --- /dev/null +++ b/old/botan/build/botan/mmap_mem.h @@ -0,0 +1,30 @@ +/* +* Memory Mapping Allocator +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MMAP_ALLOCATOR_H__ +#define BOTAN_MMAP_ALLOCATOR_H__ + +#include <botan/mem_pool.h> + +namespace Botan { + +/* +* Memory Mapping Allocator +*/ +class BOTAN_DLL MemoryMapping_Allocator : public Pooling_Allocator + { + public: + MemoryMapping_Allocator(Mutex* m) : Pooling_Allocator(m) {} + std::string type() const { return "mmap"; } + private: + void* alloc_block(u32bit); + void dealloc_block(void*, u32bit); + }; + +} + +#endif diff --git a/old/botan/build/botan/mode_pad.h b/old/botan/build/botan/mode_pad.h new file mode 100644 index 0000000..a486d3c --- /dev/null +++ b/old/botan/build/botan/mode_pad.h @@ -0,0 +1,120 @@ +/** +* CBC Padding Methods +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_CBC_PADDING_H__ +#define BOTAN_CBC_PADDING_H__ + +#include <botan/types.h> +#include <string> + +namespace Botan { + +/** +* Block Cipher Mode Padding Method +* This class is pretty limited, it cannot deal well with +* randomized padding methods, or any padding method that +* wants to add more than one block. For instance, it should +* be possible to define cipher text stealing mode as simply +* a padding mode for CBC, which happens to consume the last +* two block (and requires use of the block cipher). +*/ +class BOTAN_DLL BlockCipherModePaddingMethod + { + public: + /** + * @param block output buffer + * @param size of the block + * @param current_position in the last block + */ + virtual void pad(byte block[], + u32bit size, + u32bit current_position) const = 0; + + /** + * @param block the last block + * @param size the of the block + */ + virtual u32bit unpad(const byte block[], + u32bit size) const = 0; + + /** + * @param block_size of the cipher + * @param position in the current block + * @return number of padding bytes that will be appended + */ + virtual u32bit pad_bytes(u32bit block_size, + u32bit position) const; + + /** + * @param block_size of the cipher + * @return valid block size for this padding mode + */ + virtual bool valid_blocksize(u32bit block_size) const = 0; + + /** + * @return name of the mode + */ + virtual std::string name() const = 0; + + /** + * virtual destructor + */ + virtual ~BlockCipherModePaddingMethod() {} + }; + +/** +* PKCS#7 Padding +*/ +class BOTAN_DLL PKCS7_Padding : public BlockCipherModePaddingMethod + { + public: + void pad(byte[], u32bit, u32bit) const; + u32bit unpad(const byte[], u32bit) const; + bool valid_blocksize(u32bit) const; + std::string name() const { return "PKCS7"; } + }; + +/** +* ANSI X9.23 Padding +*/ +class BOTAN_DLL ANSI_X923_Padding : public BlockCipherModePaddingMethod + { + public: + void pad(byte[], u32bit, u32bit) const; + u32bit unpad(const byte[], u32bit) const; + bool valid_blocksize(u32bit) const; + std::string name() const { return "X9.23"; } + }; + +/** +* One And Zeros Padding +*/ +class BOTAN_DLL OneAndZeros_Padding : public BlockCipherModePaddingMethod + { + public: + void pad(byte[], u32bit, u32bit) const; + u32bit unpad(const byte[], u32bit) const; + bool valid_blocksize(u32bit) const; + std::string name() const { return "OneAndZeros"; } + }; + +/** +* Null Padding +*/ +class BOTAN_DLL Null_Padding : public BlockCipherModePaddingMethod + { + public: + void pad(byte[], u32bit, u32bit) const { return; } + u32bit unpad(const byte[], u32bit size) const { return size; } + u32bit pad_bytes(u32bit, u32bit) const { return 0; } + bool valid_blocksize(u32bit) const { return true; } + std::string name() const { return "NoPadding"; } + }; + +} + +#endif diff --git a/old/botan/build/botan/modebase.h b/old/botan/build/botan/modebase.h new file mode 100644 index 0000000..173fde5 --- /dev/null +++ b/old/botan/build/botan/modebase.h @@ -0,0 +1,39 @@ +/* +* Block Cipher Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MODEBASE_H__ +#define BOTAN_MODEBASE_H__ + +#include <botan/basefilt.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/** +* This class represents an abstract block cipher mode +*/ +class BOTAN_DLL BlockCipherMode : public Keyed_Filter + { + public: + std::string name() const; + + BlockCipherMode(BlockCipher*, const std::string&, + u32bit, u32bit = 0, u32bit = 1); + + virtual ~BlockCipherMode() { delete cipher; } + protected: + void set_iv(const InitializationVector&); + const u32bit BLOCK_SIZE, BUFFER_SIZE, IV_METHOD; + const std::string mode_name; + BlockCipher* cipher; + SecureVector<byte> buffer, state; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/mp_asm.h b/old/botan/build/botan/mp_asm.h new file mode 100644 index 0000000..7c18343 --- /dev/null +++ b/old/botan/build/botan/mp_asm.h @@ -0,0 +1,54 @@ +/* +* Lowest Level MPI Algorithms +* (C) 1999-2008 Jack Lloyd +* 2006 Luca Piccarreta +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MP_ASM_H__ +#define BOTAN_MP_ASM_H__ + +#include <botan/mp_types.h> + +#if (BOTAN_MP_WORD_BITS == 8) + typedef Botan::u16bit dword; +#elif (BOTAN_MP_WORD_BITS == 16) + typedef Botan::u32bit dword; +#elif (BOTAN_MP_WORD_BITS == 32) + typedef Botan::u64bit dword; +#elif (BOTAN_MP_WORD_BITS == 64) + #error BOTAN_MP_WORD_BITS can be 64 only with assembly support +#else + #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64 +#endif + +namespace Botan { + +extern "C" { + +/* +* Word Multiply/Add +*/ +inline word word_madd2(word a, word b, word* c) + { + dword z = (dword)a * b + *c; + *c = (word)(z >> BOTAN_MP_WORD_BITS); + return (word)z; + } + +/* +* Word Multiply/Add +*/ +inline word word_madd3(word a, word b, word c, word* d) + { + dword z = (dword)a * b + c + *d; + *d = (word)(z >> BOTAN_MP_WORD_BITS); + return (word)z; + } + +} + +} + +#endif diff --git a/old/botan/build/botan/mp_asmi.h b/old/botan/build/botan/mp_asmi.h new file mode 100644 index 0000000..21c4db2 --- /dev/null +++ b/old/botan/build/botan/mp_asmi.h @@ -0,0 +1,191 @@ +/* +* Lowest Level MPI Algorithms +* (C) 1999-2008 Jack Lloyd +* 2006 Luca Piccarreta +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MP_ASM_INTERNAL_H__ +#define BOTAN_MP_ASM_INTERNAL_H__ + +#include <botan/mp_asm.h> + +namespace Botan { + +extern "C" { + +/* +* Word Addition +*/ +inline word word_add(word x, word y, word* carry) + { + word z = x + y; + word c1 = (z < x); + z += *carry; + *carry = c1 | (z < *carry); + return z; + } + +/* +* Eight Word Block Addition, Two Argument +*/ +inline word word8_add2(word x[8], const word y[8], word carry) + { + x[0] = word_add(x[0], y[0], &carry); + x[1] = word_add(x[1], y[1], &carry); + x[2] = word_add(x[2], y[2], &carry); + x[3] = word_add(x[3], y[3], &carry); + x[4] = word_add(x[4], y[4], &carry); + x[5] = word_add(x[5], y[5], &carry); + x[6] = word_add(x[6], y[6], &carry); + x[7] = word_add(x[7], y[7], &carry); + return carry; + } + +/* +* Eight Word Block Addition, Three Argument +*/ +inline word word8_add3(word z[8], const word x[8], + const word y[8], word carry) + { + z[0] = word_add(x[0], y[0], &carry); + z[1] = word_add(x[1], y[1], &carry); + z[2] = word_add(x[2], y[2], &carry); + z[3] = word_add(x[3], y[3], &carry); + z[4] = word_add(x[4], y[4], &carry); + z[5] = word_add(x[5], y[5], &carry); + z[6] = word_add(x[6], y[6], &carry); + z[7] = word_add(x[7], y[7], &carry); + return carry; + } + +/* +* Word Subtraction +*/ +inline word word_sub(word x, word y, word* carry) + { + word t0 = x - y; + word c1 = (t0 > x); + word z = t0 - *carry; + *carry = c1 | (z > t0); + return z; + } + +/* +* Eight Word Block Subtraction, Two Argument +*/ +inline word word8_sub2(word x[4], const word y[4], word carry) + { + x[0] = word_sub(x[0], y[0], &carry); + x[1] = word_sub(x[1], y[1], &carry); + x[2] = word_sub(x[2], y[2], &carry); + x[3] = word_sub(x[3], y[3], &carry); + x[4] = word_sub(x[4], y[4], &carry); + x[5] = word_sub(x[5], y[5], &carry); + x[6] = word_sub(x[6], y[6], &carry); + x[7] = word_sub(x[7], y[7], &carry); + return carry; + } + +/* +* Eight Word Block Subtraction, Three Argument +*/ +inline word word8_sub3(word z[8], const word x[8], + const word y[8], word carry) + { + z[0] = word_sub(x[0], y[0], &carry); + z[1] = word_sub(x[1], y[1], &carry); + z[2] = word_sub(x[2], y[2], &carry); + z[3] = word_sub(x[3], y[3], &carry); + z[4] = word_sub(x[4], y[4], &carry); + z[5] = word_sub(x[5], y[5], &carry); + z[6] = word_sub(x[6], y[6], &carry); + z[7] = word_sub(x[7], y[7], &carry); + return carry; + } + +/* +* Eight Word Block Linear Multiplication +*/ +inline word word8_linmul2(word x[4], word y, word carry) + { + x[0] = word_madd2(x[0], y, &carry); + x[1] = word_madd2(x[1], y, &carry); + x[2] = word_madd2(x[2], y, &carry); + x[3] = word_madd2(x[3], y, &carry); + x[4] = word_madd2(x[4], y, &carry); + x[5] = word_madd2(x[5], y, &carry); + x[6] = word_madd2(x[6], y, &carry); + x[7] = word_madd2(x[7], y, &carry); + return carry; + } + +/* +* Eight Word Block Linear Multiplication +*/ +inline word word8_linmul3(word z[8], const word x[8], word y, word carry) + { + z[0] = word_madd2(x[0], y, &carry); + z[1] = word_madd2(x[1], y, &carry); + z[2] = word_madd2(x[2], y, &carry); + z[3] = word_madd2(x[3], y, &carry); + z[4] = word_madd2(x[4], y, &carry); + z[5] = word_madd2(x[5], y, &carry); + z[6] = word_madd2(x[6], y, &carry); + z[7] = word_madd2(x[7], y, &carry); + return carry; + } + +/* +* Eight Word Block Multiply/Add +*/ +inline word word8_madd3(word z[8], const word x[8], word y, word carry) + { + z[0] = word_madd3(x[0], y, z[0], &carry); + z[1] = word_madd3(x[1], y, z[1], &carry); + z[2] = word_madd3(x[2], y, z[2], &carry); + z[3] = word_madd3(x[3], y, z[3], &carry); + z[4] = word_madd3(x[4], y, z[4], &carry); + z[5] = word_madd3(x[5], y, z[5], &carry); + z[6] = word_madd3(x[6], y, z[6], &carry); + z[7] = word_madd3(x[7], y, z[7], &carry); + return carry; + } + +/* +* Multiply-Add Accumulator +*/ +inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b) + { + word carry = *w0; + *w0 = word_madd2(a, b, &carry); + *w1 += carry; + *w2 += (*w1 < carry) ? 1 : 0; + } + +/* +* Multiply-Add Accumulator +*/ +inline void word3_muladd_2(word* w2, word* w1, word* w0, word a, word b) + { + word carry = 0; + a = word_madd2(a, b, &carry); + b = carry; + + word top = (b >> (BOTAN_MP_WORD_BITS-1)); + b <<= 1; + b |= (a >> (BOTAN_MP_WORD_BITS-1)); + a <<= 1; + + carry = 0; + *w0 = word_add(*w0, a, &carry); + *w1 = word_add(*w1, b, &carry); + *w2 = word_add(*w2, top, &carry); + } + +} + +} + +#endif diff --git a/old/botan/build/botan/mp_core.h b/old/botan/build/botan/mp_core.h new file mode 100644 index 0000000..ea27a77 --- /dev/null +++ b/old/botan/build/botan/mp_core.h @@ -0,0 +1,98 @@ +/* +* MPI Algorithms +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MP_CORE_H__ +#define BOTAN_MP_CORE_H__ + +#include <botan/mp_types.h> + +namespace Botan { + +/* +* The size of the word type, in bits +*/ +const u32bit MP_WORD_BITS = BOTAN_MP_WORD_BITS; + +extern "C" { + +/* +* Addition/Subtraction Operations +*/ +void bigint_add2(word[], u32bit, const word[], u32bit); +void bigint_add3(word[], const word[], u32bit, const word[], u32bit); + +word bigint_add2_nc(word[], u32bit, const word[], u32bit); +word bigint_add3_nc(word[], const word[], u32bit, const word[], u32bit); + +void bigint_sub2(word[], u32bit, const word[], u32bit); +void bigint_sub3(word[], const word[], u32bit, const word[], u32bit); + +/* +* Shift Operations +*/ +void bigint_shl1(word[], u32bit, u32bit, u32bit); +void bigint_shl2(word[], const word[], u32bit, u32bit, u32bit); +void bigint_shr1(word[], u32bit, u32bit, u32bit); +void bigint_shr2(word[], const word[], u32bit, u32bit, u32bit); + +/* +* Simple O(N^2) Multiplication and Squaring +*/ +void bigint_simple_mul(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size); +void bigint_simple_sqr(word z[], const word x[], u32bit x_size); + +/* +* Linear Multiply +*/ +void bigint_linmul2(word[], u32bit, word); +void bigint_linmul3(word[], const word[], u32bit, word); +void bigint_linmul_add(word[], u32bit, const word[], u32bit, word); + +/* +* Montgomery Reduction +*/ +void bigint_monty_redc(word[], u32bit, const word[], u32bit, word); + +/* +* Misc Utility Operations +*/ +u32bit bigint_divcore(word, word, word, word, word, word); +s32bit bigint_cmp(const word[], u32bit, const word[], u32bit); +word bigint_divop(word, word, word); +word bigint_modop(word, word, word); +void bigint_wordmul(word, word, word*, word*); + +/* +* Comba Multiplication / Squaring +*/ +void bigint_comba_mul4(word[8], const word[4], const word[4]); +void bigint_comba_mul6(word[12], const word[6], const word[6]); +void bigint_comba_mul8(word[16], const word[8], const word[8]); +void bigint_comba_mul16(word[32], const word[16], const word[16]); + +void bigint_comba_sqr4(word[8], const word[4]); +void bigint_comba_sqr6(word[12], const word[6]); +void bigint_comba_sqr8(word[16], const word[8]); +void bigint_comba_sqr8(word[32], const word[16]); +void bigint_comba_sqr16(word[64], const word[32]); + +} + +/* +* High Level Multiplication/Squaring Interfaces +*/ +void bigint_mul(word[], u32bit, word[], + const word[], u32bit, u32bit, + const word[], u32bit, u32bit); + +void bigint_sqr(word[], u32bit, word[], + const word[], u32bit, u32bit); + +} + +#endif diff --git a/old/botan/build/botan/mp_types.h b/old/botan/build/botan/mp_types.h new file mode 100644 index 0000000..1648713 --- /dev/null +++ b/old/botan/build/botan/mp_types.h @@ -0,0 +1,33 @@ +/* +* Low Level MPI Types +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MPI_TYPES_H__ +#define BOTAN_MPI_TYPES_H__ + +#include <botan/types.h> + +namespace Botan { + +#if (BOTAN_MP_WORD_BITS == 8) + typedef byte word; +#elif (BOTAN_MP_WORD_BITS == 16) + typedef u16bit word; +#elif (BOTAN_MP_WORD_BITS == 32) + typedef u32bit word; +#elif (BOTAN_MP_WORD_BITS == 64) + typedef u64bit word; +#else + #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64 +#endif + +const word MP_WORD_MASK = ~static_cast<word>(0); +const word MP_WORD_TOP_BIT = static_cast<word>(1) << (8*sizeof(word) - 1); +const word MP_WORD_MAX = MP_WORD_MASK; + +} + +#endif diff --git a/old/botan/build/botan/mutex.h b/old/botan/build/botan/mutex.h new file mode 100644 index 0000000..a04ff83 --- /dev/null +++ b/old/botan/build/botan/mutex.h @@ -0,0 +1,56 @@ +/* +* Mutex +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MUTEX_H__ +#define BOTAN_MUTEX_H__ + +#include <botan/exceptn.h> + +namespace Botan { + +/* +* Mutex Base Class +*/ +class BOTAN_DLL Mutex + { + public: + virtual void lock() = 0; + virtual void unlock() = 0; + virtual ~Mutex() {} + }; + +/* +* Mutex Factory +*/ +class BOTAN_DLL Mutex_Factory + { + public: + virtual Mutex* make() = 0; + virtual ~Mutex_Factory() {} + }; + +/* +* Mutex Holding Class +*/ +class BOTAN_DLL Mutex_Holder + { + public: + Mutex_Holder(Mutex* m) : mux(m) + { + if(!mux) + throw Invalid_Argument("Mutex_Holder: Argument was NULL"); + mux->lock(); + } + + ~Mutex_Holder() { mux->unlock(); } + private: + Mutex* mux; + }; + +} + +#endif diff --git a/old/botan/build/botan/mux_noop.h b/old/botan/build/botan/mux_noop.h new file mode 100644 index 0000000..94201cb --- /dev/null +++ b/old/botan/build/botan/mux_noop.h @@ -0,0 +1,26 @@ +/* +* No-Op Mutex Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_NOOP_MUTEX_FACTORY_H__ +#define BOTAN_NOOP_MUTEX_FACTORY_H__ + +#include <botan/mutex.h> + +namespace Botan { + +/* +* No-Op Mutex Factory +*/ +class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/old/botan/build/botan/mux_pthr.h b/old/botan/build/botan/mux_pthr.h new file mode 100644 index 0000000..1188539 --- /dev/null +++ b/old/botan/build/botan/mux_pthr.h @@ -0,0 +1,26 @@ +/* +* Pthread Mutex +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MUTEX_PTHREAD_H__ +#define BOTAN_MUTEX_PTHREAD_H__ + +#include <botan/mutex.h> + +namespace Botan { + +/* +* Pthread Mutex Factory +*/ +class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/old/botan/build/botan/mux_win32.h b/old/botan/build/botan/mux_win32.h new file mode 100644 index 0000000..a91850e --- /dev/null +++ b/old/botan/build/botan/mux_win32.h @@ -0,0 +1,26 @@ +/* +* Win32 Mutex +* (C) 2006 Luca Piccarreta +* 2006-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MUTEX_WIN32_H__ +#define BOTAN_MUTEX_WIN32_H__ + +#include <botan/mutex.h> + +namespace Botan { + +/* +* Win32 Mutex Factory +*/ +class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; +} + +#endif diff --git a/old/botan/build/botan/noekeon.h b/old/botan/build/botan/noekeon.h new file mode 100644 index 0000000..8938924 --- /dev/null +++ b/old/botan/build/botan/noekeon.h @@ -0,0 +1,37 @@ +/* +* Noekeon +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_NOEKEON_H__ +#define BOTAN_NOEKEON_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* Noekeon +*/ +class BOTAN_DLL Noekeon : public BlockCipher + { + public: + void clear() throw(); + std::string name() const { return "Noekeon"; } + BlockCipher* clone() const { return new Noekeon; } + Noekeon() : BlockCipher(16, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + static const byte RC[17]; + + SecureBuffer<u32bit, 4> EK, DK; + }; + +} + +#endif diff --git a/old/botan/build/botan/nr.h b/old/botan/build/botan/nr.h new file mode 100644 index 0000000..144c5ec --- /dev/null +++ b/old/botan/build/botan/nr.h @@ -0,0 +1,63 @@ +/* +* Nyberg-Rueppel +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_NYBERG_RUEPPEL_H__ +#define BOTAN_NYBERG_RUEPPEL_H__ + +#include <botan/dl_algo.h> +#include <botan/nr_core.h> + +namespace Botan { + +/* +* Nyberg-Rueppel Public Key +*/ +class BOTAN_DLL NR_PublicKey : public PK_Verifying_with_MR_Key, + public virtual DL_Scheme_PublicKey + { + public: + std::string algo_name() const { return "NR"; } + + SecureVector<byte> verify(const byte[], u32bit) const; + u32bit max_input_bits() const; + + DL_Group::Format group_format() const { return DL_Group::ANSI_X9_57; } + u32bit message_parts() const { return 2; } + u32bit message_part_size() const; + + NR_PublicKey() {} + NR_PublicKey(const DL_Group&, const BigInt&); + protected: + NR_Core core; + private: + void X509_load_hook(); + }; + +/* +* Nyberg-Rueppel Private Key +*/ +class BOTAN_DLL NR_PrivateKey : public NR_PublicKey, + public PK_Signing_Key, + public virtual DL_Scheme_PrivateKey + { + public: + SecureVector<byte> sign(const byte[], u32bit, + RandomNumberGenerator& rng) const; + + bool check_key(RandomNumberGenerator& rng, bool) const; + + NR_PrivateKey() {} + + NR_PrivateKey(RandomNumberGenerator&, const DL_Group&, + const BigInt& = 0); + private: + void PKCS8_load_hook(RandomNumberGenerator&, bool = false); + }; + +} + +#endif diff --git a/old/botan/build/botan/nr_core.h b/old/botan/build/botan/nr_core.h new file mode 100644 index 0000000..4837736 --- /dev/null +++ b/old/botan/build/botan/nr_core.h @@ -0,0 +1,37 @@ +/* +* NR Core +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_NR_CORE_H__ +#define BOTAN_NR_CORE_H__ + +#include <botan/nr_op.h> +#include <botan/dl_group.h> + +namespace Botan { + +/* +* NR Core +*/ +class BOTAN_DLL NR_Core + { + public: + SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const; + SecureVector<byte> verify(const byte[], u32bit) const; + + NR_Core& operator=(const NR_Core&); + + NR_Core() { op = 0; } + NR_Core(const NR_Core&); + NR_Core(const DL_Group&, const BigInt&, const BigInt& = 0); + ~NR_Core() { delete op; } + private: + NR_Operation* op; + }; + +} + +#endif diff --git a/old/botan/build/botan/nr_op.h b/old/botan/build/botan/nr_op.h new file mode 100644 index 0000000..cba1465 --- /dev/null +++ b/old/botan/build/botan/nr_op.h @@ -0,0 +1,53 @@ +/* +* NR Operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_NR_OPS_H__ +#define BOTAN_NR_OPS_H__ + +#include <botan/pow_mod.h> +#include <botan/numthry.h> +#include <botan/reducer.h> +#include <botan/dl_group.h> + +namespace Botan { + +/* +* NR Operation +*/ +class BOTAN_DLL NR_Operation + { + public: + virtual SecureVector<byte> verify(const byte[], u32bit) const = 0; + virtual SecureVector<byte> sign(const byte[], u32bit, + const BigInt&) const = 0; + virtual NR_Operation* clone() const = 0; + virtual ~NR_Operation() {} + }; + +/* +* Botan's Default NR Operation +*/ +class BOTAN_DLL Default_NR_Op : public NR_Operation + { + public: + SecureVector<byte> verify(const byte[], u32bit) const; + SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const; + + NR_Operation* clone() const { return new Default_NR_Op(*this); } + + Default_NR_Op(const DL_Group&, const BigInt&, const BigInt&); + private: + const BigInt x, y; + const DL_Group group; + Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; + Modular_Reducer mod_p, mod_q; + }; + + +} + +#endif diff --git a/old/botan/build/botan/numthry.h b/old/botan/build/botan/numthry.h new file mode 100644 index 0000000..e4c0437 --- /dev/null +++ b/old/botan/build/botan/numthry.h @@ -0,0 +1,120 @@ +/* +* Number Theory Functions +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_NUMBER_THEORY_H__ +#define BOTAN_NUMBER_THEORY_H__ + +#include <botan/bigint.h> +#include <botan/reducer.h> +#include <botan/pow_mod.h> +#include <botan/rng.h> + +namespace Botan { + +/* +* Fused Arithmetic Operations +*/ +BigInt BOTAN_DLL mul_add(const BigInt&, const BigInt&, const BigInt&); +BigInt BOTAN_DLL sub_mul(const BigInt&, const BigInt&, const BigInt&); + +/* +* Number Theory Functions +*/ +inline BigInt abs(const BigInt& n) { return n.abs(); } + +void BOTAN_DLL divide(const BigInt&, const BigInt&, BigInt&, BigInt&); + +BigInt BOTAN_DLL gcd(const BigInt&, const BigInt&); +BigInt BOTAN_DLL lcm(const BigInt&, const BigInt&); + +BigInt BOTAN_DLL square(const BigInt&); +BigInt BOTAN_DLL inverse_mod(const BigInt&, const BigInt&); +s32bit BOTAN_DLL jacobi(const BigInt&, const BigInt&); + +BigInt BOTAN_DLL power_mod(const BigInt&, const BigInt&, const BigInt&); + +/* +* Compute the square root of x modulo a prime +* using the Shanks-Tonnelli algorithm +*/ +BigInt ressol(const BigInt& x, const BigInt& p); + +/* +* Utility Functions +*/ +u32bit BOTAN_DLL low_zero_bits(const BigInt&); + +/* +* Primality Testing +*/ +bool BOTAN_DLL check_prime(const BigInt&, RandomNumberGenerator&); +bool BOTAN_DLL is_prime(const BigInt&, RandomNumberGenerator&); +bool BOTAN_DLL verify_prime(const BigInt&, RandomNumberGenerator&); + +s32bit BOTAN_DLL simple_primality_tests(const BigInt&); + +bool BOTAN_DLL passes_mr_tests(RandomNumberGenerator&, + const BigInt&, u32bit = 1); + +bool BOTAN_DLL run_primality_tests(RandomNumberGenerator&, + const BigInt&, u32bit = 1); + +/* +* Random Number Generation +*/ +BigInt BOTAN_DLL random_prime(RandomNumberGenerator&, + u32bit bits, const BigInt& coprime = 1, + u32bit equiv = 1, u32bit equiv_mod = 2); + +BigInt BOTAN_DLL random_safe_prime(RandomNumberGenerator&, + u32bit); + +/* +* DSA Parameter Generation +*/ +class Algorithm_Factory; + +SecureVector<byte> BOTAN_DLL +generate_dsa_primes(RandomNumberGenerator& rng, + Algorithm_Factory& af, + BigInt& p, BigInt& q, + u32bit pbits, u32bit qbits); + +bool BOTAN_DLL +generate_dsa_primes(RandomNumberGenerator& rng, + Algorithm_Factory& af, + BigInt& p_out, BigInt& q_out, + u32bit p_bits, u32bit q_bits, + const MemoryRegion<byte>& seed); + +/* +* Prime Numbers +*/ +const u32bit PRIME_TABLE_SIZE = 6541; +const u32bit PRIME_PRODUCTS_TABLE_SIZE = 256; + +extern const u16bit BOTAN_DLL PRIMES[]; +extern const u64bit PRIME_PRODUCTS[]; + +/* +* Miller-Rabin Primality Tester +*/ +class BOTAN_DLL MillerRabin_Test + { + public: + bool passes_test(const BigInt&); + MillerRabin_Test(const BigInt&); + private: + BigInt n, r, n_minus_1; + u32bit s; + Fixed_Exponent_Power_Mod pow_mod; + Modular_Reducer reducer; + }; + +} + +#endif diff --git a/old/botan/build/botan/ofb.h b/old/botan/build/botan/ofb.h new file mode 100644 index 0000000..a3aadc1 --- /dev/null +++ b/old/botan/build/botan/ofb.h @@ -0,0 +1,33 @@ +/* +* OFB Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_OUTPUT_FEEDBACK_MODE_H__ +#define BOTAN_OUTPUT_FEEDBACK_MODE_H__ + +#include <botan/modebase.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* OFB Mode +*/ +class BOTAN_DLL OFB : public BlockCipherMode + { + public: + OFB(BlockCipher* cipher); + + OFB(BlockCipher* cipher, + const SymmetricKey& key, + const InitializationVector& iv); + private: + void write(const byte[], u32bit); + }; + +} + +#endif diff --git a/old/botan/build/botan/oids.h b/old/botan/build/botan/oids.h new file mode 100644 index 0000000..fdfe61f --- /dev/null +++ b/old/botan/build/botan/oids.h @@ -0,0 +1,58 @@ +/* +* OID Registry +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_OIDS_H__ +#define BOTAN_OIDS_H__ + +#include <botan/asn1_oid.h> + +namespace Botan { + +namespace OIDS { + +/** +* Register an OID to string mapping. +* @param oid the oid to register +* @param name the name to be associated with the oid +*/ +BOTAN_DLL void add_oid(const OID& oid, const std::string& name); + +/** +* See if an OID exists in the internal table. +* @param oid the oid to check for +* @return true if the oid is registered +*/ +BOTAN_DLL bool have_oid(const std::string& oid); + +/** +* Resolve an OID +* @param oid the OID to look up +* @return the name associated with this OID +*/ +BOTAN_DLL std::string lookup(const OID& oid); + +/** +* Find the OID to a name. The lookup will be performed in the +* general OID section of the configuration. +* @param name the name to resolve +* @return the OID associated with the specified name +*/ +BOTAN_DLL OID lookup(const std::string& name); + +/** +* Tests whether the specified OID stands for the specified name. +* @param oid the OID to check +* @param name the name to check +* @return true if the specified OID stands for the specified name +*/ +BOTAN_DLL bool name_of(const OID& oid, const std::string& name); + +} + +} + +#endif diff --git a/old/botan/build/botan/openpgp.h b/old/botan/build/botan/openpgp.h new file mode 100644 index 0000000..890fcf0 --- /dev/null +++ b/old/botan/build/botan/openpgp.h @@ -0,0 +1,34 @@ +/* +* OpenPGP +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_OPENPGP_H__ +#define BOTAN_OPENPGP_H__ + +#include <botan/data_src.h> +#include <string> +#include <map> + +namespace Botan { + +namespace OpenPGP { + +/* +* OpenPGP Base64 encoding/decoding +*/ +BOTAN_DLL std::string encode(const byte[], u32bit, const std::string&, + const std::map<std::string, std::string>&); +BOTAN_DLL SecureVector<byte> decode(DataSource&, std::string&, + std::map<std::string, std::string>&); + +BOTAN_DLL std::string encode(const byte[], u32bit, const std::string&); +BOTAN_DLL SecureVector<byte> decode(DataSource&, std::string&); + +} + +} + +#endif diff --git a/old/botan/build/botan/out_buf.h b/old/botan/build/botan/out_buf.h new file mode 100644 index 0000000..0baacda --- /dev/null +++ b/old/botan/build/botan/out_buf.h @@ -0,0 +1,43 @@ +/* +* Output Buffer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_OUTPUT_BUFFER_H__ +#define BOTAN_OUTPUT_BUFFER_H__ + +#include <botan/types.h> +#include <botan/pipe.h> +#include <deque> + +namespace Botan { + +/* +* Container of output buffers for Pipe +*/ +class BOTAN_DLL Output_Buffers + { + public: + u32bit read(byte[], u32bit, Pipe::message_id); + u32bit peek(byte[], u32bit, u32bit, Pipe::message_id) const; + u32bit remaining(Pipe::message_id) const; + + void add(class SecureQueue*); + void retire(); + + Pipe::message_id message_count() const; + + Output_Buffers(); + ~Output_Buffers(); + private: + class SecureQueue* get(Pipe::message_id) const; + + std::deque<SecureQueue*> buffers; + Pipe::message_id offset; + }; + +} + +#endif diff --git a/old/botan/build/botan/par_hash.h b/old/botan/build/botan/par_hash.h new file mode 100644 index 0000000..7e75c27 --- /dev/null +++ b/old/botan/build/botan/par_hash.h @@ -0,0 +1,36 @@ +/* +* Parallel Hash +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PARALLEL_HASH_H__ +#define BOTAN_PARALLEL_HASH_H__ + +#include <botan/hash.h> +#include <vector> + +namespace Botan { + +/* +* Parallel +*/ +class BOTAN_DLL Parallel : public HashFunction + { + public: + void clear() throw(); + std::string name() const; + HashFunction* clone() const; + + Parallel(const std::vector<HashFunction*>&); + ~Parallel(); + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + std::vector<HashFunction*> hashes; + }; + +} + +#endif diff --git a/old/botan/build/botan/parsing.h b/old/botan/build/botan/parsing.h new file mode 100644 index 0000000..2c29d5b --- /dev/null +++ b/old/botan/build/botan/parsing.h @@ -0,0 +1,41 @@ +/* +* Parser Functions +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PARSER_H__ +#define BOTAN_PARSER_H__ + +#include <botan/types.h> +#include <string> +#include <vector> + +namespace Botan { + +/* +* String Parsing Functions +*/ +BOTAN_DLL std::vector<std::string> parse_algorithm_name(const std::string&); +BOTAN_DLL std::vector<std::string> split_on(const std::string&, char); +BOTAN_DLL std::vector<u32bit> parse_asn1_oid(const std::string&); +BOTAN_DLL bool x500_name_cmp(const std::string&, const std::string&); + +/* +* String/Integer Conversions +*/ +BOTAN_DLL std::string to_string(u64bit, u32bit = 0); +BOTAN_DLL u32bit to_u32bit(const std::string&); + +BOTAN_DLL u32bit timespec_to_u32bit(const std::string& timespec); + +/* +* String/Network Address Conversions +*/ +BOTAN_DLL u32bit string_to_ipv4(const std::string&); +BOTAN_DLL std::string ipv4_to_string(u32bit); + +} + +#endif diff --git a/old/botan/build/botan/pbe.h b/old/botan/build/botan/pbe.h new file mode 100644 index 0000000..f06d593 --- /dev/null +++ b/old/botan/build/botan/pbe.h @@ -0,0 +1,56 @@ +/* +* PBE +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PBE_BASE_H__ +#define BOTAN_PBE_BASE_H__ + +#include <botan/asn1_oid.h> +#include <botan/data_src.h> +#include <botan/filter.h> +#include <botan/rng.h> + +namespace Botan { + +/** +* Password Based Encryption (PBE) Filter. +*/ +class BOTAN_DLL PBE : public Filter + { + public: + /** + * Set this filter's key. + * @param pw the password to be used for the encryption + */ + virtual void set_key(const std::string&) = 0; + + /** + * Create a new random salt value and set the default iterations value. + */ + virtual void new_params(RandomNumberGenerator& rng) = 0; + + /** + * DER encode the params (the number of iterations and the salt value) + * @return the encoded params + */ + virtual MemoryVector<byte> encode_params() const = 0; + + /** + * Decode params and use them inside this Filter. + * @param src a data source to read the encoded params from + */ + virtual void decode_params(DataSource&) = 0; + + /** + * Get this PBE's OID. + * @return the OID + */ + virtual OID get_oid() const = 0; + }; + +} + +#endif diff --git a/old/botan/build/botan/pbes1.h b/old/botan/build/botan/pbes1.h new file mode 100644 index 0000000..2e1855d --- /dev/null +++ b/old/botan/build/botan/pbes1.h @@ -0,0 +1,53 @@ +/* +* PKCS #5 v1.5 PBE +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PBE_PKCS_V15_H__ +#define BOTAN_PBE_PKCS_V15_H__ + +#include <botan/pbe.h> +#include <botan/block_cipher.h> +#include <botan/hash.h> +#include <botan/pipe.h> + +namespace Botan { + +/* +* PKCS#5 v1.5 PBE +*/ +class BOTAN_DLL PBE_PKCS5v15 : public PBE + { + public: + void write(const byte[], u32bit); + void start_msg(); + void end_msg(); + + PBE_PKCS5v15(BlockCipher* cipher, + HashFunction* hash, + Cipher_Dir); + + ~PBE_PKCS5v15(); + private: + void set_key(const std::string&); + void new_params(RandomNumberGenerator& rng); + MemoryVector<byte> encode_params() const; + void decode_params(DataSource&); + OID get_oid() const; + + void flush_pipe(bool); + + Cipher_Dir direction; + BlockCipher* block_cipher; + HashFunction* hash_function; + + SecureVector<byte> salt, key, iv; + u32bit iterations; + Pipe pipe; + }; + +} + +#endif diff --git a/old/botan/build/botan/pbes2.h b/old/botan/build/botan/pbes2.h new file mode 100644 index 0000000..fc460a2 --- /dev/null +++ b/old/botan/build/botan/pbes2.h @@ -0,0 +1,53 @@ +/* +* PKCS #5 v2.0 PBE +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PBE_PKCS_v20_H__ +#define BOTAN_PBE_PKCS_v20_H__ + +#include <botan/pbe.h> +#include <botan/block_cipher.h> +#include <botan/hash.h> +#include <botan/pipe.h> + +namespace Botan { + +/* +* PKCS#5 v2.0 PBE +*/ +class BOTAN_DLL PBE_PKCS5v20 : public PBE + { + public: + static bool known_cipher(const std::string&); + + void write(const byte[], u32bit); + void start_msg(); + void end_msg(); + + PBE_PKCS5v20(DataSource&); + PBE_PKCS5v20(BlockCipher*, HashFunction*); + + ~PBE_PKCS5v20(); + private: + void set_key(const std::string&); + void new_params(RandomNumberGenerator& rng); + MemoryVector<byte> encode_params() const; + void decode_params(DataSource&); + OID get_oid() const; + + void flush_pipe(bool); + + Cipher_Dir direction; + BlockCipher* block_cipher; + HashFunction* hash_function; + SecureVector<byte> salt, key, iv; + u32bit iterations, key_length; + Pipe pipe; + }; + +} + +#endif diff --git a/old/botan/build/botan/pbkdf1.h b/old/botan/build/botan/pbkdf1.h new file mode 100644 index 0000000..4e5cafd --- /dev/null +++ b/old/botan/build/botan/pbkdf1.h @@ -0,0 +1,44 @@ +/* +* PBKDF1 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PBKDF1_H__ +#define BOTAN_PBKDF1_H__ + +#include <botan/s2k.h> +#include <botan/hash.h> + +namespace Botan { + +/** +* This class implements the PKCS #5 PBKDF1 functionality. +*/ +class BOTAN_DLL PKCS5_PBKDF1 : public S2K + { + public: + std::string name() const; + S2K* clone() const; + + /** + * Create a PKCS #5 instance using the specified hash function. + * @param hash a pointer to a hash function object to use + */ + PKCS5_PBKDF1(HashFunction* hash_in) : hash(hash_in) {} + + PKCS5_PBKDF1(const PKCS5_PBKDF1& other) : + S2K(), hash(other.hash->clone()) {} + + ~PKCS5_PBKDF1() { delete hash; } + private: + OctetString derive(u32bit, const std::string&, + const byte[], u32bit, u32bit) const; + + HashFunction* hash; + }; + +} + +#endif diff --git a/old/botan/build/botan/pbkdf2.h b/old/botan/build/botan/pbkdf2.h new file mode 100644 index 0000000..7510338 --- /dev/null +++ b/old/botan/build/botan/pbkdf2.h @@ -0,0 +1,40 @@ +/* +* PBKDF2 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PBKDF2_H__ +#define BOTAN_PBKDF2_H__ + +#include <botan/s2k.h> +#include <botan/mac.h> + +namespace Botan { + +/** +* This class implements the PKCS #5 PBKDF2 functionality. +*/ +class BOTAN_DLL PKCS5_PBKDF2 : public S2K + { + public: + std::string name() const; + S2K* clone() const; + + /** + * Create a PKCS #5 instance using the specified message auth code + * @param mac the MAC to use + */ + PKCS5_PBKDF2(MessageAuthenticationCode* mac); + ~PKCS5_PBKDF2(); + private: + OctetString derive(u32bit, const std::string&, + const byte[], u32bit, u32bit) const; + + MessageAuthenticationCode* mac; + }; + +} + +#endif diff --git a/old/botan/build/botan/pem.h b/old/botan/build/botan/pem.h new file mode 100644 index 0000000..9fe8acb --- /dev/null +++ b/old/botan/build/botan/pem.h @@ -0,0 +1,35 @@ +/* +* PEM Encoding/Decoding +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PEM_H__ +#define BOTAN_PEM_H__ + +#include <botan/data_src.h> + +namespace Botan { + +namespace PEM_Code { + +/* +* PEM Encoding/Decoding +*/ +BOTAN_DLL std::string encode(const byte[], u32bit, + const std::string&, u32bit = 64); +BOTAN_DLL std::string encode(const MemoryRegion<byte>&, + const std::string&, u32bit = 64); + +BOTAN_DLL SecureVector<byte> decode(DataSource&, std::string&); +BOTAN_DLL SecureVector<byte> decode_check_label(DataSource&, + const std::string&); +BOTAN_DLL bool matches(DataSource&, const std::string& = "", + u32bit search_range = 4096); + +} + +} + +#endif diff --git a/old/botan/build/botan/pgp_s2k.h b/old/botan/build/botan/pgp_s2k.h new file mode 100644 index 0000000..00e95f7 --- /dev/null +++ b/old/botan/build/botan/pgp_s2k.h @@ -0,0 +1,36 @@ +/* +* OpenPGP S2K +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_OPENPGP_S2K_H__ +#define BOTAN_OPENPGP_S2K_H__ + +#include <botan/s2k.h> +#include <botan/hash.h> + +namespace Botan { + +/* +* OpenPGP S2K +*/ +class BOTAN_DLL OpenPGP_S2K : public S2K + { + public: + std::string name() const; + S2K* clone() const; + + OpenPGP_S2K(HashFunction* hash_in) : hash(hash_in) {} + ~OpenPGP_S2K() { delete hash; } + private: + OctetString derive(u32bit, const std::string&, + const byte[], u32bit, u32bit) const; + + HashFunction* hash; + }; + +} + +#endif diff --git a/old/botan/build/botan/pipe.h b/old/botan/build/botan/pipe.h new file mode 100644 index 0000000..120f2fb --- /dev/null +++ b/old/botan/build/botan/pipe.h @@ -0,0 +1,275 @@ +/* +* Pipe +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PIPE_H__ +#define BOTAN_PIPE_H__ + +#include <botan/data_src.h> +#include <botan/filter.h> +#include <botan/exceptn.h> +#include <iosfwd> + +namespace Botan { + +/** +* This class represents pipe objects. +* A set of filters can be placed into a pipe, and information flows +* through the pipe until it reaches the end, where the output is +* collected for retrieval. If you're familiar with the Unix shell +* environment, this design will sound quite familiar. +*/ + +class BOTAN_DLL Pipe : public DataSource + { + public: + typedef u32bit message_id; + + class Invalid_Message_Number : public Invalid_Argument + { + public: + Invalid_Message_Number(const std::string&, message_id); + }; + + static const message_id LAST_MESSAGE; + static const message_id DEFAULT_MESSAGE; + + /** + * Write input to the pipe, i.e. to its first filter. + * @param in the byte array to write + * @param length the length of the byte array in + */ + void write(const byte in[], u32bit length); + + /** + * Write input to the pipe, i.e. to its first filter. + * @param in the MemoryRegion containing the data to write + */ + void write(const MemoryRegion<byte>& in); + + /** + * Write input to the pipe, i.e. to its first filter. + * @param in the string containing the data to write + */ + void write(const std::string& in); + + /** + * Write input to the pipe, i.e. to its first filter. + * @param in the DataSource to read the data from + */ + void write(DataSource& in); + + /** + * Write input to the pipe, i.e. to its first filter. + * @param in a single byte to be written + */ + void write(byte in); + + /** + * Perform start_msg(), write() and end_msg() sequentially. + * @param in the byte array containing the data to write + * @param length the length of the byte array to write + */ + void process_msg(const byte in[], u32bit length); + + /** + * Perform start_msg(), write() and end_msg() sequentially. + * @param in the MemoryRegion containing the data to write + */ + void process_msg(const MemoryRegion<byte>& in); + + /** + * Perform start_msg(), write() and end_msg() sequentially. + * @param in the string containing the data to write + */ + void process_msg(const std::string& in); + + /** + * Perform start_msg(), write() and end_msg() sequentially. + * @param in the DataSource providing the data to write + */ + void process_msg(DataSource& in); + + /** + * Find out how many bytes are ready to read. + * @param msg the number identifying the message + * for which the information is desired + * @return the number of bytes that can still be read + */ + u32bit remaining(message_id msg = DEFAULT_MESSAGE) const; + + /** + * Read the default message from the pipe. Moves the internal + * offset so that every call to read will return a new portion of + * the message. + * @param output the byte array to write the read bytes to + * @param length the length of the byte array output + * @return the number of bytes actually read into output + */ + u32bit read(byte output[], u32bit length); + + /** + * Read a specified message from the pipe. Moves the internal + * offset so that every call to read will return a new portion of + * the message. + * @param output the byte array to write the read bytes to + * @param length the length of the byte array output + * @param msg the number identifying the message to read from + * @return the number of bytes actually read into output + */ + u32bit read(byte output[], u32bit length, message_id msg); + + /** + * Read a single byte from the pipe. Moves the internal offset so that + * every call to read will return a new portion of the message. + * @param output the byte to write the result to + * @return the number of bytes actually read into output + */ + u32bit read(byte& output, message_id msg = DEFAULT_MESSAGE); + + /** + * Read the full contents of the pipe. + * @param msg the number identifying the message to read from + * @return a SecureVector holding the contents of the pipe + */ + SecureVector<byte> read_all(message_id msg = DEFAULT_MESSAGE); + + /** + * Read the full contents of the pipe. + * @param msg the number identifying the message to read from + * @return a string holding the contents of the pipe + */ + std::string read_all_as_string(message_id = DEFAULT_MESSAGE); + + /** Read from the default message but do not modify the internal + * offset. Consecutive calls to peek() will return portions of + * the message starting at the same position. + * @param output the byte array to write the peeked message part to + * @param length the length of the byte array output + * @param offset the offset from the current position in message + * @return the number of bytes actually peeked and written into output + */ + u32bit peek(byte output[], u32bit length, u32bit offset) const; + + /** Read from the specified message but do not modify the + * internal offset. Consecutive calls to peek() will return + * portions of the message starting at the same position. + * @param output the byte array to write the peeked message part to + * @param length the length of the byte array output + * @param offset the offset from the current position in message + * @param msg the number identifying the message to peek from + * @return the number of bytes actually peeked and written into output + */ + u32bit peek(byte output[], u32bit length, + u32bit offset, message_id msg) const; + + /** Read a single byte from the specified message but do not + * modify the internal offset. Consecutive calls to peek() will + * return portions of the message starting at the same position. + * @param output the byte to write the peeked message byte to + * @param offset the offset from the current position in message + * @param msg the number identifying the message to peek from + * @return the number of bytes actually peeked and written into output + */ + u32bit peek(byte& output, u32bit offset, + message_id msg = DEFAULT_MESSAGE) const; + + u32bit default_msg() const { return default_read; } + + /** + * Set the default message + * @param msg the number identifying the message which is going to + * be the new default message + */ + void set_default_msg(message_id msg); + + /** + * Get the number of messages the are in this pipe. + * @return the number of messages the are in this pipe + */ + message_id message_count() const; + + /** + * Test whether this pipe has any data that can be read from. + * @return true if there is more data to read, false otherwise + */ + bool end_of_data() const; + + /** + * Start a new message in the pipe. A potential other message in this pipe + * must be closed with end_msg() before this function may be called. + */ + void start_msg(); + + /** + * End the current message. + */ + void end_msg(); + + /** + * Insert a new filter at the front of the pipe + * @param filt the new filter to insert + */ + void prepend(Filter* filt); + + /** + * Insert a new filter at the back of the pipe + * @param filt the new filter to insert + */ + void append(Filter* filt); + + /** + * Remove the first filter at the front of the pipe. + */ + void pop(); + + /** + * Reset this pipe to an empty pipe. + */ + void reset(); + + /** + * Construct a Pipe of up to four filters. The filters are set up + * in the same order as the arguments. + */ + Pipe(Filter* = 0, Filter* = 0, Filter* = 0, Filter* = 0); + + /** + * Construct a Pipe from range of filters passed as an array + * @param filters the set of filters to use + * @param count the number of elements in filters + */ + Pipe(Filter* filters[], u32bit count); + ~Pipe(); + private: + Pipe(const Pipe&) : DataSource() {} + Pipe& operator=(const Pipe&) { return (*this); } + void init(); + void destruct(Filter*); + void find_endpoints(Filter*); + void clear_endpoints(Filter*); + + message_id get_message_no(const std::string&, message_id) const; + + Filter* pipe; + class Output_Buffers* outputs; + message_id default_read; + bool inside_msg; + }; + +/* +* I/O Operators for Pipe +*/ +BOTAN_DLL std::ostream& operator<<(std::ostream&, Pipe&); +BOTAN_DLL std::istream& operator>>(std::istream&, Pipe&); + +} + +#endif + +#if defined(BOTAN_HAS_PIPE_UNIXFD_IO) + #include <botan/fd_unix.h> +#endif diff --git a/old/botan/build/botan/pk_algs.h b/old/botan/build/botan/pk_algs.h new file mode 100644 index 0000000..c41bf1a --- /dev/null +++ b/old/botan/build/botan/pk_algs.h @@ -0,0 +1,31 @@ +/* +* PK Key Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PK_KEY_FACTORY_H__ +#define BOTAN_PK_KEY_FACTORY_H__ + +#include <botan/pk_keys.h> + +namespace Botan { + +/** +* Get an empty public key object. +* @param name the name of the desired public key algorithm +* @return the public key object +*/ +BOTAN_DLL Public_Key* get_public_key(const std::string&); + +/** +* Get an empty private key object. +* @param name the name of the desired public key algorithm +* @return the private key object +*/ +BOTAN_DLL Private_Key* get_private_key(const std::string&); + +} + +#endif diff --git a/old/botan/build/botan/pk_engine.h b/old/botan/build/botan/pk_engine.h new file mode 100644 index 0000000..256a47c --- /dev/null +++ b/old/botan/build/botan/pk_engine.h @@ -0,0 +1,95 @@ +/** +* Engine for PK +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENGINE_PK_LOOKUP_H__ +#define BOTAN_ENGINE_PK_LOOKUP_H__ + +#include <botan/bigint.h> +#include <botan/pow_mod.h> + +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) + #include <botan/if_op.h> +#endif + +#if defined(BOTAN_HAS_DSA) + #include <botan/dsa_op.h> +#endif + +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) + #include <botan/dh_op.h> +#endif + +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) + #include <botan/nr_op.h> +#endif + +#if defined(BOTAN_HAS_ELGAMAL) + #include <botan/elg_op.h> +#endif + +#if defined(BOTAN_HAS_ECDSA) + #include <botan/ecdsa_op.h> + #include <botan/ec_dompar.h> +#endif + +#if defined(BOTAN_HAS_ECKAEG) + #include <botan/eckaeg_op.h> + #include <botan/ec_dompar.h> +#endif + +namespace Botan { + +class Algorithm_Factory; +class Keyed_Filter; +class Modular_Exponentiator; + +namespace Engine_Core { + +/* +* Get an operation from an Engine +*/ +Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints); + +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) +IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&); +#endif + +#if defined(BOTAN_HAS_DSA) +DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&); +#endif + +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) +NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&); +#endif + +#if defined(BOTAN_HAS_ELGAMAL) +ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); +#endif + +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) +DH_Operation* dh_op(const DL_Group&, const BigInt&); +#endif + +#if defined(BOTAN_HAS_ECDSA) +ECDSA_Operation* ecdsa_op(const EC_Domain_Params& dom_pars, + const BigInt& priv_key, + const PointGFp& pub_key); +#endif + +#if defined(BOTAN_HAS_ECKAEG) +ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars, + const BigInt& priv_key, + const PointGFp& pub_key); +#endif + +} + +} + +#endif diff --git a/old/botan/build/botan/pk_filts.h b/old/botan/build/botan/pk_filts.h new file mode 100644 index 0000000..8bf3fc2 --- /dev/null +++ b/old/botan/build/botan/pk_filts.h @@ -0,0 +1,91 @@ +/* +* PK Filters +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PK_FILTERS_H__ +#define BOTAN_PK_FILTERS_H__ + +#include <botan/filter.h> +#include <botan/pubkey.h> + +namespace Botan { + +/* +* PK_Encryptor Filter +*/ +class BOTAN_DLL PK_Encryptor_Filter : public Filter + { + public: + void write(const byte[], u32bit); + void end_msg(); + PK_Encryptor_Filter(PK_Encryptor* c, + RandomNumberGenerator& rng_ref) : + cipher(c), rng(rng_ref) {} + ~PK_Encryptor_Filter() { delete cipher; } + private: + PK_Encryptor* cipher; + RandomNumberGenerator& rng; + SecureVector<byte> buffer; + }; + +/* +* PK_Decryptor Filter +*/ +class BOTAN_DLL PK_Decryptor_Filter : public Filter + { + public: + void write(const byte[], u32bit); + void end_msg(); + PK_Decryptor_Filter(PK_Decryptor* c) : cipher(c) {} + ~PK_Decryptor_Filter() { delete cipher; } + private: + PK_Decryptor* cipher; + SecureVector<byte> buffer; + }; + +/* +* PK_Signer Filter +*/ +class BOTAN_DLL PK_Signer_Filter : public Filter + { + public: + void write(const byte[], u32bit); + void end_msg(); + + PK_Signer_Filter(PK_Signer* s, + RandomNumberGenerator& rng_ref) : + signer(s), rng(rng_ref) {} + + ~PK_Signer_Filter() { delete signer; } + private: + PK_Signer* signer; + RandomNumberGenerator& rng; + }; + +/* +* PK_Verifier Filter +*/ +class BOTAN_DLL PK_Verifier_Filter : public Filter + { + public: + void write(const byte[], u32bit); + void end_msg(); + + void set_signature(const byte[], u32bit); + void set_signature(const MemoryRegion<byte>&); + + PK_Verifier_Filter(PK_Verifier* v) : verifier(v) {} + PK_Verifier_Filter(PK_Verifier*, const byte[], u32bit); + PK_Verifier_Filter(PK_Verifier*, const MemoryRegion<byte>&); + ~PK_Verifier_Filter() { delete verifier; } + private: + PK_Verifier* verifier; + SecureVector<byte> signature; + }; + +} + +#endif diff --git a/old/botan/build/botan/pk_keys.h b/old/botan/build/botan/pk_keys.h new file mode 100644 index 0000000..5b61257 --- /dev/null +++ b/old/botan/build/botan/pk_keys.h @@ -0,0 +1,180 @@ +/* +* PK Key Types +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PK_KEYS_H__ +#define BOTAN_PK_KEYS_H__ + +#include <botan/secmem.h> +#include <botan/asn1_oid.h> +#include <botan/rng.h> + +namespace Botan { + +/** +* Public Key Base Class. +*/ +class BOTAN_DLL Public_Key + { + public: + /** + * Get the name of the underlying public key scheme. + * @return the name of the public key scheme + */ + virtual std::string algo_name() const = 0; + + /** + * Get the OID of the underlying public key scheme. + * @return the OID of the public key scheme + */ + virtual OID get_oid() const; + + /** + * Test the key values for consistency. + * @param rng rng to use + * @param strong whether to perform strong and lengthy version + * of the test + * @return true if the test is passed + */ + virtual bool check_key(RandomNumberGenerator&, bool) const + { return true; } + + /** + * Find out the number of message parts supported by this scheme. + * @return the number of message parts + */ + virtual u32bit message_parts() const { return 1; } + + /** + * Find out the message part size supported by this scheme/key. + * @return the size of the message parts + */ + virtual u32bit message_part_size() const { return 0; } + + /** + * Get the maximum message size in bits supported by this public key. + * @return the maximum message in bits + */ + virtual u32bit max_input_bits() const = 0; + + /** + * Get an X509 encoder that can be used to encode this key in X509 format. + * @return an X509 encoder for this key + */ + virtual class X509_Encoder* x509_encoder() const = 0; + + /** + * Get an X509 decoder that can be used to set the values of this + * key based on an X509 encoded key object. + * @return an X509 decoder for this key + */ + virtual class X509_Decoder* x509_decoder() = 0; + + virtual ~Public_Key() {} + protected: + virtual void load_check(RandomNumberGenerator&) const; + }; + +/** +* Private Key Base Class +*/ +class BOTAN_DLL Private_Key : public virtual Public_Key + { + public: + /** + * Get a PKCS#8 encoder that can be used to encode this key in + * PKCS#8 format. + * @return an PKCS#8 encoder for this key + */ + virtual class PKCS8_Encoder* pkcs8_encoder() const + { return 0; } + + /** + * Get an PKCS#8 decoder that can be used to set the values of this key + * based on an PKCS#8 encoded key object. + * @return an PKCS#8 decoder for this key + */ + virtual class PKCS8_Decoder* pkcs8_decoder(RandomNumberGenerator&) + { return 0; } + protected: + void load_check(RandomNumberGenerator&) const; + void gen_check(RandomNumberGenerator&) const; + }; + +/** +* PK Encrypting Key. +*/ +class BOTAN_DLL PK_Encrypting_Key : public virtual Public_Key + { + public: + virtual SecureVector<byte> encrypt(const byte[], u32bit, + RandomNumberGenerator&) const = 0; + virtual ~PK_Encrypting_Key() {} + }; + +/** +* PK Decrypting Key +*/ +class BOTAN_DLL PK_Decrypting_Key : public virtual Private_Key + { + public: + virtual SecureVector<byte> decrypt(const byte[], u32bit) const = 0; + virtual ~PK_Decrypting_Key() {} + }; + +/** +* PK Signing Key +*/ +class BOTAN_DLL PK_Signing_Key : public virtual Private_Key + { + public: + virtual SecureVector<byte> sign(const byte[], u32bit, + RandomNumberGenerator& rng) const = 0; + virtual ~PK_Signing_Key() {} + }; + +/** +* PK Verifying Key, Message Recovery Version +*/ +class BOTAN_DLL PK_Verifying_with_MR_Key : public virtual Public_Key + { + public: + virtual SecureVector<byte> verify(const byte[], u32bit) const = 0; + virtual ~PK_Verifying_with_MR_Key() {} + }; + +/** +* PK Verifying Key, No Message Recovery Version +*/ +class BOTAN_DLL PK_Verifying_wo_MR_Key : public virtual Public_Key + { + public: + virtual bool verify(const byte[], u32bit, + const byte[], u32bit) const = 0; + virtual ~PK_Verifying_wo_MR_Key() {} + }; + +/** +* PK Secret Value Derivation Key +*/ +class BOTAN_DLL PK_Key_Agreement_Key : public virtual Private_Key + { + public: + virtual SecureVector<byte> derive_key(const byte[], u32bit) const = 0; + virtual MemoryVector<byte> public_value() const = 0; + virtual ~PK_Key_Agreement_Key() {} + }; + +/* +* Typedefs +*/ +typedef PK_Key_Agreement_Key PK_KA_Key; +typedef Public_Key X509_PublicKey; +typedef Private_Key PKCS8_PrivateKey; + +} + +#endif diff --git a/old/botan/build/botan/pkcs10.h b/old/botan/build/botan/pkcs10.h new file mode 100644 index 0000000..9b435de --- /dev/null +++ b/old/botan/build/botan/pkcs10.h @@ -0,0 +1,101 @@ +/* +* PKCS #10 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PKCS10_H__ +#define BOTAN_PKCS10_H__ + +#include <botan/x509_obj.h> +#include <botan/pkcs8.h> +#include <botan/datastor.h> +#include <vector> + +namespace Botan { + +/** +* PKCS #10 Certificate Request. +*/ +class BOTAN_DLL PKCS10_Request : public X509_Object + { + public: + /** + * Get the subject public key. + * @return the subject public key + */ + Public_Key* subject_public_key() const; + + /** + * Get the raw DER encoded public key. + * @return the raw DER encoded public key + */ + MemoryVector<byte> raw_public_key() const; + + /** + * Get the subject DN. + * @return the subject DN + */ + X509_DN subject_dn() const; + + /** + * Get the subject alternative name. + * @return the subject alternative name. + */ + AlternativeName subject_alt_name() const; + + /** + * Get the key constraints for the key associated with this + * PKCS#10 object. + * @return the key constraints + */ + Key_Constraints constraints() const; + + /** + * Get the extendend key constraints (if any). + * @return the extended key constraints + */ + std::vector<OID> ex_constraints() const; + + /** + * Find out whether this is a CA request. + * @result true if it is a CA request, false otherwise. + */ + bool is_CA() const; + + /** + * Return the constraint on the path length defined + * in the BasicConstraints extension. + * @return the path limit + */ + u32bit path_limit() const; + + /** + * Get the challenge password for this request + * @return the challenge password for this request + */ + std::string challenge_password() const; + + /** + * Create a PKCS#10 Request from a data source. + * @param source the data source providing the DER encoded request + */ + PKCS10_Request(DataSource& source); + + /** + * Create a PKCS#10 Request from a file. + * @param filename the name of the file containing the DER or PEM + * encoded request file + */ + PKCS10_Request(const std::string& filename); + private: + void force_decode(); + void handle_attribute(const Attribute&); + + Data_Store info; + }; + +} + +#endif diff --git a/old/botan/build/botan/pkcs8.h b/old/botan/build/botan/pkcs8.h new file mode 100644 index 0000000..28008bd --- /dev/null +++ b/old/botan/build/botan/pkcs8.h @@ -0,0 +1,177 @@ +/* +* PKCS #8 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PKCS8_H__ +#define BOTAN_PKCS8_H__ + +#include <botan/x509_key.h> +#include <botan/ui.h> + +namespace Botan { + +/** +* PKCS #8 Private Key Encoder. +*/ +class BOTAN_DLL PKCS8_Encoder + { + public: + /** + * Get the algorithm identifier associated with the scheme + * this encoders key is part of. + * @return the algorithm identifier + */ + virtual AlgorithmIdentifier alg_id() const = 0; + + /** + * Get the DER encoded key. + * @return the DER encoded key + */ + // FIXME: Why not SecureVector? + virtual MemoryVector<byte> key_bits() const = 0; + virtual ~PKCS8_Encoder() {} + }; + +/* +* PKCS #8 Private Key Decoder +*/ +class BOTAN_DLL PKCS8_Decoder + { + public: + /** + * Set the algorithm identifier associated with the scheme + * this decoders key is part of. + * @param alg_id the algorithm identifier + */ + virtual void alg_id(const AlgorithmIdentifier&) = 0; + + /** + * Set the DER encoded key. + * @param key the DER encoded key + */ + virtual void key_bits(const MemoryRegion<byte>&) = 0; + virtual ~PKCS8_Decoder() {} + }; + +/** +* PKCS #8 General Exception +*/ +struct BOTAN_DLL PKCS8_Exception : public Decoding_Error + { + PKCS8_Exception(const std::string& error) : + Decoding_Error("PKCS #8: " + error) {} + }; + +namespace PKCS8 { + +/** +* Encode a private key into a pipe. +* @param key the private key to encode +* @param pipe the pipe to feed the encoded key into +* @param enc the encoding type to use +*/ +BOTAN_DLL void encode(const Private_Key& key, Pipe& pipe, + X509_Encoding enc = PEM); + +/** +* Encode and encrypt a private key into a pipe. +* @param key the private key to encode +* @param pipe the pipe to feed the encoded key into +* @param pass the password to use for encryption +* @param rng the rng to use +* @param pbe_algo the name of the desired password-based encryption algorithm. +* Provide an empty string to use the default PBE defined in the configuration +* under base/default_pbe. +* @param enc the encoding type to use +*/ +BOTAN_DLL void encrypt_key(const Private_Key& key, + Pipe& pipe, + RandomNumberGenerator& rng, + const std::string& pass, + const std::string& pbe_algo = "", + X509_Encoding enc = PEM); + + +/** +* Get a string containing a PEM encoded private key. +* @param key the key to encode +* @return the encoded key +*/ +BOTAN_DLL std::string PEM_encode(const Private_Key& key); + +/** +* Get a string containing a PEM encoded private key, encrypting it with a +* password. +* @param key the key to encode +* @param rng the rng to use +* @param pass the password to use for encryption +* @param pbe_algo the name of the desired password-based encryption algorithm. +* Provide an empty string to use the default PBE defined in the configuration +* under base/default_pbe. +*/ +BOTAN_DLL std::string PEM_encode(const Private_Key& key, + RandomNumberGenerator& rng, + const std::string& pass, + const std::string& pbe_algo = ""); + +/** +* Load a key from a data source. +* @param source the data source providing the encoded key +* @param rng the rng to use +* @param ui the user interface to be used for passphrase dialog +* @return the loaded private key object +*/ +BOTAN_DLL Private_Key* load_key(DataSource& source, + RandomNumberGenerator& rng, + const User_Interface& ui); + +/** Load a key from a data source. +* @param source the data source providing the encoded key +* @param rng the rng to use +* @param pass the passphrase to decrypt the key. Provide an empty +* string if the key is not encoded. +* @return the loaded private key object +*/ +BOTAN_DLL Private_Key* load_key(DataSource& source, + RandomNumberGenerator& rng, + const std::string& pass = ""); + +/** +* Load a key from a file. +* @param filename the path to the file containing the encoded key +* @param rng the rng to use +* @param ui the user interface to be used for passphrase dialog +* @return the loaded private key object +*/ +BOTAN_DLL Private_Key* load_key(const std::string& filename, + RandomNumberGenerator& rng, + const User_Interface& ui); + +/** Load a key from a file. +* @param filename the path to the file containing the encoded key +* @param rng the rng to use +* @param pass the passphrase to decrypt the key. Provide an empty +* string if the key is not encoded. +* @return the loaded private key object +*/ +BOTAN_DLL Private_Key* load_key(const std::string& filename, + RandomNumberGenerator& rng, + const std::string& pass = ""); + +/** +* Copy an existing encoded key object. +* @param key the key to copy +* @param rng the rng to use +* @return the new copy of the key +*/ +BOTAN_DLL Private_Key* copy_key(const Private_Key& key, + RandomNumberGenerator& rng); + +} + +} + +#endif diff --git a/old/botan/build/botan/point_gfp.h b/old/botan/build/botan/point_gfp.h new file mode 100644 index 0000000..771605e --- /dev/null +++ b/old/botan/build/botan/point_gfp.h @@ -0,0 +1,315 @@ +/* +* Arithmetic over GF(p) +* +* (C) 2007 Martin Doering +* Christoph Ludwig +* Falko Strenzke +* (C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_POINT_GFP_H__ +#define BOTAN_POINT_GFP_H__ + +#include <botan/curve_gfp.h> +#include <botan/gfp_element.h> +#include <botan/bigint.h> +#include <botan/exceptn.h> +#include <vector> + +namespace Botan { + +struct Illegal_Point : public Exception + { + Illegal_Point(const std::string& err = "") : Exception(err) {} + }; + +/** +* This class represents one point on a curve of GF(p). +*/ +class BOTAN_DLL PointGFp + { + public: + /** + * uncompressed encoding byte value + */ + static const int UNCOMPRESSED = 0; + + /** + * compressed encoding byte value + */ + static const int COMPRESSED = 1; + + /** + * hybrid encoding byte value + */ + static const int HYBRID = 2; + + /** + * Construct the point O + * @param curve The base curve + */ + explicit PointGFp(const CurveGFp& curve); + + /** + * Construct a point given its affine coordinates + * @param curve the base curve + * @param x affine x coordinate + * @param y affine y coordinate + */ + explicit PointGFp(const CurveGFp& curve, GFpElement const& x, + GFpElement const& y); + + /** + * Construct a point given its jacobian projective coordinates + * @param curve the base curve + * @param x jacobian projective x coordinate + * @param y jacobian projective y coordinate + * @param z jacobian projective y coordinate + */ + explicit PointGFp(const CurveGFp& curve, GFpElement const& x, + GFpElement const& y, GFpElement const& z); + + /** + * copy constructor + * @param other the value to clone + */ + PointGFp(const PointGFp& other); + + /** + * assignment operator + * @param other The point to use as source for the assignment + */ + const PointGFp& operator=(const PointGFp& other); + + /** + * assign another point which is on the same curve as *this + * @param other The point to use as source for the assignment + */ + const PointGFp& assign_within_same_curve(const PointGFp& other); + + + + /** + * += Operator + * @param rhs the PointGFp to add to the local value + * @result resulting PointGFp + */ + PointGFp& operator+=(const PointGFp& rhs); + + /** + * -= Operator + * @param rhs the PointGFp to subtract from the local value + * @result resulting PointGFp + */ + PointGFp& operator-=(const PointGFp& rhs); + + /** + * *= Operator + * This function turns on the the special reduction multiplication + * itself for fast computation, turns it off again when finished. + * @param scalar the PointGFp to multiply with *this + * @result resulting PointGFp + */ + PointGFp& operator*=(const BigInt& scalar); + + /** + * the equivalent to operator*= with countermeasures against + * sidechannel attacks, using the randomized exponent + * and add-and-double-always + * countermeasures (suitable for ECDSA and ECKAEG) + * @param scalar the scalar to multiply the point with + * @param point_order a multiple of the order of the point + *(= n * k in the general case; k is the cofactor) + * @param max_secr the maximal size of the scalar + * (will usually be n-1 ) + * @result resulting PointGFp + */ + PointGFp& mult_this_secure(const BigInt& scalar, + const BigInt& point_order, + const BigInt& max_secr + ); + + /** + * Negate internal value(*this *= -1 ) + * @return *this + */ + PointGFp& negate(); + + /** + * Multiply the point by two(*this *= 2 ) + * @return *this + */ + PointGFp& mult2_in_place(); + + /** + * Set z coordinate to one. + * @return *this + */ + const PointGFp& set_z_to_one() const; + + /** + * Turn on the special reduction multiplication (i.e. the + * Montgomery multiplication in the current implementation) for + * the coordinates. This enables fast execution of mult2_in_place() + * and operator+=(). + */ + void turn_on_sp_red_mul() const; + + /** + * Return a point + * where the coordinates are transformed + * so that z equals one, + * thus x and y have just the affine values. + * @result *this + */ + PointGFp const get_z_to_one() const; + + /** + * Return base curve of this point + * @result the curve over GF(p) of this point + */ + CurveGFp const get_curve() const; + + /** + * get affine x coordinate + * @result affine x coordinate + */ + GFpElement const get_affine_x() const; + + /** + * get affine y coordinate + * @result affine y coordinate + */ + GFpElement const get_affine_y() const; + + /** + * get the jacobian projective x coordinate + * @result jacobian projective x coordinate + */ + GFpElement const get_jac_proj_x() const; + + /** + * get the jacobian projective y coordinate + * @result jacobian projective y coordinate + */ + GFpElement const get_jac_proj_y() const; + + /** + * get the jacobian projective z coordinate + * @result jacobian projective z coordinate + */ + GFpElement const get_jac_proj_z() const; + + /** + * Is this the point at infinity? + * @result true, if this point is at infinity, false otherwise. + */ + bool is_zero() const; + + /** + * Checks whether the point is to be found on the underlying curve. + * Throws an Invalid_Point exception in case of detecting that the point + * does not satisfy the curve equation. + * To be used to ensure against fault attacks. + */ + void check_invariants() const; + + + /** + * swaps the states of *this and other, does not throw! + * @param other the object to swap values with + */ + void swap(PointGFp& other); + + /** + * Sets the shared pointer to the GFpModulus that will be + * held in *this, specifically the various members of *this. + * Warning: do not use this function unless you know in detail about + * the implications of using + * the shared GFpModulus objects! + * Do NOT spread a shared pointer to GFpModulus over different + * threads! + * @param mod a shared pointer to a GFpModulus that will + * be held in the members *this + */ + void set_shrd_mod(std::tr1::shared_ptr<GFpModulus> p_mod); + + static GFpElement decompress(bool yMod2, GFpElement const& x, const CurveGFp& curve); + + private: + static const u32bit GFPEL_WKSP_SIZE = 9; + void ensure_worksp() const; + + inline std::tr1::shared_ptr<PointGFp> mult_loop(int l, const BigInt& m, + std::tr1::shared_ptr<PointGFp> H, + std::tr1::shared_ptr<PointGFp> tmp, + const PointGFp& P); + + CurveGFp mC; + mutable GFpElement mX; // NOTE: these values must be mutable (affine<->proj) + mutable GFpElement mY; + mutable GFpElement mZ; + mutable GFpElement mZpow2; // mZ^2 + mutable GFpElement mZpow3; // mZ^3 + mutable GFpElement mAZpow4; // mA*mZ^4 + mutable bool mZpow2_set; + mutable bool mZpow3_set; + mutable bool mAZpow4_set; + mutable std::tr1::shared_ptr<std::vector<GFpElement> > mp_worksp_gfp_el; + + }; + +// relational operators +bool operator==(const PointGFp& lhs, const PointGFp& rhs); +inline bool operator!=(const PointGFp& lhs, const PointGFp& rhs ) + { + return !operator==(lhs, rhs); + } + +// arithmetic operators +PointGFp operator+(const PointGFp& lhs, const PointGFp& rhs); +PointGFp operator-(const PointGFp& lhs, const PointGFp& rhs); +PointGFp operator-(const PointGFp& lhs); + +PointGFp operator*(const BigInt& scalar, const PointGFp& point); +PointGFp operator*(const PointGFp& point, const BigInt& scalar); +PointGFp mult_point_secure(const PointGFp& point, + const BigInt& scalar, + const BigInt& point_order, + const BigInt& max_secret); + +PointGFp const mult2(const PointGFp& point); + +PointGFp const create_random_point(RandomNumberGenerator& rng, + const CurveGFp& curve); + +// encoding and decoding +SecureVector<byte> EC2OSP(const PointGFp& point, byte format); +PointGFp OS2ECP(MemoryRegion<byte> const& os, const CurveGFp& curve); + +SecureVector<byte> encode_uncompressed(const PointGFp& point); // maybe make private +SecureVector<byte> encode_hybrid(const PointGFp& point); // maybe make private +SecureVector<byte> encode_compressed(const PointGFp& point); // maybe make private + +// swaps the states of point1 and point2, does not throw! +// cf. Meyers, Item 25 +inline +void swap(PointGFp& point1, PointGFp& point2 ) + { + point1.swap(point2); + } + +} // namespace Botan + +namespace std { + +// swaps the states of point1 and point2, does not throw! +// cf. Meyers, Item 25 +template<> inline void +swap<Botan::PointGFp>(Botan::PointGFp& x, Botan::PointGFp& y) { x.swap(y); } + +} // namespace std + +#endif diff --git a/old/botan/build/botan/pow_mod.h b/old/botan/build/botan/pow_mod.h new file mode 100644 index 0000000..6952dcd --- /dev/null +++ b/old/botan/build/botan/pow_mod.h @@ -0,0 +1,93 @@ +/* +* Modular Exponentiator +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_POWER_MOD_H__ +#define BOTAN_POWER_MOD_H__ + +#include <botan/bigint.h> + +namespace Botan { + +/* +* Modular Exponentiator Interface +*/ +class BOTAN_DLL Modular_Exponentiator + { + public: + virtual void set_base(const BigInt&) = 0; + virtual void set_exponent(const BigInt&) = 0; + virtual BigInt execute() const = 0; + virtual Modular_Exponentiator* copy() const = 0; + virtual ~Modular_Exponentiator() {} + }; + +/* +* Modular Exponentiator Proxy +*/ +class BOTAN_DLL Power_Mod + { + public: + enum Usage_Hints { + NO_HINTS = 0x0000, + + BASE_IS_FIXED = 0x0001, + BASE_IS_SMALL = 0x0002, + BASE_IS_LARGE = 0x0004, + BASE_IS_2 = 0x0008, + + EXP_IS_FIXED = 0x0100, + EXP_IS_SMALL = 0x0200, + EXP_IS_LARGE = 0x0400 + }; + + void set_modulus(const BigInt&, Usage_Hints = NO_HINTS) const; + void set_base(const BigInt&) const; + void set_exponent(const BigInt&) const; + + BigInt execute() const; + + Power_Mod& operator=(const Power_Mod&); + + Power_Mod(const BigInt& = 0, Usage_Hints = NO_HINTS); + Power_Mod(const Power_Mod&); + ~Power_Mod(); + private: + mutable Modular_Exponentiator* core; + Usage_Hints hints; + }; + +/* +* Fixed Exponent Modular Exponentiator Proxy +*/ +class BOTAN_DLL Fixed_Exponent_Power_Mod : public Power_Mod + { + public: + BigInt operator()(const BigInt& b) const + { set_base(b); return execute(); } + + Fixed_Exponent_Power_Mod() {} + Fixed_Exponent_Power_Mod(const BigInt&, const BigInt&, + Usage_Hints = NO_HINTS); + }; + +/* +* Fixed Base Modular Exponentiator Proxy +*/ +class BOTAN_DLL Fixed_Base_Power_Mod : public Power_Mod + { + public: + BigInt operator()(const BigInt& e) const + { set_exponent(e); return execute(); } + + Fixed_Base_Power_Mod() {} + Fixed_Base_Power_Mod(const BigInt&, const BigInt&, + Usage_Hints = NO_HINTS); + }; + +} + +#endif diff --git a/old/botan/build/botan/prf_ssl3.h b/old/botan/build/botan/prf_ssl3.h new file mode 100644 index 0000000..165fc7c --- /dev/null +++ b/old/botan/build/botan/prf_ssl3.h @@ -0,0 +1,27 @@ +/* +* SSLv3 PRF +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SSLV3_PRF_H__ +#define BOTAN_SSLV3_PRF_H__ + +#include <botan/kdf.h> + +namespace Botan { + +/* +* SSL3 PRF +*/ +class BOTAN_DLL SSL3_PRF : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + }; + +} + +#endif diff --git a/old/botan/build/botan/prf_tls.h b/old/botan/build/botan/prf_tls.h new file mode 100644 index 0000000..d212795 --- /dev/null +++ b/old/botan/build/botan/prf_tls.h @@ -0,0 +1,34 @@ +/* +* TLS v1.0 PRF +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TLS_PRF_H__ +#define BOTAN_TLS_PRF_H__ + +#include <botan/kdf.h> +#include <botan/mac.h> + +namespace Botan { + +/* +* TLS PRF +*/ +class BOTAN_DLL TLS_PRF : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + TLS_PRF(); + ~TLS_PRF(); + private: + MessageAuthenticationCode* hmac_md5; + MessageAuthenticationCode* hmac_sha1; + }; + +} + +#endif diff --git a/old/botan/build/botan/prf_x942.h b/old/botan/build/botan/prf_x942.h new file mode 100644 index 0000000..f957566 --- /dev/null +++ b/old/botan/build/botan/prf_x942.h @@ -0,0 +1,31 @@ +/* +* X9.42 PRF +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ANSI_X942_PRF_H__ +#define BOTAN_ANSI_X942_PRF_H__ + +#include <botan/kdf.h> + +namespace Botan { + +/* +* X9.42 PRF +*/ +class BOTAN_DLL X942_PRF : public KDF + { + public: + SecureVector<byte> derive(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + X942_PRF(const std::string&); + private: + std::string key_wrap_oid; + }; + +} + +#endif diff --git a/old/botan/build/botan/pubkey.h b/old/botan/build/botan/pubkey.h new file mode 100644 index 0000000..c73a54d --- /dev/null +++ b/old/botan/build/botan/pubkey.h @@ -0,0 +1,392 @@ +/* +* Public Key Interface +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PUBKEY_H__ +#define BOTAN_PUBKEY_H__ + +#include <botan/pk_keys.h> +#include <botan/symkey.h> +#include <botan/rng.h> +#include <botan/eme.h> +#include <botan/emsa.h> +#include <botan/kdf.h> + +namespace Botan { + +/** +* The two types of signature format supported by Botan. +*/ +enum Signature_Format { IEEE_1363, DER_SEQUENCE }; + +/** +* Public Key Encryptor +*/ +class BOTAN_DLL PK_Encryptor + { + public: + + /** + * Encrypt a message. + * @param in the message as a byte array + * @param length the length of the above byte array + * @param rng the random number source to use + * @return the encrypted message + */ + SecureVector<byte> encrypt(const byte in[], u32bit length, + RandomNumberGenerator& rng) const; + + /** + * Encrypt a message. + * @param in the message + * @param rng the random number source to use + * @return the encrypted message + */ + SecureVector<byte> encrypt(const MemoryRegion<byte>& in, + RandomNumberGenerator& rng) const; + + /** + * Return the maximum allowed message size in bytes. + * @return the maximum message size in bytes + */ + virtual u32bit maximum_input_size() const = 0; + + virtual ~PK_Encryptor() {} + private: + virtual SecureVector<byte> enc(const byte[], u32bit, + RandomNumberGenerator&) const = 0; + }; + +/** +* Public Key Decryptor +*/ +class BOTAN_DLL PK_Decryptor + { + public: + /** + * Decrypt a ciphertext. + * @param in the ciphertext as a byte array + * @param length the length of the above byte array + * @return the decrypted message + */ + SecureVector<byte> decrypt(const byte in[], u32bit length) const; + + /** + * Decrypt a ciphertext. + * @param in the ciphertext + * @return the decrypted message + */ + SecureVector<byte> decrypt(const MemoryRegion<byte>& in) const; + + virtual ~PK_Decryptor() {} + private: + virtual SecureVector<byte> dec(const byte[], u32bit) const = 0; + }; + +/** +* Public Key Signer. Use the sign_message() functions for small +* messages. Use multiple calls update() to process large messages and +* generate the signature by finally calling signature(). +*/ +class BOTAN_DLL PK_Signer + { + public: + /** + * Sign a message. + * @param in the message to sign as a byte array + * @param length the length of the above byte array + * @param rng the rng to use + * @return the signature + */ + SecureVector<byte> sign_message(const byte in[], u32bit length, + RandomNumberGenerator& rng); + + /** + * Sign a message. + * @param in the message to sign + * @param rng the rng to use + * @return the signature + */ + SecureVector<byte> sign_message(const MemoryRegion<byte>& in, + RandomNumberGenerator& rng); + + /** + * Add a message part (single byte). + * @param the byte to add + */ + void update(byte in); + + /** + * Add a message part. + * @param in the message part to add as a byte array + * @param length the length of the above byte array + */ + void update(const byte in[], u32bit length); + + /** + * Add a message part. + * @param in the message part to add + */ + void update(const MemoryRegion<byte>& in); + + /** + * Get the signature of the so far processed message (provided by the + * calls to update()). + * @param rng the rng to use + * @return the signature of the total message + */ + SecureVector<byte> signature(RandomNumberGenerator& rng); + + /** + * Set the output format of the signature. + * @param format the signature format to use + */ + void set_output_format(Signature_Format format); + + /** + * Construct a PK Signer. + * @param key the key to use inside this signer + * @param emsa the EMSA to use + * An example would be "EMSA1(SHA-224)". + */ + PK_Signer(const PK_Signing_Key& key, EMSA* emsa); + + ~PK_Signer() { delete emsa; } + private: + PK_Signer(const PK_Signer&); + PK_Signer& operator=(const PK_Signer&); + + const PK_Signing_Key& key; + Signature_Format sig_format; + EMSA* emsa; + }; + +/** +* Public Key Verifier. Use the verify_message() functions for small +* messages. Use multiple calls update() to process large messages and +* verify the signature by finally calling check_signature(). +*/ +class BOTAN_DLL PK_Verifier + { + public: + /** + * Verify a signature. + * @param msg the message that the signature belongs to, as a byte array + * @param msg_length the length of the above byte array msg + * @param sig the signature as a byte array + * @param sig_length the length of the above byte array sig + * @return true if the signature is valid + */ + bool verify_message(const byte msg[], u32bit msg_length, + const byte sig[], u32bit sig_length); + /** + * Verify a signature. + * @param msg the message that the signature belongs to + * @param sig the signature + * @return true if the signature is valid + */ + bool verify_message(const MemoryRegion<byte>& msg, + const MemoryRegion<byte>& sig); + + /** + * Add a message part (single byte) of the message corresponding to the + * signature to be verified. + * @param msg_part the byte to add + */ + void update(byte msg_part); + + /** + * Add a message part of the message corresponding to the + * signature to be verified. + * @param msg_part the new message part as a byte array + * @param length the length of the above byte array + */ + void update(const byte msg_part[], u32bit length); + + /** + * Add a message part of the message corresponding to the + * signature to be verified. + * @param msg_part the new message part + */ + void update(const MemoryRegion<byte>& msg_part); + + /** + * Check the signature of the buffered message, i.e. the one build + * by successive calls to update. + * @param sig the signature to be verified as a byte array + * @param length the length of the above byte array + * @return true if the signature is valid, false otherwise + */ + bool check_signature(const byte sig[], u32bit length); + + /** + * Check the signature of the buffered message, i.e. the one build + * by successive calls to update. + * @param sig the signature to be verified + * @return true if the signature is valid, false otherwise + */ + bool check_signature(const MemoryRegion<byte>& sig); + + /** + * Set the format of the signatures fed to this verifier. + * @param format the signature format to use + */ + void set_input_format(Signature_Format format); + + /** + * Construct a PK Verifier. + * @param emsa the EMSA to use + * An example would be new EMSA1(new SHA_224) + */ + PK_Verifier(EMSA* emsa); + + virtual ~PK_Verifier(); + protected: + virtual bool validate_signature(const MemoryRegion<byte>&, + const byte[], u32bit) = 0; + virtual u32bit key_message_parts() const = 0; + virtual u32bit key_message_part_size() const = 0; + + Signature_Format sig_format; + EMSA* emsa; + private: + PK_Verifier(const PK_Verifier&); + PK_Verifier& operator=(const PK_Verifier&); + }; + +/* +* Key Agreement +*/ +class BOTAN_DLL PK_Key_Agreement + { + public: + SymmetricKey derive_key(u32bit, const byte[], u32bit, + const std::string& = "") const; + SymmetricKey derive_key(u32bit, const byte[], u32bit, + const byte[], u32bit) const; + + /** + * Construct a PK Key Agreement. + * @param key the key to use + * @param kdf the KDF to use + */ + PK_Key_Agreement(const PK_Key_Agreement_Key& key, KDF* kdf); + + ~PK_Key_Agreement() { delete kdf; } + private: + PK_Key_Agreement(const PK_Key_Agreement_Key&); + PK_Key_Agreement& operator=(const PK_Key_Agreement&); + + const PK_Key_Agreement_Key& key; + KDF* kdf; + }; + +/** +* Encryption with an MR algorithm and an EME. +*/ +class BOTAN_DLL PK_Encryptor_MR_with_EME : public PK_Encryptor + { + public: + u32bit maximum_input_size() const; + + /** + * Construct an instance. + * @param key the key to use inside the decryptor + * @param eme the EME to use + */ + PK_Encryptor_MR_with_EME(const PK_Encrypting_Key& key, + EME* eme); + + ~PK_Encryptor_MR_with_EME() { delete encoder; } + private: + PK_Encryptor_MR_with_EME(const PK_Encryptor_MR_with_EME&); + PK_Encryptor_MR_with_EME& operator=(const PK_Encryptor_MR_with_EME&); + + SecureVector<byte> enc(const byte[], u32bit, + RandomNumberGenerator& rng) const; + + const PK_Encrypting_Key& key; + const EME* encoder; + }; + +/** +* Decryption with an MR algorithm and an EME. +*/ +class BOTAN_DLL PK_Decryptor_MR_with_EME : public PK_Decryptor + { + public: + /** + * Construct an instance. + * @param key the key to use inside the encryptor + * @param eme the EME to use + */ + PK_Decryptor_MR_with_EME(const PK_Decrypting_Key& key, + EME* eme); + + ~PK_Decryptor_MR_with_EME() { delete encoder; } + private: + PK_Decryptor_MR_with_EME(const PK_Decryptor_MR_with_EME&); + PK_Decryptor_MR_with_EME& operator=(const PK_Decryptor_MR_with_EME&); + + SecureVector<byte> dec(const byte[], u32bit) const; + + const PK_Decrypting_Key& key; + const EME* encoder; + }; + +/** +* Public Key Verifier with Message Recovery. +*/ +class BOTAN_DLL PK_Verifier_with_MR : public PK_Verifier + { + public: + /** + * Construct an instance. + * @param key the key to use inside the verifier + * @param emsa_name the name of the EMSA to use + */ + PK_Verifier_with_MR(const PK_Verifying_with_MR_Key& k, + EMSA* emsa_obj) : PK_Verifier(emsa_obj), key(k) {} + + private: + PK_Verifier_with_MR(const PK_Verifying_with_MR_Key&); + PK_Verifier_with_MR& operator=(const PK_Verifier_with_MR&); + + bool validate_signature(const MemoryRegion<byte>&, const byte[], u32bit); + u32bit key_message_parts() const { return key.message_parts(); } + u32bit key_message_part_size() const { return key.message_part_size(); } + + const PK_Verifying_with_MR_Key& key; + }; + +/** +* Public Key Verifier without Message Recovery +*/ +class BOTAN_DLL PK_Verifier_wo_MR : public PK_Verifier + { + public: + /** + * Construct an instance. + * @param key the key to use inside the verifier + * @param emsa_name the name of the EMSA to use + */ + PK_Verifier_wo_MR(const PK_Verifying_wo_MR_Key& k, + EMSA* emsa_obj) : PK_Verifier(emsa_obj), key(k) {} + + private: + PK_Verifier_wo_MR(const PK_Verifying_wo_MR_Key&); + PK_Verifier_wo_MR& operator=(const PK_Verifier_wo_MR&); + + bool validate_signature(const MemoryRegion<byte>&, const byte[], u32bit); + u32bit key_message_parts() const { return key.message_parts(); } + u32bit key_message_part_size() const { return key.message_part_size(); } + + const PK_Verifying_wo_MR_Key& key; + }; + +} + +#endif diff --git a/old/botan/build/botan/pubkey_enums.h b/old/botan/build/botan/pubkey_enums.h new file mode 100644 index 0000000..53e319f --- /dev/null +++ b/old/botan/build/botan/pubkey_enums.h @@ -0,0 +1,77 @@ +/* +* Enumerations +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ENUMS_H__ +#define BOTAN_ENUMS_H__ + +#include <botan/ber_dec.h> + +namespace Botan { + +/** +* X.509v3 Key Constraints. +*/ +enum Key_Constraints { + NO_CONSTRAINTS = 0, + DIGITAL_SIGNATURE = 32768, + NON_REPUDIATION = 16384, + KEY_ENCIPHERMENT = 8192, + DATA_ENCIPHERMENT = 4096, + KEY_AGREEMENT = 2048, + KEY_CERT_SIGN = 1024, + CRL_SIGN = 512, + ENCIPHER_ONLY = 256, + DECIPHER_ONLY = 128 +}; + +/** +* BER Decoding Function for key constraints +*/ +namespace BER { + +void BOTAN_DLL decode(BER_Decoder&, Key_Constraints&); + +} + +/** +* X.509v2 CRL Reason Code. +*/ +enum CRL_Code { + UNSPECIFIED = 0, + KEY_COMPROMISE = 1, + CA_COMPROMISE = 2, + AFFILIATION_CHANGED = 3, + SUPERSEDED = 4, + CESSATION_OF_OPERATION = 5, + CERTIFICATE_HOLD = 6, + REMOVE_FROM_CRL = 8, + PRIVLEDGE_WITHDRAWN = 9, + AA_COMPROMISE = 10, + + DELETE_CRL_ENTRY = 0xFF00, + OCSP_GOOD = 0xFF01, + OCSP_UNKNOWN = 0xFF02 +}; + +/* +* Various Other Enumerations +*/ + +/** +* The two types of X509 encoding supported by Botan. +*/ +enum X509_Encoding { RAW_BER, PEM }; + +/** +* Value to encode in case of no path limit in the X509 +* BasicConstraints extension. +*/ +static const u32bit NO_CERT_PATH_LIMIT = 0xFFFFFFF0; + +} + +#endif diff --git a/old/botan/build/botan/randpool.h b/old/botan/build/botan/randpool.h new file mode 100644 index 0000000..b6a3add --- /dev/null +++ b/old/botan/build/botan/randpool.h @@ -0,0 +1,53 @@ +/* +* Randpool +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RANDPOOL_H__ +#define BOTAN_RANDPOOL_H__ + +#include <botan/rng.h> +#include <botan/block_cipher.h> +#include <botan/mac.h> +#include <vector> + +namespace Botan { + +/** +* Randpool +*/ +class BOTAN_DLL Randpool : public RandomNumberGenerator + { + public: + void randomize(byte[], u32bit); + bool is_seeded() const { return seeded; } + void clear() throw(); + std::string name() const; + + void reseed(u32bit bits_to_collect); + void add_entropy_source(EntropySource* es); + void add_entropy(const byte input[], u32bit length); + + Randpool(BlockCipher* cipher, MessageAuthenticationCode* mac, + u32bit pool_blocks = 32, + u32bit iterations_before_reseed = 128); + + ~Randpool(); + private: + void update_buffer(); + void mix_pool(); + + u32bit ITERATIONS_BEFORE_RESEED, POOL_BLOCKS; + BlockCipher* cipher; + MessageAuthenticationCode* mac; + + std::vector<EntropySource*> entropy_sources; + SecureVector<byte> pool, buffer, counter; + bool seeded; + }; + +} + +#endif diff --git a/old/botan/build/botan/rc2.h b/old/botan/build/botan/rc2.h new file mode 100644 index 0000000..cb6f58f --- /dev/null +++ b/old/botan/build/botan/rc2.h @@ -0,0 +1,37 @@ +/* +* RC2 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RC2_H__ +#define BOTAN_RC2_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* RC2 +*/ +class BOTAN_DLL RC2 : public BlockCipher + { + public: + static byte EKB_code(u32bit); + + void clear() throw() { K.clear(); } + std::string name() const { return "RC2"; } + BlockCipher* clone() const { return new RC2; } + RC2() : BlockCipher(8, 1, 32) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u16bit, 64> K; + }; + +} + +#endif diff --git a/old/botan/build/botan/rc5.h b/old/botan/build/botan/rc5.h new file mode 100644 index 0000000..0832247 --- /dev/null +++ b/old/botan/build/botan/rc5.h @@ -0,0 +1,35 @@ +/* +* RC5 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RC5_H__ +#define BOTAN_RC5_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* RC5 +*/ +class BOTAN_DLL RC5 : public BlockCipher + { + public: + void clear() throw() { S.clear(); } + std::string name() const; + BlockCipher* clone() const { return new RC5(ROUNDS); } + RC5(u32bit); + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + SecureVector<u32bit> S; + const u32bit ROUNDS; + }; + +} + +#endif diff --git a/old/botan/build/botan/rc6.h b/old/botan/build/botan/rc6.h new file mode 100644 index 0000000..cb2800b --- /dev/null +++ b/old/botan/build/botan/rc6.h @@ -0,0 +1,35 @@ +/* +* RC6 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RC6_H__ +#define BOTAN_RC6_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* RC6 +*/ +class BOTAN_DLL RC6 : public BlockCipher + { + public: + void clear() throw() { S.clear(); } + std::string name() const { return "RC6"; } + BlockCipher* clone() const { return new RC6; } + RC6() : BlockCipher(16, 1, 32) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u32bit, 44> S; + }; + +} + +#endif diff --git a/old/botan/build/botan/reducer.h b/old/botan/build/botan/reducer.h new file mode 100644 index 0000000..d234e07 --- /dev/null +++ b/old/botan/build/botan/reducer.h @@ -0,0 +1,36 @@ +/* +* Modular Reducer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MODARITH_H__ +#define BOTAN_MODARITH_H__ + +#include <botan/bigint.h> + +namespace Botan { + +/* +* Modular Reducer +*/ +class BOTAN_DLL Modular_Reducer + { + public: + BigInt multiply(const BigInt&, const BigInt&) const; + BigInt square(const BigInt&) const; + BigInt reduce(const BigInt&) const; + + bool initialized() const { return (mod_words != 0); } + + Modular_Reducer() { mod_words = 0; } + Modular_Reducer(const BigInt&); + private: + BigInt modulus, modulus_2, mu; + u32bit mod_words, mod2_words, mu_words; + }; + +} + +#endif diff --git a/old/botan/build/botan/rmd128.h b/old/botan/build/botan/rmd128.h new file mode 100644 index 0000000..031ae57 --- /dev/null +++ b/old/botan/build/botan/rmd128.h @@ -0,0 +1,35 @@ +/* +* RIPEMD-128 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RIPEMD_128_H__ +#define BOTAN_RIPEMD_128_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* RIPEMD-128 +*/ +class BOTAN_DLL RIPEMD_128 : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "RIPEMD-128"; } + HashFunction* clone() const { return new RIPEMD_128; } + RIPEMD_128() : MDx_HashFunction(16, 64, false, true) { clear(); } + private: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + SecureBuffer<u32bit, 16> M; + SecureBuffer<u32bit, 4> digest; + }; + +} + +#endif diff --git a/old/botan/build/botan/rmd160.h b/old/botan/build/botan/rmd160.h new file mode 100644 index 0000000..f2babc5 --- /dev/null +++ b/old/botan/build/botan/rmd160.h @@ -0,0 +1,35 @@ +/* +* RIPEMD-160 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RIPEMD_160_H__ +#define BOTAN_RIPEMD_160_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* RIPEMD-160 +*/ +class BOTAN_DLL RIPEMD_160 : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "RIPEMD-160"; } + HashFunction* clone() const { return new RIPEMD_160; } + RIPEMD_160() : MDx_HashFunction(20, 64, false, true) { clear(); } + private: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + SecureBuffer<u32bit, 16> M; + SecureBuffer<u32bit, 5> digest; + }; + +} + +#endif diff --git a/old/botan/build/botan/rng.h b/old/botan/build/botan/rng.h new file mode 100644 index 0000000..41904db --- /dev/null +++ b/old/botan/build/botan/rng.h @@ -0,0 +1,103 @@ +/* +* RandomNumberGenerator +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RANDOM_NUMBER_GENERATOR_H__ +#define BOTAN_RANDOM_NUMBER_GENERATOR_H__ + +#include <botan/entropy_src.h> +#include <botan/exceptn.h> +#include <string> + +namespace Botan { + +/** +* This class represents a random number (RNG) generator object. +*/ +class BOTAN_DLL RandomNumberGenerator + { + public: + /** + * Create a seeded and active RNG object for general application use + */ + static RandomNumberGenerator* make_rng(); + + /** + * Randomize a byte array. + * @param output the byte array to hold the random output. + * @param length the length of the byte array output. + */ + virtual void randomize(byte output[], u32bit length) = 0; + + /** + * Return a random byte + * @return random byte + */ + byte next_byte(); + + /** + * Check whether this RNG is seeded. + * @return true if this RNG was already seeded, false otherwise. + */ + virtual bool is_seeded() const { return true; } + + /** + * Clear all internally held values of this RNG. + */ + virtual void clear() throw() = 0; + + /** + * Return the name of this object + */ + virtual std::string name() const = 0; + + /** + * Seed this RNG using the entropy sources it contains. + * @param bits_to_collect is the number of bits of entropy to + attempt to gather from the entropy sources + */ + virtual void reseed(u32bit bits_to_collect) = 0; + + /** + * Add this entropy source to the RNG object + * @param source the entropy source which will be retained and used by RNG + */ + virtual void add_entropy_source(EntropySource* source) = 0; + + /** + * Add entropy to this RNG. + * @param in a byte array containg the entropy to be added + * @param length the length of the byte array in + */ + virtual void add_entropy(const byte in[], u32bit length) = 0; + + RandomNumberGenerator() {} + virtual ~RandomNumberGenerator() {} + private: + RandomNumberGenerator(const RandomNumberGenerator&) {} + RandomNumberGenerator& operator=(const RandomNumberGenerator&) + { return (*this); } + }; + +/* +* Null Random Number Generator +*/ +class BOTAN_DLL Null_RNG : public RandomNumberGenerator + { + public: + void randomize(byte[], u32bit) { throw PRNG_Unseeded("Null_RNG"); } + void clear() throw() {} + std::string name() const { return "Null_RNG"; } + + void reseed(u32bit) {} + bool is_seeded() const { return false; } + void add_entropy(const byte[], u32bit) {} + void add_entropy_source(EntropySource* es) { delete es; } + }; + +} + +#endif diff --git a/old/botan/build/botan/rotate.h b/old/botan/build/botan/rotate.h new file mode 100644 index 0000000..c8f8d4a --- /dev/null +++ b/old/botan/build/botan/rotate.h @@ -0,0 +1,30 @@ +/* +* Word Rotation Operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_WORD_ROTATE_H__ +#define BOTAN_WORD_ROTATE_H__ + +#include <botan/types.h> + +namespace Botan { + +/* +* Word Rotation Functions +*/ +template<typename T> inline T rotate_left(T input, u32bit rot) + { + return static_cast<T>((input << rot) | (input >> (8*sizeof(T)-rot)));; + } + +template<typename T> inline T rotate_right(T input, u32bit rot) + { + return static_cast<T>((input >> rot) | (input << (8*sizeof(T)-rot))); + } + +} + +#endif diff --git a/old/botan/build/botan/rsa.h b/old/botan/build/botan/rsa.h new file mode 100644 index 0000000..f07533a --- /dev/null +++ b/old/botan/build/botan/rsa.h @@ -0,0 +1,88 @@ +/* +* RSA +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RSA_H__ +#define BOTAN_RSA_H__ + +#include <botan/if_algo.h> + +namespace Botan { + +/** +* RSA Public Key +*/ +class BOTAN_DLL RSA_PublicKey : public PK_Encrypting_Key, + public PK_Verifying_with_MR_Key, + public virtual IF_Scheme_PublicKey + { + public: + std::string algo_name() const { return "RSA"; } + + SecureVector<byte> encrypt(const byte[], u32bit, + RandomNumberGenerator& rng) const; + + SecureVector<byte> verify(const byte[], u32bit) const; + + RSA_PublicKey() {} + RSA_PublicKey(const BigInt&, const BigInt&); + protected: + BigInt public_op(const BigInt&) const; + }; + +/** +* RSA Private Key class. +*/ +class BOTAN_DLL RSA_PrivateKey : public RSA_PublicKey, + public PK_Decrypting_Key, + public PK_Signing_Key, + public IF_Scheme_PrivateKey + { + public: + SecureVector<byte> sign(const byte[], u32bit, + RandomNumberGenerator&) const; + + SecureVector<byte> decrypt(const byte[], u32bit) const; + + bool check_key(RandomNumberGenerator& rng, bool) const; + + /** + * Default constructor, does not set any internal values. Use this + * constructor if you wish to decode a DER or PEM encoded key. + */ + RSA_PrivateKey() {} + + /** + * Construct a private key from the specified parameters. + * @param rng the random number generator to use + * @param prime1 the first prime + * @param prime2 the second prime + * @param exp the exponent + * @param d_exp if specified, this has to be d with + * exp * d = 1 mod (p - 1, q - 1). Leave it as 0 if you wish to + * the constructor to calculate it. + * @param n if specified, this must be n = p * q. Leave it as 0 + * if you wish to the constructor to calculate it. + */ + RSA_PrivateKey(RandomNumberGenerator& rng, + const BigInt& p, const BigInt& q, const BigInt& e, + const BigInt& d = 0, const BigInt& n = 0); + + /** + * Create a new private key with the specified bit length + * @param rng the random number generator to use + * @param bits the desired bit length of the private key + * @param exp the public exponent to be used + */ + RSA_PrivateKey(RandomNumberGenerator& rng, + u32bit bits, u32bit exp = 65537); + private: + BigInt private_op(const byte[], u32bit) const; + }; + +} + +#endif diff --git a/old/botan/build/botan/rw.h b/old/botan/build/botan/rw.h new file mode 100644 index 0000000..900e5eb --- /dev/null +++ b/old/botan/build/botan/rw.h @@ -0,0 +1,56 @@ +/* +* Rabin-Williams +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_RW_H__ +#define BOTAN_RW_H__ + +#include <botan/if_algo.h> + +namespace Botan { + +/* +* Rabin-Williams Public Key +*/ +class BOTAN_DLL RW_PublicKey : public PK_Verifying_with_MR_Key, + public virtual IF_Scheme_PublicKey + { + public: + std::string algo_name() const { return "RW"; } + + SecureVector<byte> verify(const byte[], u32bit) const; + + RW_PublicKey() {} + RW_PublicKey(const BigInt&, const BigInt&); + protected: + BigInt public_op(const BigInt&) const; + }; + +/* +* Rabin-Williams Private Key +*/ +class BOTAN_DLL RW_PrivateKey : public RW_PublicKey, + public PK_Signing_Key, + public IF_Scheme_PrivateKey + { + public: + SecureVector<byte> sign(const byte[], u32bit, + RandomNumberGenerator& rng) const; + + bool check_key(RandomNumberGenerator& rng, bool) const; + + RW_PrivateKey() {} + + RW_PrivateKey(RandomNumberGenerator&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt& = 0, const BigInt& = 0); + + RW_PrivateKey(RandomNumberGenerator& rng, u32bit bits, u32bit = 2); + }; + +} + +#endif diff --git a/old/botan/build/botan/s2k.h b/old/botan/build/botan/s2k.h new file mode 100644 index 0000000..7af9251 --- /dev/null +++ b/old/botan/build/botan/s2k.h @@ -0,0 +1,102 @@ +/* +* S2K +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_S2K_H__ +#define BOTAN_S2K_H__ + +#include <botan/symkey.h> +#include <botan/rng.h> + +namespace Botan { + +/* +* S2K Interface +*/ +class BOTAN_DLL S2K + { + public: + /** + * Create a copy of this object. + * @return an auto_ptr to a copy of this object + */ + virtual S2K* clone() const = 0; + + /** + * Get the algorithm name. + * @return the name of this S2K algorithm + */ + virtual std::string name() const = 0; + + /** + * Clear this objects internal values. + */ + virtual void clear() {} + + /** + * Derive a key from a passphrase with this S2K object. It will use + * the salt value and number of iterations configured in this object. + * @param key_len the desired length of the key to produce + * @param passphrase the password to derive the key from + */ + OctetString derive_key(u32bit key_len, + const std::string& passphrase) const; + + /** + * Set the number of iterations for the one-way function during + * key generation. + * @param n the desired number of iterations + */ + void set_iterations(u32bit n); + + /** + * Set a new salt value. + * @param new_salt a byte array defining the new salt value + * @param len the length of the above byte array + */ + void change_salt(const byte new_salt[], u32bit len); + + /** + * Set a new salt value. + * @param new_salt the new salt value + */ + void change_salt(const MemoryRegion<byte>& new_salt); + + /** + * Create a new random salt value using the rng + * @param rng the random number generator to use + * @param len the desired length of the new salt value + */ + void new_random_salt(RandomNumberGenerator& rng, u32bit len); + + /** + * Get the number of iterations for the key derivation currently + * configured in this S2K object. + * @return the current number of iterations + */ + u32bit iterations() const { return iter; } + + /** + * Get the currently configured salt value of this S2K object. + * @return the current salt value + */ + SecureVector<byte> current_salt() const { return salt; } + + S2K() { iter = 0; } + virtual ~S2K() {} + private: + S2K(const S2K&) {} + S2K& operator=(const S2K&) { return (*this); } + + virtual OctetString derive(u32bit, const std::string&, + const byte[], u32bit, u32bit) const = 0; + SecureVector<byte> salt; + u32bit iter; + }; + +} + +#endif diff --git a/old/botan/build/botan/safer_sk.h b/old/botan/build/botan/safer_sk.h new file mode 100644 index 0000000..e52c583 --- /dev/null +++ b/old/botan/build/botan/safer_sk.h @@ -0,0 +1,40 @@ +/* +* SAFER-SK +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SAFER_SK_H__ +#define BOTAN_SAFER_SK_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* SAFER-SK +*/ +class BOTAN_DLL SAFER_SK : public BlockCipher + { + public: + void clear() throw() { EK.clear(); } + std::string name() const; + BlockCipher* clone() const; + SAFER_SK(u32bit); + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + static const byte EXP[256]; + static const byte LOG[512]; + static const byte BIAS[208]; + static const byte KEY_INDEX[208]; + SecureVector<byte> EK; + const u32bit ROUNDS; + }; + +} + +#endif diff --git a/old/botan/build/botan/salsa20.h b/old/botan/build/botan/salsa20.h new file mode 100644 index 0000000..3dbfddb --- /dev/null +++ b/old/botan/build/botan/salsa20.h @@ -0,0 +1,41 @@ +/* +* Salsa20 +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SALSA20_H__ +#define BOTAN_SALSA20_H__ + +#include <botan/stream_cipher.h> + +namespace Botan { + +/* +* Salsa20 +*/ +class BOTAN_DLL Salsa20 : public StreamCipher + { + public: + void clear() throw(); + std::string name() const; + StreamCipher* clone() const { return new Salsa20; } + + void resync(const byte[], u32bit); + + Salsa20(); + ~Salsa20() { clear(); } + private: + void cipher(const byte[], byte[], u32bit); + void key_schedule(const byte[], u32bit); + + SecureBuffer<u32bit, 16> state; + + SecureBuffer<byte, 64> buffer; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/scan_name.h b/old/botan/build/botan/scan_name.h new file mode 100644 index 0000000..9e7af40 --- /dev/null +++ b/old/botan/build/botan/scan_name.h @@ -0,0 +1,77 @@ +/** +SCAN Name Abstraction +(C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SCAN_NAME_H__ +#define BOTAN_SCAN_NAME_H__ + +#include <botan/types.h> +#include <string> +#include <vector> +#include <set> + +namespace Botan { + +/** +A class encapsulating a SCAN name (similar to JCE conventions) +http://www.users.zetnet.co.uk/hopwood/crypto/scan/ +*/ +class SCAN_Name + { + public: + /** + @param algo_spec A SCAN name + */ + SCAN_Name(const std::string& algo_spec); + + /** + @return the original input string + */ + std::string as_string() const { return orig_algo_spec; } + + /** + @return the algorithm name + */ + std::string algo_name() const { return name[0]; } + + /** + @return the number of arguments + */ + u32bit arg_count() const { return name.size() - 1; } + + /** + @return if the number of arguments is between lower and upper + */ + bool arg_count_between(u32bit lower, u32bit upper) const + { return ((arg_count() >= lower) && (arg_count() <= upper)); } + + /** + @param i which argument + @return the ith argument + */ + std::string arg(u32bit i) const; + + /** + @param i which argument + @param def_value the default value + @return the ith argument or the default value + */ + std::string arg(u32bit i, const std::string& def_value) const; + + /** + @param i which argument + @param def_value the default value + @return the ith argument as a u32bit, or the default value + */ + u32bit arg_as_u32bit(u32bit i, u32bit def_value) const; + private: + std::string orig_algo_spec; + std::vector<std::string> name; + }; + +} + +#endif diff --git a/old/botan/build/botan/secmem.h b/old/botan/build/botan/secmem.h new file mode 100644 index 0000000..d64a376 --- /dev/null +++ b/old/botan/build/botan/secmem.h @@ -0,0 +1,438 @@ +/* +* Secure Memory Buffers +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SECURE_MEMORY_BUFFERS_H__ +#define BOTAN_SECURE_MEMORY_BUFFERS_H__ + +#include <botan/allocate.h> +#include <botan/mem_ops.h> +#include <algorithm> + +namespace Botan { + +/** +* This class represents variable length memory buffers. +*/ +template<typename T> +class MemoryRegion + { + public: + /** + * Find out the size of the buffer, i.e. how many objects of type T it + * contains. + * @return the size of the buffer + */ + u32bit size() const { return used; } + + /** + * Find out whether this buffer is empty. + * @return true if the buffer is empty, false otherwise + */ + bool is_empty() const { return (used == 0); } + + /** + * Find out whether this buffer is non-empty + * @return true if the buffer is non-empty, false otherwise + */ + bool has_items() const { return (used != 0); } + + /** + * Get a pointer to the first element in the buffer. + * @return a pointer to the first element in the buffer + */ + operator T* () { return buf; } + + /** + * Get a constant pointer to the first element in the buffer. + * @return a constant pointer to the first element in the buffer + */ + operator const T* () const { return buf; } + + /** + * Get a pointer to the first element in the buffer. + * @return a pointer to the first element in the buffer + */ + T* begin() { return buf; } + + /** + * Get a constant pointer to the first element in the buffer. + * @return a constant pointer to the first element in the buffer + */ + const T* begin() const { return buf; } + + /** + * Get a pointer to the last element in the buffer. + * @return a pointer to the last element in the buffer + */ + T* end() { return (buf + size()); } + + /** + * Get a constant pointer to the last element in the buffer. + * @return a constant pointer to the last element in the buffer + */ + const T* end() const { return (buf + size()); } + + /** + * Check two buffers for equality. + * @return true iff the content of both buffers is byte-wise equal + */ + bool operator==(const MemoryRegion<T>& other) const + { + return (size() == other.size() && + same_mem(buf, other.buf, size())); + } + + /** + * Compare two buffers lexicographically. + * @return true if this buffer is lexicographically smaller than other. + */ + bool operator<(const MemoryRegion<T>& other) const; + + /** + * Check two buffers for inequality. + * @return false if the content of both buffers is byte-wise equal, true + * otherwise. + */ + bool operator!=(const MemoryRegion<T>& in) const + { return (!(*this == in)); } + + /** + * Copy the contents of another buffer into this buffer. + * The former contents of *this are discarded. + * @param in the buffer to copy the contents from. + * @return a reference to *this + */ + MemoryRegion<T>& operator=(const MemoryRegion<T>& in) + { if(this != &in) set(in); return (*this); } + + /** + * The use of this function is discouraged because of the risk of memory + * errors. Use MemoryRegion<T>::set() + * instead. + * Copy the contents of an array of objects of type T into this buffer. + * The former contents of *this are discarded. + * The length of *this must be at least n, otherwise memory errors occur. + * @param in the array to copy the contents from + * @param n the length of in + */ + void copy(const T in[], u32bit n) + { copy(0, in, n); } + + /** + * The use of this function is discouraged because of the risk of memory + * errors. Use MemoryRegion<T>::set() + * instead. + * Copy the contents of an array of objects of type T into this buffer. + * The former contents of *this are discarded. + * The length of *this must be at least n, otherwise memory errors occur. + * @param off the offset position inside this buffer to start inserting + * the copied bytes + * @param in the array to copy the contents from + * @param n the length of in + */ + void copy(u32bit off, const T in[], u32bit n) + { copy_mem(buf + off, in, (n > size() - off) ? (size() - off) : n); } + + /** + * Set the contents of this according to the argument. The size of + * *this is increased if necessary. + * @param in the array of objects of type T to copy the contents from + * @param n the size of array in + */ + void set(const T in[], u32bit n) { create(n); copy(in, n); } + + /** + * Set the contents of this according to the argument. The size of + * *this is increased if necessary. + * @param in the buffer to copy the contents from + */ + void set(const MemoryRegion<T>& in) { set(in.begin(), in.size()); } + + /** + * Append data to the end of this buffer. + * @param data the array containing the data to append + * @param n the size of the array data + */ + void append(const T data[], u32bit n) + { grow_to(size()+n); copy(size() - n, data, n); } + + /** + * Append a single element. + * @param x the element to append + */ + void append(T x) { append(&x, 1); } + + /** + * Append data to the end of this buffer. + * @param data the buffer containing the data to append + */ + void append(const MemoryRegion<T>& x) { append(x.begin(), x.size()); } + + /** + * Zeroise the bytes of this buffer. The length remains unchanged. + */ + void clear() { clear_mem(buf, allocated); } + + /** + * Reset this buffer to an empty buffer with size zero. + */ + void destroy() { create(0); } + + /** + * Reset this buffer to a buffer of specified length. The content will be + * initialized to zero bytes. + * @param n the new length of the buffer + */ + void create(u32bit n); + + /** + * Preallocate memory, so that this buffer can grow up to size n without + * having to perform any actual memory allocations. (This is + * the same principle as for std::vector::reserve().) + */ + void grow_to(u32bit N); + + /** + * Swap this buffer with another object. + */ + void swap(MemoryRegion<T>& other); + + ~MemoryRegion() { deallocate(buf, allocated); } + protected: + MemoryRegion() { buf = 0; alloc = 0; used = allocated = 0; } + MemoryRegion(const MemoryRegion<T>& other) + { + buf = 0; + used = allocated = 0; + alloc = other.alloc; + set(other.buf, other.used); + } + + void init(bool locking, u32bit length = 0) + { alloc = Allocator::get(locking); create(length); } + private: + T* allocate(u32bit n) + { + return static_cast<T*>(alloc->allocate(sizeof(T)*n)); + } + + void deallocate(T* p, u32bit n) + { alloc->deallocate(p, sizeof(T)*n); } + + T* buf; + u32bit used; + u32bit allocated; + Allocator* alloc; + }; + +/* +* Create a new buffer +*/ +template<typename T> +void MemoryRegion<T>::create(u32bit n) + { + if(n <= allocated) { clear(); used = n; return; } + deallocate(buf, allocated); + buf = allocate(n); + allocated = used = n; + } + +/* +* Increase the size of the buffer +*/ +template<typename T> +void MemoryRegion<T>::grow_to(u32bit n) + { + if(n > used && n <= allocated) + { + clear_mem(buf + used, n - used); + used = n; + return; + } + else if(n > allocated) + { + T* new_buf = allocate(n); + copy_mem(new_buf, buf, used); + deallocate(buf, allocated); + buf = new_buf; + allocated = used = n; + } + } + +/* +* Compare this buffer with another one +*/ +template<typename T> +bool MemoryRegion<T>::operator<(const MemoryRegion<T>& in) const + { + if(size() < in.size()) return true; + if(size() > in.size()) return false; + + for(u32bit j = 0; j != size(); j++) + { + if(buf[j] < in[j]) return true; + if(buf[j] > in[j]) return false; + } + + return false; + } + +/* +* Swap this buffer with another one +*/ +template<typename T> +void MemoryRegion<T>::swap(MemoryRegion<T>& x) + { + std::swap(buf, x.buf); + std::swap(used, x.used); + std::swap(allocated, x.allocated); + std::swap(alloc, x.alloc); + } + +/** +* This class represents variable length buffers that do not +* make use of memory locking. +*/ +template<typename T> +class MemoryVector : public MemoryRegion<T> + { + public: + /** + * Copy the contents of another buffer into this buffer. + * @param in the buffer to copy the contents from + * @return a reference to *this + */ + MemoryVector<T>& operator=(const MemoryRegion<T>& in) + { if(this != &in) set(in); return (*this); } + + /** + * Create a buffer of the specified length. + * @param n the length of the buffer to create. + + */ + MemoryVector(u32bit n = 0) { MemoryRegion<T>::init(false, n); } + + /** + * Create a buffer with the specified contents. + * @param in the array containing the data to be initially copied + * into the newly created buffer + * @param n the size of the arry in + */ + MemoryVector(const T in[], u32bit n) + { MemoryRegion<T>::init(false); set(in, n); } + + /** + * Copy constructor. + */ + MemoryVector(const MemoryRegion<T>& in) + { MemoryRegion<T>::init(false); set(in); } + + /** + * Create a buffer whose content is the concatenation of two other + * buffers. + * @param in1 the first part of the new contents + * @param in2 the contents to be appended to in1 + */ + MemoryVector(const MemoryRegion<T>& in1, const MemoryRegion<T>& in2) + { MemoryRegion<T>::init(false); set(in1); append(in2); } + }; + +/** +* This class represents variable length buffers using the operating +* systems capability to lock memory, i.e. keeping it from being +* swapped out to disk. In this way, a security hole allowing attackers +* to find swapped out secret keys is closed. Please refer to +* Botan::InitializerOptions::secure_memory() for restrictions and +* further details. +*/ +template<typename T> +class SecureVector : public MemoryRegion<T> + { + public: + /** + * Copy the contents of another buffer into this buffer. + * @param in the buffer to copy the contents from + * @return a reference to *this + */ + SecureVector<T>& operator=(const MemoryRegion<T>& in) + { if(this != &in) set(in); return (*this); } + + /** + * Create a buffer of the specified length. + * @param n the length of the buffer to create. + + */ + SecureVector(u32bit n = 0) { MemoryRegion<T>::init(true, n); } + + /** + * Create a buffer with the specified contents. + * @param in the array containing the data to be initially copied + * into the newly created buffer + * @param n the size of the array in + */ + SecureVector(const T in[], u32bit n) + { MemoryRegion<T>::init(true); set(in, n); } + + /** + * Create a buffer with contents specified contents. + * @param in the buffer holding the contents that will be + * copied into the newly created buffer. + */ + SecureVector(const MemoryRegion<T>& in) + { MemoryRegion<T>::init(true); set(in); } + + /** + * Create a buffer whose content is the concatenation of two other + * buffers. + * @param in1 the first part of the new contents + * @param in2 the contents to be appended to in1 + */ + SecureVector(const MemoryRegion<T>& in1, const MemoryRegion<T>& in2) + { MemoryRegion<T>::init(true); set(in1); append(in2); } + }; + +/** +* This class represents fixed length buffers using the operating +* systems capability to lock memory, i.e. keeping it from being +* swapped out to disk. In this way, a security hole allowing attackers +* to find swapped out secret keys is closed. Please refer to +* Botan::InitializerOptions::secure_memory() for restrictions and +* further details. +*/ +template<typename T, u32bit L> +class SecureBuffer : public MemoryRegion<T> + { + public: + /** + * Copy the contents of another buffer into this buffer. + * @param in the buffer to copy the contents from + * @return a reference to *this + */ + SecureBuffer<T,L>& operator=(const SecureBuffer<T,L>& in) + { if(this != &in) set(in); return (*this); } + + /** + * Create a buffer of the length L. + */ + SecureBuffer() { MemoryRegion<T>::init(true, L); } + + /** + * Create a buffer of size L with the specified contents. + * @param in the array containing the data to be initially copied + * into the newly created buffer + * @param n the size of the array in + */ + SecureBuffer(const T in[], u32bit n) + { MemoryRegion<T>::init(true, L); copy(in, n); } + private: + SecureBuffer<T, L>& operator=(const MemoryRegion<T>& in) + { if(this != &in) set(in); return (*this); } + }; + +} + +#endif diff --git a/old/botan/build/botan/secqueue.h b/old/botan/build/botan/secqueue.h new file mode 100644 index 0000000..fc1fc21 --- /dev/null +++ b/old/botan/build/botan/secqueue.h @@ -0,0 +1,43 @@ +/* +* SecureQueue +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SECURE_QUEUE_H__ +#define BOTAN_SECURE_QUEUE_H__ + +#include <botan/data_src.h> +#include <botan/filter.h> + +namespace Botan { + +/* +* SecureQueue +*/ +class BOTAN_DLL SecureQueue : public Fanout_Filter, public DataSource + { + public: + void write(const byte[], u32bit); + + u32bit read(byte[], u32bit); + u32bit peek(byte[], u32bit, u32bit = 0) const; + + bool end_of_data() const; + u32bit size() const; + bool attachable() { return false; } + + SecureQueue& operator=(const SecureQueue&); + SecureQueue(); + SecureQueue(const SecureQueue&); + ~SecureQueue() { destroy(); } + private: + void destroy(); + class SecureQueueNode* head; + class SecureQueueNode* tail; + }; + +} + +#endif diff --git a/old/botan/build/botan/seed.h b/old/botan/build/botan/seed.h new file mode 100644 index 0000000..54c25d5 --- /dev/null +++ b/old/botan/build/botan/seed.h @@ -0,0 +1,43 @@ +/* +* SEED +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SEED_H__ +#define BOTAN_SEED_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* SEED +*/ +class BOTAN_DLL SEED : public BlockCipher + { + public: + void clear() throw() { K.clear(); } + std::string name() const { return "SEED"; } + BlockCipher* clone() const { return new SEED; } + SEED() : BlockCipher(16, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + class G_FUNC + { + public: + u32bit operator()(u32bit) const; + private: + static const u32bit S0[256], S1[256], S2[256], S3[256]; + }; + + SecureBuffer<u32bit, 32> K; + }; + +} + +#endif diff --git a/old/botan/build/botan/selftest.h b/old/botan/build/botan/selftest.h new file mode 100644 index 0000000..9e36d22 --- /dev/null +++ b/old/botan/build/botan/selftest.h @@ -0,0 +1,22 @@ +/* +* Startup Self Test +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SELF_TESTS_H__ +#define BOTAN_SELF_TESTS_H__ + +#include <botan/algo_factory.h> + +namespace Botan { + +/* +* Self Tests +*/ +BOTAN_DLL bool passes_self_tests(Algorithm_Factory& af); + +} + +#endif diff --git a/old/botan/build/botan/serpent.h b/old/botan/build/botan/serpent.h new file mode 100644 index 0000000..5b9be25 --- /dev/null +++ b/old/botan/build/botan/serpent.h @@ -0,0 +1,35 @@ +/* +* Serpent +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SERPENT_H__ +#define BOTAN_SERPENT_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* Serpent +*/ +class BOTAN_DLL Serpent : public BlockCipher + { + public: + void clear() throw() { round_key.clear(); } + std::string name() const { return "Serpent"; } + BlockCipher* clone() const { return new Serpent; } + Serpent() : BlockCipher(16, 16, 32, 8) {} + protected: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + SecureBuffer<u32bit, 132> round_key; + }; + +} + +#endif diff --git a/old/botan/build/botan/sha160.h b/old/botan/build/botan/sha160.h new file mode 100644 index 0000000..232cf03 --- /dev/null +++ b/old/botan/build/botan/sha160.h @@ -0,0 +1,38 @@ +/* +* SHA-160 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SHA_160_H__ +#define BOTAN_SHA_160_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* SHA-160 +*/ +class BOTAN_DLL SHA_160 : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "SHA-160"; } + HashFunction* clone() const { return new SHA_160; } + SHA_160(); + + protected: + SHA_160(u32bit W_size); + + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + SecureBuffer<u32bit, 5> digest; + SecureVector<u32bit> W; + }; + +} + +#endif diff --git a/old/botan/build/botan/sha2_32.h b/old/botan/build/botan/sha2_32.h new file mode 100644 index 0000000..05083d1 --- /dev/null +++ b/old/botan/build/botan/sha2_32.h @@ -0,0 +1,59 @@ +/* +* SHA-{224,256} +* (C) 1999-2008 Jack Lloyd +* 2007 FlexSecure GmbH +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SHA_256_H__ +#define BOTAN_SHA_256_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* SHA-{224,256} Base +*/ +class BOTAN_DLL SHA_224_256_BASE : public MDx_HashFunction + { + protected: + void clear() throw(); + SHA_224_256_BASE(u32bit out) : + MDx_HashFunction(out, 64, true, true) { clear(); } + + SecureBuffer<u32bit, 64> W; + SecureBuffer<u32bit, 8> digest; + private: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + }; + +/* +* SHA-224 +*/ +class BOTAN_DLL SHA_224 : public SHA_224_256_BASE + { + public: + void clear() throw(); + std::string name() const { return "SHA-224"; } + HashFunction* clone() const { return new SHA_224; } + SHA_224() : SHA_224_256_BASE(28) { clear(); } + }; + +/* +* SHA-256 +*/ +class BOTAN_DLL SHA_256 : public SHA_224_256_BASE + { + public: + void clear() throw(); + std::string name() const { return "SHA-256"; } + HashFunction* clone() const { return new SHA_256; } + SHA_256() : SHA_224_256_BASE(32) { clear (); } + }; + +} + +#endif diff --git a/old/botan/build/botan/sha2_64.h b/old/botan/build/botan/sha2_64.h new file mode 100644 index 0000000..dcc6dc8 --- /dev/null +++ b/old/botan/build/botan/sha2_64.h @@ -0,0 +1,60 @@ +/* +* SHA-{384,512} +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SHA_64BIT_H__ +#define BOTAN_SHA_64BIT_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* SHA-{384,512} Base +*/ +class BOTAN_DLL SHA_384_512_BASE : public MDx_HashFunction + { + protected: + void clear() throw(); + + SHA_384_512_BASE(u32bit out) : + MDx_HashFunction(out, 128, true, true, 16) {} + + SecureBuffer<u64bit, 8> digest; + private: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + SecureBuffer<u64bit, 80> W; + }; + +/* +* SHA-384 +*/ +class BOTAN_DLL SHA_384 : public SHA_384_512_BASE + { + public: + void clear() throw(); + std::string name() const { return "SHA-384"; } + HashFunction* clone() const { return new SHA_384; } + SHA_384() : SHA_384_512_BASE(48) { clear(); } + }; + +/* +* SHA-512 +*/ +class BOTAN_DLL SHA_512 : public SHA_384_512_BASE + { + public: + void clear() throw(); + std::string name() const { return "SHA-512"; } + HashFunction* clone() const { return new SHA_512; } + SHA_512() : SHA_384_512_BASE(64) { clear(); } + }; + +} + +#endif diff --git a/old/botan/build/botan/signed_obj.h b/old/botan/build/botan/signed_obj.h new file mode 100644 index 0000000..3c233d2 --- /dev/null +++ b/old/botan/build/botan/signed_obj.h @@ -0,0 +1,93 @@ +/* +* EAC SIGNED Object +* (C) 2007 FlexSecure GmbH +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EAC_SIGNED_OBJECT_H__ +#define BOTAN_EAC_SIGNED_OBJECT_H__ + +#include <botan/asn1_obj.h> +#include <botan/pubkey_enums.h> +#include <botan/freestore.h> +#include <botan/pipe.h> +#include <vector> + +namespace Botan { + +/** +* This class represents abstract signed EAC object +*/ +class BOTAN_DLL EAC_Signed_Object + { + public: + /** + * Get the TBS (to-be-signed) data in this object. + * @return the DER encoded TBS data of this object + */ + virtual SecureVector<byte> tbs_data() const = 0; + + /** + * Get the signature of this object as a concatenation, i.e. if the + * signature consists of multiple parts (like in the case of ECDSA) + * these will be concatenated. + * @return the signature as a concatenation of its parts + */ + + /* + NOTE: this is here only because abstract signature objects have + not yet been introduced + */ + virtual SecureVector<byte> get_concat_sig() const = 0; + + /** + * Get the signature algorithm identifier used to sign this object. + * @result the signature algorithm identifier + */ + AlgorithmIdentifier signature_algorithm() const; + + /** + * Check the signature of this object. + * @param key the public key associated with this signed object + * @return true if the signature was created by the private key + * associated with this public key + */ + virtual bool check_signature(class Public_Key&) const = 0; + + /** + * Write this object DER encoded into a specified pipe. + * @param pipe the pipe to write the encoded object to + * @param enc the encoding type to use + */ + virtual void encode(Pipe&, X509_Encoding = PEM) const = 0; + + /** + * BER encode this object. + * @return the result containing the BER representation of this object. + */ + SecureVector<byte> BER_encode() const; + + /** + * PEM encode this object. + * @return the result containing the PEM representation of this object. + */ + std::string PEM_encode() const; + + virtual ~EAC_Signed_Object() {} + protected: + void do_decode(); + EAC_Signed_Object() {} + + AlgorithmIdentifier sig_algo; + SecureVector<byte> tbs_bits; + std::string PEM_label_pref; + std::vector<std::string> PEM_labels_allowed; + private: + virtual void force_decode() = 0; + }; + +} + +#endif diff --git a/old/botan/build/botan/skein_512.h b/old/botan/build/botan/skein_512.h new file mode 100644 index 0000000..fa558fc --- /dev/null +++ b/old/botan/build/botan/skein_512.h @@ -0,0 +1,41 @@ +/** +* The Skein-512 hash function +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SKEIN_512_H__ +#define BOTAN_SKEIN_512_H__ + +#include <botan/secmem.h> +#include <botan/hash.h> +#include <string> + +namespace Botan { + +class BOTAN_DLL Skein_512 : public HashFunction + { + public: + Skein_512(u32bit output_bits = 512, + const std::string& personalization = ""); + + HashFunction* clone() const; + std::string name() const; + void clear() throw(); + private: + void add_data(const byte input[], u32bit length); + void final_result(byte out[]); + + std::string personalization; + u32bit output_bits; + SecureBuffer<u64bit, 9> H; + SecureBuffer<u64bit, 3> T; + + SecureBuffer<byte, 64> buffer; + u32bit buf_pos; + }; + +} + +#endif diff --git a/old/botan/build/botan/skipjack.h b/old/botan/build/botan/skipjack.h new file mode 100644 index 0000000..231cd9c --- /dev/null +++ b/old/botan/build/botan/skipjack.h @@ -0,0 +1,38 @@ +/* +* Skipjack +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SKIPJACK_H__ +#define BOTAN_SKIPJACK_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* Skipjack +*/ +class BOTAN_DLL Skipjack : public BlockCipher + { + public: + void clear() throw(); + std::string name() const { return "Skipjack"; } + BlockCipher* clone() const { return new Skipjack; } + Skipjack() : BlockCipher(8, 10) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + void step_A(u16bit&, u16bit&, u32bit) const; + void step_B(u16bit&, u16bit&, u32bit) const; + void step_Ai(u16bit&, u16bit&, u32bit) const; + void step_Bi(u16bit&, u16bit&, u32bit) const; + SecureBuffer<byte, 256> FTABLE[10]; + }; + +} + +#endif diff --git a/old/botan/build/botan/square.h b/old/botan/build/botan/square.h new file mode 100644 index 0000000..94a1fc3 --- /dev/null +++ b/old/botan/build/botan/square.h @@ -0,0 +1,52 @@ +/* +* Square +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SQUARE_H__ +#define BOTAN_SQUARE_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* Square +*/ +class BOTAN_DLL Square : public BlockCipher + { + public: + void clear() throw(); + std::string name() const { return "Square"; } + BlockCipher* clone() const { return new Square; } + Square() : BlockCipher(16, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + static void transform(u32bit[4]); + + static const byte SE[256]; + static const byte SD[256]; + static const byte Log[256]; + static const byte ALog[255]; + + static const u32bit TE0[256]; + static const u32bit TE1[256]; + static const u32bit TE2[256]; + static const u32bit TE3[256]; + static const u32bit TD0[256]; + static const u32bit TD1[256]; + static const u32bit TD2[256]; + static const u32bit TD3[256]; + + SecureBuffer<u32bit, 28> EK, DK; + SecureBuffer<byte, 32> ME, MD; + }; + +} + +#endif diff --git a/old/botan/build/botan/ssl3_mac.h b/old/botan/build/botan/ssl3_mac.h new file mode 100644 index 0000000..dcaf7f4 --- /dev/null +++ b/old/botan/build/botan/ssl3_mac.h @@ -0,0 +1,39 @@ +/* +* SSL3-MAC +* (C) 1999-2004 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SSL3_MAC_H__ +#define BOTAN_SSL3_MAC_H__ + +#include <botan/hash.h> +#include <botan/mac.h> + +namespace Botan { + +/* +* SSL3-MAC +*/ +class BOTAN_DLL SSL3_MAC : public MessageAuthenticationCode + { + public: + void clear() throw(); + std::string name() const; + MessageAuthenticationCode* clone() const; + + SSL3_MAC(HashFunction*); + ~SSL3_MAC() { delete hash; } + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + void key_schedule(const byte[], u32bit); + + HashFunction* hash; + SecureVector<byte> i_key, o_key; + }; + +} + +#endif diff --git a/old/botan/build/botan/stl_util.h b/old/botan/build/botan/stl_util.h new file mode 100644 index 0000000..18c8b14 --- /dev/null +++ b/old/botan/build/botan/stl_util.h @@ -0,0 +1,86 @@ +/* +* STL Utility Functions +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_STL_UTIL_H__ +#define BOTAN_STL_UTIL_H__ + +#include <map> + +namespace Botan { + +/* +* Copy-on-Predicate Algorithm +*/ +template<typename InputIterator, typename OutputIterator, typename Predicate> +OutputIterator copy_if(InputIterator current, InputIterator end, + OutputIterator dest, Predicate copy_p) + { + while(current != end) + { + if(copy_p(*current)) + *dest++ = *current; + ++current; + } + return dest; + } + +/* +* Searching through a std::map +*/ +template<typename K, typename V> +inline V search_map(const std::map<K, V>& mapping, + const K& key, + const V& null_result = V()) + { + typename std::map<K, V>::const_iterator i = mapping.find(key); + if(i == mapping.end()) + return null_result; + return i->second; + } + +template<typename K, typename V, typename R> +inline R search_map(const std::map<K, V>& mapping, const K& key, + const R& null_result, const R& found_result) + { + typename std::map<K, V>::const_iterator i = mapping.find(key); + if(i == mapping.end()) + return null_result; + return found_result; + } + +/* +* Function adaptor for delete operation +*/ +template<class T> +class del_fun : public std::unary_function<T, void> + { + public: + void operator()(T* ptr) { delete ptr; } + }; + +/* +* Delete the second half of a pair of objects +*/ +template<typename Pair> +void delete2nd(Pair& pair) + { + delete pair.second; + } + +/* +* Insert a key/value pair into a multimap +*/ +template<typename K, typename V> +void multimap_insert(std::multimap<K, V>& multimap, + const K& key, const V& value) + { + multimap.insert(std::make_pair(key, value)); + } + +} + +#endif diff --git a/old/botan/build/botan/stream_cipher.h b/old/botan/build/botan/stream_cipher.h new file mode 100644 index 0000000..8ea3591 --- /dev/null +++ b/old/botan/build/botan/stream_cipher.h @@ -0,0 +1,92 @@ +/** +* Stream Cipher +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_STREAM_CIPHER_H__ +#define BOTAN_STREAM_CIPHER_H__ + +#include <botan/sym_algo.h> + +namespace Botan { + +/* +* Stream Cipher +*/ +class BOTAN_DLL StreamCipher : public SymmetricAlgorithm + { + public: + const u32bit IV_LENGTH; + + /** + * Encrypt a message. + * @param i the plaintext + * @param o the byte array to hold the output, i.e. the ciphertext + * @param len the length of both i and o + */ + void encrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); } + + /** + * Decrypt a message. + * @param i the ciphertext to decrypt + * @param o the byte array to hold the output, i.e. the plaintext + * @param len the length of both i and o + */ + void decrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); } + + /** + * Encrypt a message. + * @param in the plaintext as input, after the function has + * returned it will hold the ciphertext + + * @param len the length of in + */ + void encrypt(byte in[], u32bit len) { cipher(in, in, len); } + + /** + * Decrypt a message. + * @param in the ciphertext as input, after the function has + * returned it will hold the plaintext + * @param len the length of in + */ + void decrypt(byte in[], u32bit len) { cipher(in, in, len); } + + /** + * Resync the cipher using the IV + * @param iv the initialization vector + * @param iv_len the length of the IV in bytes + */ + virtual void resync(const byte iv[], u32bit iv_len); + + /** + * Seek ahead in the stream. + * @param len the length to seek ahead. + */ + virtual void seek(u32bit len); + + /** + * Get a new object representing the same algorithm as *this + */ + virtual StreamCipher* clone() const = 0; + + /** + * Zeroize internal state + */ + virtual void clear() throw() = 0; + + StreamCipher(u32bit key_min, u32bit key_max = 0, + u32bit key_mod = 1, + u32bit iv_len = 0) : + SymmetricAlgorithm(key_min, key_max, key_mod), + IV_LENGTH(iv_len) {} + + virtual ~StreamCipher() {} + private: + virtual void cipher(const byte[], byte[], u32bit) = 0; + }; + +} + +#endif diff --git a/old/botan/build/botan/sym_algo.h b/old/botan/build/botan/sym_algo.h new file mode 100644 index 0000000..1c8b816 --- /dev/null +++ b/old/botan/build/botan/sym_algo.h @@ -0,0 +1,101 @@ +/** +* Symmetric Algorithm Base Class +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SYMMETRIC_ALGORITHM_H__ +#define BOTAN_SYMMETRIC_ALGORITHM_H__ + +#include <botan/types.h> +#include <botan/exceptn.h> +#include <botan/symkey.h> + +namespace Botan { + +/** +* This class represents a symmetric algorithm object. +*/ +class BOTAN_DLL SymmetricAlgorithm + { + public: + + /** + * The maximum allowed key length. + */ + const u32bit MAXIMUM_KEYLENGTH; + + /** + * The minimal allowed key length. + */ + const u32bit MINIMUM_KEYLENGTH; + + /** + * A valid keylength is a multiple of this value. + */ + const u32bit KEYLENGTH_MULTIPLE; + + /** + * The name of the algorithm. + * @return the name of the algorithm + */ + virtual std::string name() const = 0; + + /** + * Set the symmetric key of this object. + * @param key the SymmetricKey to be set. + */ + void set_key(const SymmetricKey& key) throw(Invalid_Key_Length) + { set_key(key.begin(), key.length()); } + + /** + * Set the symmetric key of this object. + * @param key the to be set as a byte array. + * @param the length of the byte array. + */ + void set_key(const byte key[], u32bit length) throw(Invalid_Key_Length) + { + if(!valid_keylength(length)) + throw Invalid_Key_Length(name(), length); + key_schedule(key, length); + } + + /** + * Check whether a given key length is valid for this algorithm. + * @param length the key length to be checked. + * @return true if the key length is valid. + */ + bool valid_keylength(u32bit length) const + { + return ((length >= MINIMUM_KEYLENGTH) && + (length <= MAXIMUM_KEYLENGTH) && + (length % KEYLENGTH_MULTIPLE == 0)); + } + + /** + * Construct a SymmetricAlgorithm. + * @param key_min the minimum allowed key length + * @param key_max the maximum allowed key length + * @param key_mod any valid key length must be a multiple of this value + */ + SymmetricAlgorithm(u32bit key_min, u32bit key_max, u32bit key_mod) : + MAXIMUM_KEYLENGTH(key_max ? key_max : key_min), + MINIMUM_KEYLENGTH(key_min), + KEYLENGTH_MULTIPLE(key_mod) + {} + + virtual ~SymmetricAlgorithm() {} + private: + virtual void key_schedule(const byte[], u32bit) = 0; + }; + +/** +* The two possible directions for cipher filters, determining whether they +* actually perform encryption or decryption. +*/ +enum Cipher_Dir { ENCRYPTION, DECRYPTION }; + +} + +#endif diff --git a/old/botan/build/botan/symkey.h b/old/botan/build/botan/symkey.h new file mode 100644 index 0000000..5504297 --- /dev/null +++ b/old/botan/build/botan/symkey.h @@ -0,0 +1,62 @@ +/* +* OctetString +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SYMKEY_H__ +#define BOTAN_SYMKEY_H__ + +#include <botan/secmem.h> +#include <string> + +namespace Botan { + +/* +* Octet String +*/ +class BOTAN_DLL OctetString + { + public: + u32bit length() const { return bits.size(); } + SecureVector<byte> bits_of() const { return bits; } + + const byte* begin() const { return bits.begin(); } + const byte* end() const { return bits.end(); } + + std::string as_string() const; + + OctetString& operator^=(const OctetString&); + + void set_odd_parity(); + + void change(const std::string&); + void change(const byte[], u32bit); + void change(const MemoryRegion<byte>& in) { bits = in; } + + OctetString(class RandomNumberGenerator&, u32bit len); + OctetString(const std::string& str = "") { change(str); } + OctetString(const byte in[], u32bit len) { change(in, len); } + OctetString(const MemoryRegion<byte>& in) { change(in); } + private: + SecureVector<byte> bits; + }; + +/* +* Operations on Octet Strings +*/ +BOTAN_DLL bool operator==(const OctetString&, const OctetString&); +BOTAN_DLL bool operator!=(const OctetString&, const OctetString&); +BOTAN_DLL OctetString operator+(const OctetString&, const OctetString&); +BOTAN_DLL OctetString operator^(const OctetString&, const OctetString&); + +/* +* Alternate Names +*/ +typedef OctetString SymmetricKey; +typedef OctetString InitializationVector; + +} + +#endif diff --git a/old/botan/build/botan/tea.h b/old/botan/build/botan/tea.h new file mode 100644 index 0000000..8ddf3e3 --- /dev/null +++ b/old/botan/build/botan/tea.h @@ -0,0 +1,34 @@ +/* +* TEA +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TEA_H__ +#define BOTAN_TEA_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* TEA +*/ +class BOTAN_DLL TEA : public BlockCipher + { + public: + void clear() throw() { K.clear(); } + std::string name() const { return "TEA"; } + BlockCipher* clone() const { return new TEA; } + TEA() : BlockCipher(8, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + SecureBuffer<u32bit, 4> K; + }; + +} + +#endif diff --git a/old/botan/build/botan/tiger.h b/old/botan/build/botan/tiger.h new file mode 100644 index 0000000..63184a9 --- /dev/null +++ b/old/botan/build/botan/tiger.h @@ -0,0 +1,44 @@ +/* +* Tiger +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIGER_H__ +#define BOTAN_TIGER_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* Tiger +*/ +class BOTAN_DLL Tiger : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const; + HashFunction* clone() const { return new Tiger(OUTPUT_LENGTH); } + Tiger(u32bit = 24, u32bit = 3); + private: + void compress_n(const byte[], u32bit block); + void copy_out(byte[]); + + static void pass(u64bit&, u64bit&, u64bit&, u64bit[8], byte); + static void mix(u64bit[8]); + + static const u64bit SBOX1[256]; + static const u64bit SBOX2[256]; + static const u64bit SBOX3[256]; + static const u64bit SBOX4[256]; + + SecureBuffer<u64bit, 8> X; + SecureBuffer<u64bit, 3> digest; + const u32bit PASS; + }; + +} + +#endif diff --git a/old/botan/build/botan/timer.h b/old/botan/build/botan/timer.h new file mode 100644 index 0000000..b6e8ef4 --- /dev/null +++ b/old/botan/build/botan/timer.h @@ -0,0 +1,45 @@ +/** +* Timestamp Functions +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMERS_H__ +#define BOTAN_TIMERS_H__ + +#include <botan/rng.h> + +namespace Botan { + +/** +* Timer Interface +*/ +class BOTAN_DLL Timer : public EntropySource + { + public: + /** + @return nanoseconds resolution timestamp, unknown epoch + */ + virtual u64bit clock() const = 0; + + void poll(Entropy_Accumulator& accum); + + virtual ~Timer() {} + protected: + static u64bit combine_timers(u32bit, u32bit, u32bit); + }; + +/** +* ANSI Clock Timer +*/ +class BOTAN_DLL ANSI_Clock_Timer : public Timer + { + public: + std::string name() const { return "ANSI clock"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/old/botan/build/botan/tm_posix.h b/old/botan/build/botan/tm_posix.h new file mode 100644 index 0000000..8bedccf --- /dev/null +++ b/old/botan/build/botan/tm_posix.h @@ -0,0 +1,27 @@ +/* +* POSIX Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMER_POSIX_H__ +#define BOTAN_TIMER_POSIX_H__ + +#include <botan/timer.h> + +namespace Botan { + +/* +* POSIX Timer +*/ +class BOTAN_DLL POSIX_Timer : public Timer + { + public: + std::string name() const { return "POSIX clock_gettime"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/old/botan/build/botan/tm_unix.h b/old/botan/build/botan/tm_unix.h new file mode 100644 index 0000000..c304dbb --- /dev/null +++ b/old/botan/build/botan/tm_unix.h @@ -0,0 +1,27 @@ +/* +* Unix Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMER_UNIX_H__ +#define BOTAN_TIMER_UNIX_H__ + +#include <botan/timer.h> + +namespace Botan { + +/* +* Unix Timer +*/ +class BOTAN_DLL Unix_Timer : public Timer + { + public: + std::string name() const { return "Unix gettimeofday"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/old/botan/build/botan/tm_win32.h b/old/botan/build/botan/tm_win32.h new file mode 100644 index 0000000..5bcb720 --- /dev/null +++ b/old/botan/build/botan/tm_win32.h @@ -0,0 +1,27 @@ +/* +* Win32 Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMER_WIN32_H__ +#define BOTAN_TIMER_WIN32_H__ + +#include <botan/timer.h> + +namespace Botan { + +/* +* Win32 Timer +*/ +class BOTAN_DLL Win32_Timer : public Timer + { + public: + std::string name() const { return "Win32 QueryPerformanceCounter"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/old/botan/build/botan/turing.h b/old/botan/build/botan/turing.h new file mode 100644 index 0000000..d48c1d8 --- /dev/null +++ b/old/botan/build/botan/turing.h @@ -0,0 +1,47 @@ +/* +* Turing +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TURING_H__ +#define BOTAN_TURING_H__ + +#include <botan/stream_cipher.h> + +namespace Botan { + +/* +* Turing +*/ +class BOTAN_DLL Turing : public StreamCipher + { + public: + void clear() throw(); + std::string name() const { return "Turing"; } + StreamCipher* clone() const { return new Turing; } + Turing() : StreamCipher(4, 32, 4) { position = 0; } + private: + void cipher(const byte[], byte[], u32bit); + void key_schedule(const byte[], u32bit); + void resync(const byte[], u32bit); + void generate(); + + static u32bit fixedS(u32bit); + static void gen_sbox(MemoryRegion<u32bit>&, u32bit, + const MemoryRegion<u32bit>&); + + static const u32bit Q_BOX[256]; + static const byte SBOX[256]; + + SecureBuffer<u32bit, 256> S0, S1, S2, S3; + SecureBuffer<u32bit, 17> R; + SecureVector<u32bit> K; + SecureBuffer<byte, 340> buffer; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/twofish.h b/old/botan/build/botan/twofish.h new file mode 100644 index 0000000..0640e32 --- /dev/null +++ b/old/botan/build/botan/twofish.h @@ -0,0 +1,48 @@ +/* +* Twofish +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TWOFISH_H__ +#define BOTAN_TWOFISH_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* Twofish +*/ +class BOTAN_DLL Twofish : public BlockCipher + { + public: + void clear() throw(); + std::string name() const { return "Twofish"; } + BlockCipher* clone() const { return new Twofish; } + Twofish() : BlockCipher(16, 16, 32, 8) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + + static void rs_mul(byte[4], byte, u32bit); + + static const u32bit MDS0[256]; + static const u32bit MDS1[256]; + static const u32bit MDS2[256]; + static const u32bit MDS3[256]; + static const byte Q0[256]; + static const byte Q1[256]; + static const byte RS[32]; + static const byte EXP_TO_POLY[255]; + static const byte POLY_TO_EXP[255]; + + SecureBuffer<u32bit, 256> SBox0, SBox1, SBox2, SBox3; + SecureBuffer<u32bit, 40> round_key; + }; + +} + +#endif diff --git a/old/botan/build/botan/types.h b/old/botan/build/botan/types.h new file mode 100644 index 0000000..304628d --- /dev/null +++ b/old/botan/build/botan/types.h @@ -0,0 +1,42 @@ +/* +* Low Level Types +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TYPES_H__ +#define BOTAN_TYPES_H__ + +#include <botan/build.h> + +namespace Botan { + +typedef unsigned char byte; +typedef unsigned short u16bit; +typedef unsigned int u32bit; + +typedef signed int s32bit; + +#if defined(_MSC_VER) || defined(__BORLANDC__) + typedef unsigned __int64 u64bit; +#elif defined(__KCC) + typedef unsigned __long_long u64bit; +#elif defined(__GNUG__) + __extension__ typedef unsigned long long u64bit; +#else + typedef unsigned long long u64bit; +#endif + +static const u32bit DEFAULT_BUFFERSIZE = BOTAN_DEFAULT_BUFFER_SIZE; + +} + +namespace Botan_types { + +using Botan::byte; +using Botan::u32bit; + +} + +#endif diff --git a/old/botan/build/botan/ui.h b/old/botan/build/botan/ui.h new file mode 100644 index 0000000..fe62c60 --- /dev/null +++ b/old/botan/build/botan/ui.h @@ -0,0 +1,36 @@ +/* +* User Interface +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_UI_H__ +#define BOTAN_UI_H__ + +#include <botan/build.h> +#include <string> + +namespace Botan { + +/* +* User Interface +*/ +class BOTAN_DLL User_Interface + { + public: + enum UI_Result { OK, CANCEL_ACTION }; + + virtual std::string get_passphrase(const std::string&, + const std::string&, + UI_Result&) const; + User_Interface(const std::string& = ""); + virtual ~User_Interface() {} + protected: + std::string preset_passphrase; + mutable bool first_try; + }; + +} + +#endif diff --git a/old/botan/build/botan/unix_cmd.h b/old/botan/build/botan/unix_cmd.h new file mode 100644 index 0000000..aec1891 --- /dev/null +++ b/old/botan/build/botan/unix_cmd.h @@ -0,0 +1,59 @@ +/** +* Unix Command Execution +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_UNIX_CMD_H__ +#define BOTAN_UNIX_CMD_H__ + +#include <botan/types.h> +#include <botan/data_src.h> +#include <string> +#include <vector> + +namespace Botan { + +/** +* Unix Program Info +*/ +struct Unix_Program + { + Unix_Program(const char* n, u32bit p) + { name_and_args = n; priority = p; working = true; } + + std::string name_and_args; + u32bit priority; + bool working; + }; + +/** +* Command Output DataSource +*/ +class BOTAN_DLL DataSource_Command : public DataSource + { + public: + u32bit read(byte[], u32bit); + u32bit peek(byte[], u32bit, u32bit) const; + bool end_of_data() const; + std::string id() const; + + int fd() const; + + DataSource_Command(const std::string&, + const std::vector<std::string>& paths); + ~DataSource_Command(); + private: + void create_pipe(const std::vector<std::string>&); + void shutdown_pipe(); + + const u32bit MAX_BLOCK_USECS, KILL_WAIT; + + std::vector<std::string> arg_list; + struct pipe_wrapper* pipe; + }; + +} + +#endif diff --git a/old/botan/build/botan/util.h b/old/botan/build/botan/util.h new file mode 100644 index 0000000..ac78673 --- /dev/null +++ b/old/botan/build/botan/util.h @@ -0,0 +1,39 @@ +/* +* Utility Functions +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_UTIL_H__ +#define BOTAN_UTIL_H__ + +#include <botan/types.h> + +namespace Botan { + +/* +* Time Access Functions +*/ +BOTAN_DLL u64bit system_time(); + +/* +* Memory Locking Functions +*/ +BOTAN_DLL bool lock_mem(void*, u32bit); +BOTAN_DLL void unlock_mem(void*, u32bit); + +/* +* Misc Utility Functions +*/ +BOTAN_DLL u32bit round_up(u32bit, u32bit); +BOTAN_DLL u32bit round_down(u32bit, u32bit); + +/* +* Work Factor Estimates +*/ +BOTAN_DLL u32bit dl_work_factor(u32bit); + +} + +#endif diff --git a/old/botan/build/botan/version.h b/old/botan/build/botan/version.h new file mode 100644 index 0000000..3cc44e8 --- /dev/null +++ b/old/botan/build/botan/version.h @@ -0,0 +1,61 @@ +/* +* Version Information +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_VERSION_H__ +#define BOTAN_VERSION_H__ + +#include <botan/types.h> +#include <string> + +namespace Botan { + +/* +* Get information describing the version +*/ + +/** +* Get the version string identifying the version of Botan. +* @return the version string +*/ +BOTAN_DLL std::string version_string(); + +/** +* Get the major version number. +* @return the major version number +*/ +BOTAN_DLL u32bit version_major(); + +/** +* Get the minor version number. +* @return the minor version number +*/ +BOTAN_DLL u32bit version_minor(); + +/** +* Get the patch number. +* @return the patch number +*/ +BOTAN_DLL u32bit version_patch(); + +/* +* Macros for compile-time version checks +*/ +#define BOTAN_VERSION_CODE_FOR(a,b,c) ((a << 16) | (b << 8) | (c)) + +/** +* Compare using BOTAN_VERSION_CODE_FOR, as in +* # if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,8,0) +* # error "Botan version too old" +* # endif +*/ +#define BOTAN_VERSION_CODE BOTAN_VERSION_CODE_FOR(BOTAN_VERSION_MAJOR, \ + BOTAN_VERSION_MINOR, \ + BOTAN_VERSION_PATCH) + +} + +#endif diff --git a/old/botan/build/botan/whrlpool.h b/old/botan/build/botan/whrlpool.h new file mode 100644 index 0000000..b72ff60 --- /dev/null +++ b/old/botan/build/botan/whrlpool.h @@ -0,0 +1,42 @@ +/* +* Whirlpool +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_WHIRLPOOL_H__ +#define BOTAN_WHIRLPOOL_H__ + +#include <botan/mdx_hash.h> + +namespace Botan { + +/* +* Whirlpool +*/ +class BOTAN_DLL Whirlpool : public MDx_HashFunction + { + public: + void clear() throw(); + std::string name() const { return "Whirlpool"; } + HashFunction* clone() const { return new Whirlpool; } + Whirlpool() : MDx_HashFunction(64, 64, true, true, 32) { clear(); } + private: + void compress_n(const byte[], u32bit blocks); + void copy_out(byte[]); + + static const u64bit C0[256]; + static const u64bit C1[256]; + static const u64bit C2[256]; + static const u64bit C3[256]; + static const u64bit C4[256]; + static const u64bit C5[256]; + static const u64bit C6[256]; + static const u64bit C7[256]; + SecureBuffer<u64bit, 8> M, digest; + }; + +} + +#endif diff --git a/old/botan/build/botan/wid_wake.h b/old/botan/build/botan/wid_wake.h new file mode 100644 index 0000000..4720afd --- /dev/null +++ b/old/botan/build/botan/wid_wake.h @@ -0,0 +1,41 @@ +/* +* WiderWake +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_WIDER_WAKE_H__ +#define BOTAN_WIDER_WAKE_H__ + +#include <botan/stream_cipher.h> + +namespace Botan { + +/* +* WiderWake4+1-BE +*/ +class BOTAN_DLL WiderWake_41_BE : public StreamCipher + { + public: + void clear() throw(); + std::string name() const { return "WiderWake4+1-BE"; } + StreamCipher* clone() const { return new WiderWake_41_BE; } + WiderWake_41_BE() : StreamCipher(16, 16, 1, 8) {} + private: + void cipher(const byte[], byte[], u32bit); + void key_schedule(const byte[], u32bit); + void resync(const byte[], u32bit); + + void generate(u32bit); + + SecureBuffer<byte, DEFAULT_BUFFERSIZE> buffer; + SecureBuffer<u32bit, 256> T; + SecureBuffer<u32bit, 5> state; + SecureBuffer<u32bit, 4> t_key; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/x509_ca.h b/old/botan/build/botan/x509_ca.h new file mode 100644 index 0000000..ef2a8d1 --- /dev/null +++ b/old/botan/build/botan/x509_ca.h @@ -0,0 +1,108 @@ +/* +* X.509 Certificate Authority +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_CA_H__ +#define BOTAN_X509_CA_H__ + +#include <botan/x509cert.h> +#include <botan/x509_crl.h> +#include <botan/x509_ext.h> +#include <botan/pkcs8.h> +#include <botan/pkcs10.h> +#include <botan/pubkey.h> + +namespace Botan { + +/** +* This class represents X.509 Certificate Authorities (CAs). +*/ +class BOTAN_DLL X509_CA + { + public: + + /** + * Sign a PKCS#10 Request. + * @param req the request to sign + * @param rng the rng to use + * @param not_before the starting time for the certificate + * @param not_after the expiration time for the certificate + * @return the resulting certificate + */ + X509_Certificate sign_request(const PKCS10_Request& req, + RandomNumberGenerator& rng, + const X509_Time& not_before, + const X509_Time& not_after); + + /** + * Get the certificate of this CA. + * @return the CA certificate + */ + X509_Certificate ca_certificate() const; + + /** + * Create a new and empty CRL for this CA. + * @param rng the random number generator to use + * @param next_update the time to set in next update in seconds + * as the offset from the current time + * @return the new CRL + */ + X509_CRL new_crl(RandomNumberGenerator& rng, u32bit = 0) const; + + /** + * Create a new CRL by with additional entries. + * @param last_crl the last CRL of this CA to add the new entries to + * @param new_entries contains the new CRL entries to be added to the CRL + * @param rng the random number generator to use + * @param next_update the time to set in next update in seconds + * as the offset from the current time + */ + X509_CRL update_crl(const X509_CRL& last_crl, + const std::vector<CRL_Entry>& new_entries, + RandomNumberGenerator& rng, + u32bit next_update = 0) const; + + static X509_Certificate make_cert(PK_Signer*, + RandomNumberGenerator&, + const AlgorithmIdentifier&, + const MemoryRegion<byte>&, + const X509_Time&, const X509_Time&, + const X509_DN&, const X509_DN&, + const Extensions&); + + /** + * Create a new CA object. + * @param ca_certificate the certificate of the CA + * @param key the private key of the CA + */ + X509_CA(const X509_Certificate& ca_certificate, const Private_Key& key); + ~X509_CA(); + private: + X509_CA(const X509_CA&) {} + X509_CA& operator=(const X509_CA&) { return (*this); } + + X509_CRL make_crl(const std::vector<CRL_Entry>&, + u32bit, u32bit, RandomNumberGenerator&) const; + + AlgorithmIdentifier ca_sig_algo; + X509_Certificate cert; + PK_Signer* signer; + }; + +/** +* Choose the default signature format for a certain public key signature +* scheme. +* @param key will be the key to choose a padding scheme for +* @param alg_id will be set to the chosen scheme +* @return A PK_Signer object for generating signatures +*/ +BOTAN_DLL PK_Signer* choose_sig_format(const Private_Key& key, + AlgorithmIdentifier& alg_id); + + +} + +#endif diff --git a/old/botan/build/botan/x509_crl.h b/old/botan/build/botan/x509_crl.h new file mode 100644 index 0000000..6caef42 --- /dev/null +++ b/old/botan/build/botan/x509_crl.h @@ -0,0 +1,90 @@ +/* +* X.509 CRL +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_CRL_H__ +#define BOTAN_X509_CRL_H__ + +#include <botan/x509_obj.h> +#include <botan/crl_ent.h> +#include <vector> + +namespace Botan { + +/** +* This class represents X.509 Certificate Revocation Lists (CRLs). +*/ +class BOTAN_DLL X509_CRL : public X509_Object + { + public: + /** + * This class represents CRL related errors. + */ + struct X509_CRL_Error : public Exception + { + X509_CRL_Error(const std::string& error) : + Exception("X509_CRL: " + error) {} + }; + + /** + * Get the entries of this CRL in the form of a vector. + * @return a vector containing the entries of this CRL. + */ + std::vector<CRL_Entry> get_revoked() const; + + /** + * Get the issuer DN of this CRL. + * @return the CRLs issuer DN + */ + X509_DN issuer_dn() const; + + /** + * Get the AuthorityKeyIdentifier of this CRL. + * @return this CRLs AuthorityKeyIdentifier + */ + MemoryVector<byte> authority_key_id() const; + + /** + * Get the serial number of this CRL. + * @return the CRLs serial number + */ + u32bit crl_number() const; + + /** + * Get the CRL's thisUpdate value. + * @return the CRLs thisUpdate + */ + X509_Time this_update() const; + + /** + * Get the CRL's nextUpdate value. + * @return the CRLs nextdUpdate + */ + X509_Time next_update() const; + + /** + * Construct a CRL from a data source. + * @param source the data source providing the DER or PEM encoded CRL. + */ + X509_CRL(DataSource&, bool throw_on_unknown_critical = false); + + /** + * Construct a CRL from a file containing the DER or PEM encoded CRL. + * @param filename the name of the CRL file + */ + X509_CRL(const std::string& filename, + bool throw_on_unknown_critical = false); + private: + void force_decode(); + + bool throw_on_unknown_critical; + std::vector<CRL_Entry> revoked; + Data_Store info; + }; + +} + +#endif diff --git a/old/botan/build/botan/x509_ext.h b/old/botan/build/botan/x509_ext.h new file mode 100644 index 0000000..108215e --- /dev/null +++ b/old/botan/build/botan/x509_ext.h @@ -0,0 +1,317 @@ +/* +* X.509 Certificate Extensions +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_EXTENSIONS_H__ +#define BOTAN_X509_EXTENSIONS_H__ + +#include <botan/asn1_int.h> +#include <botan/asn1_oid.h> +#include <botan/asn1_obj.h> +#include <botan/datastor.h> +#include <botan/pubkey_enums.h> + +namespace Botan { + +/* +* X.509 Certificate Extension +*/ +class BOTAN_DLL Certificate_Extension + { + public: + OID oid_of() const; + + virtual Certificate_Extension* copy() const = 0; + + virtual void contents_to(Data_Store&, Data_Store&) const = 0; + virtual std::string config_id() const = 0; + virtual std::string oid_name() const = 0; + + virtual ~Certificate_Extension() {} + protected: + friend class Extensions; + virtual bool should_encode() const { return true; } + virtual MemoryVector<byte> encode_inner() const = 0; + virtual void decode_inner(const MemoryRegion<byte>&) = 0; + }; + +/* +* X.509 Certificate Extension List +*/ +class BOTAN_DLL Extensions : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + void contents_to(Data_Store&, Data_Store&) const; + + void add(Certificate_Extension* extn) + { extensions.push_back(extn); } + + Extensions& operator=(const Extensions&); + + Extensions(const Extensions&); + Extensions(bool st = true) : should_throw(st) {} + ~Extensions(); + private: + static Certificate_Extension* get_extension(const OID&); + + std::vector<Certificate_Extension*> extensions; + bool should_throw; + }; + +namespace Cert_Extension { + +/* +* Basic Constraints Extension +*/ +class BOTAN_DLL Basic_Constraints : public Certificate_Extension + { + public: + Basic_Constraints* copy() const + { return new Basic_Constraints(is_ca, path_limit); } + + Basic_Constraints(bool ca = false, u32bit limit = 0) : + is_ca(ca), path_limit(limit) {} + + bool get_is_ca() const { return is_ca; } + u32bit get_path_limit() const; + private: + std::string config_id() const { return "basic_constraints"; } + std::string oid_name() const { return "X509v3.BasicConstraints"; } + + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + bool is_ca; + u32bit path_limit; + }; + +/* +* Key Usage Constraints Extension +*/ +class BOTAN_DLL Key_Usage : public Certificate_Extension + { + public: + Key_Usage* copy() const { return new Key_Usage(constraints); } + + Key_Usage(Key_Constraints c = NO_CONSTRAINTS) : constraints(c) {} + + Key_Constraints get_constraints() const { return constraints; } + private: + std::string config_id() const { return "key_usage"; } + std::string oid_name() const { return "X509v3.KeyUsage"; } + + bool should_encode() const { return (constraints != NO_CONSTRAINTS); } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + Key_Constraints constraints; + }; + +/* +* Subject Key Identifier Extension +*/ +class BOTAN_DLL Subject_Key_ID : public Certificate_Extension + { + public: + Subject_Key_ID* copy() const { return new Subject_Key_ID(key_id); } + + Subject_Key_ID() {} + Subject_Key_ID(const MemoryRegion<byte>&); + + MemoryVector<byte> get_key_id() const { return key_id; } + private: + std::string config_id() const { return "subject_key_id"; } + std::string oid_name() const { return "X509v3.SubjectKeyIdentifier"; } + + bool should_encode() const { return (key_id.size() > 0); } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + MemoryVector<byte> key_id; + }; + +/* +* Authority Key Identifier Extension +*/ +class BOTAN_DLL Authority_Key_ID : public Certificate_Extension + { + public: + Authority_Key_ID* copy() const { return new Authority_Key_ID(key_id); } + + Authority_Key_ID() {} + Authority_Key_ID(const MemoryRegion<byte>& k) : key_id(k) {} + + MemoryVector<byte> get_key_id() const { return key_id; } + private: + std::string config_id() const { return "authority_key_id"; } + std::string oid_name() const { return "X509v3.AuthorityKeyIdentifier"; } + + bool should_encode() const { return (key_id.size() > 0); } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + MemoryVector<byte> key_id; + }; + +/* +* Alternative Name Extension Base Class +*/ +class BOTAN_DLL Alternative_Name : public Certificate_Extension + { + public: + AlternativeName get_alt_name() const { return alt_name; } + + protected: + Alternative_Name(const AlternativeName&, + const std::string&, const std::string&); + + Alternative_Name(const std::string&, const std::string&); + private: + std::string config_id() const { return config_name_str; } + std::string oid_name() const { return oid_name_str; } + + bool should_encode() const { return alt_name.has_items(); } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + std::string config_name_str, oid_name_str; + AlternativeName alt_name; + }; + +/* +* Subject Alternative Name Extension +*/ +class BOTAN_DLL Subject_Alternative_Name : public Alternative_Name + { + public: + Subject_Alternative_Name* copy() const + { return new Subject_Alternative_Name(get_alt_name()); } + + Subject_Alternative_Name(const AlternativeName& = AlternativeName()); + }; + +/* +* Issuer Alternative Name Extension +*/ +class BOTAN_DLL Issuer_Alternative_Name : public Alternative_Name + { + public: + Issuer_Alternative_Name* copy() const + { return new Issuer_Alternative_Name(get_alt_name()); } + + Issuer_Alternative_Name(const AlternativeName& = AlternativeName()); + }; + +/* +* Extended Key Usage Extension +*/ +class BOTAN_DLL Extended_Key_Usage : public Certificate_Extension + { + public: + Extended_Key_Usage* copy() const { return new Extended_Key_Usage(oids); } + + Extended_Key_Usage() {} + Extended_Key_Usage(const std::vector<OID>& o) : oids(o) {} + + std::vector<OID> get_oids() const { return oids; } + private: + std::string config_id() const { return "extended_key_usage"; } + std::string oid_name() const { return "X509v3.ExtendedKeyUsage"; } + + bool should_encode() const { return (oids.size() > 0); } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + std::vector<OID> oids; + }; + +/* +* Certificate Policies Extension +*/ +class BOTAN_DLL Certificate_Policies : public Certificate_Extension + { + public: + Certificate_Policies* copy() const + { return new Certificate_Policies(oids); } + + Certificate_Policies() {} + Certificate_Policies(const std::vector<OID>& o) : oids(o) {} + + std::vector<OID> get_oids() const { return oids; } + private: + std::string config_id() const { return "policy_info"; } + std::string oid_name() const { return "X509v3.CertificatePolicies"; } + + bool should_encode() const { return (oids.size() > 0); } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + std::vector<OID> oids; + }; + +/* +* CRL Number Extension +*/ +class BOTAN_DLL CRL_Number : public Certificate_Extension + { + public: + CRL_Number* copy() const; + + CRL_Number() : has_value(false), crl_number(0) {} + CRL_Number(u32bit n) : has_value(true), crl_number(n) {} + + u32bit get_crl_number() const; + private: + std::string config_id() const { return "crl_number"; } + std::string oid_name() const { return "X509v3.CRLNumber"; } + + bool should_encode() const { return has_value; } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + bool has_value; + u32bit crl_number; + }; + +/* +* CRL Entry Reason Code Extension +*/ +class BOTAN_DLL CRL_ReasonCode : public Certificate_Extension + { + public: + CRL_ReasonCode* copy() const { return new CRL_ReasonCode(reason); } + + CRL_ReasonCode(CRL_Code r = UNSPECIFIED) : reason(r) {} + + CRL_Code get_reason() const { return reason; } + private: + std::string config_id() const { return "crl_reason"; } + std::string oid_name() const { return "X509v3.ReasonCode"; } + + bool should_encode() const { return (reason != UNSPECIFIED); } + MemoryVector<byte> encode_inner() const; + void decode_inner(const MemoryRegion<byte>&); + void contents_to(Data_Store&, Data_Store&) const; + + CRL_Code reason; + }; + +} + +} + +#endif diff --git a/old/botan/build/botan/x509_key.h b/old/botan/build/botan/x509_key.h new file mode 100644 index 0000000..9404b7e --- /dev/null +++ b/old/botan/build/botan/x509_key.h @@ -0,0 +1,110 @@ +/* +* X.509 Public Key +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_PUBLIC_KEY_H__ +#define BOTAN_X509_PUBLIC_KEY_H__ + +#include <botan/pipe.h> +#include <botan/pk_keys.h> +#include <botan/alg_id.h> +#include <botan/pubkey_enums.h> + +namespace Botan { + +/** +* This class represents abstract X.509 public key encoders. +*/ +class BOTAN_DLL X509_Encoder + { + public: + virtual AlgorithmIdentifier alg_id() const = 0; + virtual MemoryVector<byte> key_bits() const = 0; + virtual ~X509_Encoder() {} + }; + +/** +* This class represents abstract X.509 public key decoders. +*/ +class BOTAN_DLL X509_Decoder + { + public: + virtual void alg_id(const AlgorithmIdentifier&) = 0; + virtual void key_bits(const MemoryRegion<byte>&) = 0; + virtual ~X509_Decoder() {} + }; + +/** +* This namespace contains functions for handling X509 objects. +*/ +namespace X509 { + +/* +* X.509 Public Key Encoding/Decoding +*/ + +/** +* Encode a key into a pipe. +* @param key the public key to encode +* @param pipe the pipe to feed the encoded key into +* @param enc the encoding type to use +*/ +BOTAN_DLL void encode(const Public_Key& key, Pipe& pipe, + X509_Encoding enc = PEM); + +/** +* PEM encode a public key into a string. +* @param key the key to encode +* @return the PEM encoded key +*/ +BOTAN_DLL std::string PEM_encode(const Public_Key& key); + +/** +* Create a public key from a data source. +* @param source the source providing the DER or PEM encoded key +* @return the new public key object +*/ +BOTAN_DLL Public_Key* load_key(DataSource& source); + +/** +* Create a public key from a string. +* @param enc the string containing the PEM encoded key +* @return the new public key object +*/ +BOTAN_DLL Public_Key* load_key(const std::string& enc); + +/** +* Create a public key from a memory region. +* @param enc the memory region containing the DER or PEM encoded key +* @return the new public key object +*/ +BOTAN_DLL Public_Key* load_key(const MemoryRegion<byte>& enc); + +/** +* Copy a key. +* @param key the public key to copy +* @return the new public key object +*/ +BOTAN_DLL Public_Key* copy_key(const Public_Key& key); + +/** +* Create the key constraints for a specific public key. +* @param pub_key the public key from which the basic set of +* constraints to be placed in the return value is derived +* @param limits additional limits that will be incorporated into the +* return value +* @return the combination of key type specific constraints and +* additional limits +*/ + +BOTAN_DLL Key_Constraints find_constraints(const Public_Key& pub_key, + Key_Constraints limits); + +} + +} + +#endif diff --git a/old/botan/build/botan/x509_obj.h b/old/botan/build/botan/x509_obj.h new file mode 100644 index 0000000..c7f92fa --- /dev/null +++ b/old/botan/build/botan/x509_obj.h @@ -0,0 +1,67 @@ +/* +* X.509 SIGNED Object +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_OBJECT_H__ +#define BOTAN_X509_OBJECT_H__ + +#include <botan/asn1_obj.h> +#include <botan/pipe.h> +#include <botan/pubkey_enums.h> +#include <botan/rng.h> +#include <vector> + +namespace Botan { + +/** +* This class represents abstract X.509 signed objects as +* in the X.500 SIGNED macro +*/ +class BOTAN_DLL X509_Object + { + public: + SecureVector<byte> tbs_data() const; + SecureVector<byte> signature() const; + AlgorithmIdentifier signature_algorithm() const; + + /** + * Create a signed X509 object. + * @param signer the signer used to sign the object + * @param rng the random number generator to use + * @param alg_id the algorithm identifier of the signature scheme + * @param tbs the tbs bits to be signed + * @return the signed X509 object + */ + static MemoryVector<byte> make_signed(class PK_Signer* signer, + RandomNumberGenerator& rng, + const AlgorithmIdentifier& alg_id, + const MemoryRegion<byte>& tbs); + + bool check_signature(class Public_Key&) const; + + void encode(Pipe&, X509_Encoding = PEM) const; + SecureVector<byte> BER_encode() const; + std::string PEM_encode() const; + + X509_Object(DataSource&, const std::string&); + X509_Object(const std::string&, const std::string&); + virtual ~X509_Object() {} + protected: + void do_decode(); + X509_Object() {} + AlgorithmIdentifier sig_algo; + SecureVector<byte> tbs_bits, sig; + private: + virtual void force_decode() = 0; + void init(DataSource&, const std::string&); + void decode_info(DataSource&); + std::vector<std::string> PEM_labels_allowed; + std::string PEM_label_pref; + }; + +} + +#endif diff --git a/old/botan/build/botan/x509cert.h b/old/botan/build/botan/x509cert.h new file mode 100644 index 0000000..4a9d11f --- /dev/null +++ b/old/botan/build/botan/x509cert.h @@ -0,0 +1,185 @@ +/* +* X.509 Certificates +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_CERTS_H__ +#define BOTAN_X509_CERTS_H__ + +#include <botan/x509_obj.h> +#include <botan/x509_key.h> +#include <botan/datastor.h> +#include <botan/pubkey_enums.h> +#include <map> + +namespace Botan { + +/** +* This class represents X.509 Certificate +*/ +class BOTAN_DLL X509_Certificate : public X509_Object + { + public: + /** + * Get the public key associated with this certificate. + * @return the subject public key of this certificate + */ + Public_Key* subject_public_key() const; + + /** + * Get the issuer certificate DN. + * @return the issuer DN of this certificate + */ + X509_DN issuer_dn() const; + + /** + * Get the subject certificate DN. + * @return the subject DN of this certificate + */ + X509_DN subject_dn() const; + + /** + * Get a value for a specific subject_info parameter name. + * @param name the name of the paramter to look up. Possible names are + * "X509.Certificate.version", "X509.Certificate.serial", + * "X509.Certificate.start", "X509.Certificate.end", + * "X509.Certificate.v2.key_id", "X509.Certificate.public_key", + * "X509v3.BasicConstraints.path_constraint", + * "X509v3.BasicConstraints.is_ca", "X509v3.ExtendedKeyUsage", + * "X509v3.CertificatePolicies", "X509v3.SubjectKeyIdentifier" or + * "X509.Certificate.serial". + * @return the value(s) of the specified parameter + */ + std::vector<std::string> subject_info(const std::string& name) const; + + /** + * Get a value for a specific subject_info parameter name. + * @param name the name of the paramter to look up. Possible names are + * "X509.Certificate.v2.key_id" or "X509v3.AuthorityKeyIdentifier". + * @return the value(s) of the specified parameter + */ + std::vector<std::string> issuer_info(const std::string& name) const; + + /** + * Get the notBefore of the certificate. + * @return the notBefore of the certificate + */ + std::string start_time() const; + + /** + * Get the notAfter of the certificate. + * @return the notAfter of the certificate + */ + std::string end_time() const; + + /** + * Get the X509 version of this certificate object. + * @return the X509 version + */ + u32bit x509_version() const; + + /** + * Get the serial number of this certificate. + * @return the certificates serial number + */ + MemoryVector<byte> serial_number() const; + + /** + * Get the DER encoded AuthorityKeyIdentifier of this certificate. + * @return the DER encoded AuthorityKeyIdentifier + */ + MemoryVector<byte> authority_key_id() const; + + /** + * Get the DER encoded SubjectKeyIdentifier of this certificate. + * @return the DER encoded SubjectKeyIdentifier + */ + MemoryVector<byte> subject_key_id() const; + + /** + * Check whether this certificate is self signed. + * @return true if this certificate is self signed + */ + bool is_self_signed() const { return self_signed; } + + /** + * Check whether this certificate is a CA certificate. + * @return true if this certificate is a CA certificate + */ + bool is_CA_cert() const; + + /** + * Get the path limit as defined in the BasicConstraints extension of + * this certificate. + * @return the path limit + */ + u32bit path_limit() const; + + /** + * Get the key constraints as defined in the KeyUsage extension of this + * certificate. + * @return the key constraints + */ + Key_Constraints constraints() const; + + /** + * Get the key constraints as defined in the ExtendedKeyUsage + * extension of this + * certificate. + * @return the key constraints + */ + std::vector<std::string> ex_constraints() const; + + /** + * Get the policies as defined in the CertificatePolicies extension + * of this certificate. + * @return the certificate policies + */ + std::vector<std::string> policies() const; + + /** + * Check to certificates for equality. + * @return true both certificates are (binary) equal + */ + bool operator==(const X509_Certificate& other) const; + + /** + * Create a certificate from a data source providing the DER or + * PEM encoded certificate. + * @param source the data source + */ + X509_Certificate(DataSource& source); + + /** + * Create a certificate from a file containing the DER or PEM + * encoded certificate. + * @param filename the name of the certificate file + */ + X509_Certificate(const std::string& filename); + private: + void force_decode(); + friend class X509_CA; + X509_Certificate() {} + + Data_Store subject, issuer; + bool self_signed; + }; + +/** +* Check two certificates for inequality +* @return true if the arguments represent different certificates, +* false if they are binary identical +*/ +BOTAN_DLL bool operator!=(const X509_Certificate&, const X509_Certificate&); + +/* +* Data Store Extraction Operations +*/ +BOTAN_DLL X509_DN create_dn(const Data_Store&); +BOTAN_DLL AlternativeName create_alt_name(const Data_Store&); + +} + +#endif diff --git a/old/botan/build/botan/x509find.h b/old/botan/build/botan/x509find.h new file mode 100644 index 0000000..a7a84c7 --- /dev/null +++ b/old/botan/build/botan/x509find.h @@ -0,0 +1,60 @@ +/* +* X.509 Certificate Store Searching +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_CERT_STORE_SEARCH_H__ +#define BOTAN_X509_CERT_STORE_SEARCH_H__ + +#include <botan/x509stor.h> + +namespace Botan { + +/* +* Search based on the contents of a DN entry +*/ +class BOTAN_DLL DN_Check : public X509_Store::Search_Func + { + public: + typedef bool (*compare_fn)(const std::string&, const std::string&); + enum Search_Type { SUBSTRING_MATCHING, IGNORE_CASE }; + + bool match(const X509_Certificate& cert) const; + + DN_Check(const std::string&, const std::string&, compare_fn); + DN_Check(const std::string&, const std::string&, Search_Type); + private: + std::string dn_entry, looking_for; + compare_fn compare; + }; + +/* +* Search for a certificate by issuer/serial +*/ +class BOTAN_DLL IandS_Match : public X509_Store::Search_Func + { + public: + bool match(const X509_Certificate& cert) const; + IandS_Match(const X509_DN&, const MemoryRegion<byte>&); + private: + X509_DN issuer; + MemoryVector<byte> serial; + }; + +/* +* Search for a certificate by subject keyid +*/ +class BOTAN_DLL SKID_Match : public X509_Store::Search_Func + { + public: + bool match(const X509_Certificate& cert) const; + SKID_Match(const MemoryRegion<byte>& s) : skid(s) {} + private: + MemoryVector<byte> skid; + }; + +} + +#endif diff --git a/old/botan/build/botan/x509self.h b/old/botan/build/botan/x509self.h new file mode 100644 index 0000000..bd3e291 --- /dev/null +++ b/old/botan/build/botan/x509self.h @@ -0,0 +1,198 @@ +/* +* X.509 Self-Signed Certificate +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_SELF_H__ +#define BOTAN_X509_SELF_H__ + +#include <botan/x509cert.h> +#include <botan/pkcs8.h> +#include <botan/pkcs10.h> + +namespace Botan { + +/** +* Options for X.509 certificates. +*/ +class BOTAN_DLL X509_Cert_Options + { + public: + /** + * the subject common name + */ + std::string common_name; + + /** + * the subject counry + */ + std::string country; + + /** + * the subject organization + */ + std::string organization; + + /** + * the subject organizational unit + */ + std::string org_unit; + + /** + * the subject locality + */ + std::string locality; + + /** + * the subject state + */ + std::string state; + + /** + * the subject serial number + */ + std::string serial_number; + + /** + * the subject email adress + */ + std::string email; + + /** + * the subject URI + */ + std::string uri; + + /** + * the subject IPv4 address + */ + std::string ip; + + /** + * the subject DNS + */ + std::string dns; + + /** + * the subject XMPP + */ + std::string xmpp; + + /** + * the subject challenge password + */ + std::string challenge; + + /** + * the subject notBefore + */ + X509_Time start; + /** + * the subject notAfter + */ + X509_Time end; + + /** + * Indicates whether the certificate request + */ + bool is_CA; + + /** + * Indicates the BasicConstraints path limit + */ + u32bit path_limit; + + /** + * The key constraints for the subject public key + */ + Key_Constraints constraints; + + /** + * The key extended constraints for the subject public key + */ + std::vector<OID> ex_constraints; + + /** + * Check the options set in this object for validity. + */ + void sanity_check() const; + + /** + * Mark the certificate as a CA certificate and set the path limit. + * @param limit the path limit to be set in the BasicConstraints extension. + */ + void CA_key(u32bit limit = 1); + + /** + * Set the notBefore of the certificate. + * @param time the notBefore value of the certificate + */ + void not_before(const std::string& time); + + /** + * Set the notAfter of the certificate. + * @param time the notAfter value of the certificate + */ + void not_after(const std::string& time); + + /** + * Add the key constraints of the KeyUsage extension. + * @param constr the constraints to set + */ + void add_constraints(Key_Constraints constr); + + /** + * Add constraints to the ExtendedKeyUsage extension. + * @param oid the oid to add + */ + void add_ex_constraint(const OID& oid); + + /** + * Add constraints to the ExtendedKeyUsage extension. + * @param name the name to look up the oid to add + */ + void add_ex_constraint(const std::string& name); + + /** + * Construct a new options object + * @param opts define the common name of this object. An example for this + * parameter would be "common_name/country/organization/organizational_unit". + * @param expire_time the expiration time (from the current clock in seconds) + */ + X509_Cert_Options(const std::string& opts = "", + u32bit expire_time = 365 * 24 * 60 * 60); + }; + +namespace X509 { + +/** +* Create a self-signed X.509 certificate. +* @param opts the options defining the certificate to create +* @param key the private key used for signing, i.e. the key +* associated with this self-signed certificate +* @param rng the rng to use +* @return the newly created self-signed certificate +*/ +BOTAN_DLL X509_Certificate +create_self_signed_cert(const X509_Cert_Options& opts, + const Private_Key& key, + RandomNumberGenerator& rng); + +/** +* Create a PKCS#10 certificate request. +* @param opts the options defining the request to create +* @param key the key used to sign this request +* @param rng the rng to use +* @return the newly created PKCS#10 request +*/ +BOTAN_DLL PKCS10_Request create_cert_req(const X509_Cert_Options& opts, + const Private_Key& key, + RandomNumberGenerator& rng); + +} + +} + +#endif diff --git a/old/botan/build/botan/x509stor.h b/old/botan/build/botan/x509stor.h new file mode 100644 index 0000000..4e60378 --- /dev/null +++ b/old/botan/build/botan/x509stor.h @@ -0,0 +1,143 @@ +/* +* X.509 Certificate Store +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_CERT_STORE_H__ +#define BOTAN_X509_CERT_STORE_H__ + +#include <botan/x509cert.h> +#include <botan/x509_crl.h> +#include <botan/certstor.h> + +namespace Botan { + +/* +* X.509 Certificate Validation Result +*/ +enum X509_Code { + VERIFIED, + UNKNOWN_X509_ERROR, + CANNOT_ESTABLISH_TRUST, + CERT_CHAIN_TOO_LONG, + SIGNATURE_ERROR, + POLICY_ERROR, + INVALID_USAGE, + + CERT_FORMAT_ERROR, + CERT_ISSUER_NOT_FOUND, + CERT_NOT_YET_VALID, + CERT_HAS_EXPIRED, + CERT_IS_REVOKED, + + CRL_FORMAT_ERROR, + CRL_ISSUER_NOT_FOUND, + CRL_NOT_YET_VALID, + CRL_HAS_EXPIRED, + + CA_CERT_CANNOT_SIGN, + CA_CERT_NOT_FOR_CERT_ISSUER, + CA_CERT_NOT_FOR_CRL_ISSUER +}; + +/* +* X.509 Certificate Store +*/ +class BOTAN_DLL X509_Store + { + public: + class BOTAN_DLL Search_Func + { + public: + virtual bool match(const X509_Certificate&) const = 0; + virtual ~Search_Func() {} + }; + + enum Cert_Usage { + ANY = 0x00, + TLS_SERVER = 0x01, + TLS_CLIENT = 0x02, + CODE_SIGNING = 0x04, + EMAIL_PROTECTION = 0x08, + TIME_STAMPING = 0x10, + CRL_SIGNING = 0x20 + }; + + X509_Code validate_cert(const X509_Certificate&, Cert_Usage = ANY); + + std::vector<X509_Certificate> get_certs(const Search_Func&) const; + std::vector<X509_Certificate> get_cert_chain(const X509_Certificate&); + std::string PEM_encode() const; + + /* + * Made CRL_Data public for XLC for Cell 0.9, otherwise cannot + * instantiate member variable std::vector<CRL_Data> revoked + */ + class BOTAN_DLL CRL_Data + { + public: + X509_DN issuer; + MemoryVector<byte> serial, auth_key_id; + bool operator==(const CRL_Data&) const; + bool operator!=(const CRL_Data&) const; + bool operator<(const CRL_Data&) const; + }; + + X509_Code add_crl(const X509_CRL&); + void add_cert(const X509_Certificate&, bool = false); + void add_certs(DataSource&); + void add_trusted_certs(DataSource&); + + void add_new_certstore(Certificate_Store*); + + static X509_Code check_sig(const X509_Object&, Public_Key*); + + X509_Store(u32bit time_slack = 24*60*60, + u32bit cache_results = 30*60); + + X509_Store(const X509_Store&); + ~X509_Store(); + private: + X509_Store& operator=(const X509_Store&) { return (*this); } + + class BOTAN_DLL Cert_Info + { + public: + bool is_verified(u32bit timeout) const; + bool is_trusted() const; + X509_Code verify_result() const; + void set_result(X509_Code) const; + Cert_Info(const X509_Certificate&, bool = false); + + X509_Certificate cert; + bool trusted; + private: + mutable bool checked; + mutable X509_Code result; + mutable u64bit last_checked; + }; + + u32bit find_cert(const X509_DN&, const MemoryRegion<byte>&) const; + X509_Code check_sig(const Cert_Info&, const Cert_Info&) const; + void recompute_revoked_info() const; + + void do_add_certs(DataSource&, bool); + X509_Code construct_cert_chain(const X509_Certificate&, + std::vector<u32bit>&, bool = false); + + u32bit find_parent_of(const X509_Certificate&); + bool is_revoked(const X509_Certificate&) const; + + static const u32bit NO_CERT_FOUND = 0xFFFFFFFF; + std::vector<Cert_Info> certs; + std::vector<CRL_Data> revoked; + std::vector<Certificate_Store*> stores; + u32bit time_slack, validation_cache_timeout; + mutable bool revoked_info_valid; + }; + +} + +#endif diff --git a/old/botan/build/botan/x919_mac.h b/old/botan/build/botan/x919_mac.h new file mode 100644 index 0000000..1c2a06b --- /dev/null +++ b/old/botan/build/botan/x919_mac.h @@ -0,0 +1,41 @@ +/* +* ANSI X9.19 MAC +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ANSI_X919_MAC_H__ +#define BOTAN_ANSI_X919_MAC_H__ + +#include <botan/mac.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/** +* DES/3DES-based MAC from ANSI X9.19 +*/ +class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode + { + public: + void clear() throw(); + std::string name() const; + MessageAuthenticationCode* clone() const; + + ANSI_X919_MAC(BlockCipher*); + ~ANSI_X919_MAC(); + private: + void add_data(const byte[], u32bit); + void final_result(byte[]); + void key_schedule(const byte[], u32bit); + + BlockCipher* e; + BlockCipher* d; + SecureBuffer<byte, 8> state; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/x931_rng.h b/old/botan/build/botan/x931_rng.h new file mode 100644 index 0000000..44e9b44 --- /dev/null +++ b/old/botan/build/botan/x931_rng.h @@ -0,0 +1,45 @@ +/* +* ANSI X9.31 RNG +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ANSI_X931_RNG_H__ +#define BOTAN_ANSI_X931_RNG_H__ + +#include <botan/rng.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/** +* ANSI X9.31 RNG +*/ +class BOTAN_DLL ANSI_X931_RNG : public RandomNumberGenerator + { + public: + void randomize(byte[], u32bit); + bool is_seeded() const; + void clear() throw(); + std::string name() const; + + void reseed(u32bit poll_bits); + void add_entropy_source(EntropySource*); + void add_entropy(const byte[], u32bit); + + ANSI_X931_RNG(BlockCipher*, RandomNumberGenerator*); + ~ANSI_X931_RNG(); + private: + void rekey(); + void update_buffer(); + + BlockCipher* cipher; + RandomNumberGenerator* prng; + SecureVector<byte> V, R; + u32bit position; + }; + +} + +#endif diff --git a/old/botan/build/botan/xor_buf.h b/old/botan/build/botan/xor_buf.h new file mode 100644 index 0000000..39781f0 --- /dev/null +++ b/old/botan/build/botan/xor_buf.h @@ -0,0 +1,74 @@ +/** +* XOR operations +* (C) 1999-2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_XOR_BUF_H__ +#define BOTAN_XOR_BUF_H__ + +#include <botan/types.h> + +namespace Botan { + +/** +* XOR arrays. Postcondition out[i] = in[i] ^ out[i] forall i = 0...length +* @param out the input/output buffer +* @param in the read-only input buffer +* @param length the length of the buffers +*/ +inline void xor_buf(byte out[], const byte in[], u32bit length) + { + while(length >= 8) + { +#if BOTAN_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u64bit*>(out) ^= *reinterpret_cast<const u64bit*>(in); +#else + out[0] ^= in[0]; out[1] ^= in[1]; + out[2] ^= in[2]; out[3] ^= in[3]; + out[4] ^= in[4]; out[5] ^= in[5]; + out[6] ^= in[6]; out[7] ^= in[7]; +#endif + + out += 8; in += 8; length -= 8; + } + for(u32bit j = 0; j != length; ++j) + out[j] ^= in[j]; + } + +/** +* XOR arrays. Postcondition out[i] = in[i] ^ in2[i] forall i = 0...length +* @param out the output buffer +* @param in the first input buffer +* @param in2 the second output buffer +* @param length the length of the three buffers +*/ +inline void xor_buf(byte out[], + const byte in[], + const byte in2[], + u32bit length) + { + while(length >= 8) + { +#if BOTAN_UNALIGNED_LOADSTOR_OK + *reinterpret_cast<u64bit*>(out) = + *reinterpret_cast<const u64bit*>(in) ^ + *reinterpret_cast<const u64bit*>(in2); +#else + out[0] = in[0] ^ in2[0]; out[1] = in[1] ^ in2[1]; + out[2] = in[2] ^ in2[2]; out[3] = in[3] ^ in2[3]; + out[4] = in[4] ^ in2[4]; out[5] = in[5] ^ in2[5]; + out[6] = in[6] ^ in2[6]; out[7] = in[7] ^ in2[7]; +#endif + + in += 8; in2 += 8; out += 8; length -= 8; + } + + for(u32bit j = 0; j != length; ++j) + out[j] = in[j] ^ in2[j]; + } + +} + +#endif diff --git a/old/botan/build/botan/xtea.h b/old/botan/build/botan/xtea.h new file mode 100644 index 0000000..d9c6066 --- /dev/null +++ b/old/botan/build/botan/xtea.h @@ -0,0 +1,34 @@ +/* +* XTEA +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_XTEA_H__ +#define BOTAN_XTEA_H__ + +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* XTEA +*/ +class BOTAN_DLL XTEA : public BlockCipher + { + public: + void clear() throw() { EK.clear(); } + std::string name() const { return "XTEA"; } + BlockCipher* clone() const { return new XTEA; } + XTEA() : BlockCipher(8, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key_schedule(const byte[], u32bit); + SecureBuffer<u32bit, 64> EK; + }; + +} + +#endif diff --git a/old/botan/build/botan/xts.h b/old/botan/build/botan/xts.h new file mode 100644 index 0000000..0155817 --- /dev/null +++ b/old/botan/build/botan/xts.h @@ -0,0 +1,76 @@ +/* +* XTS mode, from IEEE P1619 +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_XTS_H__ +#define BOTAN_XTS_H__ + +#include <botan/basefilt.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* XTS Encryption +*/ +class BOTAN_DLL XTS_Encryption : public Keyed_Filter + { + public: + void set_key(const SymmetricKey& key); + void set_iv(const InitializationVector& iv); + + std::string name() const; + + XTS_Encryption(BlockCipher* ciph); + + XTS_Encryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv); + + ~XTS_Encryption() { delete cipher; delete cipher2; } + private: + void write(const byte[], u32bit); + void end_msg(); + void encrypt(const byte block[]); + + BlockCipher* cipher; + BlockCipher* cipher2; + SecureVector<byte> tweak; + SecureVector<byte> buffer; + u32bit position; + }; + +/* +* XTS Decryption +*/ +class BOTAN_DLL XTS_Decryption : public Keyed_Filter + { + public: + void set_key(const SymmetricKey& key); + void set_iv(const InitializationVector& iv); + + std::string name() const; + + XTS_Decryption(BlockCipher* ciph); + + XTS_Decryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv); + private: + void write(const byte[], u32bit); + void end_msg(); + void decrypt(const byte[]); + + BlockCipher* cipher; + BlockCipher* cipher2; + SecureVector<byte> tweak; + SecureVector<byte> buffer; + u32bit position; + }; + +} + +#endif |