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