Botan  2.4.0
Crypto and TLS for C++11
reducer.h
Go to the documentation of this file.
1 /*
2 * Modular Reducer
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_MODULAR_REDUCER_H_
9 #define BOTAN_MODULAR_REDUCER_H_
10 
11 #include <botan/numthry.h>
12 
13 namespace Botan {
14 
15 /**
16 * Modular Reducer (using Barrett's technique)
17 */
19  {
20  public:
21  const BigInt& get_modulus() const { return m_modulus; }
22 
23  BigInt reduce(const BigInt& x) const;
24 
25  /**
26  * Multiply mod p
27  * @param x the first operand
28  * @param y the second operand
29  * @return (x * y) % p
30  */
31  BigInt multiply(const BigInt& x, const BigInt& y) const
32  { return reduce(x * y); }
33 
34  /**
35  * Square mod p
36  * @param x the value to square
37  * @return (x * x) % p
38  */
39  BigInt square(const BigInt& x) const
40  { return reduce(Botan::square(x)); }
41 
42  /**
43  * Cube mod p
44  * @param x the value to cube
45  * @return (x * x * x) % p
46  */
47  BigInt cube(const BigInt& x) const
48  { return multiply(x, this->square(x)); }
49 
50  bool initialized() const { return (m_mod_words != 0); }
51 
52  Modular_Reducer() { m_mod_words = 0; }
53  explicit Modular_Reducer(const BigInt& mod);
54  private:
55  BigInt m_modulus, m_modulus_2, m_mu;
56  size_t m_mod_words;
57  };
58 
59 }
60 
61 #endif
BigInt cube(const BigInt &x) const
Definition: reducer.h:47
bool initialized() const
Definition: reducer.h:50
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
BigInt square(const BigInt &x)
Definition: mp_numth.cpp:19
Definition: alg_id.cpp:13
const BigInt & get_modulus() const
Definition: reducer.h:21
BigInt square(const BigInt &x) const
Definition: reducer.h:39
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31