Botan 3.13.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/bigint.h>
12
13BOTAN_DEPRECATED_HEADER("reducer.h")
14
15namespace Botan {
16
17/**
18* Modular Reducer
19*
20* This class is deprecated without replacement
21*/
23 public:
24 /**
25 * Return the modulus of this reducer
26 * @return the modulus
27 */
28 const BigInt& get_modulus() const { return m_modulus; }
29
30 /**
31 * Reduce a value modulo p
32 * @param x the value to reduce
33 * @return (x % p)
34 */
35 BigInt reduce(const BigInt& x) const;
36
37 /**
38 * Multiply mod p
39 * @param x the first operand
40 * @param y the second operand
41 * @return (x * y) % p
42 */
43 BigInt multiply(const BigInt& x, const BigInt& y) const { return reduce(x * y); }
44
45 /**
46 * Multiply mod p
47 * @return (x * y * z) % p
48 */
49 BigInt multiply(const BigInt& x, const BigInt& y, const BigInt& z) const { return multiply(x, multiply(y, z)); }
50
51 /**
52 * Square mod p
53 * @param x the value to square
54 * @return (x * x) % p
55 */
56 BigInt square(const BigInt& x) const { return reduce(x * x); }
57
58 /**
59 * Cube mod p
60 * @param x the value to cube
61 * @return (x * x * x) % p
62 */
63 BigInt cube(const BigInt& x) const { return multiply(x, this->square(x)); }
64
65 /**
66 * Low level reduction function. Mostly for internal use.
67 * Sometimes useful for performance by reducing temporaries
68 * Reduce x mod p and place the output in out.
69 *
70 * @warning X and out must not reference each other
71 *
72 * ws is an (ignored) a temporary workspace.
73 */
74 void reduce(BigInt& out, const BigInt& x, secure_vector<word>& /*ws*/) const { out = reduce(x); }
75
76 /**
77 * Test whether this reducer was initialized with a non-zero modulus
78 * @return true if a modulus is set
79 */
80 bool initialized() const { return (m_mod_words != 0); }
81
82 /**
83 * Create an uninitialized Modular_Reducer
84 */
85 BOTAN_DEPRECATED("Use for_public_modulus or for_secret_modulus") Modular_Reducer() : m_mod_words(0) {}
86
87 /**
88 * Accepts m == 0 and leaves the Modular_Reducer in an uninitialized state
89 */
90 explicit Modular_Reducer(const BigInt& mod);
91
92 /**
93 * Requires that m > 0
94 */
96
97 /**
98 * Requires that m > 0
99 */
101
102 private:
103 Modular_Reducer(const BigInt& m, BigInt mu, size_t mw) : m_modulus(m), m_mu(std::move(mu)), m_mod_words(mw) {}
104
105 BigInt m_modulus, m_mu;
106 size_t m_mod_words;
107};
108
109} // namespace Botan
110
111#endif
#define BOTAN_DEPRECATED_HEADER(hdr)
Definition api.h:100
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
const BigInt & get_modulus() const
Definition reducer.h:28
static Modular_Reducer for_public_modulus(const BigInt &m)
Definition reducer.h:95
BigInt cube(const BigInt &x) const
Definition reducer.h:63
static Modular_Reducer for_secret_modulus(const BigInt &m)
Definition reducer.h:100
void reduce(BigInt &out, const BigInt &x, secure_vector< word > &) const
Definition reducer.h:74
BigInt square(const BigInt &x) const
Definition reducer.h:56
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition reducer.h:43
bool initialized() const
Definition reducer.h:80
BigInt reduce(const BigInt &x) const
Definition reducer.cpp:23
BigInt multiply(const BigInt &x, const BigInt &y, const BigInt &z) const
Definition reducer.h:49
RetT reduce(const std::vector< KeyT > &keys, RetT acc, ReducerT reducer)
Definition stl_util.h:30
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128