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,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SHA-1 in C
|
|
3
|
+
* By Steve Reid <sreid@sea-to-sky.net>
|
|
4
|
+
* 100% Public Domain
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include "crypt-port.h"
|
|
8
|
+
#include "alg-sha1.h"
|
|
9
|
+
|
|
10
|
+
#include <stdio.h>
|
|
11
|
+
|
|
12
|
+
#if INCLUDE_sha1crypt
|
|
13
|
+
|
|
14
|
+
/* Test Vectors (from FIPS PUB 180-1) */
|
|
15
|
+
const char *test_data[3] =
|
|
16
|
+
{
|
|
17
|
+
"abc",
|
|
18
|
+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
|
19
|
+
"A million repetitions of 'a'"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const char *test_results[3] =
|
|
23
|
+
{
|
|
24
|
+
"a9993e364706816aba3e25717850c26c9cd0d89d",
|
|
25
|
+
"84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
|
26
|
+
"34aa973cd4c4daa4f61eeb2bdbad27316534016f"
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
static void
|
|
31
|
+
bin_to_hex (uint8_t *digest, char *output)
|
|
32
|
+
{
|
|
33
|
+
for (uint8_t i = 0; i < 20; ++i)
|
|
34
|
+
{
|
|
35
|
+
sprintf (output, "%02x", *digest);
|
|
36
|
+
++digest;
|
|
37
|
+
output += 2;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
int
|
|
43
|
+
main (void)
|
|
44
|
+
{
|
|
45
|
+
int k;
|
|
46
|
+
struct sha1_ctx ctx;
|
|
47
|
+
uint8_t digest[20];
|
|
48
|
+
char output[80];
|
|
49
|
+
uint8_t retval = 0;
|
|
50
|
+
|
|
51
|
+
for (k = 0; k < 2; k++)
|
|
52
|
+
{
|
|
53
|
+
sha1_init_ctx (&ctx);
|
|
54
|
+
sha1_process_bytes ((const uint8_t*)test_data[k], &ctx, strlen(test_data[k]));
|
|
55
|
+
sha1_finish_ctx (&ctx, digest);
|
|
56
|
+
bin_to_hex(digest, output);
|
|
57
|
+
|
|
58
|
+
if (strcmp(output, test_results[k]))
|
|
59
|
+
{
|
|
60
|
+
fprintf(stdout, "FAIL\n");
|
|
61
|
+
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[k]);
|
|
62
|
+
fprintf(stderr,"\t%s returned\n", output);
|
|
63
|
+
fprintf(stderr,"\t%s is correct\n", test_results[k]);
|
|
64
|
+
retval = 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/* million 'a' vector we feed separately */
|
|
68
|
+
sha1_init_ctx (&ctx);
|
|
69
|
+
for (k = 0; k < 1000000; k++)
|
|
70
|
+
sha1_process_bytes ((const uint8_t*)"a", &ctx, 1);
|
|
71
|
+
sha1_finish_ctx (&ctx, digest);
|
|
72
|
+
bin_to_hex(digest, output);
|
|
73
|
+
if (strcmp(output, test_results[2]))
|
|
74
|
+
{
|
|
75
|
+
fprintf(stdout, "FAIL\n");
|
|
76
|
+
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[2]);
|
|
77
|
+
fprintf(stderr,"\t%s returned\n", output);
|
|
78
|
+
fprintf(stderr,"\t%s is correct\n", test_results[2]);
|
|
79
|
+
retval = 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* The same test as above, but with 1000 blocks of 1000 bytes. */
|
|
83
|
+
char buf[1000];
|
|
84
|
+
memset (buf, 'a', sizeof (buf));
|
|
85
|
+
sha1_init_ctx (&ctx);
|
|
86
|
+
for (k = 0; k < 1000; ++k)
|
|
87
|
+
sha1_process_bytes ((const uint8_t*)buf, &ctx, sizeof (buf));
|
|
88
|
+
sha1_finish_ctx (&ctx, digest);
|
|
89
|
+
bin_to_hex(digest, output);
|
|
90
|
+
if (strcmp(output, test_results[2]))
|
|
91
|
+
{
|
|
92
|
+
fprintf(stdout, "FAIL\n");
|
|
93
|
+
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[2]);
|
|
94
|
+
fprintf(stderr,"\t%s returned\n", output);
|
|
95
|
+
fprintf(stderr,"\t%s is correct\n", test_results[2]);
|
|
96
|
+
retval = 1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* success */
|
|
100
|
+
return retval;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#else
|
|
104
|
+
|
|
105
|
+
int
|
|
106
|
+
main (void)
|
|
107
|
+
{
|
|
108
|
+
return 77; /* UNSUPPORTED */
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#endif
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#include "crypt-port.h"
|
|
2
|
+
#include "alg-sha256.h"
|
|
3
|
+
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
|
|
6
|
+
#if INCLUDE_sha256crypt || INCLUDE_scrypt || INCLUDE_yescrypt || \
|
|
7
|
+
INCLUDE_gost_yescrypt
|
|
8
|
+
|
|
9
|
+
static const struct
|
|
10
|
+
{
|
|
11
|
+
const char *input;
|
|
12
|
+
const char result[32 + 1];
|
|
13
|
+
} tests[] =
|
|
14
|
+
{
|
|
15
|
+
/* Test vectors from FIPS 180-2: appendix B.1. */
|
|
16
|
+
{
|
|
17
|
+
"abc",
|
|
18
|
+
"\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23"
|
|
19
|
+
"\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad"
|
|
20
|
+
},
|
|
21
|
+
/* Test vectors from FIPS 180-2: appendix B.2. */
|
|
22
|
+
{
|
|
23
|
+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
|
24
|
+
"\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
|
|
25
|
+
"\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1"
|
|
26
|
+
},
|
|
27
|
+
/* Test vectors from the NESSIE project. */
|
|
28
|
+
{
|
|
29
|
+
"",
|
|
30
|
+
"\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
|
|
31
|
+
"\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"a",
|
|
35
|
+
"\xca\x97\x81\x12\xca\x1b\xbd\xca\xfa\xc2\x31\xb3\x9a\x23\xdc\x4d"
|
|
36
|
+
"\xa7\x86\xef\xf8\x14\x7c\x4e\x72\xb9\x80\x77\x85\xaf\xee\x48\xbb"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"message digest",
|
|
40
|
+
"\xf7\x84\x6f\x55\xcf\x23\xe1\x4e\xeb\xea\xb5\xb4\xe1\x55\x0c\xad"
|
|
41
|
+
"\x5b\x50\x9e\x33\x48\xfb\xc4\xef\xa3\xa1\x41\x3d\x39\x3c\xb6\x50"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
45
|
+
"\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52"
|
|
46
|
+
"\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
50
|
+
"\xdb\x4b\xfc\xbd\x4d\xa0\xcd\x85\xa6\x0c\x3c\x37\xd3\xfb\xd8\x80"
|
|
51
|
+
"\x5c\x77\xf1\x5f\xc6\xb1\xfd\xfe\x61\x4e\xe0\xa7\xc8\xfd\xb4\xc0"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"123456789012345678901234567890123456789012345678901234567890"
|
|
55
|
+
"12345678901234567890",
|
|
56
|
+
"\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e"
|
|
57
|
+
"\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
static void
|
|
63
|
+
report_failure(int n, const char *tag,
|
|
64
|
+
const char expected[32], uint8_t actual[32])
|
|
65
|
+
{
|
|
66
|
+
int i;
|
|
67
|
+
printf ("FAIL: test %d (%s):\n exp:", n, tag);
|
|
68
|
+
for (i = 0; i < 32; i++)
|
|
69
|
+
{
|
|
70
|
+
if (i % 4 == 0)
|
|
71
|
+
putchar (' ');
|
|
72
|
+
printf ("%02x", (unsigned int)(unsigned char)expected[i]);
|
|
73
|
+
}
|
|
74
|
+
printf ("\n got:");
|
|
75
|
+
for (i = 0; i < 32; i++)
|
|
76
|
+
{
|
|
77
|
+
if (i % 4 == 0)
|
|
78
|
+
putchar (' ');
|
|
79
|
+
printf ("%02x", (unsigned int)(unsigned char)actual[i]);
|
|
80
|
+
}
|
|
81
|
+
putchar ('\n');
|
|
82
|
+
putchar ('\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
int
|
|
86
|
+
main (void)
|
|
87
|
+
{
|
|
88
|
+
SHA256_CTX ctx;
|
|
89
|
+
uint8_t sum[32];
|
|
90
|
+
int result = 0;
|
|
91
|
+
int cnt;
|
|
92
|
+
int i;
|
|
93
|
+
|
|
94
|
+
for (cnt = 0; cnt < (int) ARRAY_SIZE (tests); ++cnt)
|
|
95
|
+
{
|
|
96
|
+
SHA256_Buf (tests[cnt].input, strlen (tests[cnt].input), sum);
|
|
97
|
+
if (memcmp (tests[cnt].result, sum, 32) != 0)
|
|
98
|
+
{
|
|
99
|
+
report_failure (cnt, "all at once", tests[cnt].result, sum);
|
|
100
|
+
result = 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
SHA256_Init (&ctx);
|
|
104
|
+
for (i = 0; tests[cnt].input[i] != '\0'; ++i)
|
|
105
|
+
SHA256_Update (&ctx, &tests[cnt].input[i], 1);
|
|
106
|
+
SHA256_Final (sum, &ctx);
|
|
107
|
+
if (memcmp (tests[cnt].result, sum, 32) != 0)
|
|
108
|
+
{
|
|
109
|
+
report_failure (cnt, "byte by byte", tests[cnt].result, sum);
|
|
110
|
+
result = 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Test vector from FIPS 180-2: appendix B.3. */
|
|
115
|
+
char buf[1000];
|
|
116
|
+
memset (buf, 'a', sizeof (buf));
|
|
117
|
+
SHA256_Init (&ctx);
|
|
118
|
+
for (i = 0; i < 1000; ++i)
|
|
119
|
+
SHA256_Update (&ctx, buf, sizeof (buf));
|
|
120
|
+
SHA256_Final (sum, &ctx);
|
|
121
|
+
static const char expected[32 + 1] =
|
|
122
|
+
"\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67"
|
|
123
|
+
"\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0";
|
|
124
|
+
if (memcmp (expected, sum, 32) != 0)
|
|
125
|
+
{
|
|
126
|
+
report_failure (cnt, "block by block", expected, sum);
|
|
127
|
+
result = 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#else
|
|
134
|
+
|
|
135
|
+
int
|
|
136
|
+
main (void)
|
|
137
|
+
{
|
|
138
|
+
return 77; /* UNSUPPORTED */
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#endif
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#include "crypt-port.h"
|
|
2
|
+
#include "alg-sha512.h"
|
|
3
|
+
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
|
|
6
|
+
#if INCLUDE_sha512crypt
|
|
7
|
+
|
|
8
|
+
static const struct
|
|
9
|
+
{
|
|
10
|
+
const char *input;
|
|
11
|
+
const char result[64 + 1];
|
|
12
|
+
} tests[] =
|
|
13
|
+
{
|
|
14
|
+
/* Test vectors from FIPS 180-2: appendix C.1. */
|
|
15
|
+
{
|
|
16
|
+
"abc",
|
|
17
|
+
"\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31"
|
|
18
|
+
"\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a"
|
|
19
|
+
"\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd"
|
|
20
|
+
"\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f"
|
|
21
|
+
},
|
|
22
|
+
/* Test vectors from FIPS 180-2: appendix C.2. */
|
|
23
|
+
{
|
|
24
|
+
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
|
|
25
|
+
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
|
|
26
|
+
"\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f"
|
|
27
|
+
"\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18"
|
|
28
|
+
"\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a"
|
|
29
|
+
"\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09"
|
|
30
|
+
},
|
|
31
|
+
/* Test vectors from the NESSIE project. */
|
|
32
|
+
{
|
|
33
|
+
"",
|
|
34
|
+
"\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80\x07"
|
|
35
|
+
"\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c\xe9\xce"
|
|
36
|
+
"\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87\x7e\xec\x2f"
|
|
37
|
+
"\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a\xf9\x27\xda\x3e"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"a",
|
|
41
|
+
"\x1f\x40\xfc\x92\xda\x24\x16\x94\x75\x09\x79\xee\x6c\xf5\x82\xf2"
|
|
42
|
+
"\xd5\xd7\xd2\x8e\x18\x33\x5d\xe0\x5a\xbc\x54\xd0\x56\x0e\x0f\x53"
|
|
43
|
+
"\x02\x86\x0c\x65\x2b\xf0\x8d\x56\x02\x52\xaa\x5e\x74\x21\x05\x46"
|
|
44
|
+
"\xf3\x69\xfb\xbb\xce\x8c\x12\xcf\xc7\x95\x7b\x26\x52\xfe\x9a\x75"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"message digest",
|
|
48
|
+
"\x10\x7d\xbf\x38\x9d\x9e\x9f\x71\xa3\xa9\x5f\x6c\x05\x5b\x92\x51"
|
|
49
|
+
"\xbc\x52\x68\xc2\xbe\x16\xd6\xc1\x34\x92\xea\x45\xb0\x19\x9f\x33"
|
|
50
|
+
"\x09\xe1\x64\x55\xab\x1e\x96\x11\x8e\x8a\x90\x5d\x55\x97\xb7\x20"
|
|
51
|
+
"\x38\xdd\xb3\x72\xa8\x98\x26\x04\x6d\xe6\x66\x87\xbb\x42\x0e\x7c"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
55
|
+
"\x4d\xbf\xf8\x6c\xc2\xca\x1b\xae\x1e\x16\x46\x8a\x05\xcb\x98\x81"
|
|
56
|
+
"\xc9\x7f\x17\x53\xbc\xe3\x61\x90\x34\x89\x8f\xaa\x1a\xab\xe4\x29"
|
|
57
|
+
"\x95\x5a\x1b\xf8\xec\x48\x3d\x74\x21\xfe\x3c\x16\x46\x61\x3a\x59"
|
|
58
|
+
"\xed\x54\x41\xfb\x0f\x32\x13\x89\xf7\x7f\x48\xa8\x79\xc7\xb1\xf1"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
|
62
|
+
"\x20\x4a\x8f\xc6\xdd\xa8\x2f\x0a\x0c\xed\x7b\xeb\x8e\x08\xa4\x16"
|
|
63
|
+
"\x57\xc1\x6e\xf4\x68\xb2\x28\xa8\x27\x9b\xe3\x31\xa7\x03\xc3\x35"
|
|
64
|
+
"\x96\xfd\x15\xc1\x3b\x1b\x07\xf9\xaa\x1d\x3b\xea\x57\x78\x9c\xa0"
|
|
65
|
+
"\x31\xad\x85\xc7\xa7\x1d\xd7\x03\x54\xec\x63\x12\x38\xca\x34\x45"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
69
|
+
"\x1e\x07\xbe\x23\xc2\x6a\x86\xea\x37\xea\x81\x0c\x8e\xc7\x80\x93"
|
|
70
|
+
"\x52\x51\x5a\x97\x0e\x92\x53\xc2\x6f\x53\x6c\xfc\x7a\x99\x96\xc4"
|
|
71
|
+
"\x5c\x83\x70\x58\x3e\x0a\x78\xfa\x4a\x90\x04\x1d\x71\xa4\xce\xab"
|
|
72
|
+
"\x74\x23\xf1\x9c\x71\xb9\xd5\xa3\xe0\x12\x49\xf0\xbe\xbd\x58\x94"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"123456789012345678901234567890123456789012345678901234567890"
|
|
76
|
+
"12345678901234567890",
|
|
77
|
+
"\x72\xec\x1e\xf1\x12\x4a\x45\xb0\x47\xe8\xb7\xc7\x5a\x93\x21\x95"
|
|
78
|
+
"\x13\x5b\xb6\x1d\xe2\x4e\xc0\xd1\x91\x40\x42\x24\x6e\x0a\xec\x3a"
|
|
79
|
+
"\x23\x54\xe0\x93\xd7\x6f\x30\x48\xb4\x56\x76\x43\x46\x90\x0c\xb1"
|
|
80
|
+
"\x30\xd2\xa4\xfd\x5d\xd1\x6a\xbb\x5e\x30\xbc\xb8\x50\xde\xe8\x43"
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
static void
|
|
86
|
+
report_failure(int n, const char *tag,
|
|
87
|
+
const char expected[64], const uint8_t actual[64])
|
|
88
|
+
{
|
|
89
|
+
int i;
|
|
90
|
+
printf ("FAIL: test %d (%s):\n exp:", n, tag);
|
|
91
|
+
for (i = 0; i < 64; i++)
|
|
92
|
+
{
|
|
93
|
+
if (i == 32)
|
|
94
|
+
printf ("\n ");
|
|
95
|
+
else if (i % 4 == 0)
|
|
96
|
+
putchar (' ');
|
|
97
|
+
printf ("%02x", (unsigned int)(unsigned char)expected[i]);
|
|
98
|
+
}
|
|
99
|
+
printf ("\n got:");
|
|
100
|
+
for (i = 0; i < 64; i++)
|
|
101
|
+
{
|
|
102
|
+
if (i == 32)
|
|
103
|
+
printf ("\n ");
|
|
104
|
+
else if (i % 4 == 0)
|
|
105
|
+
putchar (' ');
|
|
106
|
+
printf ("%02x", (unsigned int)(unsigned char)actual[i]);
|
|
107
|
+
}
|
|
108
|
+
putchar ('\n');
|
|
109
|
+
putchar ('\n');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
int
|
|
113
|
+
main (void)
|
|
114
|
+
{
|
|
115
|
+
SHA512_CTX ctx;
|
|
116
|
+
uint8_t sum[64];
|
|
117
|
+
int result = 0;
|
|
118
|
+
int cnt;
|
|
119
|
+
int i;
|
|
120
|
+
|
|
121
|
+
for (cnt = 0; cnt < (int) ARRAY_SIZE (tests); ++cnt)
|
|
122
|
+
{
|
|
123
|
+
SHA512_Buf (tests[cnt].input, strlen (tests[cnt].input), sum);
|
|
124
|
+
if (memcmp (tests[cnt].result, sum, 64) != 0)
|
|
125
|
+
{
|
|
126
|
+
report_failure (cnt, "all at once", tests[cnt].result, sum);
|
|
127
|
+
result = 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
SHA512_Init (&ctx);
|
|
131
|
+
for (i = 0; tests[cnt].input[i] != '\0'; ++i)
|
|
132
|
+
SHA512_Update (&ctx, &tests[cnt].input[i], 1);
|
|
133
|
+
SHA512_Final (sum, &ctx);
|
|
134
|
+
if (memcmp (tests[cnt].result, sum, 64) != 0)
|
|
135
|
+
{
|
|
136
|
+
report_failure (cnt, "byte by byte", tests[cnt].result, sum);
|
|
137
|
+
result = 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* Test vector from FIPS 180-2: appendix C.3. */
|
|
142
|
+
char buf[1000];
|
|
143
|
+
memset (buf, 'a', sizeof (buf));
|
|
144
|
+
SHA512_Init (&ctx);
|
|
145
|
+
for (i = 0; i < 1000; ++i)
|
|
146
|
+
SHA512_Update (&ctx, buf, sizeof (buf));
|
|
147
|
+
SHA512_Final (sum, &ctx);
|
|
148
|
+
static const char expected[64 + 1] =
|
|
149
|
+
"\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63"
|
|
150
|
+
"\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb"
|
|
151
|
+
"\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b"
|
|
152
|
+
"\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b";
|
|
153
|
+
if (memcmp (expected, sum, 64) != 0)
|
|
154
|
+
{
|
|
155
|
+
report_failure (cnt, "block by block", expected, sum);
|
|
156
|
+
result = 1;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#else
|
|
163
|
+
|
|
164
|
+
int
|
|
165
|
+
main (void)
|
|
166
|
+
{
|
|
167
|
+
return 77; /* UNSUPPORTED */
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
#endif
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* Copyright (C) 2018, 2024, 2025 Björn Esser besser82@fedoraproject.org
|
|
2
|
+
*
|
|
3
|
+
* Redistribution and use in source and binary forms, with or without
|
|
4
|
+
* modification, are permitted.
|
|
5
|
+
*
|
|
6
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
7
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
8
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
9
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
10
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
11
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
12
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
13
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
14
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
15
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
16
|
+
* SUCH DAMAGE.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "crypt-port.h"
|
|
20
|
+
|
|
21
|
+
#if INCLUDE_sm3_yescrypt
|
|
22
|
+
|
|
23
|
+
#include "alg-sm3-hmac.h"
|
|
24
|
+
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
|
|
27
|
+
struct testcase
|
|
28
|
+
{
|
|
29
|
+
const char *subject;
|
|
30
|
+
const char *t;
|
|
31
|
+
size_t tlen;
|
|
32
|
+
const char *k;
|
|
33
|
+
size_t ksize;
|
|
34
|
+
const char *match;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/* Test vectors as published in GM/T 0042-2015 Appendix D.3 */
|
|
38
|
+
static const struct testcase testcases[] =
|
|
39
|
+
{
|
|
40
|
+
{
|
|
41
|
+
"First test vector for HMAC-SM3 from GM/T 0042-2015 Appendix D.3",
|
|
42
|
+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
|
43
|
+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 112,
|
|
44
|
+
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
|
|
45
|
+
"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20", 32,
|
|
46
|
+
"\xca\x05\xe1\x44\xed\x05\xd1\x85\x78\x40\xd1\xf3\x18\xa4\xa8\x66"
|
|
47
|
+
"\x9e\x55\x9f\xc8\x39\x1f\x41\x44\x85\xbf\xdf\x7b\xb4\x08\x96\x3a"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"Second test vector for HMAC-SM3 from GM/T 0042-2015 Appendix D.3",
|
|
51
|
+
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
|
|
52
|
+
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
|
|
53
|
+
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
|
|
54
|
+
"\xcd\xcd", 50,
|
|
55
|
+
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
|
|
56
|
+
"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"
|
|
57
|
+
"\x21\x22\x23\x24\x25", 37,
|
|
58
|
+
"\x22\x0b\xf5\x79\xde\xd5\x55\x39\x3f\x01\x59\xf6\x6c\x99\x87\x78"
|
|
59
|
+
"\x22\xa3\xec\xf6\x10\xd1\x55\x21\x54\xb4\x1d\x44\xb9\x4d\xb3\xae"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"Third test vector for HMAC-SM3 from GM/T 0042-2015 Appendix D.3",
|
|
63
|
+
"Hi There", 8,
|
|
64
|
+
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
|
|
65
|
+
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 32,
|
|
66
|
+
"\xc0\xba\x18\xc6\x8b\x90\xc8\x8b\xc0\x7d\xe7\x94\xbf\xc7\xd2\xc8"
|
|
67
|
+
"\xd1\x9e\xc3\x1e\xd8\x77\x3b\xc2\xb3\x90\xc9\x60\x4e\x0b\xe1\x1e"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"Fourth test vector for HMAC-SM3 from GM/T 0042-2015 Appendix D.3",
|
|
71
|
+
"what do ya want for nothing?", 28,
|
|
72
|
+
"Jefe", 4,
|
|
73
|
+
"\x2e\x87\xf1\xd1\x68\x62\xe6\xd9\x64\xb5\x0a\x52\x00\xbf\x2b\x10"
|
|
74
|
+
"\xb7\x64\xfa\xa9\x68\x0a\x29\x6a\x24\x05\xf2\x4b\xec\x39\xf8\x82"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"Custom test vector for HMAC-SM3 with key length > 64",
|
|
78
|
+
"What is the purpose of this test???", 35,
|
|
79
|
+
"\x49\x74\x27\x73\x20\x63\x6f\x6d\x70\x6c\x69\x63\x61\x74\x65\x64"
|
|
80
|
+
"\x20\x74\x6f\x20\x65\x78\x70\x6c\x61\x69\x6e\x2c\x20\x62\x75\x74"
|
|
81
|
+
"\x20\x77\x65\x20\x6e\x65\x65\x64\x20\x73\x6f\x6d\x65\x20\x74\x65"
|
|
82
|
+
"\x78\x74\x20\x74\x68\x61\x74\x20\x63\x6c\x65\x61\x72\x6c\x79\x20"
|
|
83
|
+
"\x65\x78\x63\x65\x65\x64\x73\x20\x73\x69\x78\x74\x79\x66\x6f\x75"
|
|
84
|
+
"\x72\x20\x62\x79\x74\x65\x73\x20\x6f\x66\x20\x64\x61\x74\x61\x20"
|
|
85
|
+
"\x66\x6f\x72\x20\x74\x68\x65\x20\x6b\x65\x79\x20\x74\x6f\x20\x74"
|
|
86
|
+
"\x65\x73\x74\x20\x63\x6f\x76\x65\x72\x61\x67\x65\x2e\x2e\x2e\x2e", 128,
|
|
87
|
+
"\xd3\xde\xc8\x63\xe3\x16\x59\x62\x38\x09\x0e\xac\xe6\x61\xe6\xd3"
|
|
88
|
+
"\xc4\xcb\xae\x43\xdc\xf0\x06\x0c\x71\xf0\xe4\xe5\xdc\x5f\xf7\xd3"
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
static void
|
|
94
|
+
dumphex(const void *ptr, size_t size)
|
|
95
|
+
{
|
|
96
|
+
size_t i;
|
|
97
|
+
|
|
98
|
+
for (i = 0; i < size; i++)
|
|
99
|
+
printf("\\x%02x", ((const unsigned char *)ptr)[i]);
|
|
100
|
+
printf("\n");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static int
|
|
104
|
+
test_sm3_hmac(const struct testcase *tc)
|
|
105
|
+
{
|
|
106
|
+
uint8_t digest[32];
|
|
107
|
+
|
|
108
|
+
sm3_hmac_buf((const uint8_t *)tc->t, tc->tlen,
|
|
109
|
+
(const uint8_t *)tc->k, tc->ksize, digest);
|
|
110
|
+
|
|
111
|
+
if (memcmp(digest, tc->match, 32))
|
|
112
|
+
{
|
|
113
|
+
fprintf(stderr, "ERROR: %s\n", tc->subject);
|
|
114
|
+
printf(" key: ");
|
|
115
|
+
dumphex(tc->k, tc->ksize);
|
|
116
|
+
printf(" t: ");
|
|
117
|
+
dumphex(tc->t, tc->tlen);
|
|
118
|
+
printf(" hmac=");
|
|
119
|
+
dumphex(digest, 32);
|
|
120
|
+
printf(" expect=");
|
|
121
|
+
dumphex(tc->match, 32);
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
fprintf(stderr, " ok: %s\n", tc->subject);
|
|
126
|
+
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
int
|
|
131
|
+
main (void)
|
|
132
|
+
{
|
|
133
|
+
int result = 0;
|
|
134
|
+
|
|
135
|
+
for (size_t i = 0; i < ARRAY_SIZE (testcases); i++)
|
|
136
|
+
result |= test_sm3_hmac(&testcases[i]);
|
|
137
|
+
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#else
|
|
142
|
+
|
|
143
|
+
int
|
|
144
|
+
main (void)
|
|
145
|
+
{
|
|
146
|
+
return 77; /* UNSUPPORTED */
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#endif /* INCLUDE_sm3_yescrypt */
|