-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributed_signer_test.cc
73 lines (53 loc) · 1.84 KB
/
distributed_signer_test.cc
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
#include <glog/logging.h>
#include <gtest/gtest.h>
#include "sm2/distributed_sm2_pubkey.h"
#include "sm2/distributed_sm2_signer.h"
#include "sm2/distributed_sm2_verifier.h"
namespace primihub::crypto {
static std::string gen_random(uint32_t len) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
std::string tmp_s;
tmp_s.reserve(len);
for (uint32_t i = 0; i < len; ++i)
tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)];
return tmp_s;
}
TEST(DistributedSM2Signature, DistributedSM2Signature) {
srand(time(nullptr));
uint32_t rand_len = rand() % 10000;
std::string rand_str = gen_random(rand_len);
DistributedSM2Pubkeygen party0("12345678");
DistributedSM2Pubkeygen party1("12345678");
party0.cal_P_part();
party1.cal_P_part();
std::string P_part_str;
party0.export_P_part(P_part_str);
party1.import_P_part(P_part_str);
party1.cal_P_reconst();
std::string PublicKey_str;
party1.export_PublicKey(PublicKey_str);
party0.import_PublicKey(PublicKey_str);
DistributedSM2Signature signer_p0(party0);
DistributedSM2Signature signer_p1(party1);
// signer_p0.cal_Q1(rand_str);
signer_p0.cal_Q1(rand_str);
std::string e_and_q1;
signer_p0.export_e_Q1(e_and_q1);
signer_p1.import_e_Q1(e_and_q1);
signer_p1.cal_S2();
std::string r_s2_s3;
signer_p1.export_r_S2_S3(r_s2_s3);
signer_p0.import_r_S2_S3(r_s2_s3);
std::string r, s;
signer_p0.get_signature_result(r, s);
DistributedSM2Verification verifier_P0(signer_p0);
LOG(INFO) << "Signature result is " << r << ", " << s << ".";
auto sign_result = std::make_pair(r, s);
LOG(INFO) << "Begin the process of verification......";
verifier_P0.get_verification_result(sign_result, rand_str);
LOG(INFO) << "End the process of verification......";
}
} // namespace primihub::crypto