Botan  1.10.9
bn_powm.cpp
Go to the documentation of this file.
1 /*
2 * OpenSSL Modular Exponentiation
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #include <botan/internal/openssl_engine.h>
9 #include <botan/internal/bn_wrap.h>
10 
11 namespace Botan {
12 
13 namespace {
14 
15 /*
16 * OpenSSL Modular Exponentiator
17 */
18 class OpenSSL_Modular_Exponentiator : public Modular_Exponentiator
19  {
20  public:
21  void set_base(const BigInt& b) { base = b; }
22  void set_exponent(const BigInt& e) { exp = e; }
23  BigInt execute() const;
24  Modular_Exponentiator* copy() const
25  { return new OpenSSL_Modular_Exponentiator(*this); }
26 
27  OpenSSL_Modular_Exponentiator(const BigInt& n) : mod(n) {}
28  private:
29  OSSL_BN base, exp, mod;
30  OSSL_BN_CTX ctx;
31  };
32 
33 /*
34 * Compute the result
35 */
36 BigInt OpenSSL_Modular_Exponentiator::execute() const
37  {
38  OSSL_BN r;
39  BN_mod_exp(r.value, base.value, exp.value, mod.value, ctx.value);
40  return r.to_bigint();
41  }
42 
43 }
44 
45 /*
46 * Return the OpenSSL-based modular exponentiator
47 */
50  {
51  return new OpenSSL_Modular_Exponentiator(n);
52  }
53 
54 }
BigInt n
Definition: numthry.cpp:26
Modular_Exponentiator * mod_exp(const BigInt &, Power_Mod::Usage_Hints) const
Definition: bn_powm.cpp:48
OSSL_BN base
Definition: bn_powm.cpp:29
BigInt r
Definition: numthry.cpp:26
OSSL_BN mod
Definition: bn_powm.cpp:29
BN_CTX * value
Definition: bn_wrap.h:45
OSSL_BN exp
Definition: bn_powm.cpp:29
BIGNUM * value
Definition: bn_wrap.h:22
OSSL_BN_CTX ctx
Definition: bn_powm.cpp:30