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

From: Tianjia Zhang
Date: Tue Jan 21 2020 - 04:57:40 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 | 25 +++++++++++++++++++++++++
2 files changed, 32 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..9bee14ebfff6 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -809,6 +809,31 @@ static const struct akcipher_testvec pkcs1pad_rsa_tv_template[] = {
}
};

+/*
+ * SM2 test vectors.
+ */
+static const struct akcipher_testvec sm2_tv_template[] = {
+ {
+ .key =
+ "\x30\x68" /* 104 bytes */
+ "\x02\x01\x01" /* version */
+ "\x04\x20" /* priv 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"
+ "\x03\x41" /* pub key */
+ "\x04"
+ "\x8a\x68\x9f\x2e\xa8\x7a\x60\x1c\xdb\xa2\xcd\x46\xe0\x86\x2d\x66"
+ "\xde\xb4\x8f\xf1\xc6\x36\xd0\x68\xed\x1d\xdb\xe4\x72\x01\xbb\xdd"
+ "\x02\xbe\x58\xc5\xac\xc9\x4f\xa3\xfb\x82\xe1\xcb\xd2\x20\x17\x2f"
+ "\x1f\x30\x4b\xdd\x89\xab\x7e\x29\x4a\x4f\x67\x2c\x04\xeb\x3d\xe4",
+ .m = "\x39\xb3\x2c\x59\x82\xc7\xdf\x11\x8a\x64\x2d",
+ .c = NULL,
+ .key_len = 106,
+ .m_size = 11,
+ .c_size = 0,
+ }
+};
+
static const struct kpp_testvec dh_tv_template[] = {
{
.secret =
--
2.17.1