Botan 3.4.0
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 public:
20 const BigInt& get_modulus() const { return m_modulus; }
21
22 BigInt reduce(const BigInt& x) const;
23
24 /**
25 * Multiply mod p
26 * @param x the first operand
27 * @param y the second operand
28 * @return (x * y) % p
29 */
30 BigInt multiply(const BigInt& x, const BigInt& y) const { return reduce(x * y); }
31
32 /**
33 * Multiply mod p
34 * @return (x * y * z) % p
35 */
36 BigInt multiply(const BigInt& x, const BigInt& y, const BigInt& z) const { return multiply(x, multiply(y, z)); }
37
38 /**
39 * Square mod p
40 * @param x the value to square
41 * @return (x * x) % p
42 */
43 BigInt square(const BigInt& x) const { return reduce(Botan::square(x)); }
44
45 /**
46 * Cube mod p
47 * @param x the value to cube
48 * @return (x * x * x) % p
49 */
50 BigInt cube(const BigInt& x) const { return multiply(x, this->square(x)); }
51
52 /**
53 * Low level reduction function. Mostly for internal use.
54 * Sometimes useful for performance by reducing temporaries
55 * Reduce x mod p and place the output in out. ** X and out must not reference each other **
56 * ws is a temporary workspace.
57 */
58 void reduce(BigInt& out, const BigInt& x, secure_vector<word>& ws) const;
59
60 bool initialized() const { return (m_mod_words != 0); }
61
62 Modular_Reducer() { m_mod_words = 0; }
63
64 explicit Modular_Reducer(const BigInt& mod);
65
66 private:
67 BigInt m_modulus, m_mu;
68 size_t m_mod_words;
69};
70
71} // namespace Botan
72
73#endif
const BigInt & get_modulus() const
Definition reducer.h:20
BigInt cube(const BigInt &x) const
Definition reducer.h:50
BigInt square(const BigInt &x) const
Definition reducer.h:43
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition reducer.h:30
bool initialized() const
Definition reducer.h:60
BigInt multiply(const BigInt &x, const BigInt &y, const BigInt &z) const
Definition reducer.h:36
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
BigInt square(const BigInt &x)
Definition numthry.cpp:157
RetT reduce(const std::vector< KeyT > &keys, RetT acc, ReducerT reducer)
Definition stl_util.h:48
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61