-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecure_id_test.cpp
More file actions
56 lines (43 loc) · 1.41 KB
/
secure_id_test.cpp
File metadata and controls
56 lines (43 loc) · 1.41 KB
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
#include "gtest/gtest.h"
#include "secure_id.hpp"
class SecureIDTest : public ::testing::Test {
protected:
void SetUp() override {
secret_key = SecureID::SecretKey::generate();
public_key = secret_key.public_key();
}
void TearDown() override {
}
SecureID::SecretKey secret_key;
SecureID::PublicKey public_key;
};
TEST_F(SecureIDTest, compute) {
const char msg[9] = "38654201";
unsigned char signed_id[SID_BYTE_SIZE];
secret_key.sign1(signed_id, msg, 8);
mcl::bn::Fr random;
random.setByCSPRNG();
unsigned char blinded[SID_BYTE_SIZE], signed2[SID_BYTE_SIZE], unblinded[SID_BYTE_SIZE];
public_key.blind(blinded, msg, 8, &random);
secret_key.sign2(signed2, blinded);
public_key.unblind(unblinded, signed2, &random);
for (int i = 0; i < SID_BYTE_SIZE; ++i) {
ASSERT_EQ(signed_id[i], unblinded[i]);
}
}
TEST_F(SecureIDTest, sign1) {
SecureID::SecretKey sk;
*reinterpret_cast<mcl::bn::Fr*>(&sk) = 123456;
unsigned char signed_id[SID_BYTE_SIZE];
sk.sign1(signed_id, "hello world", 11);
char hex[SID_BYTE_SIZE * 2];
char *ptr = hex;
for (unsigned char i : signed_id) {
ptr += sprintf(ptr, "%02x", i);
}
ASSERT_STREQ("120a19ba42d66e3b07f9b1042ecc241658b98fbd0066ac3a98ec7cd55e487b15", hex);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}