File: reducer.cpp

package info (click to toggle)
monotone 0.31-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 20,680 kB
  • ctags: 14,801
  • sloc: cpp: 87,711; ansic: 64,862; sh: 5,691; lisp: 954; perl: 783; makefile: 509; python: 265; sql: 98; sed: 16
file content (54 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*************************************************
* Modular Reducer Source File                    *
* (C) 1999-2005 The Botan Project                *
*************************************************/

#include <botan/reducer.h>
#include <botan/bit_ops.h>

namespace Botan {

/*************************************************
* Construct a ModularReducer                     *
*************************************************/
ModularReducer::ModularReducer(const BigInt& n) : modulus(n)
   {
   if(modulus <= 0)
      throw Invalid_Argument("ModularReducer: modulus must be positive");
   if(modulus.size() > 8 && !power_of_2(modulus.size()))
      modulus.grow_reg((1 << high_bit(modulus.size())) - modulus.size());
   }

/*************************************************
* Convert to the modular form                    *
*************************************************/
BigInt ModularReducer::convert_in(const BigInt& i) const
   {
   return i;
   }

/*************************************************
* Convert from the modular form                  *
*************************************************/
BigInt ModularReducer::convert_out(const BigInt& i) const
   {
   return i;
   }

/*************************************************
* Modular Multiplication                         *
*************************************************/
BigInt ModularReducer::multiply(const BigInt& x, const BigInt& y) const
   {
   return reduce(x * y);
   }

/*************************************************
* Modular Squaring                               *
*************************************************/
BigInt ModularReducer::square(const BigInt& x) const
   {
   return multiply(x, x);
   }

}