-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathecdsa_test.c
216 lines (198 loc) · 23 KB
/
ecdsa_test.c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include "ecdsa.h"
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <assert.h>
int static is_equal(uint8_t* r, uint8_t* s, uint8_t* expected_r, uint8_t* expected_s){
for(int i =0; i< 32; i++){
if(r[i]!=expected_r[i] || s[i]!=expected_s[i]){
return 0;
}
}
return 1;
}
void sig_gen_test(){
/*
Msg = 5905238877c77421f73e43ee3da6f2d9e2ccad5fc942dcec0cbd25482935faaf416983fe165b1a045ee2bcd2e6dca3bdf46c4310a7461f9a37960ca672d3feb5473e253605fb1ddfd28065b53cb5858a8ad28175bf9bd386a5e471ea7a65c17cc934a9d791e91491eb3754d03799790fe2d308d16146d5c9b0d0debd97d79ce8
d = 519b423d715f8b581f4fa8ee59f4771a5b44c8130b4e3eacca54a56dda72b464
Qx = 1ccbe91c075fc7f4f033bfa248db8fccd3565de94bbfb12f3c59ff46c271bf83
Qy = ce4014c68811f9a21a1fdb2c0e6113e06db7ca93b7404e78dc7ccd5ca89a4ca9
k = 94a1bbb14b906a61a280f245f9e93c7f3b4a6247824f5d33b9670787642a68de
R = f3ac8061b514795b8843e3d6629527ed2afd6b1f6a555a7acabb5e6f79c8c2ac
S = 8bf77819ca05a6b2786c76262bf7371cef97b218e96f175a3ccdda2acc058903
*/
uint8_t msg[128] ={0xe8, 0x9c, 0xd7, 0x97, 0xbd, 0xde, 0xd0, 0xb0, 0xc9, 0xd5, 0x46, 0x61, 0xd1, 0x08, 0xd3, 0xe2, 0x0f, 0x79, 0x99, 0x37, 0xd0, 0x54, 0x37, 0xeb, 0x91, 0x14, 0xe9, 0x91, 0xd7, 0xa9, 0x34, 0xc9, 0x7c, 0xc1, 0x65, 0x7a, 0xea, 0x71, 0xe4, 0xa5, 0x86, 0xd3, 0x9b, 0xbf, 0x75, 0x81, 0xd2, 0x8a, 0x8a, 0x85, 0xb5, 0x3c, 0xb5, 0x65, 0x80, 0xd2, 0xdf, 0x1d, 0xfb, 0x05, 0x36, 0x25, 0x3e, 0x47, 0xb5, 0xfe, 0xd3, 0x72, 0xa6, 0x0c, 0x96, 0x37, 0x9a, 0x1f, 0x46, 0xa7, 0x10, 0x43, 0x6c, 0xf4, 0xbd, 0xa3, 0xdc, 0xe6, 0xd2, 0xbc, 0xe2, 0x5e, 0x04, 0x1a, 0x5b, 0x16, 0xfe, 0x83, 0x69, 0x41, 0xaf, 0xfa, 0x35, 0x29, 0x48, 0x25, 0xbd, 0x0c, 0xec, 0xdc, 0x42, 0xc9, 0x5f, 0xad, 0xcc, 0xe2, 0xd9, 0xf2, 0xa6, 0x3d, 0xee, 0x43, 0x3e, 0xf7, 0x21, 0x74, 0xc7, 0x77, 0x88, 0x23, 0x05, 0x59};
size_t mlen = 1024;
uint8_t d[32] = {0x64, 0xb4, 0x72, 0xda, 0x6d, 0xa5, 0x54, 0xca, 0xac, 0x3e, 0x4e, 0x0b, 0x13, 0xc8, 0x44, 0x5b, 0x1a, 0x77, 0xf4, 0x59, 0xee, 0xa8, 0x4f, 0x1f, 0x58, 0x8b, 0x5f, 0x71, 0x3d, 0x42, 0x9b, 0x51};
uint8_t k[32] = {0xde, 0x68, 0x2a, 0x64, 0x87, 0x07, 0x67, 0xb9, 0x33, 0x5d, 0x4f, 0x82, 0x47, 0x62, 0x4a, 0x3b, 0x7f, 0x3c, 0xe9, 0xf9, 0x45, 0xf2, 0x80, 0xa2, 0x61, 0x6a, 0x90, 0x4b, 0xb1, 0xbb, 0xa1, 0x94};
uint8_t expected_s[32]={0x03, 0x89, 0x05, 0xcc, 0x2a, 0xda, 0xcd, 0x3c, 0x5a, 0x17, 0x6f, 0xe9, 0x18, 0xb2, 0x97, 0xef, 0x1c, 0x37, 0xf7, 0x2b, 0x26, 0x76, 0x6c, 0x78, 0xb2, 0xa6, 0x05, 0xca, 0x19, 0x78, 0xf7, 0x8b};
uint8_t expected_r[32]={0xac, 0xc2, 0xc8, 0x79, 0x6f, 0x5e, 0xbb, 0xca, 0x7a, 0x5a, 0x55, 0x6a, 0x1f, 0x6b, 0xfd, 0x2a, 0xed, 0x27, 0x95, 0x62, 0xd6, 0xe3, 0x43, 0x88, 0x5b, 0x79, 0x14, 0xb5, 0x61, 0x80, 0xac, 0xf3};
uint8_t s[32]={0};
uint8_t r[32]={0};
ecdsa_p256_sha256_sign(r, s, d, k, msg, mlen);
assert(is_equal(r, s, expected_r, expected_s));
printf("PASS signature gen test case 1\n");
/*
Msg = c35e2f092553c55772926bdbe87c9796827d17024dbb9233a545366e2e5987dd344deb72df987144b8c6c43bc41b654b94cc856e16b96d7a821c8ec039b503e3d86728c494a967d83011a0e090b5d54cd47f4e366c0912bc808fbb2ea96efac88fb3ebec9342738e225f7c7c2b011ce375b56621a20642b4d36e060db4524af1
d = 0f56db78ca460b055c500064824bed999a25aaf48ebb519ac201537b85479813
Qx = e266ddfdc12668db30d4ca3e8f7749432c416044f2d2b8c10bf3d4012aeffa8a
Qy = bfa86404a2e9ffe67d47c587ef7a97a7f456b863b4d02cfc6928973ab5b1cb39
k = 6d3e71882c3b83b156bb14e0ab184aa9fb728068d3ae9fac421187ae0b2f34c6
R = 976d3a4e9d23326dc0baa9fa560b7c4e53f42864f508483a6473b6a11079b2db
S = 1b766e9ceb71ba6c01dcd46e0af462cd4cfa652ae5017d4555b8eeefe36e1932
*/
uint8_t msg2[128] ={0xf1,0x4a,0x52,0xb4,0x0d,0x06,0x6e,0xd3,0xb4,0x42,0x06,0xa2,0x21,0x66,0xb5,0x75,0xe3,0x1c,0x01,0x2b,0x7c,0x7c,0x5f,0x22,0x8e,0x73,0x42,0x93,0xec,0xeb,0xb3,0x8f,0xc8,0xfa,0x6e,0xa9,0x2e,0xbb,0x8f,0x80,0xbc,0x12,0x09,0x6c,0x36,0x4e,0x7f,0xd4,0x4c,0xd5,0xb5,0x90,0xe0,0xa0,0x11,0x30,0xd8,0x67,0xa9,0x94,0xc4,0x28,0x67,0xd8,0xe3,0x03,0xb5,0x39,0xc0,0x8e,0x1c,0x82,0x7a,0x6d,0xb9,0x16,0x6e,0x85,0xcc,0x94,0x4b,0x65,0x1b,0xc4,0x3b,0xc4,0xc6,0xb8,0x44,0x71,0x98,0xdf,0x72,0xeb,0x4d,0x34,0xdd,0x87,0x59,0x2e,0x6e,0x36,0x45,0xa5,0x33,0x92,0xbb,0x4d,0x02,0x17,0x7d,0x82,0x96,0x97,0x7c,0xe8,0xdb,0x6b,0x92,0x72,0x57,0xc5,0x53,0x25,0x09,0x2f,0x5e,0xc3};
size_t mlen2 = 1024;
uint8_t d2[32] = {0x13,0x98,0x47,0x85,0x7b,0x53,0x01,0xc2,0x9a,0x51,0xbb,0x8e,0xf4,0xaa,0x25,0x9a,0x99,0xed,0x4b,0x82,0x64,0x00,0x50,0x5c,0x05,0x0b,0x46,0xca,0x78,0xdb,0x56,0x0f};
uint8_t k2[32] = {0xc6,0x34,0x2f,0x0b,0xae,0x87,0x11,0x42,0xac,0x9f,0xae,0xd3,0x68,0x80,0x72,0xfb,0xa9,0x4a,0x18,0xab,0xe0,0x14,0xbb,0x56,0xb1,0x83,0x3b,0x2c,0x88,0x71,0x3e,0x6d};
uint8_t expected_s2[32]={0x32,0x19,0x6e,0xe3,0xef,0xee,0xb8,0x55,0x45,0x7d,0x01,0xe5,0x2a,0x65,0xfa,0x4c,0xcd,0x62,0xf4,0x0a,0x6e,0xd4,0xdc,0x01,0x6c,0xba,0x71,0xeb,0x9c,0x6e,0x76,0x1b};
uint8_t expected_r2[32]={0xdb,0xb2,0x79,0x10,0xa1,0xb6,0x73,0x64,0x3a,0x48,0x08,0xf5,0x64,0x28,0xf4,0x53,0x4e,0x7c,0x0b,0x56,0xfa,0xa9,0xba,0xc0,0x6d,0x32,0x23,0x9d,0x4e,0x3a,0x6d,0x97};
uint8_t s2[32]={0};
uint8_t r2[32]={0};
ecdsa_p256_sha256_sign(r2, s2, d2, k2, msg2, mlen2);
assert(is_equal(r2, s2, expected_r2, expected_s2));
printf("PASS signature gen test case 2\n");
/*
Msg = 0x3c054e333a94259c36af09ab5b4ff9beb3492f8d5b4282d16801daccb29f70fe61a0b37ffef5c04cd1b70e85b1f549a1c4dc672985e50f43ea037efa9964f096b5f62f7ffdf8d6bfb2cc859558f5a393cb949dbd48f269343b5263dcdb9c556eca074f2e98e6d94c2c29a677afaf806edf79b15a3fcd46e7067b7669f83188ee
d = 0xe283871239837e13b95f789e6e1af63bf61c918c992e62bca040d64cad1fc2ef
Qx = 0x74ccd8a62fba0e667c50929a53f78c21b8ff0c3c737b0b40b1750b2302b0bde8
Qy = 0x29074e21f3a0ef88b9efdf10d06aa4c295cc1671f758ca0e4cd108803d0f2614
k = 0xad5e887eb2b380b8d8280ad6e5ff8a60f4d26243e0124c2f31a297b5d0835de2
R = 0x35fb60f5ca0f3ca08542fb3cc641c8263a2cab7a90ee6a5e1583fac2bb6f6bd1
S = 0xee59d81bc9db1055cc0ed97b159d8784af04e98511d0a9a407b99bb292572e96
*/
uint8_t msg3[128] ={0xee,0x88,0x31,0xf8,0x69,0x76,0x7b,0x06,0xe7,0x46,0xcd,0x3f,0x5a,0xb1,0x79,0xdf,0x6e,0x80,0xaf,0xaf,0x77,0xa6,0x29,0x2c,0x4c,0xd9,0xe6,0x98,0x2e,0x4f,0x07,0xca,0x6e,0x55,0x9c,0xdb,0xdc,0x63,0x52,0x3b,0x34,0x69,0xf2,0x48,0xbd,0x9d,0x94,0xcb,0x93,0xa3,0xf5,0x58,0x95,0x85,0xcc,0xb2,0xbf,0xd6,0xf8,0xfd,0x7f,0x2f,0xf6,0xb5,0x96,0xf0,0x64,0x99,0xfa,0x7e,0x03,0xea,0x43,0x0f,0xe5,0x85,0x29,0x67,0xdc,0xc4,0xa1,0x49,0xf5,0xb1,0x85,0x0e,0xb7,0xd1,0x4c,0xc0,0xf5,0xfe,0x7f,0xb3,0xa0,0x61,0xfe,0x70,0x9f,0xb2,0xcc,0xda,0x01,0x68,0xd1,0x82,0x42,0x5b,0x8d,0x2f,0x49,0xb3,0xbe,0xf9,0x4f,0x5b,0xab,0x09,0xaf,0x36,0x9c,0x25,0x94,0x3a,0x33,0x4e,0x05,0x3c};
size_t mlen3 = 1024;
uint8_t d3[32] = {0xef,0xc2,0x1f,0xad,0x4c,0xd6,0x40,0xa0,0xbc,0x62,0x2e,0x99,0x8c,0x91,0x1c,0xf6,0x3b,0xf6,0x1a,0x6e,0x9e,0x78,0x5f,0xb9,0x13,0x7e,0x83,0x39,0x12,0x87,0x83,0xe2};
uint8_t k3[32] = {0xe2,0x5d,0x83,0xd0,0xb5,0x97,0xa2,0x31,0x2f,0x4c,0x12,0xe0,0x43,0x62,0xd2,0xf4,0x60,0x8a,0xff,0xe5,0xd6,0x0a,0x28,0xd8,0xb8,0x80,0xb3,0xb2,0x7e,0x88,0x5e,0xad};
uint8_t expected_r3[32]={0xd1,0x6b,0x6f,0xbb,0xc2,0xfa,0x83,0x15,0x5e,0x6a,0xee,0x90,0x7a,0xab,0x2c,0x3a,0x26,0xc8,0x41,0xc6,0x3c,0xfb,0x42,0x85,0xa0,0x3c,0x0f,0xca,0xf5,0x60,0xfb,0x35};
uint8_t expected_s3[32]={0x96,0x2e,0x57,0x92,0xb2,0x9b,0xb9,0x07,0xa4,0xa9,0xd0,0x11,0x85,0xe9,0x04,0xaf,0x84,0x87,0x9d,0x15,0x7b,0xd9,0x0e,0xcc,0x55,0x10,0xdb,0xc9,0x1b,0xd8,0x59,0xee};
uint8_t s3[32]={0};
uint8_t r3[32]={0};
ecdsa_p256_sha256_sign(r3, s3, d3, k3, msg3, mlen3);
assert(is_equal(r3, s3, expected_r3, expected_s3));
printf("PASS signature gen test case 3\n");
/*
Msg = 0x0989122410d522af64ceb07da2c865219046b4c3d9d99b01278c07ff63eaf1039cb787ae9e2dd46436cc0415f280c562bebb83a23e639e476a02ec8cff7ea06cd12c86dcc3adefbf1a9e9a9b6646c7599ec631b0da9a60debeb9b3e19324977f3b4f36892c8a38671c8e1cc8e50fcd50f9e51deaf98272f9266fc702e4e57c30
d = 0xa3d2d3b7596f6592ce98b4bfe10d41837f10027a90d7bb75349490018cf72d07
Qx = 0x322f80371bf6e044bc49391d97c1714ab87f990b949bc178cb7c43b7c22d89e1
Qy = 0x3c15d54a5cc6b9f09de8457e873eb3deb1fceb54b0b295da6050294fae7fd999
k = 0x24fc90e1da13f17ef9fe84cc96b9471ed1aaac17e3a4bae33a115df4e5834f18
R = 0xd7c562370af617b581c84a2468cc8bd50bb1cbf322de41b7887ce07c0e5884ca
S = 0xb46d9f2d8c4bf83546ff178f1d78937c008d64e8ecc5cbb825cb21d94d670d89
*/
uint8_t msg4[128] ={0x30,0x7c,0xe5,0xe4,0x02,0xc7,0x6f,0x26,0xf9,0x72,0x82,0xf9,0xea,0x1d,0xe5,0xf9,0x50,0xcd,0x0f,0xe5,0xc8,0x1c,0x8e,0x1c,0x67,0x38,0x8a,0x2c,0x89,0x36,0x4f,0x3b,0x7f,0x97,0x24,0x93,0xe1,0xb3,0xb9,0xbe,0xde,0x60,0x9a,0xda,0xb0,0x31,0xc6,0x9e,0x59,0xc7,0x46,0x66,0x9b,0x9a,0x9e,0x1a,0xbf,0xef,0xad,0xc3,0xdc,0x86,0x2c,0xd1,0x6c,0xa0,0x7e,0xff,0x8c,0xec,0x02,0x6a,0x47,0x9e,0x63,0x3e,0xa2,0x83,0xbb,0xbe,0x62,0xc5,0x80,0xf2,0x15,0x04,0xcc,0x36,0x64,0xd4,0x2d,0x9e,0xae,0x87,0xb7,0x9c,0x03,0xf1,0xea,0x63,0xff,0x07,0x8c,0x27,0x01,0x9b,0xd9,0xd9,0xc3,0xb4,0x46,0x90,0x21,0x65,0xc8,0xa2,0x7d,0xb0,0xce,0x64,0xaf,0x22,0xd5,0x10,0x24,0x12,0x89,0x09};
size_t mlen4 = 1024;
uint8_t d4[32] = {0x07,0x2d,0xf7,0x8c,0x01,0x90,0x94,0x34,0x75,0xbb,0xd7,0x90,0x7a,0x02,0x10,0x7f,0x83,0x41,0x0d,0xe1,0xbf,0xb4,0x98,0xce,0x92,0x65,0x6f,0x59,0xb7,0xd3,0xd2,0xa3};
uint8_t k4[32] = {0x18,0x4f,0x83,0xe5,0xf4,0x5d,0x11,0x3a,0xe3,0xba,0xa4,0xe3,0x17,0xac,0xaa,0xd1,0x1e,0x47,0xb9,0x96,0xcc,0x84,0xfe,0xf9,0x7e,0xf1,0x13,0xda,0xe1,0x90,0xfc,0x24};
uint8_t expected_r4[32]={0xca,0x84,0x58,0x0e,0x7c,0xe0,0x7c,0x88,0xb7,0x41,0xde,0x22,0xf3,0xcb,0xb1,0x0b,0xd5,0x8b,0xcc,0x68,0x24,0x4a,0xc8,0x81,0xb5,0x17,0xf6,0x0a,0x37,0x62,0xc5,0xd7};
uint8_t expected_s4[32]={0x89,0x0d,0x67,0x4d,0xd9,0x21,0xcb,0x25,0xb8,0xcb,0xc5,0xec,0xe8,0x64,0x8d,0x00,0x7c,0x93,0x78,0x1d,0x8f,0x17,0xff,0x46,0x35,0xf8,0x4b,0x8c,0x2d,0x9f,0x6d,0xb4};
uint8_t s4[32]={0};
uint8_t r4[32]={0};
ecdsa_p256_sha256_sign(r4, s4, d4, k4, msg4, mlen4);
assert(is_equal(r4, s4, expected_r4, expected_s4));
printf("PASS signature gen test case 4\n");
/*
Msg = 0xdc66e39f9bbfd9865318531ffe9207f934fa615a5b285708a5e9c46b7775150e818d7f24d2a123df3672fff2094e3fd3df6fbe259e3989dd5edfcccbe7d45e26a775a5c4329a084f057c42c13f3248e3fd6f0c76678f890f513c32292dd306eaa84a59abe34b16cb5e38d0e885525d10336ca443e1682aa04a7af832b0eee4e7
d = 0x53a0e8a8fe93db01e7ae94e1a9882a102ebd079b3a535827d583626c272d280d
Qx = 0x1bcec4570e1ec2436596b8ded58f60c3b1ebc6a403bc5543040ba82963057244
Qy = 0x8af62a4c683f096b28558320737bf83b9959a46ad2521004ef74cf85e67494e1
k = 0x5d833e8d24cc7a402d7ee7ec852a3587cddeb48358cea71b0bedb8fabe84e0c4
R = 0x18caaf7b663507a8bcd992b836dec9dc5703c080af5e51dfa3a9a7c387182604
S = 0x77c68928ac3b88d985fb43fb615fb7ff45c18ba5c81af796c613dfa98352d29c
*/
uint8_t msg5[128] ={0xe7,0xe4,0xee,0xb0,0x32,0xf8,0x7a,0x4a,0xa0,0x2a,0x68,0xe1,0x43,0xa4,0x6c,0x33,0x10,0x5d,0x52,0x85,0xe8,0xd0,0x38,0x5e,0xcb,0x16,0x4b,0xe3,0xab,0x59,0x4a,0xa8,0xea,0x06,0xd3,0x2d,0x29,0x32,0x3c,0x51,0x0f,0x89,0x8f,0x67,0x76,0x0c,0x6f,0xfd,0xe3,0x48,0x32,0x3f,0xc1,0x42,0x7c,0x05,0x4f,0x08,0x9a,0x32,0xc4,0xa5,0x75,0xa7,0x26,0x5e,0xd4,0xe7,0xcb,0xcc,0xdf,0x5e,0xdd,0x89,0x39,0x9e,0x25,0xbe,0x6f,0xdf,0xd3,0x3f,0x4e,0x09,0xf2,0xff,0x72,0x36,0xdf,0x23,0xa1,0xd2,0x24,0x7f,0x8d,0x81,0x0e,0x15,0x75,0x77,0x6b,0xc4,0xe9,0xa5,0x08,0x57,0x28,0x5b,0x5a,0x61,0xfa,0x34,0xf9,0x07,0x92,0xfe,0x1f,0x53,0x18,0x53,0x86,0xd9,0xbf,0x9b,0x9f,0xe3,0x66,0xdc};
size_t mlen5 = 1024;
uint8_t d5[32] = {0x0d,0x28,0x2d,0x27,0x6c,0x62,0x83,0xd5,0x27,0x58,0x53,0x3a,0x9b,0x07,0xbd,0x2e,0x10,0x2a,0x88,0xa9,0xe1,0x94,0xae,0xe7,0x01,0xdb,0x93,0xfe,0xa8,0xe8,0xa0,0x53};
uint8_t k5[32] = {0xc4,0xe0,0x84,0xbe,0xfa,0xb8,0xed,0x0b,0x1b,0xa7,0xce,0x58,0x83,0xb4,0xde,0xcd,0x87,0x35,0x2a,0x85,0xec,0xe7,0x7e,0x2d,0x40,0x7a,0xcc,0x24,0x8d,0x3e,0x83,0x5d};
uint8_t expected_r5[32]={0x04,0x26,0x18,0x87,0xc3,0xa7,0xa9,0xa3,0xdf,0x51,0x5e,0xaf,0x80,0xc0,0x03,0x57,0xdc,0xc9,0xde,0x36,0xb8,0x92,0xd9,0xbc,0xa8,0x07,0x35,0x66,0x7b,0xaf,0xca,0x18};
uint8_t expected_s5[32]={0x9c,0xd2,0x52,0x83,0xa9,0xdf,0x13,0xc6,0x96,0xf7,0x1a,0xc8,0xa5,0x8b,0xc1,0x45,0xff,0xb7,0x5f,0x61,0xfb,0x43,0xfb,0x85,0xd9,0x88,0x3b,0xac,0x28,0x89,0xc6,0x77};
uint8_t s5[32]={0};
uint8_t r5[32]={0};
ecdsa_p256_sha256_sign(r5, s5, d5, k5, msg5, mlen5);
assert(is_equal(r5, s5, expected_r5, expected_s5));
printf("PASS signature gen test case 5\n");
}
void sig_ver_test(){
uint8_t msg[128] ={0xe8, 0x9c, 0xd7, 0x97, 0xbd, 0xde, 0xd0, 0xb0, 0xc9, 0xd5, 0x46, 0x61, 0xd1, 0x08, 0xd3, 0xe2, 0x0f, 0x79, 0x99, 0x37, 0xd0, 0x54, 0x37, 0xeb, 0x91, 0x14, 0xe9, 0x91, 0xd7, 0xa9, 0x34, 0xc9, 0x7c, 0xc1, 0x65, 0x7a, 0xea, 0x71, 0xe4, 0xa5, 0x86, 0xd3, 0x9b, 0xbf, 0x75, 0x81, 0xd2, 0x8a, 0x8a, 0x85, 0xb5, 0x3c, 0xb5, 0x65, 0x80, 0xd2, 0xdf, 0x1d, 0xfb, 0x05, 0x36, 0x25, 0x3e, 0x47, 0xb5, 0xfe, 0xd3, 0x72, 0xa6, 0x0c, 0x96, 0x37, 0x9a, 0x1f, 0x46, 0xa7, 0x10, 0x43, 0x6c, 0xf4, 0xbd, 0xa3, 0xdc, 0xe6, 0xd2, 0xbc, 0xe2, 0x5e, 0x04, 0x1a, 0x5b, 0x16, 0xfe, 0x83, 0x69, 0x41, 0xaf, 0xfa, 0x35, 0x29, 0x48, 0x25, 0xbd, 0x0c, 0xec, 0xdc, 0x42, 0xc9, 0x5f, 0xad, 0xcc, 0xe2, 0xd9, 0xf2, 0xa6, 0x3d, 0xee, 0x43, 0x3e, 0xf7, 0x21, 0x74, 0xc7, 0x77, 0x88, 0x23, 0x05, 0x59};
size_t mlen = 1024;
uint8_t qx[32] ={0x83,0xbf,0x71,0xc2,0x46,0xff,0x59,0x3c,0x2f,0xb1,0xbf,0x4b,0xe9,0x5d,0x56,0xd3,0xcc,0x8f,0xdb,0x48,0xa2,0xbf,0x33,0xf0,0xf4,0xc7,0x5f,0x07,0x1c,0xe9,0xcb,0x1c};
uint8_t qy[32] ={0xa9,0x4c,0x9a,0xa8,0x5c,0xcd,0x7c,0xdc,0x78,0x4e,0x40,0xb7,0x93,0xca,0xb7,0x6d,0xe0,0x13,0x61,0x0e,0x2c,0xdb,0x1f,0x1a,0xa2,0xf9,0x11,0x88,0xc6,0x14,0x40,0xce};
uint8_t expected_s[32]={0x03, 0x89, 0x05, 0xcc, 0x2a, 0xda, 0xcd, 0x3c, 0x5a, 0x17, 0x6f, 0xe9, 0x18, 0xb2, 0x97, 0xef, 0x1c, 0x37, 0xf7, 0x2b, 0x26, 0x76, 0x6c, 0x78, 0xb2, 0xa6, 0x05, 0xca, 0x19, 0x78, 0xf7, 0x8b};
uint8_t expected_r[32]={0xac, 0xc2, 0xc8, 0x79, 0x6f, 0x5e, 0xbb, 0xca, 0x7a, 0x5a, 0x55, 0x6a, 0x1f, 0x6b, 0xfd, 0x2a, 0xed, 0x27, 0x95, 0x62, 0xd6, 0xe3, 0x43, 0x88, 0x5b, 0x79, 0x14, 0xb5, 0x61, 0x80, 0xac, 0xf3};
assert(ecdsa_p256_sha256_verify(expected_r, expected_s, qx, qy, msg, mlen));
printf("PASS signature verify test case 1\n");
/*
Msg = c35e2f092553c55772926bdbe87c9796827d17024dbb9233a545366e2e5987dd344deb72df987144b8c6c43bc41b654b94cc856e16b96d7a821c8ec039b503e3d86728c494a967d83011a0e090b5d54cd47f4e366c0912bc808fbb2ea96efac88fb3ebec9342738e225f7c7c2b011ce375b56621a20642b4d36e060db4524af1
d = 0f56db78ca460b055c500064824bed999a25aaf48ebb519ac201537b85479813
Qx = e266ddfdc12668db30d4ca3e8f7749432c416044f2d2b8c10bf3d4012aeffa8a
Qy = bfa86404a2e9ffe67d47c587ef7a97a7f456b863b4d02cfc6928973ab5b1cb39
k = 6d3e71882c3b83b156bb14e0ab184aa9fb728068d3ae9fac421187ae0b2f34c6
R = 976d3a4e9d23326dc0baa9fa560b7c4e53f42864f508483a6473b6a11079b2db
S = 1b766e9ceb71ba6c01dcd46e0af462cd4cfa652ae5017d4555b8eeefe36e1932
*/
uint8_t msg2[128] ={0xf1,0x4a,0x52,0xb4,0x0d,0x06,0x6e,0xd3,0xb4,0x42,0x06,0xa2,0x21,0x66,0xb5,0x75,0xe3,0x1c,0x01,0x2b,0x7c,0x7c,0x5f,0x22,0x8e,0x73,0x42,0x93,0xec,0xeb,0xb3,0x8f,0xc8,0xfa,0x6e,0xa9,0x2e,0xbb,0x8f,0x80,0xbc,0x12,0x09,0x6c,0x36,0x4e,0x7f,0xd4,0x4c,0xd5,0xb5,0x90,0xe0,0xa0,0x11,0x30,0xd8,0x67,0xa9,0x94,0xc4,0x28,0x67,0xd8,0xe3,0x03,0xb5,0x39,0xc0,0x8e,0x1c,0x82,0x7a,0x6d,0xb9,0x16,0x6e,0x85,0xcc,0x94,0x4b,0x65,0x1b,0xc4,0x3b,0xc4,0xc6,0xb8,0x44,0x71,0x98,0xdf,0x72,0xeb,0x4d,0x34,0xdd,0x87,0x59,0x2e,0x6e,0x36,0x45,0xa5,0x33,0x92,0xbb,0x4d,0x02,0x17,0x7d,0x82,0x96,0x97,0x7c,0xe8,0xdb,0x6b,0x92,0x72,0x57,0xc5,0x53,0x25,0x09,0x2f,0x5e,0xc3};
size_t mlen2 = 1024;
uint8_t qx2[32] ={0x8a,0xfa,0xef,0x2a,0x01,0xd4,0xf3,0x0b,0xc1,0xb8,0xd2,0xf2,0x44,0x60,0x41,0x2c,0x43,0x49,0x77,0x8f,0x3e,0xca,0xd4,0x30,0xdb,0x68,0x26,0xc1,0xfd,0xdd,0x66,0xe2};
uint8_t qy2[32] ={0x39,0xcb,0xb1,0xb5,0x3a,0x97,0x28,0x69,0xfc,0x2c,0xd0,0xb4,0x63,0xb8,0x56,0xf4,0xa7,0x97,0x7a,0xef,0x87,0xc5,0x47,0x7d,0xe6,0xff,0xe9,0xa2,0x04,0x64,0xa8,0xbf};
uint8_t expected_s2[32]={0x32,0x19,0x6e,0xe3,0xef,0xee,0xb8,0x55,0x45,0x7d,0x01,0xe5,0x2a,0x65,0xfa,0x4c,0xcd,0x62,0xf4,0x0a,0x6e,0xd4,0xdc,0x01,0x6c,0xba,0x71,0xeb,0x9c,0x6e,0x76,0x1b};
uint8_t expected_r2[32]={0xdb,0xb2,0x79,0x10,0xa1,0xb6,0x73,0x64,0x3a,0x48,0x08,0xf5,0x64,0x28,0xf4,0x53,0x4e,0x7c,0x0b,0x56,0xfa,0xa9,0xba,0xc0,0x6d,0x32,0x23,0x9d,0x4e,0x3a,0x6d,0x97};
assert(ecdsa_p256_sha256_verify(expected_r2, expected_s2, qx2, qy2, msg2, mlen2));
printf("PASS signature verify test case 2\n");
/*
Msg = 0x3c054e333a94259c36af09ab5b4ff9beb3492f8d5b4282d16801daccb29f70fe61a0b37ffef5c04cd1b70e85b1f549a1c4dc672985e50f43ea037efa9964f096b5f62f7ffdf8d6bfb2cc859558f5a393cb949dbd48f269343b5263dcdb9c556eca074f2e98e6d94c2c29a677afaf806edf79b15a3fcd46e7067b7669f83188ee
d = 0xe283871239837e13b95f789e6e1af63bf61c918c992e62bca040d64cad1fc2ef
Qx = 0x74ccd8a62fba0e667c50929a53f78c21b8ff0c3c737b0b40b1750b2302b0bde8
Qy = 0x29074e21f3a0ef88b9efdf10d06aa4c295cc1671f758ca0e4cd108803d0f2614
k = 0xad5e887eb2b380b8d8280ad6e5ff8a60f4d26243e0124c2f31a297b5d0835de2
R = 0x35fb60f5ca0f3ca08542fb3cc641c8263a2cab7a90ee6a5e1583fac2bb6f6bd1
S = 0xee59d81bc9db1055cc0ed97b159d8784af04e98511d0a9a407b99bb292572e96
*/
uint8_t msg3[128] ={0xee,0x88,0x31,0xf8,0x69,0x76,0x7b,0x06,0xe7,0x46,0xcd,0x3f,0x5a,0xb1,0x79,0xdf,0x6e,0x80,0xaf,0xaf,0x77,0xa6,0x29,0x2c,0x4c,0xd9,0xe6,0x98,0x2e,0x4f,0x07,0xca,0x6e,0x55,0x9c,0xdb,0xdc,0x63,0x52,0x3b,0x34,0x69,0xf2,0x48,0xbd,0x9d,0x94,0xcb,0x93,0xa3,0xf5,0x58,0x95,0x85,0xcc,0xb2,0xbf,0xd6,0xf8,0xfd,0x7f,0x2f,0xf6,0xb5,0x96,0xf0,0x64,0x99,0xfa,0x7e,0x03,0xea,0x43,0x0f,0xe5,0x85,0x29,0x67,0xdc,0xc4,0xa1,0x49,0xf5,0xb1,0x85,0x0e,0xb7,0xd1,0x4c,0xc0,0xf5,0xfe,0x7f,0xb3,0xa0,0x61,0xfe,0x70,0x9f,0xb2,0xcc,0xda,0x01,0x68,0xd1,0x82,0x42,0x5b,0x8d,0x2f,0x49,0xb3,0xbe,0xf9,0x4f,0x5b,0xab,0x09,0xaf,0x36,0x9c,0x25,0x94,0x3a,0x33,0x4e,0x05,0x3c};
size_t mlen3 = 1024;
uint8_t qx3[32] ={0xe8,0xbd,0xb0,0x02,0x23,0x0b,0x75,0xb1,0x40,0x0b,0x7b,0x73,0x3c,0x0c,0xff,0xb8,0x21,0x8c,0xf7,0x53,0x9a,0x92,0x50,0x7c,0x66,0x0e,0xba,0x2f,0xa6,0xd8,0xcc,0x74};
uint8_t qy3[32] ={0x14,0x26,0x0f,0x3d,0x80,0x08,0xd1,0x4c,0x0e,0xca,0x58,0xf7,0x71,0x16,0xcc,0x95,0xc2,0xa4,0x6a,0xd0,0x10,0xdf,0xef,0xb9,0x88,0xef,0xa0,0xf3,0x21,0x4e,0x07,0x29};
uint8_t expected_r3[32]={0xd1,0x6b,0x6f,0xbb,0xc2,0xfa,0x83,0x15,0x5e,0x6a,0xee,0x90,0x7a,0xab,0x2c,0x3a,0x26,0xc8,0x41,0xc6,0x3c,0xfb,0x42,0x85,0xa0,0x3c,0x0f,0xca,0xf5,0x60,0xfb,0x35};
uint8_t expected_s3[32]={0x96,0x2e,0x57,0x92,0xb2,0x9b,0xb9,0x07,0xa4,0xa9,0xd0,0x11,0x85,0xe9,0x04,0xaf,0x84,0x87,0x9d,0x15,0x7b,0xd9,0x0e,0xcc,0x55,0x10,0xdb,0xc9,0x1b,0xd8,0x59,0xee};
assert(ecdsa_p256_sha256_verify(expected_r3, expected_s3, qx3, qy3, msg3, mlen3));
printf("PASS signature verify test case 3\n");
/*
Msg = 0x0989122410d522af64ceb07da2c865219046b4c3d9d99b01278c07ff63eaf1039cb787ae9e2dd46436cc0415f280c562bebb83a23e639e476a02ec8cff7ea06cd12c86dcc3adefbf1a9e9a9b6646c7599ec631b0da9a60debeb9b3e19324977f3b4f36892c8a38671c8e1cc8e50fcd50f9e51deaf98272f9266fc702e4e57c30
d = 0xa3d2d3b7596f6592ce98b4bfe10d41837f10027a90d7bb75349490018cf72d07
Qx = 0x322f80371bf6e044bc49391d97c1714ab87f990b949bc178cb7c43b7c22d89e1
Qy = 0x3c15d54a5cc6b9f09de8457e873eb3deb1fceb54b0b295da6050294fae7fd999
k = 0x24fc90e1da13f17ef9fe84cc96b9471ed1aaac17e3a4bae33a115df4e5834f18
R = 0xd7c562370af617b581c84a2468cc8bd50bb1cbf322de41b7887ce07c0e5884ca
S = 0xb46d9f2d8c4bf83546ff178f1d78937c008d64e8ecc5cbb825cb21d94d670d89
*/
uint8_t msg4[128] ={0x30,0x7c,0xe5,0xe4,0x02,0xc7,0x6f,0x26,0xf9,0x72,0x82,0xf9,0xea,0x1d,0xe5,0xf9,0x50,0xcd,0x0f,0xe5,0xc8,0x1c,0x8e,0x1c,0x67,0x38,0x8a,0x2c,0x89,0x36,0x4f,0x3b,0x7f,0x97,0x24,0x93,0xe1,0xb3,0xb9,0xbe,0xde,0x60,0x9a,0xda,0xb0,0x31,0xc6,0x9e,0x59,0xc7,0x46,0x66,0x9b,0x9a,0x9e,0x1a,0xbf,0xef,0xad,0xc3,0xdc,0x86,0x2c,0xd1,0x6c,0xa0,0x7e,0xff,0x8c,0xec,0x02,0x6a,0x47,0x9e,0x63,0x3e,0xa2,0x83,0xbb,0xbe,0x62,0xc5,0x80,0xf2,0x15,0x04,0xcc,0x36,0x64,0xd4,0x2d,0x9e,0xae,0x87,0xb7,0x9c,0x03,0xf1,0xea,0x63,0xff,0x07,0x8c,0x27,0x01,0x9b,0xd9,0xd9,0xc3,0xb4,0x46,0x90,0x21,0x65,0xc8,0xa2,0x7d,0xb0,0xce,0x64,0xaf,0x22,0xd5,0x10,0x24,0x12,0x89,0x09};
size_t mlen4 = 1024;
uint8_t qx4[32] = {0xe1,0x89,0x2d,0xc2,0xb7,0x43,0x7c,0xcb,0x78,0xc1,0x9b,0x94,0x0b,0x99,0x7f,0xb8,0x4a,0x71,0xc1,0x97,0x1d,0x39,0x49,0xbc,0x44,0xe0,0xf6,0x1b,0x37,0x80,0x2f,0x32};
uint8_t qy4[32] = {0x99,0xd9,0x7f,0xae,0x4f,0x29,0x50,0x60,0xda,0x95,0xb2,0xb0,0x54,0xeb,0xfc,0xb1,0xde,0xb3,0x3e,0x87,0x7e,0x45,0xe8,0x9d,0xf0,0xb9,0xc6,0x5c,0x4a,0xd5,0x15,0x3c};
uint8_t expected_r4[32]={0xca,0x84,0x58,0x0e,0x7c,0xe0,0x7c,0x88,0xb7,0x41,0xde,0x22,0xf3,0xcb,0xb1,0x0b,0xd5,0x8b,0xcc,0x68,0x24,0x4a,0xc8,0x81,0xb5,0x17,0xf6,0x0a,0x37,0x62,0xc5,0xd7};
uint8_t expected_s4[32]={0x89,0x0d,0x67,0x4d,0xd9,0x21,0xcb,0x25,0xb8,0xcb,0xc5,0xec,0xe8,0x64,0x8d,0x00,0x7c,0x93,0x78,0x1d,0x8f,0x17,0xff,0x46,0x35,0xf8,0x4b,0x8c,0x2d,0x9f,0x6d,0xb4};
assert(ecdsa_p256_sha256_verify(expected_r4, expected_s4, qx4, qy4, msg4, mlen4));
printf("PASS signature verify test case 4\n");
/*
Msg = 0xdc66e39f9bbfd9865318531ffe9207f934fa615a5b285708a5e9c46b7775150e818d7f24d2a123df3672fff2094e3fd3df6fbe259e3989dd5edfcccbe7d45e26a775a5c4329a084f057c42c13f3248e3fd6f0c76678f890f513c32292dd306eaa84a59abe34b16cb5e38d0e885525d10336ca443e1682aa04a7af832b0eee4e7
d = 0x53a0e8a8fe93db01e7ae94e1a9882a102ebd079b3a535827d583626c272d280d
Qx = 0x1bcec4570e1ec2436596b8ded58f60c3b1ebc6a403bc5543040ba82963057244
Qy = 0x8af62a4c683f096b28558320737bf83b9959a46ad2521004ef74cf85e67494e1
k = 0x5d833e8d24cc7a402d7ee7ec852a3587cddeb48358cea71b0bedb8fabe84e0c4
R = 0x18caaf7b663507a8bcd992b836dec9dc5703c080af5e51dfa3a9a7c387182604
S = 0x77c68928ac3b88d985fb43fb615fb7ff45c18ba5c81af796c613dfa98352d29c
*/
uint8_t msg5[128] ={0xe7,0xe4,0xee,0xb0,0x32,0xf8,0x7a,0x4a,0xa0,0x2a,0x68,0xe1,0x43,0xa4,0x6c,0x33,0x10,0x5d,0x52,0x85,0xe8,0xd0,0x38,0x5e,0xcb,0x16,0x4b,0xe3,0xab,0x59,0x4a,0xa8,0xea,0x06,0xd3,0x2d,0x29,0x32,0x3c,0x51,0x0f,0x89,0x8f,0x67,0x76,0x0c,0x6f,0xfd,0xe3,0x48,0x32,0x3f,0xc1,0x42,0x7c,0x05,0x4f,0x08,0x9a,0x32,0xc4,0xa5,0x75,0xa7,0x26,0x5e,0xd4,0xe7,0xcb,0xcc,0xdf,0x5e,0xdd,0x89,0x39,0x9e,0x25,0xbe,0x6f,0xdf,0xd3,0x3f,0x4e,0x09,0xf2,0xff,0x72,0x36,0xdf,0x23,0xa1,0xd2,0x24,0x7f,0x8d,0x81,0x0e,0x15,0x75,0x77,0x6b,0xc4,0xe9,0xa5,0x08,0x57,0x28,0x5b,0x5a,0x61,0xfa,0x34,0xf9,0x07,0x92,0xfe,0x1f,0x53,0x18,0x53,0x86,0xd9,0xbf,0x9b,0x9f,0xe3,0x66,0xdc};
size_t mlen5 = 1024;
uint8_t qx5[32] = {0x44,0x72,0x05,0x63,0x29,0xa8,0x0b,0x04,0x43,0x55,0xbc,0x03,0xa4,0xc6,0xeb,0xb1,0xc3,0x60,0x8f,0xd5,0xde,0xb8,0x96,0x65,0x43,0xc2,0x1e,0x0e,0x57,0xc4,0xce,0x1b};
uint8_t qy5[32] = {0xe1,0x94,0x74,0xe6,0x85,0xcf,0x74,0xef,0x04,0x10,0x52,0xd2,0x6a,0xa4,0x59,0x99,0x3b,0xf8,0x7b,0x73,0x20,0x83,0x55,0x28,0x6b,0x09,0x3f,0x68,0x4c,0x2a,0xf6,0x8a};
uint8_t expected_r5[32]={0x04,0x26,0x18,0x87,0xc3,0xa7,0xa9,0xa3,0xdf,0x51,0x5e,0xaf,0x80,0xc0,0x03,0x57,0xdc,0xc9,0xde,0x36,0xb8,0x92,0xd9,0xbc,0xa8,0x07,0x35,0x66,0x7b,0xaf,0xca,0x18};
uint8_t expected_s5[32]={0x9c,0xd2,0x52,0x83,0xa9,0xdf,0x13,0xc6,0x96,0xf7,0x1a,0xc8,0xa5,0x8b,0xc1,0x45,0xff,0xb7,0x5f,0x61,0xfb,0x43,0xfb,0x85,0xd9,0x88,0x3b,0xac,0x28,0x89,0xc6,0x77};
assert(ecdsa_p256_sha256_verify(expected_r5, expected_s5, qx5, qy5, msg5, mlen5));
printf("PASS signature verify test case 5\n");
}
int main(){
ECDSA_DEBUG = false;
sig_gen_test();
sig_ver_test();
}