forked from dsprenkels/sss
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_slip39_wordlist.c
76 lines (58 loc) · 1.45 KB
/
test_slip39_wordlist.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
#include "slip39.h"
uint8_t test_toWords_fromWords(void);
uint8_t test_lookups(void);
#include "slip39_wordlist_english.h"
uint8_t test_lookups(void) {
uint8_t fail = 0;
for(uint16_t i=0; i<1024; ++i) {
int16_t j = lookup(wordlist[i]);
if(i != j) {
fail = 1;
}
}
if(lookup("foobar") != -1) {
fail = 1;
}
if(lookup("aaa") != -1) {
fail = 1;
}
if(lookup("zzz") != -1) {
fail = 1;
}
if(lookup("") != -1) {
fail = 1;
}
return fail;
}
uint8_t test_toWords_fromWords(void) {
uint8_t fail = 0;
char *x = " abcdefghijklmnopqrstuvwxyz";
uint16_t words[25];
uint8_t results[30];
int32_t w;
for(uint8_t i=0; i<26; i+=2) {
w = to_words((uint8_t *)x+i , strlen(x+i)+1, words, 25);
from_words(words, w, results, 30);
if(strcmp((char *)results,x+i) !=0) {
printf("Fail: '%s' != '%s'\n", x+i, results);
//return;
for(unsigned char j=0;j<w;j++) {
printf("%d ", words[j]);
}
printf("\n");
fail = 1;
}
}
return fail;
}
int main(void) {
uint8_t fail =0;
uint8_t t;
t = test_lookups();
fail = fail || t;
printf("Test lookups: %s\n", t ? "fail" : "pass" );
t = test_toWords_fromWords();
fail = fail || t;
printf("Test toWords and fromWords: %s\n", t ? "fail" : "pass" );
return fail;
}