xcrypt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +106 -0
- data/ext/libxcrypt/AUTHORS +38 -0
- data/ext/libxcrypt/COPYING.LIB +502 -0
- data/ext/libxcrypt/ChangeLog +239 -0
- data/ext/libxcrypt/INSTALL +380 -0
- data/ext/libxcrypt/LICENSING +152 -0
- data/ext/libxcrypt/Makefile.am +704 -0
- data/ext/libxcrypt/Makefile.in +4110 -0
- data/ext/libxcrypt/NEWS +630 -0
- data/ext/libxcrypt/README +1 -0
- data/ext/libxcrypt/README.md +179 -0
- data/ext/libxcrypt/THANKS +13 -0
- data/ext/libxcrypt/TODO +1 -0
- data/ext/libxcrypt/TODO.md +100 -0
- data/ext/libxcrypt/aclocal.m4 +2617 -0
- data/ext/libxcrypt/autogen.sh +33 -0
- data/ext/libxcrypt/autom4te.cache/output.0 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.1 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.2 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.3 +19885 -0
- data/ext/libxcrypt/autom4te.cache/requests +714 -0
- data/ext/libxcrypt/autom4te.cache/traces.0 +4088 -0
- data/ext/libxcrypt/autom4te.cache/traces.1 +1060 -0
- data/ext/libxcrypt/autom4te.cache/traces.2 +4088 -0
- data/ext/libxcrypt/autom4te.cache/traces.3 +1060 -0
- data/ext/libxcrypt/build-aux/ci/ci-log-dependency-versions +79 -0
- data/ext/libxcrypt/build-aux/ci/ci-log-logfiles +22 -0
- data/ext/libxcrypt/build-aux/ci/clang-gcov-wrapper +2 -0
- data/ext/libxcrypt/build-aux/ci/configure-wrapper +10 -0
- data/ext/libxcrypt/build-aux/ci/summarize-coverage +24 -0
- data/ext/libxcrypt/build-aux/m4/ax_append_compile_flags.m4 +46 -0
- data/ext/libxcrypt/build-aux/m4/ax_append_flag.m4 +50 -0
- data/ext/libxcrypt/build-aux/m4/ax_check_compile_flag.m4 +53 -0
- data/ext/libxcrypt/build-aux/m4/ax_check_vscript.m4 +142 -0
- data/ext/libxcrypt/build-aux/m4/ax_gcc_func_attribute.m4 +246 -0
- data/ext/libxcrypt/build-aux/m4/ax_require_defined.m4 +37 -0
- data/ext/libxcrypt/build-aux/m4/ax_valgrind_check.m4 +239 -0
- data/ext/libxcrypt/build-aux/m4/libtool.m4 +8488 -0
- data/ext/libxcrypt/build-aux/m4/ltoptions.m4 +467 -0
- data/ext/libxcrypt/build-aux/m4/ltsugar.m4 +124 -0
- data/ext/libxcrypt/build-aux/m4/ltversion.m4 +24 -0
- data/ext/libxcrypt/build-aux/m4/lt~obsolete.m4 +99 -0
- data/ext/libxcrypt/build-aux/m4/pkg_compat.m4 +88 -0
- data/ext/libxcrypt/build-aux/m4/zw_alignment.m4 +90 -0
- data/ext/libxcrypt/build-aux/m4/zw_automodern.m4 +307 -0
- data/ext/libxcrypt/build-aux/m4/zw_detect_asan.m4 +24 -0
- data/ext/libxcrypt/build-aux/m4/zw_endianness.m4 +152 -0
- data/ext/libxcrypt/build-aux/m4/zw_ld_wrap.m4 +47 -0
- data/ext/libxcrypt/build-aux/m4/zw_prog_perl.m4 +40 -0
- data/ext/libxcrypt/build-aux/m4/zw_simple_warnings.m4 +150 -0
- data/ext/libxcrypt/build-aux/m4/zw_static_assert.m4 +68 -0
- data/ext/libxcrypt/build-aux/m4-autogen/compile +364 -0
- data/ext/libxcrypt/build-aux/m4-autogen/config.guess +1815 -0
- data/ext/libxcrypt/build-aux/m4-autogen/config.sub +2354 -0
- data/ext/libxcrypt/build-aux/m4-autogen/depcomp +792 -0
- data/ext/libxcrypt/build-aux/m4-autogen/install-sh +541 -0
- data/ext/libxcrypt/build-aux/m4-autogen/ltmain.sh +11524 -0
- data/ext/libxcrypt/build-aux/m4-autogen/missing +236 -0
- data/ext/libxcrypt/build-aux/m4-autogen/test-driver +160 -0
- data/ext/libxcrypt/build-aux/scripts/BuildCommon.pm +712 -0
- data/ext/libxcrypt/build-aux/scripts/check-perlcritic-config +76 -0
- data/ext/libxcrypt/build-aux/scripts/compute-symver-floor +116 -0
- data/ext/libxcrypt/build-aux/scripts/expand-selected-hashes +80 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-h +131 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-hashes-h +141 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-symbol-vers-h +150 -0
- data/ext/libxcrypt/build-aux/scripts/gen-libcrypt-map +67 -0
- data/ext/libxcrypt/build-aux/scripts/move-if-change +84 -0
- data/ext/libxcrypt/build-aux/scripts/skip-if-exec-format-error +78 -0
- data/ext/libxcrypt/codecov.yml +4 -0
- data/ext/libxcrypt/config.h.in +303 -0
- data/ext/libxcrypt/configure +19885 -0
- data/ext/libxcrypt/configure.ac +549 -0
- data/ext/libxcrypt/doc/crypt.3 +512 -0
- data/ext/libxcrypt/doc/crypt.5 +343 -0
- data/ext/libxcrypt/doc/crypt_checksalt.3 +106 -0
- data/ext/libxcrypt/doc/crypt_gensalt.3 +285 -0
- data/ext/libxcrypt/doc/crypt_gensalt_ra.3 +1 -0
- data/ext/libxcrypt/doc/crypt_gensalt_rn.3 +1 -0
- data/ext/libxcrypt/doc/crypt_preferred_method.3 +68 -0
- data/ext/libxcrypt/doc/crypt_r.3 +1 -0
- data/ext/libxcrypt/doc/crypt_ra.3 +1 -0
- data/ext/libxcrypt/doc/crypt_rn.3 +1 -0
- data/ext/libxcrypt/lib/alg-des-tables.c +3858 -0
- data/ext/libxcrypt/lib/alg-des.c +269 -0
- data/ext/libxcrypt/lib/alg-des.h +74 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-const.h +313 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-core.c +238 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-core.h +51 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.c +78 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.h +46 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-precalc.h +1426 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-ref.h +67 -0
- data/ext/libxcrypt/lib/alg-hmac-sha1.c +140 -0
- data/ext/libxcrypt/lib/alg-hmac-sha1.h +35 -0
- data/ext/libxcrypt/lib/alg-md4.c +270 -0
- data/ext/libxcrypt/lib/alg-md4.h +43 -0
- data/ext/libxcrypt/lib/alg-md5.c +291 -0
- data/ext/libxcrypt/lib/alg-md5.h +43 -0
- data/ext/libxcrypt/lib/alg-sha1.c +288 -0
- data/ext/libxcrypt/lib/alg-sha1.h +34 -0
- data/ext/libxcrypt/lib/alg-sha256.c +630 -0
- data/ext/libxcrypt/lib/alg-sha256.h +123 -0
- data/ext/libxcrypt/lib/alg-sha512.c +311 -0
- data/ext/libxcrypt/lib/alg-sha512.h +81 -0
- data/ext/libxcrypt/lib/alg-sm3-hmac.c +113 -0
- data/ext/libxcrypt/lib/alg-sm3-hmac.h +42 -0
- data/ext/libxcrypt/lib/alg-sm3.c +449 -0
- data/ext/libxcrypt/lib/alg-sm3.h +63 -0
- data/ext/libxcrypt/lib/alg-yescrypt-common.c +713 -0
- data/ext/libxcrypt/lib/alg-yescrypt-opt.c +1568 -0
- data/ext/libxcrypt/lib/alg-yescrypt-platform.c +106 -0
- data/ext/libxcrypt/lib/alg-yescrypt.h +360 -0
- data/ext/libxcrypt/lib/byteorder.h +164 -0
- data/ext/libxcrypt/lib/crypt-bcrypt.c +1061 -0
- data/ext/libxcrypt/lib/crypt-des-obsolete.c +215 -0
- data/ext/libxcrypt/lib/crypt-des.c +491 -0
- data/ext/libxcrypt/lib/crypt-gensalt-static.c +40 -0
- data/ext/libxcrypt/lib/crypt-gost-yescrypt.c +182 -0
- data/ext/libxcrypt/lib/crypt-md5.c +232 -0
- data/ext/libxcrypt/lib/crypt-nthash.c +134 -0
- data/ext/libxcrypt/lib/crypt-obsolete.h +40 -0
- data/ext/libxcrypt/lib/crypt-pbkdf1-sha1.c +260 -0
- data/ext/libxcrypt/lib/crypt-port.h +514 -0
- data/ext/libxcrypt/lib/crypt-scrypt.c +247 -0
- data/ext/libxcrypt/lib/crypt-sha256.c +308 -0
- data/ext/libxcrypt/lib/crypt-sha512.c +323 -0
- data/ext/libxcrypt/lib/crypt-sm3-yescrypt.c +189 -0
- data/ext/libxcrypt/lib/crypt-sm3.c +308 -0
- data/ext/libxcrypt/lib/crypt-static.c +44 -0
- data/ext/libxcrypt/lib/crypt-sunmd5.c +314 -0
- data/ext/libxcrypt/lib/crypt-yescrypt.c +177 -0
- data/ext/libxcrypt/lib/crypt.c +421 -0
- data/ext/libxcrypt/lib/crypt.h.in +249 -0
- data/ext/libxcrypt/lib/gen-des-tables.c +363 -0
- data/ext/libxcrypt/lib/hashes.conf +59 -0
- data/ext/libxcrypt/lib/libcrypt.map.in +48 -0
- data/ext/libxcrypt/lib/libcrypt.minver +97 -0
- data/ext/libxcrypt/lib/libxcrypt.pc.in +15 -0
- data/ext/libxcrypt/lib/util-base64.c +26 -0
- data/ext/libxcrypt/lib/util-gensalt-sha.c +88 -0
- data/ext/libxcrypt/lib/util-get-random-bytes.c +154 -0
- data/ext/libxcrypt/lib/util-make-failure-token.c +48 -0
- data/ext/libxcrypt/lib/util-xbzero.c +43 -0
- data/ext/libxcrypt/lib/util-xstrcpy.c +42 -0
- data/ext/libxcrypt/lib/xcrypt.h.in +58 -0
- data/ext/libxcrypt/libxcrypt.spec.rpkg +481 -0
- data/ext/libxcrypt/rpkg.conf +2 -0
- data/ext/libxcrypt/rpkg.macros +86 -0
- data/ext/libxcrypt/test/TestCommon.pm +326 -0
- data/ext/libxcrypt/test/alg-des.c +80 -0
- data/ext/libxcrypt/test/alg-gost3411-2012-hmac.c +90 -0
- data/ext/libxcrypt/test/alg-gost3411-2012.c +191 -0
- data/ext/libxcrypt/test/alg-hmac-sha1.c +187 -0
- data/ext/libxcrypt/test/alg-md4.c +111 -0
- data/ext/libxcrypt/test/alg-md5.c +134 -0
- data/ext/libxcrypt/test/alg-pbkdf-hmac-sha256.c +269 -0
- data/ext/libxcrypt/test/alg-sha1.c +111 -0
- data/ext/libxcrypt/test/alg-sha256.c +141 -0
- data/ext/libxcrypt/test/alg-sha512.c +170 -0
- data/ext/libxcrypt/test/alg-sm3-hmac.c +149 -0
- data/ext/libxcrypt/test/alg-sm3.c +168 -0
- data/ext/libxcrypt/test/alg-yescrypt.c +466 -0
- data/ext/libxcrypt/test/badsalt.c +726 -0
- data/ext/libxcrypt/test/badsetting.c +350 -0
- data/ext/libxcrypt/test/byteorder.c +254 -0
- data/ext/libxcrypt/test/checksalt.c +265 -0
- data/ext/libxcrypt/test/compile-strong-alias.c +43 -0
- data/ext/libxcrypt/test/crypt-badargs.c +392 -0
- data/ext/libxcrypt/test/crypt-gost-yescrypt.c +149 -0
- data/ext/libxcrypt/test/crypt-nested-call.c +180 -0
- data/ext/libxcrypt/test/crypt-sm3-yescrypt.c +149 -0
- data/ext/libxcrypt/test/crypt-too-long-phrase.c +157 -0
- data/ext/libxcrypt/test/des-cases.h +196 -0
- data/ext/libxcrypt/test/des-obsolete.c +206 -0
- data/ext/libxcrypt/test/des-obsolete_r.c +207 -0
- data/ext/libxcrypt/test/explicit-bzero.c +334 -0
- data/ext/libxcrypt/test/gensalt-bcrypt_x.c +54 -0
- data/ext/libxcrypt/test/gensalt-extradata.c +246 -0
- data/ext/libxcrypt/test/gensalt-nested-call.c +126 -0
- data/ext/libxcrypt/test/gensalt-nthash.c +65 -0
- data/ext/libxcrypt/test/gensalt.c +599 -0
- data/ext/libxcrypt/test/getrandom-fallbacks.c +295 -0
- data/ext/libxcrypt/test/getrandom-interface.c +211 -0
- data/ext/libxcrypt/test/ka-table-gen.py +945 -0
- data/ext/libxcrypt/test/ka-table.inc +5849 -0
- data/ext/libxcrypt/test/ka-tester.c +240 -0
- data/ext/libxcrypt/test/preferred-method.c +133 -0
- data/ext/libxcrypt/test/short-outbuf.c +119 -0
- data/ext/libxcrypt/test/special-char-salt.c +1160 -0
- data/ext/libxcrypt/test/symbols-compat.pl +137 -0
- data/ext/libxcrypt/test/symbols-renames.pl +107 -0
- data/ext/libxcrypt/test/symbols-static.pl +87 -0
- data/ext/xcrypt/xcrypt.c +9 -0
- data/lib/xcrypt/ffi.rb +76 -0
- data/lib/xcrypt/version.rb +5 -0
- data/lib/xcrypt.rb +89 -0
- metadata +267 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2017, Björn Esser <besser82@fedoraproject.org>
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions
|
|
7
|
+
* are met:
|
|
8
|
+
*
|
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
|
11
|
+
*
|
|
12
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
14
|
+
* documentation and/or other materials provided with the distribution.
|
|
15
|
+
*
|
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
20
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
21
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
22
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
#include "crypt-port.h"
|
|
30
|
+
#include "alg-sha1.h"
|
|
31
|
+
#include "alg-hmac-sha1.h"
|
|
32
|
+
|
|
33
|
+
#include <stdio.h>
|
|
34
|
+
#include <stdlib.h>
|
|
35
|
+
|
|
36
|
+
#if INCLUDE_sha1crypt
|
|
37
|
+
|
|
38
|
+
#define HASH_LENGTH 20
|
|
39
|
+
|
|
40
|
+
static char *
|
|
41
|
+
bin_to_char (char *buf, size_t bufsz, const char *data, size_t nbytes)
|
|
42
|
+
{
|
|
43
|
+
size_t i;
|
|
44
|
+
|
|
45
|
+
buf[0] = '\0';
|
|
46
|
+
if (bufsz <= (nbytes * 2))
|
|
47
|
+
return NULL;
|
|
48
|
+
for (i = 0; i < nbytes; i++)
|
|
49
|
+
{
|
|
50
|
+
(void)sprintf (&buf[i*2], "%02x", (unsigned char)data[i]);
|
|
51
|
+
}
|
|
52
|
+
return buf;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static int
|
|
56
|
+
char_to_bin (char *buf, size_t bufsz, const char *data, size_t nbytes)
|
|
57
|
+
{
|
|
58
|
+
size_t i;
|
|
59
|
+
uint32_t c;
|
|
60
|
+
|
|
61
|
+
if (nbytes < 1)
|
|
62
|
+
nbytes = strlen (data);
|
|
63
|
+
nbytes /= 2;
|
|
64
|
+
if (bufsz <= nbytes)
|
|
65
|
+
return 0;
|
|
66
|
+
for (i = 0; i < nbytes; i++)
|
|
67
|
+
{
|
|
68
|
+
if (sscanf (&data[i*2], "%02x", &c) < 1)
|
|
69
|
+
break;
|
|
70
|
+
buf[i] = (char)(c & 0xff);
|
|
71
|
+
}
|
|
72
|
+
buf[i] = 0;
|
|
73
|
+
return (int)i;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/*
|
|
77
|
+
* If a test key or data starts with 0x we'll convert to binary.
|
|
78
|
+
*/
|
|
79
|
+
#define X2B(v, b) do { \
|
|
80
|
+
if (memcmp (v, "0x", 2) == 0) { \
|
|
81
|
+
v += 2; \
|
|
82
|
+
char_to_bin (b, sizeof(b), v, strlen(v)); \
|
|
83
|
+
v = b; \
|
|
84
|
+
} \
|
|
85
|
+
} while (0)
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
* Run some of the known answer tests from RFC 2202.
|
|
89
|
+
*/
|
|
90
|
+
int
|
|
91
|
+
main (void)
|
|
92
|
+
{
|
|
93
|
+
struct test_s
|
|
94
|
+
{
|
|
95
|
+
const char *key;
|
|
96
|
+
const char *data;
|
|
97
|
+
const char *expect;
|
|
98
|
+
const size_t data_size;
|
|
99
|
+
} tests[] =
|
|
100
|
+
{
|
|
101
|
+
{
|
|
102
|
+
"0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
|
|
103
|
+
"Hi There",
|
|
104
|
+
"0xb617318655057264e28bc0b6fb378c8ef146be00",
|
|
105
|
+
8,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"Jefe",
|
|
109
|
+
"what do ya want for nothing?",
|
|
110
|
+
"0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
|
|
111
|
+
28,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
115
|
+
"0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
|
|
116
|
+
"0x125d7342b9ac11cd91a39af48aa17b4f63f175d3",
|
|
117
|
+
50,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"0x0102030405060708090a0b0c0d0e0f10111213141516171819",
|
|
121
|
+
"0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd",
|
|
122
|
+
"0x4c9007f4026250c6bc8414f9bf50c86c2d7235da",
|
|
123
|
+
50,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c",
|
|
127
|
+
"Test With Truncation",
|
|
128
|
+
"0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04",
|
|
129
|
+
20,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
133
|
+
"Test Using Larger Than Block-Size Key - Hash Key First",
|
|
134
|
+
"0xaa4ae5e15272d00e95705637ce8a3b55ed402112",
|
|
135
|
+
54,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
139
|
+
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
|
|
140
|
+
"0xe8e99d0f45237d786d6bbaa7965c7808bbff1a91",
|
|
141
|
+
73,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
0, 0, 0, 0,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
struct test_s *test = tests;
|
|
148
|
+
char digest[HASH_LENGTH];
|
|
149
|
+
char kbuf[BUFSIZ];
|
|
150
|
+
char dbuf[BUFSIZ];
|
|
151
|
+
int n = 0;
|
|
152
|
+
|
|
153
|
+
for (test = tests; test->key; test++)
|
|
154
|
+
{
|
|
155
|
+
X2B(test->key, kbuf);
|
|
156
|
+
X2B(test->data, dbuf);
|
|
157
|
+
hmac_sha1_process_data ((const uint8_t *)test->data, test->data_size,
|
|
158
|
+
(const uint8_t *)test->key, strlen(test->key), digest);
|
|
159
|
+
strncpy (dbuf, "0x", BUFSIZ);
|
|
160
|
+
bin_to_char (&dbuf[2], (sizeof dbuf) - 2, digest, HASH_LENGTH);
|
|
161
|
+
|
|
162
|
+
if (strcmp (dbuf, test->expect) != 0)
|
|
163
|
+
{
|
|
164
|
+
n = 1;
|
|
165
|
+
fputs ("\nkey=", stdout);
|
|
166
|
+
fputs (test->key, stdout);
|
|
167
|
+
fputs (", data=", stdout);
|
|
168
|
+
fputs (test->data, stdout);
|
|
169
|
+
fputs (",\nresult=", stdout);
|
|
170
|
+
fputs (dbuf, stdout);
|
|
171
|
+
fputs (": ", stdout);
|
|
172
|
+
fputs (test->expect, stdout);
|
|
173
|
+
fputs ("\n", stdout);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return n;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
#else
|
|
180
|
+
|
|
181
|
+
int
|
|
182
|
+
main (void)
|
|
183
|
+
{
|
|
184
|
+
return 77; /* UNSUPPORTED */
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
#endif
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#include "crypt-port.h"
|
|
2
|
+
#include "alg-md4.h"
|
|
3
|
+
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
|
|
6
|
+
#if INCLUDE_nt
|
|
7
|
+
|
|
8
|
+
static const struct
|
|
9
|
+
{
|
|
10
|
+
const char *input;
|
|
11
|
+
const char result[16 + 1] ;
|
|
12
|
+
} tests[] =
|
|
13
|
+
{
|
|
14
|
+
/* Test vectors as defined in RFC 1320, appendix A, section 5.
|
|
15
|
+
https://tools.ietf.org/html/rfc1320#appendix-A.5 */
|
|
16
|
+
{
|
|
17
|
+
"",
|
|
18
|
+
"\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"a",
|
|
22
|
+
"\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb\x24"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"abc",
|
|
26
|
+
"\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"message digest",
|
|
30
|
+
"\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01\x4b"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
34
|
+
"\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d\xa9"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
38
|
+
"\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
|
42
|
+
"\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05\x36"
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
static void
|
|
47
|
+
report_failure(int n, const char *tag,
|
|
48
|
+
const char expected[16], uint8_t actual[16])
|
|
49
|
+
{
|
|
50
|
+
int i;
|
|
51
|
+
printf ("FAIL: test %d (%s):\n exp:", n, tag);
|
|
52
|
+
for (i = 0; i < 16; i++)
|
|
53
|
+
{
|
|
54
|
+
if (i % 4 == 0)
|
|
55
|
+
putchar (' ');
|
|
56
|
+
printf ("%02x", (unsigned int)(unsigned char)expected[i]);
|
|
57
|
+
}
|
|
58
|
+
printf ("\n got:");
|
|
59
|
+
for (i = 0; i < 16; i++)
|
|
60
|
+
{
|
|
61
|
+
if (i % 4 == 0)
|
|
62
|
+
putchar (' ');
|
|
63
|
+
printf ("%02x", (unsigned int)(unsigned char)actual[i]);
|
|
64
|
+
}
|
|
65
|
+
putchar ('\n');
|
|
66
|
+
putchar ('\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
int
|
|
70
|
+
main (void)
|
|
71
|
+
{
|
|
72
|
+
MD4_CTX ctx;
|
|
73
|
+
uint8_t sum[16];
|
|
74
|
+
int result = 0;
|
|
75
|
+
int cnt;
|
|
76
|
+
int i;
|
|
77
|
+
|
|
78
|
+
for (cnt = 0; cnt < (int) ARRAY_SIZE (tests); ++cnt)
|
|
79
|
+
{
|
|
80
|
+
MD4_Init (&ctx);
|
|
81
|
+
MD4_Update (&ctx, tests[cnt].input, strlen (tests[cnt].input));
|
|
82
|
+
MD4_Final (sum, &ctx);
|
|
83
|
+
if (memcmp (tests[cnt].result, sum, 16))
|
|
84
|
+
{
|
|
85
|
+
report_failure (cnt, "all at once", tests[cnt].result, sum);
|
|
86
|
+
result = 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
MD4_Init (&ctx);
|
|
90
|
+
for (i = 0; tests[cnt].input[i] != '\0'; ++i)
|
|
91
|
+
MD4_Update (&ctx, &tests[cnt].input[i], 1);
|
|
92
|
+
MD4_Final (sum, &ctx);
|
|
93
|
+
if (memcmp (tests[cnt].result, sum, 16))
|
|
94
|
+
{
|
|
95
|
+
report_failure (cnt, "byte by byte", tests[cnt].result, sum);
|
|
96
|
+
result = 1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#else
|
|
104
|
+
|
|
105
|
+
int
|
|
106
|
+
main (void)
|
|
107
|
+
{
|
|
108
|
+
return 77; /* UNSUPPORTED */
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#endif
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#include "crypt-port.h"
|
|
2
|
+
#include "alg-md5.h"
|
|
3
|
+
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
|
|
6
|
+
#if INCLUDE_md5crypt || INCLUDE_sunmd5
|
|
7
|
+
|
|
8
|
+
static const struct
|
|
9
|
+
{
|
|
10
|
+
const char *input;
|
|
11
|
+
const char result[16 + 1];
|
|
12
|
+
} tests[] =
|
|
13
|
+
{
|
|
14
|
+
/* "Informal" test vectors from
|
|
15
|
+
https://www.nist.gov/itl/ssd/software-quality-group/nsrl-test-data
|
|
16
|
+
(these were once in FIPS 180-2, but MD5 has been withdrawn). */
|
|
17
|
+
{
|
|
18
|
+
"abc",
|
|
19
|
+
"\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
|
23
|
+
"\x82\x15\xef\x07\x96\xa2\x0b\xca\xaa\xe1\x16\xd3\x87\x6c\x66\x4a"
|
|
24
|
+
},
|
|
25
|
+
/* Test vectors from the NESSIE project. */
|
|
26
|
+
{
|
|
27
|
+
"",
|
|
28
|
+
"\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"a",
|
|
32
|
+
"\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"message digest",
|
|
36
|
+
"\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
40
|
+
"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
44
|
+
"\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"123456789012345678901234567890123456789012345678901234567890"
|
|
48
|
+
"12345678901234567890",
|
|
49
|
+
"\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6\x7a"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
static void
|
|
54
|
+
report_failure(int n, const char *tag,
|
|
55
|
+
const char expected[16], uint8_t actual[16])
|
|
56
|
+
{
|
|
57
|
+
int i;
|
|
58
|
+
printf ("FAIL: test %d (%s):\n exp:", n, tag);
|
|
59
|
+
for (i = 0; i < 16; i++)
|
|
60
|
+
{
|
|
61
|
+
if (i % 4 == 0)
|
|
62
|
+
putchar (' ');
|
|
63
|
+
printf ("%02x", (unsigned int)(unsigned char)expected[i]);
|
|
64
|
+
}
|
|
65
|
+
printf ("\n got:");
|
|
66
|
+
for (i = 0; i < 16; i++)
|
|
67
|
+
{
|
|
68
|
+
if (i % 4 == 0)
|
|
69
|
+
putchar (' ');
|
|
70
|
+
printf ("%02x", (unsigned int)(unsigned char)actual[i]);
|
|
71
|
+
}
|
|
72
|
+
putchar ('\n');
|
|
73
|
+
putchar ('\n');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
int
|
|
77
|
+
main (void)
|
|
78
|
+
{
|
|
79
|
+
MD5_CTX ctx;
|
|
80
|
+
uint8_t sum[16];
|
|
81
|
+
int result = 0;
|
|
82
|
+
int cnt;
|
|
83
|
+
int i;
|
|
84
|
+
|
|
85
|
+
for (cnt = 0; cnt < (int) ARRAY_SIZE (tests); ++cnt)
|
|
86
|
+
{
|
|
87
|
+
MD5_Init (&ctx);
|
|
88
|
+
MD5_Update (&ctx, tests[cnt].input, strlen (tests[cnt].input));
|
|
89
|
+
MD5_Final (sum, &ctx);
|
|
90
|
+
if (memcmp (tests[cnt].result, sum, 16))
|
|
91
|
+
{
|
|
92
|
+
report_failure (cnt, "all at once", tests[cnt].result, sum);
|
|
93
|
+
result = 1;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
MD5_Init (&ctx);
|
|
97
|
+
for (i = 0; tests[cnt].input[i] != '\0'; ++i)
|
|
98
|
+
MD5_Update (&ctx, &tests[cnt].input[i], 1);
|
|
99
|
+
MD5_Final (sum, &ctx);
|
|
100
|
+
if (memcmp (tests[cnt].result, sum, 16))
|
|
101
|
+
{
|
|
102
|
+
report_failure (cnt, "byte by byte", tests[cnt].result, sum);
|
|
103
|
+
result = 1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* The third "informal" test vector from
|
|
108
|
+
<https://www.nist.gov/itl/ssd/software-quality-group/nsrl-test-data>. */
|
|
109
|
+
char buf[1000];
|
|
110
|
+
memset (buf, 'a', sizeof (buf));
|
|
111
|
+
MD5_Init (&ctx);
|
|
112
|
+
for (i = 0; i < 1000; ++i)
|
|
113
|
+
MD5_Update (&ctx, buf, sizeof (buf));
|
|
114
|
+
MD5_Final (sum, &ctx);
|
|
115
|
+
static const char expected[64] =
|
|
116
|
+
"\x77\x07\xd6\xae\x4e\x02\x7c\x70\xee\xa2\xa9\x35\xc2\x29\x6f\x21";
|
|
117
|
+
if (memcmp (expected, sum, 16) != 0)
|
|
118
|
+
{
|
|
119
|
+
report_failure (cnt, "block by block", expected, sum);
|
|
120
|
+
result = 1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#else
|
|
127
|
+
|
|
128
|
+
int
|
|
129
|
+
main (void)
|
|
130
|
+
{
|
|
131
|
+
return 77; /* UNSUPPORTED */
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#endif
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/* Test HMAC_SHA256 and PBKDF2_HMAC_SHA256 implementations.
|
|
2
|
+
*
|
|
3
|
+
* Written by Zack Weinberg <zackw at panix.com> in 2018.
|
|
4
|
+
* Incorporates standard test vectors from sources documented below.
|
|
5
|
+
* To the extent possible under law, the named authors have waived all
|
|
6
|
+
* copyright and related or neighboring rights to this work.
|
|
7
|
+
*
|
|
8
|
+
* See https://creativecommons.org/publicdomain/zero/1.0/ for further
|
|
9
|
+
* details.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include "crypt-port.h"
|
|
13
|
+
#include "alg-sha256.h"
|
|
14
|
+
|
|
15
|
+
#include <stdio.h>
|
|
16
|
+
|
|
17
|
+
#if INCLUDE_scrypt || INCLUDE_yescrypt || INCLUDE_gost_yescrypt
|
|
18
|
+
|
|
19
|
+
struct hmac_sha256_test
|
|
20
|
+
{
|
|
21
|
+
const char *key;
|
|
22
|
+
const char *message;
|
|
23
|
+
uint8_t digest[32 + 1];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/* HMAC-SHA256 test vectors from RFC 4231. */
|
|
27
|
+
static const struct hmac_sha256_test hmac_sha256_tests[] =
|
|
28
|
+
{
|
|
29
|
+
{
|
|
30
|
+
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
|
|
31
|
+
"\x0b\x0b\x0b\x0b",
|
|
32
|
+
"Hi There",
|
|
33
|
+
"\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b"
|
|
34
|
+
"\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"Jefe",
|
|
38
|
+
"what do ya want for nothing?",
|
|
39
|
+
"\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75\xc7"
|
|
40
|
+
"\x5a\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec\x38\x43"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
44
|
+
"\xaa\xaa\xaa\xaa",
|
|
45
|
+
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
|
|
46
|
+
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
|
|
47
|
+
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
|
|
48
|
+
"\xdd\xdd",
|
|
49
|
+
"\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81\xa7"
|
|
50
|
+
"\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5\x65\xfe"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
|
|
54
|
+
"\x11\x12\x13\x14\x15\x16\x17\x18\x19",
|
|
55
|
+
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
|
|
56
|
+
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
|
|
57
|
+
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
|
|
58
|
+
"\xcd\xcd",
|
|
59
|
+
"\x82\x55\x8a\x38\x9a\x44\x3c\x0e\xa4\xcc\x81\x98\x99\xf2\x08\x3a"
|
|
60
|
+
"\x85\xf0\xfa\xa3\xe5\x78\xf8\x07\x7a\x2e\x3f\xf4\x67\x29\x66\x5b"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
|
|
64
|
+
"\x0c\x0c\x0c\x0c",
|
|
65
|
+
"Test With Truncation",
|
|
66
|
+
/* N.B. the RFC only supplies the high 16 bytes of this vector; the rest
|
|
67
|
+
were filled in with the current implementation's output. */
|
|
68
|
+
"\xa3\xb6\x16\x74\x73\x10\x0e\xe0\x6e\x0c\x79\x6c\x29\x55\x55\x2b"
|
|
69
|
+
"\xfa\x6f\x7c\x0a\x6a\x8a\xef\x8b\x93\xf8\x60\xaa\xb0\xcd\x20\xc5"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
73
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
74
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
75
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
76
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
77
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
78
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
79
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
80
|
+
"\xaa\xaa\xaa",
|
|
81
|
+
"Test Using Larger Than Block-Size Key - Hash Key First",
|
|
82
|
+
"\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7\x7f"
|
|
83
|
+
"\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3\x7f\x54"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
87
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
88
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
89
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
90
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
91
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
92
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
93
|
+
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
|
94
|
+
"\xaa\xaa\xaa",
|
|
95
|
+
"This is a test using a larger than block-size key and a larger t"
|
|
96
|
+
"han block-size data. The key needs to be hashed before being use"
|
|
97
|
+
"d by the HMAC algorithm.",
|
|
98
|
+
"\x9b\x09\xff\xa7\x1b\x94\x2f\xcb\x27\x63\x5f\xbc\xd5\xb0\xe9\x44"
|
|
99
|
+
"\xbf\xdc\x63\x64\x4f\x07\x13\x93\x8a\x7f\x51\x53\x5c\x3a\x35\xe2"
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
struct pbkdf2_hmac_sha256_test
|
|
104
|
+
{
|
|
105
|
+
const char *passwd;
|
|
106
|
+
const char *salt;
|
|
107
|
+
uint32_t plen;
|
|
108
|
+
uint32_t slen;
|
|
109
|
+
uint32_t c;
|
|
110
|
+
uint32_t dklen;
|
|
111
|
+
const char *dk; /* [dklen] */
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
struct pbkdf2_hmac_sha256_test pbkdf2_hmac_sha256_tests[] =
|
|
115
|
+
{
|
|
116
|
+
/* PBKDF2-HMAC-SHA256 test vectors from RFC 7914. */
|
|
117
|
+
{
|
|
118
|
+
"passwd", "salt", 6, 4, 1, 64,
|
|
119
|
+
"\x55\xac\x04\x6e\x56\xe3\x08\x9f\xec\x16\x91\xc2\x25\x44\xb6\x05"
|
|
120
|
+
"\xf9\x41\x85\x21\x6d\xde\x04\x65\xe6\x8b\x9d\x57\xc2\x0d\xac\xbc"
|
|
121
|
+
"\x49\xca\x9c\xcc\xf1\x79\xb6\x45\x99\x16\x64\xb3\x9d\x77\xef\x31"
|
|
122
|
+
"\x7c\x71\xb8\x45\xb1\xe3\x0b\xd5\x09\x11\x20\x41\xd3\xa1\x97\x83"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"Password", "NaCl", 8, 4, 80000, 64,
|
|
126
|
+
"\x4d\xdc\xd8\xf6\x0b\x98\xbe\x21\x83\x0c\xee\x5e\xf2\x27\x01\xf9"
|
|
127
|
+
"\x64\x1a\x44\x18\xd0\x4c\x04\x14\xae\xff\x08\x87\x6b\x34\xab\x56"
|
|
128
|
+
"\xa1\xd4\x25\xa1\x22\x58\x33\x54\x9a\xdb\x84\x1b\x51\xc9\xb3\x17"
|
|
129
|
+
"\x6a\x27\x2b\xde\xbb\xa1\xd0\x78\x47\x8f\x62\xb3\x97\xf3\x3c\x8d"
|
|
130
|
+
},
|
|
131
|
+
/* Test vectors from RFC 6070 (which defines PBKDF2-HMAC-SHA1)
|
|
132
|
+
recalculated with SHA256 instead of SHA1 and a larger dklen by
|
|
133
|
+
'aaz' at <https://stackoverflow.com/a/5136918/388520>. */
|
|
134
|
+
{
|
|
135
|
+
"password", "salt", 8, 4, 1, 32,
|
|
136
|
+
"\x12\x0f\xb6\xcf\xfc\xf8\xb3\x2c\x43\xe7\x22\x52\x56\xc4\xf8\x37"
|
|
137
|
+
"\xa8\x65\x48\xc9\x2c\xcc\x35\x48\x08\x05\x98\x7c\xb7\x0b\xe1\x7b"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"password", "salt", 8, 4, 2, 32,
|
|
141
|
+
"\xae\x4d\x0c\x95\xaf\x6b\x46\xd3\x2d\x0a\xdf\xf9\x28\xf0\x6d\xd0"
|
|
142
|
+
"\x2a\x30\x3f\x8e\xf3\xc2\x51\xdf\xd6\xe2\xd8\x5a\x95\x47\x4c\x43"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"password", "salt", 8, 4, 4096, 32,
|
|
146
|
+
"\xc5\xe4\x78\xd5\x92\x88\xc8\x41\xaa\x53\x0d\xb6\x84\x5c\x4c\x8d"
|
|
147
|
+
"\x96\x28\x93\xa0\x01\xce\x4e\x11\xa4\x96\x38\x73\xaa\x98\x13\x4a"
|
|
148
|
+
},
|
|
149
|
+
#ifdef SLOW_TESTS
|
|
150
|
+
/* With this test vector included, the program takes 40 seconds to run
|
|
151
|
+
to completion on a 2017-generation x86. Without, half a second. */
|
|
152
|
+
{
|
|
153
|
+
"password", "salt", 8, 4, 16777216, 32,
|
|
154
|
+
"\xcf\x81\xc6\x6f\xe8\xcf\xc0\x4d\x1f\x31\xec\xb6\x5d\xab\x40\x89"
|
|
155
|
+
"\xf7\xf1\x79\xe8\x9b\x3b\x0b\xcb\x17\xad\x10\xe3\xac\x6e\xba\x46"
|
|
156
|
+
},
|
|
157
|
+
#endif
|
|
158
|
+
{
|
|
159
|
+
"passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt",
|
|
160
|
+
24, 36, 4096, 40,
|
|
161
|
+
"\x34\x8c\x89\xdb\xcb\xd3\x2b\x2f\x32\xd8\x14\xb8\x11\x6e\x84\xcf"
|
|
162
|
+
"\x2b\x17\x34\x7e\xbc\x18\x00\x18\x1c\x4e\x2a\x1f\xb8\xdd\x53\xe1"
|
|
163
|
+
"\xc6\x35\x51\x8c\x7d\xac\x47\xe9"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"pass\0word", "sa\0lt", 9, 5, 4096, 16,
|
|
167
|
+
"\x89\xb6\x9d\x05\x16\xf8\x29\x89\x3c\x69\x62\x26\x65\x0a\x86\x87"
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
static void
|
|
173
|
+
report_failure(const char *tag, size_t n, size_t len,
|
|
174
|
+
const uint8_t expected[], const uint8_t actual[])
|
|
175
|
+
{
|
|
176
|
+
size_t i;
|
|
177
|
+
printf ("FAIL: %s/%zu:\n exp:", tag, n);
|
|
178
|
+
for (i = 0; i < len; i++)
|
|
179
|
+
{
|
|
180
|
+
if (i % 4 == 0)
|
|
181
|
+
putchar (' ');
|
|
182
|
+
printf ("%02x", (unsigned int)(unsigned char)expected[i]);
|
|
183
|
+
}
|
|
184
|
+
printf ("\n got:");
|
|
185
|
+
for (i = 0; i < len; i++)
|
|
186
|
+
{
|
|
187
|
+
if (i % 4 == 0)
|
|
188
|
+
putchar (' ');
|
|
189
|
+
printf ("%02x", (unsigned int)(unsigned char)actual[i]);
|
|
190
|
+
}
|
|
191
|
+
putchar ('\n');
|
|
192
|
+
putchar ('\n');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
static int
|
|
196
|
+
test_hmac_sha256 (void)
|
|
197
|
+
{
|
|
198
|
+
uint8_t output[32];
|
|
199
|
+
HMAC_SHA256_CTX ctx;
|
|
200
|
+
int status = 0;
|
|
201
|
+
size_t j;
|
|
202
|
+
for (size_t i = 0; i < ARRAY_SIZE (hmac_sha256_tests); i++)
|
|
203
|
+
{
|
|
204
|
+
const struct hmac_sha256_test *t = &hmac_sha256_tests[i];
|
|
205
|
+
HMAC_SHA256_Buf (t->key, strlen (t->key),
|
|
206
|
+
t->message, strlen (t->message),
|
|
207
|
+
output);
|
|
208
|
+
if (memcmp (output, t->digest, 32))
|
|
209
|
+
{
|
|
210
|
+
report_failure ("HMAC-SHA256 (one shot)",
|
|
211
|
+
i, 32, t->digest, output);
|
|
212
|
+
status = 1;
|
|
213
|
+
}
|
|
214
|
+
HMAC_SHA256_Init(&ctx, t->key, strlen (t->key));
|
|
215
|
+
for (j = 0; t->message[j] != '\0'; j++)
|
|
216
|
+
HMAC_SHA256_Update(&ctx, &t->message[j], 1);
|
|
217
|
+
HMAC_SHA256_Final(output, &ctx);
|
|
218
|
+
if (memcmp (output, t->digest, 32))
|
|
219
|
+
{
|
|
220
|
+
report_failure ("HMAC-SHA256 (incremental)",
|
|
221
|
+
i, 32, t->digest, output);
|
|
222
|
+
status = 1;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return status;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static int
|
|
229
|
+
test_pbkdf2_hmac_sha256 (void)
|
|
230
|
+
{
|
|
231
|
+
uint8_t output[64];
|
|
232
|
+
int status = 0;
|
|
233
|
+
for (size_t i = 0; i < ARRAY_SIZE (pbkdf2_hmac_sha256_tests); i++)
|
|
234
|
+
{
|
|
235
|
+
const struct pbkdf2_hmac_sha256_test *t = &pbkdf2_hmac_sha256_tests[i];
|
|
236
|
+
assert (t->dklen <= sizeof output);
|
|
237
|
+
|
|
238
|
+
PBKDF2_SHA256 ((const unsigned char *)t->passwd, t->plen,
|
|
239
|
+
(const unsigned char *)t->salt, t->slen,
|
|
240
|
+
t->c, output, t->dklen);
|
|
241
|
+
if (memcmp (output, t->dk, t->dklen))
|
|
242
|
+
{
|
|
243
|
+
report_failure ("PBKDF2-HMAC-SHA256", i, t->dklen,
|
|
244
|
+
(const unsigned char *)t->dk, output);
|
|
245
|
+
status = 1;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return status;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
int
|
|
253
|
+
main (void)
|
|
254
|
+
{
|
|
255
|
+
int status = 0;
|
|
256
|
+
status |= test_hmac_sha256 ();
|
|
257
|
+
status |= test_pbkdf2_hmac_sha256 ();
|
|
258
|
+
return status;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
#else /* INCLUDE_scrypt || INCLUDE_yescrypt */
|
|
262
|
+
|
|
263
|
+
int
|
|
264
|
+
main (void)
|
|
265
|
+
{
|
|
266
|
+
return 77; /* UNSUPPORTED */
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
#endif
|