Botan: src/engine/openssl/bn_powm.cpp Source File

Botan 1.10.17

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 */
48 Modular_Exponentiator* OpenSSL_Engine::mod_exp(const BigInt& n,
49 Power_Mod::Usage_Hints) const
50 {
51 return new OpenSSL_Modular_Exponentiator(n);
52 }
53
54 }
Botan::BigInt
Definition: bigint.h:22
Botan
Definition: algo_base.h:14
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22
Botan::Power_Mod::Usage_Hints
Usage_Hints
Definition: pow_mod.h:35
Botan::OSSL_BN_CTX::value
BN_CTX * value
Definition: bn_wrap.h:45
Botan::OpenSSL_Engine::mod_exp
Modular_Exponentiator * mod_exp(const BigInt &, Power_Mod::Usage_Hints) const
Definition: bn_powm.cpp:48
Botan::Modular_Exponentiator
Definition: pow_mod.h:18