forked from cryptozeny/zny_yespower_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.c
145 lines (120 loc) · 4.59 KB
/
tests.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
/*-
* Copyright 2013-2018 Alexander Peslyak
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include "yespower.h"
#undef TEST_PBKDF2_SHA256
#ifdef TEST_PBKDF2_SHA256
#include <assert.h>
#include "sha256.h"
static void print_PBKDF2_SHA256_raw(const char *passwd, size_t passwdlen,
const char *salt, size_t saltlen, uint64_t c, size_t dkLen)
{
uint8_t dk[64];
int i;
assert(dkLen <= sizeof(dk));
/* XXX This prints the strings truncated at first NUL */
printf("PBKDF2_SHA256(\"%s\", \"%s\", %llu, %llu) = ",
passwd, salt, (unsigned long long)c, (unsigned long long)dkLen);
PBKDF2_SHA256((const uint8_t *) passwd, passwdlen,
(const uint8_t *) salt, saltlen, c, dk, dkLen);
for (i = 0; i < dkLen; i++)
printf("%02x%c", dk[i], i < dkLen - 1 ? ' ' : '\n');
}
static void print_PBKDF2_SHA256(const char *passwd,
const char *salt, uint64_t c, size_t dkLen)
{
print_PBKDF2_SHA256_raw(passwd, strlen(passwd), salt, strlen(salt), c,
dkLen);
}
#endif
static const char *pers_bsty_magic = "BSTY";
static void print_yespower(yespower_version_t version, uint32_t N, uint32_t r,
const char *pers)
{
yespower_params_t params = {
.version = version,
.N = N,
.r = r,
.pers = (const uint8_t *)pers,
.perslen = pers ? strlen(pers) : 0
};
uint8_t src[80];
yespower_binary_t dst;
int i;
const char *q = (pers && pers != pers_bsty_magic) ? "\"": "";
printf("yespower(%u, %u, %u, %s%s%s) = ", version, N, r,
q, pers ? pers : "NULL", q);
for (i = 0; i < sizeof(src); i++)
src[i] = i * 3;
if (pers == pers_bsty_magic) {
params.pers = src;
params.perslen = sizeof(src);
}
if (yespower_tls(src, sizeof(src), ¶ms, &dst)) {
puts("FAILED");
return;
}
for (i = 0; i < sizeof(dst); i++)
printf("%02x%c", dst.uc[i], i < sizeof(dst) - 1 ? ' ' : '\n');
}
int main(int argc, const char * const *argv)
{
setvbuf(stdout, NULL, _IOLBF, 0);
#ifdef TEST_PBKDF2_SHA256
print_PBKDF2_SHA256("password", "salt", 1, 20);
print_PBKDF2_SHA256("password", "salt", 2, 20);
print_PBKDF2_SHA256("password", "salt", 4096, 20);
print_PBKDF2_SHA256("password", "salt", 16777216, 20);
print_PBKDF2_SHA256("passwordPASSWORDpassword",
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 4096, 25);
print_PBKDF2_SHA256_raw("pass\0word", 9, "sa\0lt", 5, 4096, 16);
#if 0
print_PBKDF2_SHA256("password", "salt", 1, 32);
print_PBKDF2_SHA256("password", "salt", 2, 32);
print_PBKDF2_SHA256("password", "salt", 4096, 32);
print_PBKDF2_SHA256("password", "salt", 16777216, 32);
print_PBKDF2_SHA256("passwordPASSWORDpassword",
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 4096, 40);
print_PBKDF2_SHA256("password", "salt", 4096, 16);
print_PBKDF2_SHA256("password", "salt", 1, 20);
print_PBKDF2_SHA256("password", "salt", 2, 20);
print_PBKDF2_SHA256("password", "salt", 4096, 20);
print_PBKDF2_SHA256("password", "salt", 16777216, 20);
print_PBKDF2_SHA256("password", "salt", 4096, 25);
print_PBKDF2_SHA256("password", "salt", 4096, 16);
#endif
#endif
print_yespower(YESPOWER_0_5, 2048, 8, "Client Key"); /* yescrypt 0.5 */
print_yespower(YESPOWER_0_5, 2048, 8, pers_bsty_magic); /* BSTY */
print_yespower(YESPOWER_0_5, 4096, 16, "Client Key"); /* Cryply */
print_yespower(YESPOWER_0_5, 4096, 24, "Jagaricoin");
print_yespower(YESPOWER_0_5, 4096, 32, "WaviBanana");
print_yespower(YESPOWER_0_5, 2048, 32, "Client Key");
print_yespower(YESPOWER_0_5, 1024, 32, "Client Key");
print_yespower(YESPOWER_0_5, 2048, 8, NULL); /* no personality */
print_yespower(YESPOWER_0_9, 2048, 8, NULL);
print_yespower(YESPOWER_0_9, 4096, 16, NULL);
print_yespower(YESPOWER_0_9, 4096, 32, NULL);
print_yespower(YESPOWER_0_9, 2048, 32, NULL);
print_yespower(YESPOWER_0_9, 1024, 32, NULL);
print_yespower(YESPOWER_0_9, 1024, 32, "personality test");
return 0;
}