@@ -608,6 +608,7 @@ static inline void print_asym_capa(
608
608
break ;
609
609
case RTE_CRYPTO_ASYM_XFORM_ECDSA :
610
610
case RTE_CRYPTO_ASYM_XFORM_ECPM :
611
+ case RTE_CRYPTO_ASYM_XFORM_SM2 :
611
612
default :
612
613
break ;
613
614
}
@@ -1806,7 +1807,7 @@ test_ecpm_all_curve(void)
1806
1807
}
1807
1808
1808
1809
static int
1809
- _test_sm2_sign ( bool rnd_secret )
1810
+ test_sm2_sign ( void )
1810
1811
{
1811
1812
struct crypto_testsuite_params_asym * ts_params = & testsuite_params ;
1812
1813
struct crypto_testsuite_sm2_params input_params = sm2_param_fp256 ;
@@ -1875,11 +1876,19 @@ _test_sm2_sign(bool rnd_secret)
1875
1876
else
1876
1877
asym_op -> sm2 .hash = RTE_CRYPTO_AUTH_NULL ;
1877
1878
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 ) {
1883
1892
asym_op -> sm2 .k .data = NULL ;
1884
1893
asym_op -> sm2 .k .length = 0 ;
1885
1894
} else {
@@ -1928,7 +1937,7 @@ _test_sm2_sign(bool rnd_secret)
1928
1937
debug_hexdump (stdout , "s:" ,
1929
1938
asym_op -> sm2 .s .data , asym_op -> sm2 .s .length );
1930
1939
1931
- if (! rnd_secret ) {
1940
+ if (capa -> internal_rng == 0 ) {
1932
1941
/* Verify sign (by comparison). */
1933
1942
if (memcmp (input_params .sign_r .data , asym_op -> sm2 .r .data ,
1934
1943
asym_op -> sm2 .r .length ) != 0 ) {
@@ -1989,18 +1998,6 @@ _test_sm2_sign(bool rnd_secret)
1989
1998
return status ;
1990
1999
};
1991
2000
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
-
2004
2001
static int
2005
2002
test_sm2_verify (void )
2006
2003
{
@@ -2064,19 +2061,28 @@ test_sm2_verify(void)
2064
2061
2065
2062
/* Populate op with operational details */
2066
2063
asym_op -> sm2 .op_type = RTE_CRYPTO_ASYM_OP_VERIFY ;
2064
+
2067
2065
if (rte_cryptodev_asym_xform_capability_check_hash (capa , RTE_CRYPTO_AUTH_SM3 ))
2068
2066
asym_op -> sm2 .hash = RTE_CRYPTO_AUTH_SM3 ;
2069
2067
else
2070
2068
asym_op -> sm2 .hash = RTE_CRYPTO_AUTH_NULL ;
2071
2069
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
+
2074
2082
asym_op -> sm2 .r .data = input_params .sign_r .data ;
2075
2083
asym_op -> sm2 .r .length = input_params .sign_r .length ;
2076
2084
asym_op -> sm2 .s .data = input_params .sign_s .data ;
2077
2085
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 ;
2080
2086
2081
2087
RTE_LOG (DEBUG , USER1 , "Process ASYM operation\n" );
2082
2088
@@ -2116,7 +2122,7 @@ test_sm2_verify(void)
2116
2122
};
2117
2123
2118
2124
static int
2119
- _test_sm2_enc ( bool rnd_secret )
2125
+ test_sm2_enc ( void )
2120
2126
{
2121
2127
struct crypto_testsuite_params_asym * ts_params = & testsuite_params ;
2122
2128
struct crypto_testsuite_sm2_params input_params = sm2_param_fp256 ;
@@ -2185,7 +2191,8 @@ _test_sm2_enc(bool rnd_secret)
2185
2191
2186
2192
asym_op -> sm2 .message .data = input_params .message .data ;
2187
2193
asym_op -> sm2 .message .length = input_params .message .length ;
2188
- if (rnd_secret ) {
2194
+
2195
+ if (capa -> internal_rng != 0 ) {
2189
2196
asym_op -> sm2 .k .data = NULL ;
2190
2197
asym_op -> sm2 .k .length = 0 ;
2191
2198
} else {
@@ -2231,7 +2238,7 @@ _test_sm2_enc(bool rnd_secret)
2231
2238
debug_hexdump (stdout , "cipher:" ,
2232
2239
asym_op -> sm2 .cipher .data , asym_op -> sm2 .cipher .length );
2233
2240
2234
- if (! rnd_secret ) {
2241
+ if (capa -> internal_rng == 0 ) {
2235
2242
if (memcmp (input_params .cipher .data , asym_op -> sm2 .cipher .data ,
2236
2243
asym_op -> sm2 .cipher .length ) != 0 ) {
2237
2244
status = TEST_FAILED ;
@@ -2295,18 +2302,6 @@ _test_sm2_enc(bool rnd_secret)
2295
2302
return status ;
2296
2303
};
2297
2304
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
-
2310
2305
static int
2311
2306
test_sm2_dec (void )
2312
2307
{
@@ -2737,9 +2732,9 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
2737
2732
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym , test_dsa ),
2738
2733
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym ,
2739
2734
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 ),
2741
2736
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 ),
2743
2738
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym , test_sm2_dec ),
2744
2739
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym , test_rsa_enc_dec ),
2745
2740
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym ,
@@ -2803,6 +2798,8 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
2803
2798
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym , test_mod_exp ),
2804
2799
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym ,
2805
2800
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 ),
2806
2803
TEST_CASE_ST (ut_setup_asym , ut_teardown_asym ,
2807
2804
test_ecpm_all_curve ),
2808
2805
TEST_CASES_END () /**< NULL terminate unit test array */
0 commit comments