Skip to content

Commit 8b805b9

Browse files
uudiinherbertx
authored andcommitted
crypto: sm2 - add SM2 test vectors to testmgr
Add testmgr test vectors for SM2 algorithm. These vectors come from `openssl pkeyutl -sign` and libgcrypt. Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com> Tested-by: Xufeng Zhang <yunbo.xufeng@linux.alibaba.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2b40386 commit 8b805b9

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎crypto/testmgr.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5385,6 +5385,12 @@ static const struct alg_test_desc alg_test_descs[] = {
53855385
.suite = {
53865386
.hash = __VECS(sha512_tv_template)
53875387
}
5388+
}, {
5389+
.alg = "sm2",
5390+
.test = alg_test_akcipher,
5391+
.suite = {
5392+
.akcipher = __VECS(sm2_tv_template)
5393+
}
53885394
}, {
53895395
.alg = "sm3",
53905396
.test = alg_test_hash,

‎crypto/testmgr.h‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,6 +3792,65 @@ static const struct hash_testvec hmac_streebog512_tv_template[] = {
37923792
},
37933793
};
37943794

3795+
/*
3796+
* SM2 test vectors.
3797+
*/
3798+
static const struct akcipher_testvec sm2_tv_template[] = {
3799+
{ /* Generated from openssl */
3800+
.key =
3801+
"\x04"
3802+
"\x8e\xa0\x33\x69\x91\x7e\x3d\xec\xad\x8e\xf0\x45\x5e\x13\x3e\x68"
3803+
"\x5b\x8c\xab\x5c\xc6\xc8\x50\xdf\x91\x00\xe0\x24\x73\x4d\x31\xf2"
3804+
"\x2e\xc0\xd5\x6b\xee\xda\x98\x93\xec\xd8\x36\xaa\xb9\xcf\x63\x82"
3805+
"\xef\xa7\x1a\x03\xed\x16\xba\x74\xb8\x8b\xf9\xe5\x70\x39\xa4\x70",
3806+
.key_len = 65,
3807+
.param_len = 0,
3808+
.c =
3809+
"\x30\x45"
3810+
"\x02\x20"
3811+
"\x70\xab\xb6\x7d\xd6\x54\x80\x64\x42\x7e\x2d\x05\x08\x36\xc9\x96"
3812+
"\x25\xc2\xbb\xff\x08\xe5\x43\x15\x5e\xf3\x06\xd9\x2b\x2f\x0a\x9f"
3813+
"\x02\x21"
3814+
"\x00"
3815+
"\xbf\x21\x5f\x7e\x5d\x3f\x1a\x4d\x8f\x84\xc2\xe9\xa6\x4c\xa4\x18"
3816+
"\xb2\xb8\x46\xf4\x32\x96\xfa\x57\xc6\x29\xd4\x89\xae\xcc\xda\xdb",
3817+
.c_size = 71,
3818+
.algo = OID_SM2_with_SM3,
3819+
.m =
3820+
"\x47\xa7\xbf\xd3\xda\xc4\x79\xee\xda\x8b\x4f\xe8\x40\x94\xd4\x32"
3821+
"\x8f\xf1\xcd\x68\x4d\xbd\x9b\x1d\xe0\xd8\x9a\x5d\xad\x85\x47\x5c",
3822+
.m_size = 32,
3823+
.public_key_vec = true,
3824+
.siggen_sigver_test = true,
3825+
},
3826+
{ /* From libgcrypt */
3827+
.key =
3828+
"\x04"
3829+
"\x87\x59\x38\x9a\x34\xaa\xad\x07\xec\xf4\xe0\xc8\xc2\x65\x0a\x44"
3830+
"\x59\xc8\xd9\x26\xee\x23\x78\x32\x4e\x02\x61\xc5\x25\x38\xcb\x47"
3831+
"\x75\x28\x10\x6b\x1e\x0b\x7c\x8d\xd5\xff\x29\xa9\xc8\x6a\x89\x06"
3832+
"\x56\x56\xeb\x33\x15\x4b\xc0\x55\x60\x91\xef\x8a\xc9\xd1\x7d\x78",
3833+
.key_len = 65,
3834+
.param_len = 0,
3835+
.c =
3836+
"\x30\x44"
3837+
"\x02\x20"
3838+
"\xd9\xec\xef\xe8\x5f\xee\x3c\x59\x57\x8e\x5b\xab\xb3\x02\xe1\x42"
3839+
"\x4b\x67\x2c\x0b\x26\xb6\x51\x2c\x3e\xfc\xc6\x49\xec\xfe\x89\xe5"
3840+
"\x02\x20"
3841+
"\x43\x45\xd0\xa5\xff\xe5\x13\x27\x26\xd0\xec\x37\xad\x24\x1e\x9a"
3842+
"\x71\x9a\xa4\x89\xb0\x7e\x0f\xc4\xbb\x2d\x50\xd0\xe5\x7f\x7a\x68",
3843+
.c_size = 70,
3844+
.algo = OID_SM2_with_SM3,
3845+
.m =
3846+
"\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x00"
3847+
"\x12\x34\x56\x78\x9a\xbc\xde\xf0\x12\x34\x56\x78\x9a\xbc\xde\xf0",
3848+
.m_size = 32,
3849+
.public_key_vec = true,
3850+
.siggen_sigver_test = true,
3851+
},
3852+
};
3853+
37953854
/* Example vectors below taken from
37963855
* http://www.oscca.gov.cn/UpFile/20101222141857786.pdf
37973856
*

0 commit comments

Comments
 (0)