1
/*************************************************
2
* OpenSSL Modular Exponentiation Source File *
3
* (C) 1999-2007 The Botan Project *
4
*************************************************/
6
#include <botan/eng_ossl.h>
7
#include <botan/bn_wrap.h>
13
/*************************************************
14
* OpenSSL Modular Exponentiator *
15
*************************************************/
16
class OpenSSL_Modular_Exponentiator : public Modular_Exponentiator
19
void set_base(const BigInt& b) { base = b; }
20
void set_exponent(const BigInt& e) { exp = e; }
21
BigInt execute() const;
22
Modular_Exponentiator* copy() const
23
{ return new OpenSSL_Modular_Exponentiator(*this); }
25
OpenSSL_Modular_Exponentiator(const BigInt& n) : mod(n) {}
27
OSSL_BN base, exp, mod;
31
/*************************************************
32
* Compute the result *
33
*************************************************/
34
BigInt OpenSSL_Modular_Exponentiator::execute() const
37
BN_mod_exp(r.value, base.value, exp.value, mod.value, ctx.value);
43
/*************************************************
44
* Return the OpenSSL-based modular exponentiator *
45
*************************************************/
46
Modular_Exponentiator* OpenSSL_Engine::mod_exp(const BigInt& n,
47
Power_Mod::Usage_Hints) const
49
return new OpenSSL_Modular_Exponentiator(n);