File: blinding.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 (84 lines) | stat: -rw-r--r-- 2,327 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*************************************************
* Blinder Source File                            *
* (C) 1999-2005 The Botan Project                *
*************************************************/

#include <botan/blinding.h>
#include <botan/numthry.h>

namespace Botan {

/*************************************************
* Blinder Constructor                            *
*************************************************/
Blinder::Blinder()
   {
   reducer = 0;
   }

/*************************************************
* Blinder Copy Constructor                       *
*************************************************/
Blinder::Blinder(const Blinder& blinder)
   {
   reducer = 0;
   initialize(blinder.e, blinder.d, blinder.n);
   }

/*************************************************
* Blinder Assignment Operator                    *
*************************************************/
Blinder& Blinder::operator=(const Blinder& blinder)
   {
   delete reducer;
   reducer = 0;

   if(blinder.reducer)
      initialize(blinder.e, blinder.d, blinder.n);
   return (*this);
   }

/*************************************************
* Initialize a Blinder object                    *
*************************************************/
void Blinder::initialize(const BigInt& e1, const BigInt& d1, const BigInt& n1)
   {
   if(e1 < 1 || d1 < 1 || n1 < 1)
      throw Invalid_Argument("Blinder::initialize: Arguments too small");

   e = e1;
   d = d1;
   n = n1;
   delete reducer;
   reducer = get_reducer(n);
   }

/*************************************************
* Blinder Destructor                             *
*************************************************/
Blinder::~Blinder()
   {
   delete reducer;
   }

/*************************************************
* Blind a number                                 *
*************************************************/
BigInt Blinder::blind(const BigInt& i) const
   {
   if(!reducer) return i;
   e = reducer->square(e);
   d = reducer->square(d);
   return reducer->multiply(i, e);
   }

/*************************************************
* Unblind a number                               *
*************************************************/
BigInt Blinder::unblind(const BigInt& i) const
   {
   if(!reducer) return i;
   return reducer->multiply(i, d);
   }

}