Botan: src/math/numbertheory/reducer.h Source File

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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
Botan::BigInt
Definition: bigint.h:22
Botan::Modular_Reducer::cube
BigInt cube(const BigInt &x) const
Definition: reducer.h:47
Botan::Modular_Reducer::initialized
bool initialized() const
Definition: reducer.h:50
Botan::Modular_Reducer::multiply
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
Botan
Definition: algo_base.h:14
Botan::Modular_Reducer::Modular_Reducer
Modular_Reducer()
Definition: reducer.h:52
Botan::square
BigInt square(const BigInt &x)
Definition: mp_numth.cpp:18
Botan::Modular_Reducer::square
BigInt square(const BigInt &x) const
Definition: reducer.h:39
Botan::Modular_Reducer
Definition: reducer.h:18
Botan::Modular_Reducer::get_modulus
const BigInt & get_modulus() const
Definition: reducer.h:21