[openssl] master update
Dr. Paul Dale
pauli at openssl.org
Mon Jun 21 01:35:03 UTC 2021
The branch master has been updated
via c3708f9f7acb37c78fcbb1ee635d47aa0266e8ba (commit)
from ecd699b6dae054d368ca9ff04f3b80013f3c241f (commit)
- Log -----------------------------------------------------------------
commit c3708f9f7acb37c78fcbb1ee635d47aa0266e8ba
Author: 杨明君 <yangmingjun at uniontech.com>
Date: Mon Feb 22 14:50:11 2021 +0800
test: add sm3 low level test case to test suite.
Reviewed-by: Paul Yang <kaishen.yy at antfin.com>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14271)
-----------------------------------------------------------------------
Summary of changes:
test/build.info | 7 ++++
test/recipes/03-test_internal_sm3.t | 15 +++++++
test/sm3_internal_test.c | 84 +++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+)
create mode 100644 test/recipes/03-test_internal_sm3.t
create mode 100644 test/sm3_internal_test.c
diff --git a/test/build.info b/test/build.info
index f4acaa0e6a..568fcff3ed 100644
--- a/test/build.info
+++ b/test/build.info
@@ -585,6 +585,9 @@ IF[{- !$disabled{tests} -}]
IF[{- !$disabled{sm2} -}]
PROGRAMS{noinst}=sm2_internal_test
ENDIF
+ IF[{- !$disabled{sm3} -}]
+ PROGRAMS{noinst}=sm3_internal_test
+ ENDIF
IF[{- !$disabled{sm4} -}]
PROGRAMS{noinst}=sm4_internal_test
ENDIF
@@ -681,6 +684,10 @@ IF[{- !$disabled{tests} -}]
INCLUDE[sm2_internal_test]=../include ../apps/include
DEPEND[sm2_internal_test]=../libcrypto.a libtestutil.a
+ SOURCE[sm3_internal_test]=sm3_internal_test.c
+ INCLUDE[sm3_internal_test]=../include ../apps/include
+ DEPEND[sm3_internal_test]=../libcrypto.a libtestutil.a
+
SOURCE[sm4_internal_test]=sm4_internal_test.c
INCLUDE[sm4_internal_test]=.. ../include ../apps/include
DEPEND[sm4_internal_test]=../libcrypto.a libtestutil.a
diff --git a/test/recipes/03-test_internal_sm3.t b/test/recipes/03-test_internal_sm3.t
new file mode 100644
index 0000000000..9cda58d66e
--- /dev/null
+++ b/test/recipes/03-test_internal_sm3.t
@@ -0,0 +1,15 @@
+#! /usr/bin/env perl
+# Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2021 [UnionTech](https://www.uniontech.com). All Rights Reserved.
+#
+# Licensed under the OpenSSL license (the "License"). You may not use
+# this file except in compliance with the License. You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+use OpenSSL::Test; # get 'plan'
+use OpenSSL::Test::Simple;
+
+setup("test_internal_sm3");
+
+simple_test("test_internal_sm3", "sm3_internal_test", "sm3");
diff --git a/test/sm3_internal_test.c b/test/sm3_internal_test.c
new file mode 100644
index 0000000000..a92da8031e
--- /dev/null
+++ b/test/sm3_internal_test.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2021 UnionTech. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/*
+ * Internal tests for the SM3 module.
+ */
+
+#include <string.h>
+#include <openssl/opensslconf.h>
+#include "testutil.h"
+
+#ifndef OPENSSL_NO_SM3
+# include "internal/sm3.h"
+
+static int test_sm3(void)
+{
+ static const unsigned char input1[] = {
+ 0x61, 0x62, 0x63
+ };
+
+ /*
+ * This test vector comes from Example 1 (A.1) of GM/T 0004-2012
+ */
+ static const unsigned char expected1[SM3_DIGEST_LENGTH] = {
+ 0x66, 0xc7, 0xf0, 0xf4, 0x62, 0xee, 0xed, 0xd9,
+ 0xd1, 0xf2, 0xd4, 0x6b, 0xdc, 0x10, 0xe4, 0xe2,
+ 0x41, 0x67, 0xc4, 0x87, 0x5c, 0xf2, 0xf7, 0xa2,
+ 0x29, 0x7d, 0xa0, 0x2b, 0x8f, 0x4b, 0xa8, 0xe0
+ };
+
+ static const unsigned char input2[] = {
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
+ 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64
+ };
+
+ /*
+ * This test vector comes from Example 2 (A.2) from GM/T 0004-2012
+ */
+ static const unsigned char expected2[SM3_DIGEST_LENGTH] = {
+ 0xde, 0xbe, 0x9f, 0xf9, 0x22, 0x75, 0xb8, 0xa1,
+ 0x38, 0x60, 0x48, 0x89, 0xc1, 0x8e, 0x5a, 0x4d,
+ 0x6f, 0xdb, 0x70, 0xe5, 0x38, 0x7e, 0x57, 0x65,
+ 0x29, 0x3d, 0xcb, 0xa3, 0x9c, 0x0c, 0x57, 0x32
+ };
+
+ SM3_CTX ctx1, ctx2;
+ unsigned char md1[SM3_DIGEST_LENGTH], md2[SM3_DIGEST_LENGTH];
+
+ if (!TEST_true(sm3_init(&ctx1))
+ || !TEST_true(sm3_update(&ctx1, input1, sizeof(input1)))
+ || !TEST_true(sm3_final(md1, &ctx1))
+ || !TEST_mem_eq(md1, SM3_DIGEST_LENGTH, expected1, SM3_DIGEST_LENGTH))
+ return 0;
+
+ if (!TEST_true(sm3_init(&ctx2))
+ || !TEST_true(sm3_update(&ctx2, input2, sizeof(input2)))
+ || !TEST_true(sm3_final(md2, &ctx2))
+ || !TEST_mem_eq(md2, SM3_DIGEST_LENGTH, expected2, SM3_DIGEST_LENGTH))
+ return 0;
+
+ return 1;
+}
+#endif
+
+int setup_tests(void)
+{
+#ifndef OPENSSL_NO_SM3
+ ADD_TEST(test_sm3);
+#endif
+ return 1;
+}
More information about the openssl-commits
mailing list