diff options
Diffstat (limited to 'src/core/libstate')
-rw-r--r-- | src/core/libstate/def_powm.cpp | 22 | ||||
-rw-r--r-- | src/core/libstate/eng_base.cpp | 76 | ||||
-rw-r--r-- | src/core/libstate/eng_def.h | 49 | ||||
-rw-r--r-- | src/core/libstate/engine.cpp | 2 | ||||
-rw-r--r-- | src/core/libstate/engine.h | 36 | ||||
-rw-r--r-- | src/core/libstate/info.txt | 2 |
6 files changed, 103 insertions, 84 deletions
diff --git a/src/core/libstate/def_powm.cpp b/src/core/libstate/def_powm.cpp new file mode 100644 index 000000000..a28438f5b --- /dev/null +++ b/src/core/libstate/def_powm.cpp @@ -0,0 +1,22 @@ +/************************************************* +* Modular Exponentiation Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/eng_def.h> +#include <botan/def_powm.h> + +namespace Botan { + +/************************************************* +* Choose a modular exponentation algorithm * +*************************************************/ +Modular_Exponentiator* +Default_Engine::mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) const + { + if(n.is_odd()) + return new Montgomery_Exponentiator(n, hints); + return new Fixed_Window_Exponentiator(n, hints); + } + +} diff --git a/src/core/libstate/eng_base.cpp b/src/core/libstate/eng_base.cpp index a296a2762..aaaf46723 100644 --- a/src/core/libstate/eng_base.cpp +++ b/src/core/libstate/eng_base.cpp @@ -64,82 +64,6 @@ class Algorithm_Cache_Impl : public Engine::Algorithm_Cache<T> } /************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -IF_Operation* Engine::if_op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -DSA_Operation* Engine::dsa_op(const DL_Group&, const BigInt&, - const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -NR_Operation* Engine::nr_op(const DL_Group&, const BigInt&, - const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -ELG_Operation* Engine::elg_op(const DL_Group&, const BigInt&, - const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -DH_Operation* Engine::dh_op(const DL_Group&, const BigInt&) const - { - return 0; - } - -#if defined(BOTAN_HAS_ECDSA) -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -ECDSA_Operation* Engine::ecdsa_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -ECKAEG_Operation* Engine::eckaeg_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const - { - return 0; - } -#endif - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -Modular_Exponentiator* Engine::mod_exp(const BigInt&, - Power_Mod::Usage_Hints) const - { - return 0; - } - -/************************************************* * Acquire a BlockCipher * *************************************************/ const BlockCipher* Engine::block_cipher(const std::string& name) const diff --git a/src/core/libstate/eng_def.h b/src/core/libstate/eng_def.h new file mode 100644 index 000000000..7d7ecce58 --- /dev/null +++ b/src/core/libstate/eng_def.h @@ -0,0 +1,49 @@ +/************************************************* +* 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; + +#if defined(BOTAN_HAS_DH) + DH_Operation* dh_op(const DL_Group&, const BigInt&) const; +#endif + + 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/core/libstate/engine.cpp b/src/core/libstate/engine.cpp index fb2477936..13ab63193 100644 --- a/src/core/libstate/engine.cpp +++ b/src/core/libstate/engine.cpp @@ -83,6 +83,7 @@ ELG_Operation* elg_op(const DL_Group& group, const BigInt& y, const BigInt& x) throw Lookup_Error("Engine_Core::elg_op: Unable to find a working engine"); } +#if defined(BOTAN_HAS_DH) /************************************************* * Acquire a DH op * *************************************************/ @@ -99,6 +100,7 @@ DH_Operation* dh_op(const DL_Group& group, const BigInt& x) throw Lookup_Error("Engine_Core::dh_op: Unable to find a working engine"); } +#endif #if defined(BOTAN_HAS_ECDSA) /************************************************* diff --git a/src/core/libstate/engine.h b/src/core/libstate/engine.h index 212d02d7a..12c69385b 100644 --- a/src/core/libstate/engine.h +++ b/src/core/libstate/engine.h @@ -13,6 +13,10 @@ #include <botan/basefilt.h> #include <botan/enums.h> +#if defined(BOTAN_HAS_DH) + #include <botan/dh_op.h> +#endif + #if defined(BOTAN_HAS_ECDSA) #include <botan/ec_dompar.h> #endif @@ -39,27 +43,41 @@ class BOTAN_DLL Engine virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&) const; + const BigInt&, const BigInt&) const + { return 0; } + virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&, - const BigInt&) const; + const BigInt&) const + { return 0; } + virtual NR_Operation* nr_op(const DL_Group&, const BigInt&, - const BigInt&) const; + const BigInt&) const + { return 0; } + virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, - const BigInt&) const; - virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const; + const BigInt&) const + { return 0; } + +#if defined(BOTAN_HAS_DH) + 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& dom_pars, const BigInt& priv_key, - const PointGFp& pub_key) const; + const PointGFp& pub_key) const + { return 0; } virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars, const BigInt& priv_key, - const PointGFp& pub_key) const; + const PointGFp& pub_key) const + { return 0; } #endif virtual Modular_Exponentiator* mod_exp(const BigInt&, - Power_Mod::Usage_Hints) const; + Power_Mod::Usage_Hints) const + { return 0; } virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); @@ -129,7 +147,9 @@ NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&); ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); +#if defined(BOTAN_HAS_DH) 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, diff --git a/src/core/libstate/info.txt b/src/core/libstate/info.txt index f160ca771..6a54463ac 100644 --- a/src/core/libstate/info.txt +++ b/src/core/libstate/info.txt @@ -7,7 +7,9 @@ define LIBSTATE_MODULE <add> def_alg.cpp def_mode.cpp +def_powm.cpp eng_base.cpp +eng_def.h engine.cpp engine.h get_enc.cpp |