forked from dsprenkels/sss
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_generate_combine.c
119 lines (89 loc) · 2.91 KB
/
test_generate_combine.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
#include "slip39.h"
void test_generate_combine(void);
void test_generate_combine_passwords(void);
void test_generate_combine(void) {
char *test = "abcdefghijklmnopqrstuvwxyz.";
unsigned int secret_length = strlen(test)+1;
uint16_t mnemonics[1024];
unsigned char buffer[1024];
unsigned int words_per_share = 0;
group_descriptor groups[3] = {
{2,3, NULL},
{1,1, NULL},
{3,5, NULL}
};
int shares = generate_mnemonics(3, groups, 3, (unsigned char *)test, secret_length,
"", 0,
&words_per_share, mnemonics, 1024);
if(shares < 0) {
printf("An error occurred during generation.\n");
exit(-1);
}
for(int i=0; i < shares; ++i) {
print_mnemonic(mnemonics + i*words_per_share, words_per_share);
printf("\n");
}
const uint16_t* recovery_mnemonics[] = {
// two from the first group
mnemonics, mnemonics + words_per_share,
// one from the second
mnemonics + 3*words_per_share,
// three from the third
mnemonics + 6*words_per_share,
mnemonics + 5*words_per_share,
mnemonics + 4*words_per_share,
};
int result = combine_mnemonics(recovery_mnemonics, words_per_share, 6, "", NULL, buffer, 1024);
if(result < 0) {
printf("Recovery failed. %d\n", result);
exit(-1);
}
printf("%s\n", buffer);
}
void test_generate_combine_passwords(void) {
char *test = "abcdefghijklmnopqrstuvwxyz.";
unsigned int secret_length = strlen(test)+1;
uint16_t mnemonics[1024];
unsigned char buffer[1024];
unsigned int words_per_share = 0;
const char*p1[] = {"a",NULL,"c"};
const char*p3[] = {"e","f", "g", "h", "i"};
group_descriptor groups[3] = {
{2,3, p1},
{1,1, NULL},
{3,5, p3}
};
int shares = generate_mnemonics(3, groups, 3, (unsigned char *)test, secret_length,
"", 0,
&words_per_share, mnemonics, 1024);
if(shares < 0) {
printf("An error occurred during generation.\n");
exit(-1);
}
for(int i=0; i < shares; ++i) {
print_mnemonic(mnemonics + i*words_per_share, words_per_share);
printf("\n");
}
const uint16_t* recovery_mnemonics[] = {
// two from the first group
mnemonics, mnemonics + words_per_share,
// one from the second
mnemonics + 3*words_per_share,
// three from the third
mnemonics + 6*words_per_share,
mnemonics + 5*words_per_share,
mnemonics + 4*words_per_share,
};
const char* passwords[] = {"a", NULL, NULL, "g" ,"f", "e"};
int result = combine_mnemonics(recovery_mnemonics, words_per_share, 6, "", passwords, buffer, 1024);
if(result < 0) {
printf("Recovery failed.\n");
exit(-1);
}
printf("%s\n", buffer);
}
int main(void) {
test_generate_combine();
test_generate_combine_passwords();
return 0;
}