-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpaillierprivatekey.cpp
More file actions
37 lines (32 loc) · 862 Bytes
/
paillierprivatekey.cpp
File metadata and controls
37 lines (32 loc) · 862 Bytes
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
#include <QDebug>
#include <gmp.h>
#include <QtCrypto>
#include "paillierprivatekey.hpp"
#include "modularmath.hpp"
#include "bigintmath.hpp"
PaillierPrivateKey::PaillierPrivateKey(unsigned int bits):
pub(nullptr)
{
QCA::RSAPrivateKey delegate = QCA::KeyGenerator().createRSA(bits).toRSA();
p = delegate.p();
q = delegate.q();
n = delegate.n();
n2 = n*n;
l = (p-1) * (q-1);
g = randomInRange(1, n2);
mu = ModularMath::invmod((ModularMath::modexp(g, l, n2)-1)/n, n);
}
PaillierPrivateKey::~PaillierPrivateKey()
{
delete pub;
}
PaillierPublicKey PaillierPrivateKey::derivePublicKey() const
{
if (pub == nullptr)
pub = new PaillierPublicKey(n,g);
return *pub;
}
QCA::BigInteger PaillierPrivateKey::decrypt(QCA::BigInteger cipher) const
{
return (((ModularMath::modexp(cipher, l, n2)-1)/n)*mu) % n;
}