Botan 3.9.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 const BigInt& get_modulus() const { return m_modulus; }
25
26 BigInt reduce(const BigInt& x) const;
27
28 /**
29 * Multiply mod p
30 * @param x the first operand
31 * @param y the second operand
32 * @return (x * y) % p
33 */
34 BigInt multiply(const BigInt& x, const BigInt& y) const { return reduce(x * y); }
35
36 /**
37 * Multiply mod p
38 * @return (x * y * z) % p
39 */
40 BigInt multiply(const BigInt& x, const BigInt& y, const BigInt& z) const { return multiply(x, multiply(y, z)); }
41
42 /**
43 * Square mod p
44 * @param x the value to square
45 * @return (x * x) % p
46 */
47 BigInt square(const BigInt& x) const { return reduce(x * x); }
48
49 /**
50 * Cube mod p
51 * @param x the value to cube
52 * @return (x * x * x) % p
53 */
54 BigInt cube(const BigInt& x) const { return multiply(x, this->square(x)); }
55
56 /**
57 * Low level reduction function. Mostly for internal use.
58 * Sometimes useful for performance by reducing temporaries
59 * Reduce x mod p and place the output in out.
60 *
61 * @warning X and out must not reference each other
62 *
63 * ws is an (ignored) a temporary workspace.
64 */
65 void reduce(BigInt& out, const BigInt& x, secure_vector<word>& /*ws*/) const { out = reduce(x); }
66
67 bool initialized() const { return (m_mod_words != 0); }
68
69 BOTAN_DEPRECATED("Use for_public_modulus or for_secret_modulus") Modular_Reducer() : m_mod_words(0) {}
70
71 /**
72 * Accepts m == 0 and leaves the Modular_Reducer in an uninitialized state
73 */
74 explicit Modular_Reducer(const BigInt& mod);
75
76 /**
77 * Requires that m > 0
78 */
80
81 /**
82 * Requires that m > 0
83 */
85
86 private:
87 Modular_Reducer(const BigInt& m, BigInt mu, size_t mw) : m_modulus(m), m_mu(std::move(mu)), m_mod_words(mw) {}
88
89 BigInt m_modulus, m_mu;
90 size_t m_mod_words;
91};
92
93} // namespace Botan
94
95#endif
#define BOTAN_DEPRECATED_HEADER(hdr)
Definition api.h:94
#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:24
static Modular_Reducer for_public_modulus(const BigInt &m)
Definition reducer.h:79
BigInt cube(const BigInt &x) const
Definition reducer.h:54
static Modular_Reducer for_secret_modulus(const BigInt &m)
Definition reducer.h:84
void reduce(BigInt &out, const BigInt &x, secure_vector< word > &) const
Definition reducer.h:65
BigInt square(const BigInt &x) const
Definition reducer.h:47
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition reducer.h:34
bool initialized() const
Definition reducer.h:67
BigInt reduce(const BigInt &x) const
Definition reducer.cpp:22
BigInt multiply(const BigInt &x, const BigInt &y, const BigInt &z) const
Definition reducer.h:40
RetT reduce(const std::vector< KeyT > &keys, RetT acc, ReducerT reducer)
Definition stl_util.h:39
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69