monotone

monotone Mtn Source Tree

Root/botan/reducer.cpp

1/*************************************************
2* Modular Reducer Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/reducer.h>
7#include <botan/bit_ops.h>
8
9namespace Botan {
10
11/*************************************************
12* Construct a ModularReducer *
13*************************************************/
14ModularReducer::ModularReducer(const BigInt& n) : modulus(n)
15 {
16 if(modulus <= 0)
17 throw Invalid_Argument("ModularReducer: modulus must be positive");
18 if(modulus.size() > 8 && !power_of_2(modulus.size()))
19 modulus.grow_reg((1 << high_bit(modulus.size())) - modulus.size());
20 }
21
22/*************************************************
23* Convert to the modular form *
24*************************************************/
25BigInt ModularReducer::convert_in(const BigInt& i) const
26 {
27 return i;
28 }
29
30/*************************************************
31* Convert from the modular form *
32*************************************************/
33BigInt ModularReducer::convert_out(const BigInt& i) const
34 {
35 return i;
36 }
37
38/*************************************************
39* Modular Multiplication *
40*************************************************/
41BigInt ModularReducer::multiply(const BigInt& x, const BigInt& y) const
42 {
43 return reduce(x * y);
44 }
45
46/*************************************************
47* Modular Squaring *
48*************************************************/
49BigInt ModularReducer::square(const BigInt& x) const
50 {
51 return multiply(x, x);
52 }
53
54}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status