Coverage Report

Created: 2026-08-14 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/build/include/public/botan/reducer.h
Line
Count
Source
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
13
BOTAN_DEPRECATED_HEADER("reducer.h")
14
15
namespace Botan {
16
17
/**
18
* Modular Reducer
19
*
20
* This class is deprecated without replacement
21
*/
22
class BOTAN_PUBLIC_API(2, 0) Modular_Reducer final {
23
   public:
24
0
      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
0
      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
0
      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
0
      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
0
      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
0
      void reduce(BigInt& out, const BigInt& x, secure_vector<word>& /*ws*/) const { out = reduce(x); }
66
67
0
      bool initialized() const { return (m_mod_words != 0); }
68
69
0
      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
      */
79
0
      static Modular_Reducer for_public_modulus(const BigInt& m) { return Modular_Reducer(m); }
80
81
      /**
82
      * Requires that m > 0
83
      */
84
0
      static Modular_Reducer for_secret_modulus(const BigInt& m) { return Modular_Reducer(m); }
85
86
   private:
87
0
      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