Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Macros
Pages
elgamal
ciphergroup.cpp
Go to the documentation of this file.
1
12
#include "
ciphertext.hpp
"
13
#include "
ciphergroup.hpp
"
14
#include "
arrayofciphers.hpp
"
15
16
using namespace
elGamal;
17
18
19
20
CipherGroup::CipherGroup
(
arithm::Group
* group)
21
{
22
grp
= group;
23
}
24
25
26
arithm::Group
*
CipherGroup::getGrp
()
27
{
28
return
grp
;
29
}
30
31
32
CipherText
CipherGroup::getCipherText
(
verifierUtils::ByteTree
* bt)
33
{
34
return
CipherText
(bt,*
this
);
35
}
36
37
38
ArrayOfCiphers
CipherGroup::getArrayOfCiphers
(
39
verifierUtils::ByteTree
* bt)
40
{
41
return
ArrayOfCiphers
(bt,*
this
);
42
}
43
44
45
// -------------------------------------------- Encryption/Decryption
46
47
48
49
CipherText
CipherGroup::enc
(
arithm::Elmt
y,
arithm::Elmt
m,
50
arithm::Elmt
s)
51
{
52
arithm::Elmt
u =
grp
->
exponentiation
(
grp
->
getGenerator
(),s);
53
arithm::Elmt
v =
grp
->
multiplication
(
grp
->
exponentiation
(y,s),m);
54
return
CipherText
(u,v);
55
}
56
57
58
arithm::Elmt
CipherGroup::dec
(
arithm::Elmt
x,
CipherText
uv)
59
{
60
return
grp
->
multiplication
(
61
grp
->
exponentiation
(
grp
->
multInverse
(uv.
getU
()),x),
62
uv.
getV
());
63
}
64
65
66
arithm::Elmt
CipherGroup::pdec
(
arithm::Elmt
xl,
CipherText
uv)
67
{
68
return
grp
->
exponentiation
(uv.
getU
(),xl);
69
}
70
71
72
arithm::ArrayOfElmts
CipherGroup::pdec
(
arithm::Elmt
xl,
ArrayOfCiphers
uv)
73
{
74
arithm::ArrayOfElmts
result;
75
for
(
unsigned
int
i=0; i<uv.
size
(); i++)
76
result.
addElmt
(
pdec
(xl, uv.
getCipherText
(i)));
77
return
result;
78
}
79
80
81
arithm::Elmt
CipherGroup::tdec
(
CipherText
uv,
arithm::Elmt
f)
82
{
83
return
grp
->
multiplication
(uv.
getV
(),
grp
->
multInverse
(f));
84
}
85
86
87
arithm::ArrayOfElmts
CipherGroup::tdec
(
ArrayOfCiphers
uv,
arithm::ArrayOfElmts
f)
88
{
89
arithm::ArrayOfElmts
result;
90
for
(
unsigned
int
i=0; i<uv.
size
(); i++)
91
result.
addElmt
(
tdec
(uv.
getCipherText
(i),f.
getElmt
(i)));
92
return
result;
93
}
94
95
96
// ------------------------------------------------ Group operations
97
98
99
100
CipherText
CipherGroup::exponentiation
(
CipherText
c,
arithm::Elmt
s)
101
{
102
return
CipherText
(
grp
->
exponentiation
(c.
getU
(),s),
103
grp
->
exponentiation
(c.
getV
(),s));
104
105
}
106
107
108
CipherText
CipherGroup::multiplication
(
CipherText
c1,
CipherText
c2)
109
{
110
return
CipherText
(
grp
->
multiplication
(c1.
getU
(),c2.
getU
()),
111
grp
->
multiplication
(c1.
getV
(),c2.
getV
()));
112
}
113
114
115
ArrayOfCiphers
CipherGroup::exponentiation
(
ArrayOfCiphers
c,
116
arithm::ArrayOfElmts
s)
117
{
118
return
ArrayOfCiphers
(
grp
->
exponentiation
(c.
getUarray
(),s),
119
grp
->
exponentiation
(c.
getVarray
(),s));
120
}
121
122
123
CipherText
CipherGroup::expProduct
(
ArrayOfCiphers
c,
124
arithm::ArrayOfElmts
s)
125
{
126
return
CipherText
(
grp
->
expProduct
(c.
getUarray
(),s),
127
grp
->
expProduct
(c.
getVarray
(),s));
128
}
129
130
131
bool
CipherGroup::compare
(
CipherText
c1,
CipherText
c2)
132
{
133
return
( (
grp
->
compare
(c1.
getU
(), c2.
getU
())) &&
134
(
grp
->
compare
(c1.
getV
(), c2.
getV
())) );
135
}
136
137
138
bool
CipherGroup::compare
(
ArrayOfCiphers
c1,
ArrayOfCiphers
c2)
139
{
140
for
(
unsigned
int
i=0; i<c1.
size
(); i++)
141
if
(!
compare
(c1.
getCipherText
(i), c2.
getCipherText
(i)) )
142
return
false
;
143
return
true
;
144
}