Botan  1.10.9
reducer.h
Go to the documentation of this file.
1 /*
2 * Modular Reducer
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
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 */
18 class BOTAN_DLL Modular_Reducer
19  {
20  public:
21  const BigInt& get_modulus() const { return modulus; }
22 
23  BigInt reduce(const BigInt& x) const;
24 
25  /**
26  * Multiply mod p
27  * @param x
28  * @param y
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
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
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 (mod_words != 0); }
51 
52  Modular_Reducer() { mod_words = 0; }
53  Modular_Reducer(const BigInt& mod);
54  private:
55  BigInt modulus, modulus_2, mu;
56  size_t 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
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
GMP_MPZ mod
Definition: gmp_powm.cpp:29
BigInt square(const BigInt &x)
Definition: mp_numth.cpp:18
BigInt square(const BigInt &x) const
Definition: reducer.h:39
const BigInt & get_modulus() const
Definition: reducer.h:21