Botan  2.7.0
Crypto and TLS for C++11
powm_mnt.cpp
Go to the documentation of this file.
1 /*
2 * Montgomery Exponentiation
3 * (C) 1999-2010,2012,2018 Jack Lloyd
4 * 2016 Matthias Gierlings
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #include <botan/internal/def_powm.h>
10 #include <botan/numthry.h>
11 #include <botan/monty.h>
12 #include <botan/internal/monty_exp.h>
13 #include <botan/internal/rounding.h>
14 
15 namespace Botan {
16 
18  {
19  m_e = exp;
20  }
21 
23  {
24  size_t window_bits = Power_Mod::window_bits(m_e.bits(), base.bits(), m_hints);
25  m_monty = monty_precompute(m_monty_params, base, window_bits);
26  }
27 
29  {
30  /*
31  This leaks size of e via loop iterations, not possible to fix without
32  breaking this API. Round up to avoid leaking fine details.
33  */
34  return monty_execute(*m_monty, m_e, round_up(m_e.bits(), 8));
35  }
36 
38  Power_Mod::Usage_Hints hints) :
39  m_p(mod),
40  m_mod_p(mod),
41  m_monty_params(std::make_shared<Montgomery_Params>(m_p, m_mod_p)),
42  m_hints(hints)
43  {
44  }
45 
46 }
size_t bits() const
Definition: bigint.cpp:228
Definition: bigint.h:796
BigInt execute() const override
Definition: powm_mnt.cpp:28
void set_exponent(const BigInt &) override
Definition: powm_mnt.cpp:17
Montgomery_Exponentiator(const BigInt &, Power_Mod::Usage_Hints)
Definition: powm_mnt.cpp:37
void set_base(const BigInt &) override
Definition: powm_mnt.cpp:22
std::shared_ptr< const Montgomery_Exponentation_State > monty_precompute(std::shared_ptr< const Montgomery_Params > params, const BigInt &g, size_t window_bits, bool const_time)
Definition: monty_exp.cpp:151
Definition: alg_id.cpp:13
static size_t window_bits(size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints)
Definition: pow_mod.cpp:102
BigInt monty_execute(const Montgomery_Exponentation_State &precomputed_state, const BigInt &k, size_t max_k_bits)
Definition: monty_exp.cpp:159
size_t round_up(size_t n, size_t align_to)
Definition: rounding.h:21
Modular_Reducer m_mod_p
Definition: rsa.cpp:280