diff options
author | lloyd <[email protected]> | 2008-09-29 00:15:14 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-29 00:15:14 +0000 |
commit | 68d3d539ad7752dc80c20c1a2ade909b1a4c4a6e (patch) | |
tree | c7e588d28427960c95eca9900844d5bf36c079df /src | |
parent | 8269e2897e0a652bbd949d38b74873976a98adeb (diff) |
Move what is left of the uncategorized library to 'core'. There is still
a lot of public key stuff in here that needs to be extracted however,
and probably 2-3 other modules worth of stuff to split off (engines, etc)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/base.cpp (renamed from src/base.cpp) | 0 | ||||
-rw-r--r-- | src/core/base.h | 146 | ||||
-rw-r--r-- | src/core/botan.h | 11 | ||||
-rw-r--r-- | src/core/data_src.cpp (renamed from src/data_src.cpp) | 0 | ||||
-rw-r--r-- | src/core/data_src.h | 78 | ||||
-rw-r--r-- | src/core/datastor.cpp (renamed from src/datastor.cpp) | 0 | ||||
-rw-r--r-- | src/core/datastor.h | 59 | ||||
-rw-r--r-- | src/core/def_alg.cpp (renamed from src/def_alg.cpp) | 0 | ||||
-rw-r--r-- | src/core/def_mode.cpp (renamed from src/def_mode.cpp) | 0 | ||||
-rw-r--r-- | src/core/dh_op.cpp (renamed from src/dh_op.cpp) | 0 | ||||
-rw-r--r-- | src/core/dsa_op.cpp (renamed from src/dsa_op.cpp) | 0 | ||||
-rw-r--r-- | src/core/elg_op.cpp (renamed from src/elg_op.cpp) | 0 | ||||
-rw-r--r-- | src/core/eng_base.cpp (renamed from src/eng_base.cpp) | 0 | ||||
-rw-r--r-- | src/core/eng_def.h | 46 | ||||
-rw-r--r-- | src/core/engine.cpp (renamed from src/engine.cpp) | 0 | ||||
-rw-r--r-- | src/core/engine.h | 123 | ||||
-rw-r--r-- | src/core/enums.h | 67 | ||||
-rw-r--r-- | src/core/exceptn.cpp (renamed from src/exceptn.cpp) | 0 | ||||
-rw-r--r-- | src/core/exceptn.h | 195 | ||||
-rw-r--r-- | src/core/get_algo.cpp (renamed from src/get_algo.cpp) | 0 | ||||
-rw-r--r-- | src/core/get_enc.cpp (renamed from src/get_enc.cpp) | 0 | ||||
-rw-r--r-- | src/core/get_pbe.cpp (renamed from src/get_pbe.cpp) | 0 | ||||
-rw-r--r-- | src/core/init.h | 50 | ||||
-rw-r--r-- | src/core/init_def.cpp (renamed from src/init_def.cpp) | 0 | ||||
-rw-r--r-- | src/core/init_opt.cpp (renamed from src/init_opt.cpp) | 0 | ||||
-rw-r--r-- | src/core/kdf.cpp (renamed from src/kdf.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate.cpp (renamed from src/libstate.cpp) | 0 | ||||
-rw-r--r-- | src/core/libstate.h | 90 | ||||
-rw-r--r-- | src/core/look_add.h | 27 | ||||
-rw-r--r-- | src/core/look_pk.cpp (renamed from src/look_pk.cpp) | 0 | ||||
-rw-r--r-- | src/core/look_pk.h | 38 | ||||
-rw-r--r-- | src/core/lookup.h | 92 | ||||
-rw-r--r-- | src/core/mlock.cpp (renamed from src/mlock.cpp) | 0 | ||||
-rw-r--r-- | src/core/modules.cpp (renamed from src/modules.cpp) | 0 | ||||
-rw-r--r-- | src/core/modules.h | 51 | ||||
-rw-r--r-- | src/core/mutex.h | 54 | ||||
-rw-r--r-- | src/core/nr_op.cpp (renamed from src/nr_op.cpp) | 0 | ||||
-rw-r--r-- | src/core/oids.cpp (renamed from src/oids.cpp) | 0 | ||||
-rw-r--r-- | src/core/oids.h | 36 | ||||
-rw-r--r-- | src/core/pk_algs.cpp (renamed from src/pk_algs.cpp) | 0 | ||||
-rw-r--r-- | src/core/pk_algs.h | 22 | ||||
-rw-r--r-- | src/core/pk_core.cpp (renamed from src/pk_core.cpp) | 0 | ||||
-rw-r--r-- | src/core/pk_core.h | 128 | ||||
-rw-r--r-- | src/core/pk_keys.cpp (renamed from src/pk_keys.cpp) | 0 | ||||
-rw-r--r-- | src/core/pk_keys.h | 127 | ||||
-rw-r--r-- | src/core/pk_ops.h | 79 | ||||
-rw-r--r-- | src/core/pk_util.cpp (renamed from src/pk_util.cpp) | 0 | ||||
-rw-r--r-- | src/core/pk_util.h | 92 | ||||
-rw-r--r-- | src/core/pkcs8.cpp (renamed from src/pkcs8.cpp) | 0 | ||||
-rw-r--r-- | src/core/pkcs8.h | 85 | ||||
-rw-r--r-- | src/core/policy.cpp (renamed from src/policy.cpp) | 0 | ||||
-rw-r--r-- | src/core/pubkey.cpp (renamed from src/pubkey.cpp) | 0 | ||||
-rw-r--r-- | src/core/pubkey.h | 210 | ||||
-rw-r--r-- | src/core/rng.cpp (renamed from src/rng.cpp) | 0 | ||||
-rw-r--r-- | src/core/rng.h | 66 | ||||
-rw-r--r-- | src/core/rsa_op.cpp (renamed from src/rsa_op.cpp) | 0 | ||||
-rw-r--r-- | src/core/s2k.cpp (renamed from src/s2k.cpp) | 0 | ||||
-rw-r--r-- | src/core/s2k.h | 45 | ||||
-rw-r--r-- | src/core/symkey.cpp (renamed from src/symkey.cpp) | 0 | ||||
-rw-r--r-- | src/core/symkey.h | 60 | ||||
-rw-r--r-- | src/core/x509_key.cpp (renamed from src/x509_key.cpp) | 0 | ||||
-rw-r--r-- | src/core/x509_key.h | 58 | ||||
-rw-r--r-- | src/pk/dsa/modinfo.txt | 1 | ||||
-rw-r--r-- | src/pk/elgamal/modinfo.txt | 7 | ||||
-rw-r--r-- | src/pk/keypair/keypair.cpp (renamed from src/keypair.cpp) | 0 | ||||
-rw-r--r-- | src/pk/keypair/keypair.h | 25 | ||||
-rw-r--r-- | src/pk/nr/modinfo.txt | 1 | ||||
-rw-r--r-- | src/pk/rsa/modinfo.txt | 1 | ||||
-rw-r--r-- | src/pk/rw/modinfo.txt | 1 | ||||
-rw-r--r-- | src/secalloc/ml_unix/xxxinfo.txt (renamed from src/secalloc/ml_unix/modinfo.txt) | 0 | ||||
-rw-r--r-- | src/secalloc/ml_win32/xxxinfo.txt (renamed from src/secalloc/ml_win32/modinfo.txt) | 0 | ||||
-rw-r--r-- | src/utils/modinfo.txt | 2 | ||||
-rw-r--r-- | src/utils/ui.cpp (renamed from src/ui.cpp) | 0 | ||||
-rw-r--r-- | src/utils/ui.h | 34 |
74 files changed, 2207 insertions, 0 deletions
diff --git a/src/base.cpp b/src/core/base.cpp index eb38d0c85..eb38d0c85 100644 --- a/src/base.cpp +++ b/src/core/base.cpp diff --git a/src/core/base.h b/src/core/base.h new file mode 100644 index 000000000..b05feaacb --- /dev/null +++ b/src/core/base.h @@ -0,0 +1,146 @@ +/************************************************* +* Base Classes Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_BASE_H__ +#define BOTAN_BASE_H__ + +#include <botan/exceptn.h> +#include <botan/symkey.h> + +namespace Botan { + +/************************************************* +* Constants * +*************************************************/ +static const u32bit DEFAULT_BUFFERSIZE = BOTAN_DEFAULT_BUFFER_SIZE; + +/************************************************* +* Symmetric Algorithm * +*************************************************/ +class BOTAN_DLL SymmetricAlgorithm + { + public: + const u32bit MAXIMUM_KEYLENGTH, MINIMUM_KEYLENGTH, KEYLENGTH_MULTIPLE; + + virtual std::string name() const = 0; + + void set_key(const SymmetricKey&) throw(Invalid_Key_Length); + void set_key(const byte[], u32bit) throw(Invalid_Key_Length); + bool valid_keylength(u32bit) const; + SymmetricAlgorithm(u32bit, u32bit, u32bit); + virtual ~SymmetricAlgorithm() {} + private: + virtual void key(const byte[], u32bit) = 0; + }; + +/************************************************* +* Block Cipher * +*************************************************/ +class BOTAN_DLL BlockCipher : public SymmetricAlgorithm + { + public: + const u32bit BLOCK_SIZE; + + void encrypt(const byte in[], byte out[]) const { enc(in, out); } + void decrypt(const byte in[], byte out[]) const { dec(in, out); } + void encrypt(byte block[]) const { enc(block, block); } + void decrypt(byte block[]) const { dec(block, block); } + + virtual BlockCipher* clone() const = 0; + virtual void clear() throw() = 0; + + BlockCipher(u32bit, u32bit, u32bit = 0, u32bit = 1); + virtual ~BlockCipher() {} + private: + virtual void enc(const byte[], byte[]) const = 0; + virtual void dec(const byte[], byte[]) const = 0; + }; + +/************************************************* +* Stream Cipher * +*************************************************/ +class BOTAN_DLL StreamCipher : public SymmetricAlgorithm + { + public: + const u32bit IV_LENGTH; + void encrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); } + void decrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); } + void encrypt(byte in[], u32bit len) { cipher(in, in, len); } + void decrypt(byte in[], u32bit len) { cipher(in, in, len); } + + virtual void resync(const byte[], u32bit); + virtual void seek(u32bit); + + virtual StreamCipher* clone() const = 0; + virtual void clear() throw() = 0; + + StreamCipher(u32bit, u32bit = 0, u32bit = 1, u32bit = 0); + virtual ~StreamCipher() {} + private: + virtual void cipher(const byte[], byte[], u32bit) = 0; + }; + +/************************************************* +* Buffered Computation * +*************************************************/ +class BOTAN_DLL BufferedComputation + { + public: + const u32bit OUTPUT_LENGTH; + void update(const byte[], u32bit); + void update(const MemoryRegion<byte>&); + void update(const std::string&); + void update(byte); + void final(byte out[]) { final_result(out); } + SecureVector<byte> final(); + SecureVector<byte> process(const byte[], u32bit); + SecureVector<byte> process(const MemoryRegion<byte>&); + SecureVector<byte> process(const std::string&); + BufferedComputation(u32bit); + virtual ~BufferedComputation() {} + private: + BufferedComputation& operator=(const BufferedComputation&); + virtual void add_data(const byte[], u32bit) = 0; + virtual void final_result(byte[]) = 0; + }; + +/************************************************* +* Hash Function * +*************************************************/ +class BOTAN_DLL HashFunction : public BufferedComputation + { + public: + const u32bit HASH_BLOCK_SIZE; + + virtual HashFunction* clone() const = 0; + virtual std::string name() const = 0; + virtual void clear() throw() = 0; + + HashFunction(u32bit, u32bit = 0); + virtual ~HashFunction() {} + private: + HashFunction& operator=(const HashFunction&); + }; + +/************************************************* +* Message Authentication Code * +*************************************************/ +class BOTAN_DLL MessageAuthenticationCode : public BufferedComputation, + public SymmetricAlgorithm + { + public: + virtual bool verify_mac(const byte[], u32bit); + + virtual MessageAuthenticationCode* clone() const = 0; + virtual std::string name() const = 0; + virtual void clear() throw() = 0; + + MessageAuthenticationCode(u32bit, u32bit, u32bit = 0, u32bit = 1); + virtual ~MessageAuthenticationCode() {} + }; + +} + +#endif diff --git a/src/core/botan.h b/src/core/botan.h new file mode 100644 index 000000000..70261398a --- /dev/null +++ b/src/core/botan.h @@ -0,0 +1,11 @@ +/************************************************* +* Botan Core Interface Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/base.h> +#include <botan/rng.h> +#include <botan/init.h> +#include <botan/lookup.h> +#include <botan/version.h> +#include <botan/parsing.h> diff --git a/src/data_src.cpp b/src/core/data_src.cpp index 1ec1ae090..1ec1ae090 100644 --- a/src/data_src.cpp +++ b/src/core/data_src.cpp diff --git a/src/core/data_src.h b/src/core/data_src.h new file mode 100644 index 000000000..f7285e8fb --- /dev/null +++ b/src/core/data_src.h @@ -0,0 +1,78 @@ +/************************************************* +* DataSource Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_DATA_SRC_H__ +#define BOTAN_DATA_SRC_H__ + +#include <botan/base.h> +#include <iosfwd> + +namespace Botan { + +/************************************************* +* Generic DataSource Interface * +*************************************************/ +class BOTAN_DLL DataSource + { + public: + virtual u32bit read(byte[], u32bit) = 0; + virtual u32bit peek(byte[], u32bit, u32bit) const = 0; + virtual bool end_of_data() const = 0; + virtual std::string id() const { return ""; } + + u32bit read_byte(byte&); + u32bit peek_byte(byte&) const; + u32bit discard_next(u32bit); + + DataSource() {} + virtual ~DataSource() {} + private: + DataSource& operator=(const DataSource&) { return (*this); } + DataSource(const DataSource&); + }; + +/************************************************* +* 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; + + DataSource_Memory(const std::string&); + DataSource_Memory(const byte[], u32bit); + DataSource_Memory(const MemoryRegion<byte>&); + private: + SecureVector<byte> source; + u32bit offset; + }; + +/************************************************* +* 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 = ""); + DataSource_Stream(const std::string&, bool = false); + ~DataSource_Stream(); + private: + const std::string identifier; + const bool owner; + + std::istream* source; + u32bit total_read; + }; + +} + +#endif diff --git a/src/datastor.cpp b/src/core/datastor.cpp index bff6bcf5b..bff6bcf5b 100644 --- a/src/datastor.cpp +++ b/src/core/datastor.cpp diff --git a/src/core/datastor.h b/src/core/datastor.h new file mode 100644 index 000000000..0f6029189 --- /dev/null +++ b/src/core/datastor.h @@ -0,0 +1,59 @@ +/************************************************* +* Data Store Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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/src/def_alg.cpp b/src/core/def_alg.cpp index b13439fe2..b13439fe2 100644 --- a/src/def_alg.cpp +++ b/src/core/def_alg.cpp diff --git a/src/def_mode.cpp b/src/core/def_mode.cpp index b062cc34b..b062cc34b 100644 --- a/src/def_mode.cpp +++ b/src/core/def_mode.cpp diff --git a/src/dh_op.cpp b/src/core/dh_op.cpp index 0bcfd4ef8..0bcfd4ef8 100644 --- a/src/dh_op.cpp +++ b/src/core/dh_op.cpp diff --git a/src/dsa_op.cpp b/src/core/dsa_op.cpp index ee94cb256..ee94cb256 100644 --- a/src/dsa_op.cpp +++ b/src/core/dsa_op.cpp diff --git a/src/elg_op.cpp b/src/core/elg_op.cpp index 0d852d145..0d852d145 100644 --- a/src/elg_op.cpp +++ b/src/core/elg_op.cpp diff --git a/src/eng_base.cpp b/src/core/eng_base.cpp index 38234d462..38234d462 100644 --- a/src/eng_base.cpp +++ b/src/core/eng_base.cpp diff --git a/src/core/eng_def.h b/src/core/eng_def.h new file mode 100644 index 000000000..95f1fc0f7 --- /dev/null +++ b/src/core/eng_def.h @@ -0,0 +1,46 @@ +/************************************************* +* Default Engine Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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: + IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&) const; + DSA_Operation* dsa_op(const DL_Group&, const BigInt&, + const BigInt&) const; + NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const; + ELG_Operation* elg_op(const DL_Group&, const BigInt&, + const BigInt&) const; + DH_Operation* dh_op(const DL_Group&, const BigInt&) const; + + Modular_Exponentiator* mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const; + + Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); + private: + BlockCipher* find_block_cipher(const std::string&) const; + StreamCipher* find_stream_cipher(const std::string&) const; + HashFunction* find_hash(const std::string&) const; + MessageAuthenticationCode* find_mac(const std::string&) const; + + class S2K* find_s2k(const std::string&) const; + class BlockCipherModePaddingMethod* + find_bc_pad(const std::string&) const; + }; + +} + +#endif diff --git a/src/engine.cpp b/src/core/engine.cpp index 8511c07c2..8511c07c2 100644 --- a/src/engine.cpp +++ b/src/core/engine.cpp diff --git a/src/core/engine.h b/src/core/engine.h new file mode 100644 index 000000000..13007e662 --- /dev/null +++ b/src/core/engine.h @@ -0,0 +1,123 @@ +/************************************************* +* Engine Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_ENGINE_H__ +#define BOTAN_ENGINE_H__ + +#include <botan/base.h> +#include <botan/mutex.h> +#include <botan/pk_ops.h> +#include <botan/pow_mod.h> +#include <botan/basefilt.h> +#include <botan/enums.h> +#include <utility> +#include <map> + +namespace Botan { + +/************************************************* +* Engine Base Class * +*************************************************/ +class BOTAN_DLL Engine + { + public: + template<typename T> + class BOTAN_DLL Algorithm_Cache + { + public: + virtual T* get(const std::string&) const = 0; + virtual void add(T* algo, const std::string& = "") const = 0; + virtual ~Algorithm_Cache() {} + }; + + virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&) const; + virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&, + const BigInt&) const; + virtual NR_Operation* nr_op(const DL_Group&, const BigInt&, + const BigInt&) const; + virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, + const BigInt&) const; + virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const; + + virtual Modular_Exponentiator* mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const; + + virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); + + const BlockCipher* block_cipher(const std::string&) const; + const StreamCipher* stream_cipher(const std::string&) const; + const HashFunction* hash(const std::string&) const; + const MessageAuthenticationCode* mac(const std::string&) const; + const class S2K* s2k(const std::string&) const; + const class BlockCipherModePaddingMethod* + bc_pad(const std::string&) const; + + void add_algorithm(BlockCipher*) const; + void add_algorithm(StreamCipher*) const; + void add_algorithm(HashFunction*) const; + void add_algorithm(MessageAuthenticationCode*) const; + void add_algorithm(class S2K*) const; + void add_algorithm(class BlockCipherModePaddingMethod*) const; + + Engine(); + virtual ~Engine(); + private: + virtual BlockCipher* find_block_cipher(const std::string&) const; + virtual StreamCipher* find_stream_cipher(const std::string&) const; + virtual HashFunction* find_hash(const std::string&) const; + virtual MessageAuthenticationCode* find_mac(const std::string&) const; + virtual class S2K* find_s2k(const std::string&) const; + virtual class BlockCipherModePaddingMethod* + find_bc_pad(const std::string&) const; + + template<typename T> + const T* lookup_algo(const Algorithm_Cache<T>* cache, + const std::string& name, + const Engine* engine, + T* (Engine::*find)(const std::string&) const) const + { + T* algo = cache->get(name); + if(!algo) + { + algo = (engine->*find)(name); + if(algo) + cache->add(algo, name); + } + return algo; + } + + Algorithm_Cache<BlockCipher>* cache_of_bc; + Algorithm_Cache<StreamCipher>* cache_of_sc; + Algorithm_Cache<HashFunction>* cache_of_hf; + Algorithm_Cache<MessageAuthenticationCode>* cache_of_mac; + Algorithm_Cache<BlockCipherModePaddingMethod>* cache_of_bc_pad; + Algorithm_Cache<S2K>* cache_of_s2k; + }; + +namespace Engine_Core { + +/************************************************* +* Get an operation from an Engine * +*************************************************/ +Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints); + +IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&); + +DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&); +NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&); + +ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); + +DH_Operation* dh_op(const DL_Group&, const BigInt&); + +} + +} + +#endif diff --git a/src/core/enums.h b/src/core/enums.h new file mode 100644 index 000000000..dc404b728 --- /dev/null +++ b/src/core/enums.h @@ -0,0 +1,67 @@ +/************************************************* +* Enumerations Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_ENUMS_H__ +#define BOTAN_ENUMS_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 +}; + +/************************************************* +* 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 * +*************************************************/ +enum Decoder_Checking { NONE, IGNORE_WS, FULL_CHECK }; + +enum X509_Encoding { RAW_BER, PEM }; + +enum Cipher_Dir { ENCRYPTION, DECRYPTION }; + +enum Character_Set { + LOCAL_CHARSET, + UCS2_CHARSET, + UTF8_CHARSET, + LATIN1_CHARSET +}; + +static const u32bit NO_CERT_PATH_LIMIT = 0xFFFFFFF0; + +} + +#endif diff --git a/src/exceptn.cpp b/src/core/exceptn.cpp index 29357afa5..29357afa5 100644 --- a/src/exceptn.cpp +++ b/src/core/exceptn.cpp diff --git a/src/core/exceptn.h b/src/core/exceptn.h new file mode 100644 index 000000000..3bfec2fd2 --- /dev/null +++ b/src/core/exceptn.h @@ -0,0 +1,195 @@ +/************************************************* +* Exceptions Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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/src/get_algo.cpp b/src/core/get_algo.cpp index 2325c144d..2325c144d 100644 --- a/src/get_algo.cpp +++ b/src/core/get_algo.cpp diff --git a/src/get_enc.cpp b/src/core/get_enc.cpp index fb5952a3e..fb5952a3e 100644 --- a/src/get_enc.cpp +++ b/src/core/get_enc.cpp diff --git a/src/get_pbe.cpp b/src/core/get_pbe.cpp index 6bd85b3e1..6bd85b3e1 100644 --- a/src/get_pbe.cpp +++ b/src/core/get_pbe.cpp diff --git a/src/core/init.h b/src/core/init.h new file mode 100644 index 000000000..f4296a868 --- /dev/null +++ b/src/core/init.h @@ -0,0 +1,50 @@ +/************************************************* +* Library Initialization Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_INIT_H__ +#define BOTAN_INIT_H__ + +#include <botan/build.h> +#include <string> +#include <map> + +namespace Botan { + +/************************************************* +* Options for initializing the library * +*************************************************/ +class BOTAN_DLL InitializerOptions + { + public: + bool thread_safe() const; + bool use_engines() const; + bool secure_memory() const; + bool fips_mode() const; + bool self_test() const; + + InitializerOptions(const std::string&); + private: + std::map<std::string, std::string> args; + }; + +/************************************************* +* Library Initialization/Shutdown Object * +*************************************************/ +class BOTAN_DLL LibraryInitializer + { + public: + static void initialize(const std::string& = ""); + static void initialize(const InitializerOptions&); + static void initialize(const InitializerOptions&, class Modules&); + static void deinitialize(); + + LibraryInitializer(const std::string& args = "") { initialize(args); } + LibraryInitializer(const InitializerOptions& args) { initialize(args); } + ~LibraryInitializer() { deinitialize(); } + }; + +} + +#endif diff --git a/src/init_def.cpp b/src/core/init_def.cpp index 03f97252e..03f97252e 100644 --- a/src/init_def.cpp +++ b/src/core/init_def.cpp diff --git a/src/init_opt.cpp b/src/core/init_opt.cpp index 5c4fbee65..5c4fbee65 100644 --- a/src/init_opt.cpp +++ b/src/core/init_opt.cpp diff --git a/src/kdf.cpp b/src/core/kdf.cpp index dca56e1a6..dca56e1a6 100644 --- a/src/kdf.cpp +++ b/src/core/kdf.cpp diff --git a/src/libstate.cpp b/src/core/libstate.cpp index df9d2b519..df9d2b519 100644 --- a/src/libstate.cpp +++ b/src/core/libstate.cpp diff --git a/src/core/libstate.h b/src/core/libstate.h new file mode 100644 index 000000000..4b1221c84 --- /dev/null +++ b/src/core/libstate.h @@ -0,0 +1,90 @@ +/************************************************* +* Library Internal/Global State Header File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LIB_STATE_H__ +#define BOTAN_LIB_STATE_H__ + +#include <botan/base.h> +#include <botan/init.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(const InitializerOptions&, Modules&); + + void load(Modules&); + + void add_engine(class Engine*); + + class BOTAN_DLL Engine_Iterator + { + public: + class Engine* next(); + Engine_Iterator(const Library_State& l) : lib(l) { n = 0; } + private: + const Library_State& lib; + u32bit n; + }; + friend class Engine_Iterator; + + Allocator* get_allocator(const std::string& = "") const; + void add_allocator(Allocator*); + void set_default_allocator(const std::string&); + + std::string get(const std::string&, const std::string&) const; + bool is_set(const std::string&, const std::string&) const; + void set(const std::string&, const std::string&, + const std::string&, bool = true); + + std::string option(const std::string&) const; + void set_option(const std::string, const std::string&); + + void add_alias(const std::string&, const std::string&); + 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 Engine* get_engine_n(u32bit) const; + + 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; + + class Mutex* engine_lock; + std::vector<class Engine*> engines; + }; + +/************************************************* +* 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/src/core/look_add.h b/src/core/look_add.h new file mode 100644 index 000000000..4185cbc0a --- /dev/null +++ b/src/core/look_add.h @@ -0,0 +1,27 @@ +/************************************************* +* Lookup Table Management Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LOOKUP_MANGEMENT_H__ +#define BOTAN_LOOKUP_MANGEMENT_H__ + +#include <botan/base.h> +#include <botan/mode_pad.h> +#include <botan/s2k.h> + +namespace Botan { + +/************************************************* +* Add an algorithm to the lookup table * +*************************************************/ +BOTAN_DLL void add_algorithm(BlockCipher*); +BOTAN_DLL void add_algorithm(StreamCipher*); +BOTAN_DLL void add_algorithm(HashFunction*); +BOTAN_DLL void add_algorithm(MessageAuthenticationCode*); +BOTAN_DLL void add_algorithm(S2K*); +BOTAN_DLL void add_algorithm(BlockCipherModePaddingMethod*); + +} + +#endif diff --git a/src/look_pk.cpp b/src/core/look_pk.cpp index a4062b57c..a4062b57c 100644 --- a/src/look_pk.cpp +++ b/src/core/look_pk.cpp diff --git a/src/core/look_pk.h b/src/core/look_pk.h new file mode 100644 index 000000000..63756ad22 --- /dev/null +++ b/src/core/look_pk.h @@ -0,0 +1,38 @@ +/************************************************* +* PK Algorithm Lookup Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PK_LOOKUP_H__ +#define BOTAN_PK_LOOKUP_H__ + +#include <botan/pubkey.h> + +namespace Botan { + +/************************************************* +* Get an PK algorithm object * +*************************************************/ +BOTAN_DLL PK_Encryptor* get_pk_encryptor(const PK_Encrypting_Key&, + const std::string&); + +BOTAN_DLL PK_Decryptor* get_pk_decryptor(const PK_Decrypting_Key&, + const std::string&); + +BOTAN_DLL PK_Signer* get_pk_signer(const PK_Signing_Key&, + const std::string&, + Signature_Format = IEEE_1363); + +BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_with_MR_Key&, + const std::string&, + Signature_Format = IEEE_1363); +BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_wo_MR_Key&, + const std::string&, + Signature_Format = IEEE_1363); + +BOTAN_DLL PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key&, + const std::string&); + +} + +#endif diff --git a/src/core/lookup.h b/src/core/lookup.h new file mode 100644 index 000000000..97c2eff50 --- /dev/null +++ b/src/core/lookup.h @@ -0,0 +1,92 @@ +/************************************************* +* Algorithm Lookup Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LOOKUP_H__ +#define BOTAN_LOOKUP_H__ + +#include <botan/base.h> +#include <botan/enums.h> +#include <botan/filters.h> +#include <botan/mode_pad.h> +#include <botan/pk_util.h> +#include <botan/s2k.h> +#include <botan/pbe.h> + +namespace Botan { + +/************************************************* +* Retrieve an object from the lookup table * +*************************************************/ +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&); +BOTAN_DLL const S2K* retrieve_s2k(const std::string&); + +BOTAN_DLL const BlockCipherModePaddingMethod* +retrieve_bc_pad(const std::string&); + +/************************************************* +* Get an algorithm object * +*************************************************/ +BOTAN_DLL BlockCipher* get_block_cipher(const std::string&); +BOTAN_DLL StreamCipher* get_stream_cipher(const std::string&); +BOTAN_DLL HashFunction* get_hash(const std::string&); +BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string&); +BOTAN_DLL S2K* get_s2k(const std::string&); +BOTAN_DLL const BlockCipherModePaddingMethod* get_bc_pad(const std::string&); + +/************************************************* +* Get a PBE object * +*************************************************/ +BOTAN_DLL PBE* get_pbe(const std::string&); +BOTAN_DLL PBE* get_pbe(const OID&, DataSource&); + +/************************************************* +* Get an EMSA/EME/KDF/MGF function * +*************************************************/ +BOTAN_DLL EME* get_eme(const std::string&); +BOTAN_DLL EMSA* get_emsa(const std::string&); +BOTAN_DLL MGF* get_mgf(const std::string&); +BOTAN_DLL KDF* get_kdf(const std::string&); + +/************************************************* +* Get a cipher object * +*************************************************/ +BOTAN_DLL Keyed_Filter* get_cipher(const std::string&, + const SymmetricKey&, + const InitializationVector&, + Cipher_Dir); + +BOTAN_DLL Keyed_Filter* get_cipher(const std::string&, + const SymmetricKey&, + Cipher_Dir); + +BOTAN_DLL Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); + +/************************************************* +* Check to see if an algorithm exists * +*************************************************/ +BOTAN_DLL bool have_algorithm(const std::string&); + +BOTAN_DLL bool have_block_cipher(const std::string&); +BOTAN_DLL bool have_stream_cipher(const std::string&); +BOTAN_DLL bool have_hash(const std::string&); +BOTAN_DLL bool have_mac(const std::string&); + +/************************************************* +* Query information about an algorithm * +*************************************************/ +BOTAN_DLL u32bit block_size_of(const std::string&); +BOTAN_DLL u32bit output_length_of(const std::string&); + +BOTAN_DLL bool valid_keylength_for(u32bit, const std::string&); +BOTAN_DLL u32bit min_keylength_of(const std::string&); +BOTAN_DLL u32bit max_keylength_of(const std::string&); +BOTAN_DLL u32bit keylength_multiple_of(const std::string&); + +} + +#endif diff --git a/src/mlock.cpp b/src/core/mlock.cpp index e4456658d..e4456658d 100644 --- a/src/mlock.cpp +++ b/src/core/mlock.cpp diff --git a/src/modules.cpp b/src/core/modules.cpp index 08ab0cdbb..08ab0cdbb 100644 --- a/src/modules.cpp +++ b/src/core/modules.cpp diff --git a/src/core/modules.h b/src/core/modules.h new file mode 100644 index 000000000..69a6e1ffb --- /dev/null +++ b/src/core/modules.h @@ -0,0 +1,51 @@ +/************************************************* +* Module Factory Header File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_MODULE_FACTORIES_H__ +#define BOTAN_MODULE_FACTORIES_H__ + +#include <botan/init.h> +#include <string> +#include <vector> + +namespace Botan { + +/************************************************* +* Module Builder Interface * +*************************************************/ +class BOTAN_DLL Modules + { + public: + virtual class Mutex_Factory* mutex_factory(bool) const = 0; + + virtual std::string default_allocator() const = 0; + + virtual std::vector<class Allocator*> allocators() const = 0; + virtual std::vector<class Engine*> engines() const = 0; + + virtual ~Modules() {} + }; + +/************************************************* +* Built In Modules * +*************************************************/ +class BOTAN_DLL Builtin_Modules : public Modules + { + public: + class Mutex_Factory* mutex_factory(bool) const; + + std::string default_allocator() const; + + std::vector<class Allocator*> allocators() const; + std::vector<class Engine*> engines() const; + + Builtin_Modules(const InitializerOptions&); + private: + const bool should_lock, use_engines; + }; + +} + +#endif diff --git a/src/core/mutex.h b/src/core/mutex.h new file mode 100644 index 000000000..e30b48eb0 --- /dev/null +++ b/src/core/mutex.h @@ -0,0 +1,54 @@ +/************************************************* +* Mutex Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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/src/nr_op.cpp b/src/core/nr_op.cpp index 01e96a822..01e96a822 100644 --- a/src/nr_op.cpp +++ b/src/core/nr_op.cpp diff --git a/src/oids.cpp b/src/core/oids.cpp index 0823625ea..0823625ea 100644 --- a/src/oids.cpp +++ b/src/core/oids.cpp diff --git a/src/core/oids.h b/src/core/oids.h new file mode 100644 index 000000000..b5be0e01f --- /dev/null +++ b/src/core/oids.h @@ -0,0 +1,36 @@ +/************************************************* +* OID Registry Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_OIDS_H__ +#define BOTAN_OIDS_H__ + +#include <botan/asn1_oid.h> + +namespace Botan { + +namespace OIDS { + +/************************************************* +* Register an OID to string mapping * +*************************************************/ +BOTAN_DLL void add_oid(const OID&, const std::string&); + +/************************************************* +* See if an OID exists in the internal table * +*************************************************/ +BOTAN_DLL bool have_oid(const std::string&); + +/************************************************* +* Perform OID<->string mappings * +*************************************************/ +BOTAN_DLL std::string lookup(const OID&); +BOTAN_DLL OID lookup(const std::string&); +BOTAN_DLL bool name_of(const OID&, const std::string&); + +} + +} + +#endif diff --git a/src/pk_algs.cpp b/src/core/pk_algs.cpp index 83ceb61c7..83ceb61c7 100644 --- a/src/pk_algs.cpp +++ b/src/core/pk_algs.cpp diff --git a/src/core/pk_algs.h b/src/core/pk_algs.h new file mode 100644 index 000000000..a8fa5f176 --- /dev/null +++ b/src/core/pk_algs.h @@ -0,0 +1,22 @@ +/************************************************* +* PK Key Factory Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PK_KEY_FACTORY_H__ +#define BOTAN_PK_KEY_FACTORY_H__ + +#include <botan/x509_key.h> +#include <botan/pkcs8.h> + +namespace Botan { + +/************************************************* +* Get an PK key object * +*************************************************/ +BOTAN_DLL Public_Key* get_public_key(const std::string&); +BOTAN_DLL Private_Key* get_private_key(const std::string&); + +} + +#endif diff --git a/src/pk_core.cpp b/src/core/pk_core.cpp index 82fe4c217..82fe4c217 100644 --- a/src/pk_core.cpp +++ b/src/core/pk_core.cpp diff --git a/src/core/pk_core.h b/src/core/pk_core.h new file mode 100644 index 000000000..585c12ee4 --- /dev/null +++ b/src/core/pk_core.h @@ -0,0 +1,128 @@ +/************************************************* +* PK Algorithm Core Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PK_CORE_H__ +#define BOTAN_PK_CORE_H__ + +#include <botan/bigint.h> +#include <botan/dl_group.h> +#include <botan/blinding.h> +#include <botan/pk_ops.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; + }; + +/************************************************* +* 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; + }; + +/************************************************* +* 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; + }; + +/************************************************* +* 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; + }; + +/************************************************* +* 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/src/pk_keys.cpp b/src/core/pk_keys.cpp index d991f3788..d991f3788 100644 --- a/src/pk_keys.cpp +++ b/src/core/pk_keys.cpp diff --git a/src/core/pk_keys.h b/src/core/pk_keys.h new file mode 100644 index 000000000..16109c634 --- /dev/null +++ b/src/core/pk_keys.h @@ -0,0 +1,127 @@ +/************************************************* +* PK Key Types Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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: + virtual std::string algo_name() const = 0; + virtual OID get_oid() const; + + virtual bool check_key(RandomNumberGenerator&, bool) const + { return true; } + + virtual u32bit message_parts() const { return 1; } + virtual u32bit message_part_size() const { return 0; } + virtual u32bit max_input_bits() const = 0; + + virtual class X509_Encoder* x509_encoder() const = 0; + 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: + virtual class PKCS8_Encoder* pkcs8_encoder() const + { return 0; } + 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/src/core/pk_ops.h b/src/core/pk_ops.h new file mode 100644 index 000000000..fad87b573 --- /dev/null +++ b/src/core/pk_ops.h @@ -0,0 +1,79 @@ +/************************************************* +* Public Key Operations Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PK_OPS_H__ +#define BOTAN_PK_OPS_H__ + +#include <botan/bigint.h> +#include <botan/dl_group.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() {} + }; + +/************************************************* +* 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() {} + }; + +/************************************************* +* 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() {} + }; + +/************************************************* +* 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() {} + }; + +/************************************************* +* DH Operation * +*************************************************/ +class BOTAN_DLL DH_Operation + { + public: + virtual BigInt agree(const BigInt&) const = 0; + virtual DH_Operation* clone() const = 0; + virtual ~DH_Operation() {} + }; + +} + +#endif diff --git a/src/pk_util.cpp b/src/core/pk_util.cpp index 1976436ea..1976436ea 100644 --- a/src/pk_util.cpp +++ b/src/core/pk_util.cpp diff --git a/src/core/pk_util.h b/src/core/pk_util.h new file mode 100644 index 000000000..aa7a71234 --- /dev/null +++ b/src/core/pk_util.h @@ -0,0 +1,92 @@ +/************************************************* +* PK Utility Classes Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PUBKEY_UTIL_H__ +#define BOTAN_PUBKEY_UTIL_H__ + +#include <botan/base.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; + }; + +/************************************************* +* 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() {} + }; + +/************************************************* +* Key Derivation Function * +*************************************************/ +class BOTAN_DLL KDF + { + public: + SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&, + const std::string& = "") const; + SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&, + const MemoryRegion<byte>&) const; + SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&, + const byte[], u32bit) const; + + SecureVector<byte> derive_key(u32bit, const byte[], u32bit, + const std::string& = "") const; + SecureVector<byte> derive_key(u32bit, const byte[], u32bit, + const byte[], u32bit) 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[], u32bit, byte[], u32bit) const = 0; + virtual ~MGF() {} + }; + +} + +#endif diff --git a/src/pkcs8.cpp b/src/core/pkcs8.cpp index 2963c9d86..2963c9d86 100644 --- a/src/pkcs8.cpp +++ b/src/core/pkcs8.cpp diff --git a/src/core/pkcs8.h b/src/core/pkcs8.h new file mode 100644 index 000000000..383b1604a --- /dev/null +++ b/src/core/pkcs8.h @@ -0,0 +1,85 @@ +/************************************************* +* PKCS #8 Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PKCS8_H__ +#define BOTAN_PKCS8_H__ + +#include <botan/x509_key.h> +#include <botan/ui.h> +#include <botan/enums.h> + +namespace Botan { + +/************************************************* +* PKCS #8 Private Key Encoder * +*************************************************/ +class BOTAN_DLL PKCS8_Encoder + { + public: + virtual AlgorithmIdentifier alg_id() const = 0; + virtual MemoryVector<byte> key_bits() const = 0; + virtual ~PKCS8_Encoder() {} + }; + +/************************************************* +* PKCS #8 Private Key Decoder * +*************************************************/ +class BOTAN_DLL PKCS8_Decoder + { + public: + virtual void alg_id(const AlgorithmIdentifier&) = 0; + 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 { + +/************************************************* +* PKCS #8 Private Key Encoding/Decoding * +*************************************************/ +BOTAN_DLL void encode(const Private_Key&, Pipe&, X509_Encoding = PEM); +BOTAN_DLL std::string PEM_encode(const Private_Key&); + +BOTAN_DLL void encrypt_key(const Private_Key&, + Pipe&, + RandomNumberGenerator&, + const std::string&, + const std::string& = "", + X509_Encoding = PEM); + +BOTAN_DLL std::string PEM_encode(const Private_Key&, + RandomNumberGenerator&, + const std::string&, + const std::string& = ""); + +BOTAN_DLL Private_Key* load_key(DataSource&, RandomNumberGenerator&, + const User_Interface&); +BOTAN_DLL Private_Key* load_key(DataSource&, RandomNumberGenerator&, + const std::string& = ""); + +BOTAN_DLL Private_Key* load_key(const std::string&, + RandomNumberGenerator&, + const User_Interface&); +BOTAN_DLL Private_Key* load_key(const std::string&, + RandomNumberGenerator&, + const std::string& = ""); + +BOTAN_DLL Private_Key* copy_key(const Private_Key&, + RandomNumberGenerator& rng); + +} + +} + +#endif diff --git a/src/policy.cpp b/src/core/policy.cpp index f1c844017..f1c844017 100644 --- a/src/policy.cpp +++ b/src/core/policy.cpp diff --git a/src/pubkey.cpp b/src/core/pubkey.cpp index 06bb44bca..06bb44bca 100644 --- a/src/pubkey.cpp +++ b/src/core/pubkey.cpp diff --git a/src/core/pubkey.h b/src/core/pubkey.h new file mode 100644 index 000000000..0c9abf18f --- /dev/null +++ b/src/core/pubkey.h @@ -0,0 +1,210 @@ +/************************************************* +* Public Key Interface Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PUBKEY_H__ +#define BOTAN_PUBKEY_H__ + +#include <botan/base.h> +#include <botan/pk_keys.h> +#include <botan/pk_util.h> + +namespace Botan { + +enum Signature_Format { IEEE_1363, DER_SEQUENCE }; + +/************************************************* +* Public Key Encryptor * +*************************************************/ +class BOTAN_DLL PK_Encryptor + { + public: + SecureVector<byte> encrypt(const byte[], u32bit, + RandomNumberGenerator&) const; + SecureVector<byte> encrypt(const MemoryRegion<byte>&, + RandomNumberGenerator&) const; + + 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: + SecureVector<byte> decrypt(const byte[], u32bit) const; + SecureVector<byte> decrypt(const MemoryRegion<byte>&) const; + virtual ~PK_Decryptor() {} + private: + virtual SecureVector<byte> dec(const byte[], u32bit) const = 0; + }; + +/************************************************* +* Public Key Signer * +*************************************************/ +class BOTAN_DLL PK_Signer + { + public: + SecureVector<byte> sign_message(const byte[], u32bit, + RandomNumberGenerator&); + SecureVector<byte> sign_message(const MemoryRegion<byte>&, + RandomNumberGenerator&); + + void update(byte); + void update(const byte[], u32bit); + void update(const MemoryRegion<byte>&); + + SecureVector<byte> signature(RandomNumberGenerator&); + + void set_output_format(Signature_Format); + + PK_Signer(const PK_Signing_Key&, const std::string&); + ~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 * +*************************************************/ +class BOTAN_DLL PK_Verifier + { + public: + bool verify_message(const byte[], u32bit, const byte[], u32bit); + bool verify_message(const MemoryRegion<byte>&, + const MemoryRegion<byte>&); + + void update(byte); + void update(const byte[], u32bit); + void update(const MemoryRegion<byte>&); + + bool check_signature(const byte[], u32bit); + bool check_signature(const MemoryRegion<byte>&); + + void set_input_format(Signature_Format); + + PK_Verifier(const std::string&); + 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; + + PK_Key_Agreement(const PK_Key_Agreement_Key&, const std::string&); + private: + PK_Key_Agreement(const PK_Key_Agreement_Key&); + PK_Key_Agreement& operator=(const PK_Key_Agreement&); + + const PK_Key_Agreement_Key& key; + const std::string kdf_name; + }; + +/************************************************* +* 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; + + PK_Encryptor_MR_with_EME(const PK_Encrypting_Key&, const std::string&); + ~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: + PK_Decryptor_MR_with_EME(const PK_Decrypting_Key&, const std::string&); + ~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: + PK_Verifier_with_MR(const PK_Verifying_with_MR_Key&, const std::string&); + 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: + PK_Verifier_wo_MR(const PK_Verifying_wo_MR_Key&, const std::string&); + 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/src/rng.cpp b/src/core/rng.cpp index 9bed40dc1..9bed40dc1 100644 --- a/src/rng.cpp +++ b/src/core/rng.cpp diff --git a/src/core/rng.h b/src/core/rng.h new file mode 100644 index 000000000..f8b9a7f62 --- /dev/null +++ b/src/core/rng.h @@ -0,0 +1,66 @@ +/************************************************* +* RandomNumberGenerator Header File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_RANDOM_NUMBER_GENERATOR__ +#define BOTAN_RANDOM_NUMBER_GENERATOR__ + +#include <botan/exceptn.h> + +namespace Botan { + +/************************************************* +* Entropy Source * +*************************************************/ +class BOTAN_DLL EntropySource + { + public: + virtual u32bit slow_poll(byte[], u32bit) = 0; + virtual u32bit fast_poll(byte[], u32bit); + virtual ~EntropySource() {} + }; + +/************************************************* +* Random Number Generator * +*************************************************/ +class BOTAN_DLL RandomNumberGenerator + { + public: + static RandomNumberGenerator* make_rng(); + + virtual void randomize(byte[], u32bit) = 0; + virtual bool is_seeded() const = 0; + virtual void clear() throw() = 0; + + byte next_byte(); + + virtual void reseed() {} + virtual void add_entropy_source(EntropySource*) = 0; + virtual void add_entropy(const byte[], u32bit) = 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() {}; + + bool is_seeded() const { return false; } + void add_entropy(const byte[], u32bit) {} + void add_entropy_source(EntropySource* es) { delete es; } + }; + +} + +#endif diff --git a/src/rsa_op.cpp b/src/core/rsa_op.cpp index 0b151bf3b..0b151bf3b 100644 --- a/src/rsa_op.cpp +++ b/src/core/rsa_op.cpp diff --git a/src/s2k.cpp b/src/core/s2k.cpp index 9c67aef10..9c67aef10 100644 --- a/src/s2k.cpp +++ b/src/core/s2k.cpp diff --git a/src/core/s2k.h b/src/core/s2k.h new file mode 100644 index 000000000..031592513 --- /dev/null +++ b/src/core/s2k.h @@ -0,0 +1,45 @@ +/************************************************* +* S2K Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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: + virtual S2K* clone() const = 0; + virtual std::string name() const = 0; + virtual void clear() {} + + OctetString derive_key(u32bit, const std::string&) const; + + void set_iterations(u32bit); + void change_salt(const byte[], u32bit); + void change_salt(const MemoryRegion<byte>&); + void new_random_salt(RandomNumberGenerator& rng, u32bit); + + u32bit iterations() const { return iter; } + SecureVector<byte> current_salt() const { return salt; } + + S2K() { iter = 0; } + virtual ~S2K() {} + private: + virtual OctetString derive(u32bit, const std::string&, + const byte[], u32bit, u32bit) const = 0; + SecureVector<byte> salt; + u32bit iter; + }; + +} + +#endif diff --git a/src/symkey.cpp b/src/core/symkey.cpp index 7cc1bce64..7cc1bce64 100644 --- a/src/symkey.cpp +++ b/src/core/symkey.cpp diff --git a/src/core/symkey.h b/src/core/symkey.h new file mode 100644 index 000000000..f3211eb0f --- /dev/null +++ b/src/core/symkey.h @@ -0,0 +1,60 @@ +/************************************************* +* OctetString Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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/src/x509_key.cpp b/src/core/x509_key.cpp index 26ce16a72..26ce16a72 100644 --- a/src/x509_key.cpp +++ b/src/core/x509_key.cpp diff --git a/src/core/x509_key.h b/src/core/x509_key.h new file mode 100644 index 000000000..abaeaaced --- /dev/null +++ b/src/core/x509_key.h @@ -0,0 +1,58 @@ +/************************************************* +* X.509 Public Key Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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/enums.h> + +namespace Botan { + +/************************************************* +* X.509 Public Key Encoder * +*************************************************/ +class BOTAN_DLL X509_Encoder + { + public: + virtual AlgorithmIdentifier alg_id() const = 0; + virtual MemoryVector<byte> key_bits() const = 0; + virtual ~X509_Encoder() {} + }; + +/************************************************* +* X.509 Public Key Decoder * +*************************************************/ +class BOTAN_DLL X509_Decoder + { + public: + virtual void alg_id(const AlgorithmIdentifier&) = 0; + virtual void key_bits(const MemoryRegion<byte>&) = 0; + virtual ~X509_Decoder() {} + }; + +namespace X509 { + +/************************************************* +* X.509 Public Key Encoding/Decoding * +*************************************************/ +BOTAN_DLL void encode(const Public_Key&, Pipe&, X509_Encoding = PEM); +BOTAN_DLL std::string PEM_encode(const Public_Key&); + +BOTAN_DLL Public_Key* load_key(DataSource&); +BOTAN_DLL Public_Key* load_key(const std::string&); +BOTAN_DLL Public_Key* load_key(const MemoryRegion<byte>&); + +BOTAN_DLL Public_Key* copy_key(const Public_Key&); + +BOTAN_DLL Key_Constraints find_constraints(const Public_Key&, Key_Constraints); + +} + +} + +#endif diff --git a/src/pk/dsa/modinfo.txt b/src/pk/dsa/modinfo.txt index 503d9f23a..c29593e36 100644 --- a/src/pk/dsa/modinfo.txt +++ b/src/pk/dsa/modinfo.txt @@ -12,4 +12,5 @@ dsa.h <requires> asn1 dl_algo +keypair </requires> diff --git a/src/pk/elgamal/modinfo.txt b/src/pk/elgamal/modinfo.txt index df38d48d6..ffae2a667 100644 --- a/src/pk/elgamal/modinfo.txt +++ b/src/pk/elgamal/modinfo.txt @@ -8,3 +8,10 @@ load_on auto elgamal.cpp elgamal.h </add> + +<requires> +asn1 +bigint +dl_algo +keypair +</requires> diff --git a/src/keypair.cpp b/src/pk/keypair/keypair.cpp index 940f0c028..940f0c028 100644 --- a/src/keypair.cpp +++ b/src/pk/keypair/keypair.cpp diff --git a/src/pk/keypair/keypair.h b/src/pk/keypair/keypair.h new file mode 100644 index 000000000..da322c075 --- /dev/null +++ b/src/pk/keypair/keypair.h @@ -0,0 +1,25 @@ +/************************************************* +* Keypair Checks Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_KEYPAIR_H__ +#define BOTAN_KEYPAIR_H__ + +#include <botan/look_pk.h> + +namespace Botan { + +namespace KeyPair { + +/************************************************* +* Check key pair consistency * +*************************************************/ +BOTAN_DLL void check_key(RandomNumberGenerator&, PK_Encryptor*, PK_Decryptor*); +BOTAN_DLL void check_key(RandomNumberGenerator&, PK_Signer*, PK_Verifier*); + +} + +} + +#endif diff --git a/src/pk/nr/modinfo.txt b/src/pk/nr/modinfo.txt index c54631f16..c30dbb4cc 100644 --- a/src/pk/nr/modinfo.txt +++ b/src/pk/nr/modinfo.txt @@ -12,4 +12,5 @@ nr.h <requires> asn1 dl_algo +keypair </requires> diff --git a/src/pk/rsa/modinfo.txt b/src/pk/rsa/modinfo.txt index 041c01ca9..793ff95e3 100644 --- a/src/pk/rsa/modinfo.txt +++ b/src/pk/rsa/modinfo.txt @@ -12,4 +12,5 @@ rsa.h <requires> asn1 if_algo +keypair </requires> diff --git a/src/pk/rw/modinfo.txt b/src/pk/rw/modinfo.txt index f9989b3b8..58320a927 100644 --- a/src/pk/rw/modinfo.txt +++ b/src/pk/rw/modinfo.txt @@ -12,4 +12,5 @@ rw.h <requires> asn1 if_algo +keypair </requires> diff --git a/src/secalloc/ml_unix/modinfo.txt b/src/secalloc/ml_unix/xxxinfo.txt index 201a30ead..201a30ead 100644 --- a/src/secalloc/ml_unix/modinfo.txt +++ b/src/secalloc/ml_unix/xxxinfo.txt diff --git a/src/secalloc/ml_win32/modinfo.txt b/src/secalloc/ml_win32/xxxinfo.txt index 92936e1de..92936e1de 100644 --- a/src/secalloc/ml_win32/modinfo.txt +++ b/src/secalloc/ml_win32/xxxinfo.txt diff --git a/src/utils/modinfo.txt b/src/utils/modinfo.txt index ed4450ff9..538057fcf 100644 --- a/src/utils/modinfo.txt +++ b/src/utils/modinfo.txt @@ -21,4 +21,6 @@ types.h util.h version.h xor_buf.h +ui.h +ui.cpp </add> diff --git a/src/ui.cpp b/src/utils/ui.cpp index fb81ae23c..fb81ae23c 100644 --- a/src/ui.cpp +++ b/src/utils/ui.cpp diff --git a/src/utils/ui.h b/src/utils/ui.h new file mode 100644 index 000000000..f66ac3e56 --- /dev/null +++ b/src/utils/ui.h @@ -0,0 +1,34 @@ +/************************************************* +* User Interface Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#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 |