-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathSchnorrTests.cpp
96 lines (71 loc) · 2.36 KB
/
SchnorrTests.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
#include "SchnorrTests.h"
CPPUNIT_TEST_SUITE_REGISTRATION(SchnorrTest);
SchnorrTest::SchnorrTest() {
}
SchnorrTest::~SchnorrTest() {
}
void SchnorrTest::setUp() {
schnorr = new CryptoKernel::Schnorr();
}
void SchnorrTest::tearDown() {
delete schnorr;
}
/**
* Tests that the Crypto module initialised correctly
*/
void SchnorrTest::testInit() {
CPPUNIT_ASSERT(schnorr->getStatus());
}
/**
* Tests that a keypair has been generated
*/
void SchnorrTest::testKeygen() {
const std::string privateKey = schnorr->getPrivateKey();
const std::string publicKey = schnorr->getPublicKey();
CPPUNIT_ASSERT(privateKey.size() > 0);
CPPUNIT_ASSERT(publicKey.size() > 0);
}
/**
* Tests that signing and verifying works
*/
void SchnorrTest::testSignVerify() {
const std::string privateKey = schnorr->getPrivateKey();
const std::string publicKey = schnorr->getPublicKey();
const std::string signature = schnorr->signSingle(plainText);
CPPUNIT_ASSERT(signature.size() > 0);
CPPUNIT_ASSERT(schnorr->verify(plainText, signature));
}
/**
* Tests passing key to class
*/
void SchnorrTest::testPassingKeys() {
CryptoKernel::Schnorr *tempSchnorr = new CryptoKernel::Schnorr();
const std::string signature = tempSchnorr->signSingle(plainText);
CPPUNIT_ASSERT(signature.size() > 0);
CPPUNIT_ASSERT(schnorr->setPublicKey(tempSchnorr->getPublicKey()));
CPPUNIT_ASSERT(schnorr->verify(plainText, signature));
delete tempSchnorr;
}
/**
* Tests permuting a valid signature causes a failure s
*/
void SchnorrTest::testPermutedSigFail() {
CryptoKernel::Schnorr *tempSchnorr = new CryptoKernel::Schnorr();
std::string signature = tempSchnorr->signSingle(plainText);
CPPUNIT_ASSERT(signature.size() > 0);
const std::string pubKey = tempSchnorr->getPublicKey();
delete tempSchnorr;
tempSchnorr = new CryptoKernel::Schnorr();
CPPUNIT_ASSERT(schnorr->setPublicKey(pubKey));
CPPUNIT_ASSERT(schnorr->verify(plainText, signature));
signature.replace(0, 1, "0");
signature.replace(5, 1, "C");
signature.replace(10, 1, "D");
CPPUNIT_ASSERT(!schnorr->verify(plainText, signature));
delete tempSchnorr;
}
void SchnorrTest::testSamePubkeyAfterSign() {
const std::string publicKey = schnorr->getPublicKey();
schnorr->signSingle(plainText);
CPPUNIT_ASSERT_EQUAL(publicKey, schnorr->getPublicKey());
}