Skip to content

Commit e7aef44

Browse files
gmuthukrishnAkhil Goyal
authored andcommitted
test/crypto: check asymmetric capabilities for SM2
Check asymmetric capabilities such as SM3 hash support and internal RNG and accordingly choose op params for SM2 test. Signed-off-by: Gowrishankar Muthukrishnan <[email protected]> Acked-by: Arkadiusz Kusztal <[email protected]>
1 parent f4fdf63 commit e7aef44

File tree

2 files changed

+57
-48
lines changed

2 files changed

+57
-48
lines changed

app/test/test_cryptodev_asym.c

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ static inline void print_asym_capa(
608608
break;
609609
case RTE_CRYPTO_ASYM_XFORM_ECDSA:
610610
case RTE_CRYPTO_ASYM_XFORM_ECPM:
611+
case RTE_CRYPTO_ASYM_XFORM_SM2:
611612
default:
612613
break;
613614
}
@@ -1806,7 +1807,7 @@ test_ecpm_all_curve(void)
18061807
}
18071808

18081809
static int
1809-
_test_sm2_sign(bool rnd_secret)
1810+
test_sm2_sign(void)
18101811
{
18111812
struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
18121813
struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
@@ -1875,11 +1876,19 @@ _test_sm2_sign(bool rnd_secret)
18751876
else
18761877
asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
18771878

1878-
asym_op->sm2.message.data = input_params.message.data;
1879-
asym_op->sm2.message.length = input_params.message.length;
1880-
asym_op->sm2.id.data = input_params.id.data;
1881-
asym_op->sm2.id.length = input_params.id.length;
1882-
if (rnd_secret) {
1879+
if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
1880+
asym_op->sm2.message.data = input_params.message.data;
1881+
asym_op->sm2.message.length = input_params.message.length;
1882+
asym_op->sm2.id.data = input_params.id.data;
1883+
asym_op->sm2.id.length = input_params.id.length;
1884+
} else {
1885+
asym_op->sm2.message.data = input_params.digest.data;
1886+
asym_op->sm2.message.length = input_params.digest.length;
1887+
asym_op->sm2.id.data = NULL;
1888+
asym_op->sm2.id.length = 0;
1889+
}
1890+
1891+
if (capa->internal_rng != 0) {
18831892
asym_op->sm2.k.data = NULL;
18841893
asym_op->sm2.k.length = 0;
18851894
} else {
@@ -1928,7 +1937,7 @@ _test_sm2_sign(bool rnd_secret)
19281937
debug_hexdump(stdout, "s:",
19291938
asym_op->sm2.s.data, asym_op->sm2.s.length);
19301939

1931-
if (!rnd_secret) {
1940+
if (capa->internal_rng == 0) {
19321941
/* Verify sign (by comparison). */
19331942
if (memcmp(input_params.sign_r.data, asym_op->sm2.r.data,
19341943
asym_op->sm2.r.length) != 0) {
@@ -1989,18 +1998,6 @@ _test_sm2_sign(bool rnd_secret)
19891998
return status;
19901999
};
19912000

1992-
static int
1993-
test_sm2_sign_rnd_secret(void)
1994-
{
1995-
return _test_sm2_sign(true);
1996-
}
1997-
1998-
__rte_used static int
1999-
test_sm2_sign_plain_secret(void)
2000-
{
2001-
return _test_sm2_sign(false);
2002-
}
2003-
20042001
static int
20052002
test_sm2_verify(void)
20062003
{
@@ -2064,19 +2061,28 @@ test_sm2_verify(void)
20642061

20652062
/* Populate op with operational details */
20662063
asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2064+
20672065
if (rte_cryptodev_asym_xform_capability_check_hash(capa, RTE_CRYPTO_AUTH_SM3))
20682066
asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
20692067
else
20702068
asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
20712069

2072-
asym_op->sm2.message.data = input_params.message.data;
2073-
asym_op->sm2.message.length = input_params.message.length;
2070+
if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
2071+
asym_op->sm2.message.data = input_params.message.data;
2072+
asym_op->sm2.message.length = input_params.message.length;
2073+
asym_op->sm2.id.data = input_params.id.data;
2074+
asym_op->sm2.id.length = input_params.id.length;
2075+
} else {
2076+
asym_op->sm2.message.data = input_params.digest.data;
2077+
asym_op->sm2.message.length = input_params.digest.length;
2078+
asym_op->sm2.id.data = NULL;
2079+
asym_op->sm2.id.length = 0;
2080+
}
2081+
20742082
asym_op->sm2.r.data = input_params.sign_r.data;
20752083
asym_op->sm2.r.length = input_params.sign_r.length;
20762084
asym_op->sm2.s.data = input_params.sign_s.data;
20772085
asym_op->sm2.s.length = input_params.sign_s.length;
2078-
asym_op->sm2.id.data = input_params.id.data;
2079-
asym_op->sm2.id.length = input_params.id.length;
20802086

20812087
RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
20822088

@@ -2116,7 +2122,7 @@ test_sm2_verify(void)
21162122
};
21172123

21182124
static int
2119-
_test_sm2_enc(bool rnd_secret)
2125+
test_sm2_enc(void)
21202126
{
21212127
struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
21222128
struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
@@ -2185,7 +2191,8 @@ _test_sm2_enc(bool rnd_secret)
21852191

21862192
asym_op->sm2.message.data = input_params.message.data;
21872193
asym_op->sm2.message.length = input_params.message.length;
2188-
if (rnd_secret) {
2194+
2195+
if (capa->internal_rng != 0) {
21892196
asym_op->sm2.k.data = NULL;
21902197
asym_op->sm2.k.length = 0;
21912198
} else {
@@ -2231,7 +2238,7 @@ _test_sm2_enc(bool rnd_secret)
22312238
debug_hexdump(stdout, "cipher:",
22322239
asym_op->sm2.cipher.data, asym_op->sm2.cipher.length);
22332240

2234-
if (!rnd_secret) {
2241+
if (capa->internal_rng == 0) {
22352242
if (memcmp(input_params.cipher.data, asym_op->sm2.cipher.data,
22362243
asym_op->sm2.cipher.length) != 0) {
22372244
status = TEST_FAILED;
@@ -2295,18 +2302,6 @@ _test_sm2_enc(bool rnd_secret)
22952302
return status;
22962303
};
22972304

2298-
static int
2299-
test_sm2_enc_rnd_secret(void)
2300-
{
2301-
return _test_sm2_enc(true);
2302-
}
2303-
2304-
__rte_used static int
2305-
test_sm2_enc_plain_secret(void)
2306-
{
2307-
return _test_sm2_enc(false);
2308-
}
2309-
23102305
static int
23112306
test_sm2_dec(void)
23122307
{
@@ -2737,9 +2732,9 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
27372732
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
27382733
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
27392734
test_dh_key_generation),
2740-
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign_rnd_secret),
2735+
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
27412736
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
2742-
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_enc_rnd_secret),
2737+
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_enc),
27432738
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_dec),
27442739
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
27452740
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
@@ -2803,6 +2798,8 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
28032798
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
28042799
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
28052800
test_ecdsa_sign_verify_all_curve),
2801+
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
2802+
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
28062803
TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
28072804
test_ecpm_all_curve),
28082805
TEST_CASES_END() /**< NULL terminate unit test array */

app/test/test_cryptodev_sm2_test_vectors.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct crypto_testsuite_sm2_params {
1717
rte_crypto_param id;
1818
rte_crypto_param cipher;
1919
rte_crypto_param message;
20+
rte_crypto_param digest;
2021
int curve;
2122
};
2223

@@ -46,17 +47,17 @@ static uint8_t fp256_k[] = {
4647
};
4748

4849
static uint8_t fp256_sign_r[] = {
49-
0xf3, 0x26, 0x10, 0xde, 0xfb, 0xbf, 0x13, 0xd4,
50-
0x73, 0xb1, 0xc2, 0x80, 0x51, 0x06, 0x29, 0xf9,
51-
0xfb, 0xc8, 0x11, 0xa7, 0x8d, 0x2c, 0xcb, 0x09,
52-
0x7c, 0xb2, 0xcf, 0x58, 0x0b, 0x5e, 0x25, 0xff
50+
0x75, 0x2B, 0x8C, 0x15, 0x38, 0x10, 0xF6, 0xC0,
51+
0x28, 0xC9, 0x8A, 0x51, 0xD0, 0x62, 0x69, 0x4B,
52+
0xF6, 0x58, 0x06, 0xEB, 0xF1, 0x91, 0x1F, 0x15,
53+
0x8B, 0x08, 0x09, 0xF9, 0x88, 0x0A, 0x44, 0x24
5354
};
5455

5556
static uint8_t fp256_sign_s[] = {
56-
0x8d, 0x8d, 0xb5, 0x40, 0xe3, 0xfb, 0x98, 0xf9,
57-
0x8c, 0xe4, 0x58, 0x60, 0xf2, 0x78, 0x8f, 0xd9,
58-
0xbf, 0xb8, 0x47, 0x73, 0x88, 0xc1, 0xd1, 0xcd,
59-
0x2d, 0xdb, 0xe3, 0xc1, 0x44, 0x30, 0x25, 0x86
57+
0x5A, 0x3C, 0x96, 0x3E, 0x1C, 0xB4, 0x19, 0xF9,
58+
0xD7, 0x78, 0xB8, 0xCE, 0xFF, 0x9D, 0xB1, 0x31,
59+
0x77, 0xDB, 0xA0, 0xFE, 0x84, 0x61, 0x1A, 0xD9,
60+
0x4E, 0xFF, 0x82, 0x13, 0x1C, 0xCA, 0x04, 0x75,
6061
};
6162

6263
static uint8_t fp256_id[] = {
@@ -68,6 +69,13 @@ static uint8_t fp256_message[] = {
6869
0x64, 0x69, 0x67, 0x65, 0x73, 0x74
6970
};
7071

72+
static uint8_t fp256_digest[] = {
73+
0x0F, 0xB5, 0xCE, 0xF3, 0x3C, 0xB7, 0xD1, 0x35,
74+
0xA9, 0x3A, 0xC7, 0xA7, 0x89, 0x2A, 0x6D, 0x9A,
75+
0xF3, 0x1E, 0xC5, 0x38, 0xD3, 0x65, 0x1B, 0xB9,
76+
0xDF, 0x5F, 0x7F, 0x4A, 0xD8, 0x89, 0x57, 0xF1
77+
};
78+
7179
static uint8_t fp256_cipher[] = {
7280
0x30, 0x78, 0x02, 0x21, 0x00, 0xAB, 0xBD, 0xE8,
7381
0xE8, 0x80, 0x93, 0x36, 0x77, 0xB6, 0x44, 0x47,
@@ -121,6 +129,10 @@ struct crypto_testsuite_sm2_params sm2_param_fp256 = {
121129
.data = fp256_message,
122130
.length = sizeof(fp256_message),
123131
},
132+
.digest = {
133+
.data = fp256_digest,
134+
.length = sizeof(fp256_digest),
135+
},
124136
.cipher = {
125137
.data = fp256_cipher,
126138
.length = sizeof(fp256_cipher),

0 commit comments

Comments
 (0)