Coverage Report

Created: 2020-06-30 13:58

/src/botan/build/include/botan/reducer.h
Line
Count
Source (jump to first uncovered line)
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
13
namespace Botan {
14
15
/**
16
* Modular Reducer (using Barrett's technique)
17
*/
18
class BOTAN_PUBLIC_API(2,0) Modular_Reducer
19
   {
20
   public:
21
1.29k
      const BigInt& get_modulus() const { return m_modulus; }
22
23
      BigInt reduce(const BigInt& x) const;
24
25
      /**
26
      * Multiply mod p
27
      * @param x the first operand
28
      * @param y the second operand
29
      * @return (x * y) % p
30
      */
31
      BigInt multiply(const BigInt& x, const BigInt& y) const
32
1.19M
         { return reduce(x * y); }
33
34
      /**
35
      * Square mod p
36
      * @param x the value to square
37
      * @return (x * x) % p
38
      */
39
      BigInt square(const BigInt& x) const
40
4.19M
         { return reduce(Botan::square(x)); }
41
42
      /**
43
      * Cube mod p
44
      * @param x the value to cube
45
      * @return (x * x * x) % p
46
      */
47
      BigInt cube(const BigInt& x) const
48
0
         { return multiply(x, this->square(x)); }
49
50
      /**
51
      * Low level reduction function. Mostly for internal use.
52
      * Sometimes useful for performance by reducing temporaries
53
      * Reduce x mod p and place the output in out. ** X and out must not reference each other **
54
      * ws is a temporary workspace.
55
      */
56
      void reduce(BigInt& out, const BigInt& x, secure_vector<word>& ws) const;
57
58
4.67k
      bool initialized() const { return (m_mod_words != 0); }
59
60
0
      Modular_Reducer() { m_mod_words = 0; }
61
      explicit Modular_Reducer(const BigInt& mod);
62
   private:
63
      BigInt m_modulus, m_mu;
64
      size_t m_mod_words;
65
   };
66
67
}
68
69
#endif