diff options
author | lloyd <[email protected]> | 2008-11-11 19:20:32 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-11 19:20:32 +0000 |
commit | 2af6c4499013911d7b01ce3ce1acc5aa8fef15ab (patch) | |
tree | 894612d39bbcd50187334c1bedf197c4475c7393 /src/engine/openssl/bn_powm.cpp | |
parent | 25d7b7aa9e9896df45f12fa59db4c44411bc21f0 (diff) |
Move most of the remaining libstate code to pk_engine.cpp, move engines
back to the toplevel since most othe dependencies have been removed now
(except get_cipher which still needs changes)
Diffstat (limited to 'src/engine/openssl/bn_powm.cpp')
-rw-r--r-- | src/engine/openssl/bn_powm.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/engine/openssl/bn_powm.cpp b/src/engine/openssl/bn_powm.cpp new file mode 100644 index 000000000..f54411240 --- /dev/null +++ b/src/engine/openssl/bn_powm.cpp @@ -0,0 +1,52 @@ +/************************************************* +* OpenSSL Modular Exponentiation Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/eng_ossl.h> +#include <botan/bn_wrap.h> + +namespace Botan { + +namespace { + +/************************************************* +* OpenSSL Modular Exponentiator * +*************************************************/ +class OpenSSL_Modular_Exponentiator : public Modular_Exponentiator + { + public: + void set_base(const BigInt& b) { base = b; } + void set_exponent(const BigInt& e) { exp = e; } + BigInt execute() const; + Modular_Exponentiator* copy() const + { return new OpenSSL_Modular_Exponentiator(*this); } + + OpenSSL_Modular_Exponentiator(const BigInt& n) : mod(n) {} + private: + OSSL_BN base, exp, mod; + OSSL_BN_CTX ctx; + }; + +/************************************************* +* Compute the result * +*************************************************/ +BigInt OpenSSL_Modular_Exponentiator::execute() const + { + OSSL_BN r; + BN_mod_exp(r.value, base.value, exp.value, mod.value, ctx.value); + return r.to_bigint(); + } + +} + +/************************************************* +* Return the OpenSSL-based modular exponentiator * +*************************************************/ +Modular_Exponentiator* OpenSSL_Engine::mod_exp(const BigInt& n, + Power_Mod::Usage_Hints) const + { + return new OpenSSL_Modular_Exponentiator(n); + } + +} |