summaryrefslogtreecommitdiff
path: root/src/regress/lib/libcrypto/sm3
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libcrypto/sm3')
-rw-r--r--src/regress/lib/libcrypto/sm3/Makefile9
-rw-r--r--src/regress/lib/libcrypto/sm3/sm3test.c98
2 files changed, 0 insertions, 107 deletions
diff --git a/src/regress/lib/libcrypto/sm3/Makefile b/src/regress/lib/libcrypto/sm3/Makefile
deleted file mode 100644
index a0b5006ebc..0000000000
--- a/src/regress/lib/libcrypto/sm3/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1# $OpenBSD: Makefile,v 1.1 2018/11/11 07:12:33 tb Exp $
2
3PROG= sm3test
4LDADD= -lcrypto
5DPADD= ${LIBCRYPTO}
6WARNINGS= Yes
7CFLAGS+= -DLIBRESSL_INTERNAL -Werror
8
9.include <bsd.regress.mk>
diff --git a/src/regress/lib/libcrypto/sm3/sm3test.c b/src/regress/lib/libcrypto/sm3/sm3test.c
deleted file mode 100644
index 6611372848..0000000000
--- a/src/regress/lib/libcrypto/sm3/sm3test.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/* $OpenBSD: sm3test.c,v 1.2 2018/11/12 15:55:59 tb Exp $ */
2/*
3 * Copyright (c) 2018 Ribose Inc
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <err.h>
19#include <stdio.h>
20#include <string.h>
21
22#include <openssl/evp.h>
23
24#define SM3_TESTS 3
25
26const char *sm3_input[SM3_TESTS] = {
27 "",
28 "abc",
29 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd",
30};
31
32const uint8_t sm3_expected[SM3_TESTS][32] = {
33 {
34 0x1a, 0xb2, 0x1d, 0x83, 0x55, 0xcf, 0xa1, 0x7f,
35 0x8e, 0x61, 0x19, 0x48, 0x31, 0xe8, 0x1a, 0x8f,
36 0x22, 0xbe, 0xc8, 0xc7, 0x28, 0xfe, 0xfb, 0x74,
37 0x7e, 0xd0, 0x35, 0xeb, 0x50, 0x82, 0xaa, 0x2b,
38 },
39 {
40 0x66, 0xc7, 0xf0, 0xf4, 0x62, 0xee, 0xed, 0xd9,
41 0xd1, 0xf2, 0xd4, 0x6b, 0xdc, 0x10, 0xe4, 0xe2,
42 0x41, 0x67, 0xc4, 0x87, 0x5c, 0xf2, 0xf7, 0xa2,
43 0x29, 0x7d, 0xa0, 0x2b, 0x8f, 0x4b, 0xa8, 0xe0,
44 },
45 {
46 0xde, 0xbe, 0x9f, 0xf9, 0x22, 0x75, 0xb8, 0xa1,
47 0x38, 0x60, 0x48, 0x89, 0xc1, 0x8e, 0x5a, 0x4d,
48 0x6f, 0xdb, 0x70, 0xe5, 0x38, 0x7e, 0x57, 0x65,
49 0x29, 0x3d, 0xcb, 0xa3, 0x9c, 0x0c, 0x57, 0x32,
50 },
51};
52
53/* Tweaked version of libssl/key_schedule/key_schedule.c. */
54static void
55hexdump(const uint8_t *buf, size_t len)
56{
57 size_t i;
58
59 for (i = 1; i <= len; i++)
60 fprintf(stderr, " 0x%02x,%s", buf[i - 1], (i % 8) ? "" : "\n");
61
62 if (i % 8 != 1)
63 fprintf(stderr, "\n");
64}
65
66int
67main(int argc, char *argv[])
68{
69 EVP_MD_CTX *ctx;
70 uint8_t digest[32];
71 int numerrors = 0, i;
72
73 if ((ctx = EVP_MD_CTX_new()) == NULL)
74 err(1, NULL);
75
76 for (i = 0; i != SM3_TESTS; ++i) {
77 if (!EVP_DigestInit(ctx, EVP_sm3()))
78 errx(1, "EVP_DigestInit() failed");
79 if (!EVP_DigestUpdate(ctx, sm3_input[i], strlen(sm3_input[i])))
80 errx(1, "EVP_DigestInit() failed");
81 if (!EVP_DigestFinal(ctx, digest, NULL))
82 errx(1, "EVP_DigestFinal() failed");
83
84 if (memcmp(digest, sm3_expected[i], sizeof(digest)) != 0) {
85 fprintf(stderr, "TEST %d failed\n", i);
86 fprintf(stderr, "Produced:\n");
87 hexdump(digest, sizeof(digest));
88 fprintf(stderr, "Expected:\n");
89 hexdump(sm3_expected[i], sizeof(sm3_expected[i]));
90 numerrors++;
91 } else
92 fprintf(stderr, "SM3 test %d ok\n", i);
93 }
94
95 EVP_MD_CTX_free(ctx);
96
97 return (numerrors > 0) ? 1 : 0;
98}