forked from dsprenkels/sss
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_slip39_encrypt.c
67 lines (48 loc) · 1.57 KB
/
test_slip39_encrypt.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
#include "slip39.h"
uint8_t test_round_function(void);
uint8_t test_encrypt_function(void);
uint8_t test_round_function(void) {
uint8_t fail = 0;
// data from this test was taken from running the round function
// on pass one of encrypting the string "abcd" with the empty
// password, and a group identifier of 1234
uint8_t salt[] = { 's', 'h', 'a', 'm', 'i', 'r', 4, 210 };
uint8_t r[] = { 'c', 'd' };
uint8_t d[2];
round_function(0,"",0,salt,8,r,2,d,2);
if(!(d[0] == 183 && d[1] == 32)) {
fail = 1;
}
round_function(0,"TREZOR",0,salt,8,r,2,d,2);
if(!(d[0] == 156 && d[1] == 169)) {
fail = 1;
}
return fail;
}
uint8_t test_encrypt_function(void) {
uint8_t fail = 0;
// Data for this test was generated by running the equivalent
// _encrypt() function in the python reference code
char *input = "abcd";
uint8_t output[4];
slip39_encrypt((uint8_t *)input, 4, "", 0, 1234, output);
if(!(output[0] == 167 && output[1] == 251 && output[2]==61 && output[3] == 147)) {
fail = 1;
}
slip39_encrypt((uint8_t *)input, 4, "TREZOR", 0, 1234, output);
if( !(output[0] == 41 && output[1] == 155 && output[2]==1 && output[3] == 50) ) {
fail = 1;
}
return fail;
}
int main(void) {
uint8_t fail = 0;
uint8_t t;
t=test_round_function();
fail = fail || t;
printf("test round function: %s\n", t ? "fail" : "pass");
t=test_encrypt_function();
fail = fail || t;
printf("test encrypt function: %s\n", t ? "fail" : "pass");
return fail;
}