Botan 2.19.2
Crypto and TLS for C&
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
13namespace 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 /**
51 * Low level reduction function. Mostly for internal use.
52 * Sometimes useful for performance by reducing temporaries
53 * Reduce x mod p and place the output in out. ** X and out must not reference each other **
54 * ws is a temporary workspace.
55 */
56 void reduce(BigInt& out, const BigInt& x, secure_vector<word>& ws) const;
57
58 bool initialized() const { return (m_mod_words != 0); }
59
60 Modular_Reducer() { m_mod_words = 0; }
61 explicit Modular_Reducer(const BigInt& mod);
62 private:
63 BigInt m_modulus, m_mu;
64 size_t m_mod_words;
65 };
66
67}
68
69#endif
const BigInt & get_modulus() const
Definition: reducer.h:21
BigInt cube(const BigInt &x) const
Definition: reducer.h:47
BigInt square(const BigInt &x) const
Definition: reducer.h:39
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
bool initialized() const
Definition: reducer.h:58
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:13
BigInt square(const BigInt &x)
Definition: mp_numth.cpp:19
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65