[PATCH 5/7] crypto: testmgr - Add SM2 test vectors

From: Tianjia Zhang
Date: Sun Feb 16 2020 - 04:00:08 EST


Add testmgr tests and vectors for SM2 asymmetric cipher.

Signed-off-by: Tianjia Zhang <tianjia.zhang@xxxxxxxxxxxxxxxxx>
---
crypto/testmgr.c | 7 +++++++
crypto/testmgr.h | 16 ++++++++++++++++
2 files changed, 23 insertions(+)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index db9b5ac878e7..ecc6b27c1dd3 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -5050,6 +5050,13 @@ static const struct alg_test_desc alg_test_descs[] = {
.suite = {
.hash = __VECS(sha512_tv_template)
}
+ }, {
+ .alg = "sm2",
+ .test = alg_test_akcipher,
+ .fips_allowed = 1,
+ .suite = {
+ .akcipher = __VECS(sm2_tv_template)
+ }
}, {
.alg = "sm3",
.test = alg_test_hash,
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 48da646651cb..d46720b07fcf 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -809,6 +809,22 @@ static const struct akcipher_testvec pkcs1pad_rsa_tv_template[] = {
}
};

+/*
+ * SM2 test vectors.
+ */
+static const struct akcipher_testvec sm2_tv_template[] = {
+ {
+ .key =
+ "\xbd\xca\x64\x55\xa5\x5b\x9c\x27\x22\xd0\xf5\x80\xf7\xf3\xc5\x63"
+ "\x3c\xbf\xce\xe8\x55\x17\xaa\xa5\x7f\x11\x9b\x4b\x25\x56\x9b\x43",
+ .m = "\x39\xb3\x2c\x59\x82\xc7\xdf\x11\x8a\x64\x2d",
+ .c = NULL,
+ .key_len = 32,
+ .m_size = 11,
+ .c_size = 0,
+ }
+};
+
static const struct kpp_testvec dh_tv_template[] = {
{
.secret =
--
2.17.1