monotone

monotone Mtn Source Tree

Root/botan/blinding.cpp

1/*************************************************
2* Blinder Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/blinding.h>
7#include <botan/numthry.h>
8
9namespace Botan {
10
11/*************************************************
12* Blinder Constructor *
13*************************************************/
14Blinder::Blinder()
15 {
16 reducer = 0;
17 }
18
19/*************************************************
20* Blinder Copy Constructor *
21*************************************************/
22Blinder::Blinder(const Blinder& blinder)
23 {
24 reducer = 0;
25 initialize(blinder.e, blinder.d, blinder.n);
26 }
27
28/*************************************************
29* Blinder Assignment Operator *
30*************************************************/
31Blinder& Blinder::operator=(const Blinder& blinder)
32 {
33 delete reducer;
34 reducer = 0;
35
36 if(blinder.reducer)
37 initialize(blinder.e, blinder.d, blinder.n);
38 return (*this);
39 }
40
41/*************************************************
42* Initialize a Blinder object *
43*************************************************/
44void Blinder::initialize(const BigInt& e1, const BigInt& d1, const BigInt& n1)
45 {
46 if(e1 < 1 || d1 < 1 || n1 < 1)
47 throw Invalid_Argument("Blinder::initialize: Arguments too small");
48
49 e = e1;
50 d = d1;
51 n = n1;
52 delete reducer;
53 reducer = get_reducer(n);
54 }
55
56/*************************************************
57* Blinder Destructor *
58*************************************************/
59Blinder::~Blinder()
60 {
61 delete reducer;
62 }
63
64/*************************************************
65* Blind a number *
66*************************************************/
67BigInt Blinder::blind(const BigInt& i) const
68 {
69 if(!reducer) return i;
70 e = reducer->square(e);
71 d = reducer->square(d);
72 return reducer->multiply(i, e);
73 }
74
75/*************************************************
76* Unblind a number *
77*************************************************/
78BigInt Blinder::unblind(const BigInt& i) const
79 {
80 if(!reducer) return i;
81 return reducer->multiply(i, d);
82 }
83
84}

Archive Download this file

Branches

Tags

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