From 52aee7360dbf4184e8f3151db7a6dc503d5a84f5 Mon Sep 17 00:00:00 2001 From: "Jing, Ran" Date: Wed, 7 Jun 2023 19:17:28 +0800 Subject: [PATCH] Add QAT_HW SM3 support. - Support SM3 via QAT_HW on 4xxx, C4xxx devices. (Disabled by default). Signed-off-by: Jing, Ran --- Makefile.am | 3 +- configure.ac | 14 +- docs/config_options.md | 5 + docs/features.md | 1 + docs/limitations.md | 2 + docs/qat_hw_algo.md | 1 + e_qat.c | 2 + e_qat.h | 1 + e_qat.txt | 214 +++++------ e_qat_err.c | 8 + e_qat_err.h | 214 +++++------ qat_bssl_err.c | 8 + qat_bssl_err.h | 214 +++++------ qat_evp.c | 24 +- qat_evp.h | 1 + qat_hw_hkdf.c | 11 +- qat_hw_prf.c | 7 + qat_hw_sm3.c | 795 +++++++++++++++++++++++++++++++++++++++++ qat_hw_sm3.h | 108 ++++++ qat_prov.txt | 83 ++--- qat_prov_err.c | 1 + qat_prov_err.h | 83 ++--- test/tests_sm3.c | 265 +++++++++++--- 23 files changed, 1615 insertions(+), 450 deletions(-) create mode 100644 qat_hw_sm3.c create mode 100644 qat_hw_sm3.h diff --git a/Makefile.am b/Makefile.am index 695b3021..80a89164 100644 --- a/Makefile.am +++ b/Makefile.am @@ -78,7 +78,8 @@ if QAT_HW qat_hw_ecx.c \ qat_hw_sha3.c \ qat_hw_chachapoly.c \ - qat_hw_sm4_cbc.c + qat_hw_sm4_cbc.c \ + qat_hw_sm3.c endif if QAT_SW diff --git a/configure.ac b/configure.ac index 9960f2c1..846c52f5 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,11 @@ AC_ARG_ENABLE(qat_hw_sm4_cbc, [Enable qat_hw SM4-CBC acceleration])) AC_SUBST(enable_qat_hw_sm4_cbc) +AC_ARG_ENABLE(qat_hw_sm3, + AS_HELP_STRING([--enable-qat_hw_sm3], + [Enable qat_hw SM3 acceleration])) +AC_SUBST(enable_qat_hw_sm3) + AC_ARG_ENABLE(qat_sw_gcm, AS_HELP_STRING([--disable-qat_sw_gcm], [Disable qat_sw AES-GCM acceleration])) @@ -535,6 +540,8 @@ then [cflags_qat_hw="${cflags_qat_hw} -DENABLE_QAT_HW_HKDF"; AC_MSG_NOTICE([Accelerating HKDF to Hardware])]) AS_IF([test "x$enable_qat_hw_sha3" = "xyes"], [cflags_qat_hw="${cflags_qat_hw} -DENABLE_QAT_HW_SHA3"; AC_MSG_NOTICE([Accelerating SHA3 to Hardware])]) + AS_IF([test "x$enable_qat_hw_sm3" = "xyes"], + [cflags_qat_hw="${cflags_qat_hw} -DENABLE_QAT_HW_SM3"; AC_MSG_NOTICE([Accelerating SM3 to Hardware])]) AS_IF([test "x$enable_qat_hw_ciphers" != "xno"], [cflags_qat_hw="${cflags_qat_hw} -DENABLE_QAT_HW_CIPHERS"; AC_MSG_NOTICE([Accelerating CIPHERS to Hardware])]) AS_IF([test "x$enable_qat_hw_gcm" = "xyes"], @@ -558,7 +565,7 @@ then [cflags_qat_sw="${cflags_qat_sw} -DENABLE_QAT_SW_ECX"; AC_MSG_NOTICE([Accelerating X25519/X448 to Software (Multi-buffer)])]) AS_IF([test "x$enable_qat_sw_sm2" != "xno"], [cflags_qat_sw="${cflags_qat_sw} -DENABLE_QAT_SW_SM2"; AC_MSG_NOTICE([Accelerating SM2 to Software (Multi-buffer)])]) - AS_IF([test "x$enable_qat_sw_sm3" = "xyes"], + AS_IF([test "x$enable_qat_sw_sm3" = "xyes"], [cflags_qat_sw="${cflags_qat_sw} -DENABLE_QAT_SW_SM3"; AC_MSG_NOTICE([Accelerating SM3 to Software (Multi-buffer)])]) AS_IF([test "x$enable_qat_sw_sm4_cbc" = "xyes"], [cflags_qat_sw="${cflags_qat_sw} -DENABLE_QAT_SW_SM4_CBC"; AC_MSG_NOTICE([Accelerating SM4-CBC to Software (Multi-buffer)])]) @@ -577,6 +584,11 @@ fi if test "x$cflags_qat_hw" != "x" -a "x$cflags_qat_sw" != "x" then AC_MSG_NOTICE([QAT_HW & QAT_SW Co-existence]) + + if test "x$enable_qat_hw_sm3" != "x" -a "x$enable_qat_sw_sm3" != "x" + then + AC_MSG_ERROR(Co-existence not supported by SM3) + fi fi #Enable additional QAT_HW & QAT_SW flags diff --git a/docs/config_options.md b/docs/config_options.md index cf7d29c0..022dbea3 100644 --- a/docs/config_options.md +++ b/docs/config_options.md @@ -160,6 +160,11 @@ The following is a list of the options that can be used with the This flag is valid only on 4xxx(QAT gen 4 devices) as the support is not available for earlier generations of QAT devices (e.g. c62x, dh895xxcc, etc.) +--disable-qat_hw_sm3/--enable-qat_hw_sm3 + Disable/Enable Intel(R) QAT Hardware SM3 acceleration (disabled by default). + This flag is valid only on 4xxx(QAT gen 4 devices) as the support is not available + for earlier generations of QAT devices (e.g. c62x, dh895xxcc, etc.) + --disable-qat_hw_chachapoly/--enable-qat_hw_chachapoly Disable/Enable Intel(R) QAT Hardware CHACHA20-POLY1305 acceleration (disabled by default). This flag is valid only on 4xxx(QAT gen 4 devices) as the support is not available diff --git a/docs/features.md b/docs/features.md index 36e894cc..ac93c2e5 100644 --- a/docs/features.md +++ b/docs/features.md @@ -30,6 +30,7 @@ * SM4-CBC (Not supported in qatlib) * SHA3-224/256/384/512 * ChaCha20-Poly1305 + * SM3 (Not supported in qatlib) Please refer [here](qat_hw_algo.md) for supported platforms list and default behaviour. diff --git a/docs/limitations.md b/docs/limitations.md index b6d7e02e..09153805 100644 --- a/docs/limitations.md +++ b/docs/limitations.md @@ -41,6 +41,8 @@ * SM4-GCM and SM4-CCM are only supported with BabaSSL versions based on OpenSSL 1.1.1. They are not supported with OpenSSL 1.1.1, OpenSSL 3.0 and BabaSSL versions based on OpenSSL 3.0. +* HKDF based on SM3 is not supported in QAT_HW, The request will fallback to OpenSSL software if + fallback been enabled otherwise failures are observed. ## Known Issues diff --git a/docs/qat_hw_algo.md b/docs/qat_hw_algo.md index e942c273..8b4114c9 100644 --- a/docs/qat_hw_algo.md +++ b/docs/qat_hw_algo.md @@ -25,6 +25,7 @@ | SHA3-256/384/512 | | *** | *** | *** | | ChachaPoly | | *** | *** | *** | | SM4-CBC | | # | # | | +| SM3 | | *** | *** | | \* Enabled in the default build of qatengine for the specified platforms when `--with-qat_hw_dir` is provided in qatengine/qatprovider build configure.
\** Insecure algorithms which are disabled by default in QAT_HW driver version 1.7 & 1.8 and qatengine/qatprovider. Can be enabled using configure flag `--enable-qat_insecure_algorithms`. Driver will also needs to be built with the flag `./configure --enable-legacy-algorithms` to enable these algortihms at driver.
diff --git a/e_qat.c b/e_qat.c index f95aff57..af678516 100644 --- a/e_qat.c +++ b/e_qat.c @@ -183,6 +183,7 @@ int qat_hw_aes_cbc_hmac_sha_offload = 0; int qat_hw_sm4_cbc_offload = 0; int qat_sw_sm2_offload = 0; int qat_hw_sha_offload = 0; +int qat_hw_sm3_offload = 0; int qat_sw_sm3_offload = 0; int qat_sw_sm4_cbc_offload = 0; int qat_sw_sm4_gcm_offload = 0; @@ -480,6 +481,7 @@ static int qat_engine_destroy(ENGINE *e) qat_sw_sm4_cbc_offload = 0; qat_sw_sm4_gcm_offload = 0; qat_sw_sm4_ccm_offload = 0; + qat_hw_sm3_offload = 0; QAT_DEBUG_LOG_CLOSE(); ERR_unload_QAT_strings(); return 1; diff --git a/e_qat.h b/e_qat.h index 80fa0c4e..a0974a10 100644 --- a/e_qat.h +++ b/e_qat.h @@ -403,6 +403,7 @@ extern int qat_sw_ecdsa_offload; extern int qat_sw_gcm_offload; extern int qat_sw_sm2_offload; extern int qat_hw_sha_offload; +extern int qat_hw_sm3_offload; extern int qat_sw_sm3_offload; extern int qat_sw_sm4_cbc_offload; extern int qat_sw_sm4_gcm_offload; diff --git a/e_qat.txt b/e_qat.txt index 58864083..9b9dbdd0 100644 --- a/e_qat.txt +++ b/e_qat.txt @@ -77,68 +77,75 @@ QAT_F_QAT_GET_RSA_METHODS:167:qat_get_RSA_methods QAT_F_QAT_HKDF_DERIVE:168:qat_hkdf_derive QAT_F_QAT_HKDF_INIT:169:qat_hkdf_init QAT_F_QAT_HKDF_PMETH:170:qat_hkdf_pmeth -QAT_F_QAT_HW_FINISH_INT:171:qat_hw_finish_int -QAT_F_QAT_HW_INIT:172:qat_hw_init -QAT_F_QAT_HW_SHA3_OFFLOAD:173:qat_hw_sha3_offload -QAT_F_QAT_INIT_OP_DONE:174:qat_init_op_done -QAT_F_QAT_INIT_OP_DONE_PIPE:175:qat_init_op_done_pipe -QAT_F_QAT_INIT_OP_DONE_RSA_CRT:176:qat_init_op_done_rsa_crt -QAT_F_QAT_MOD_EXP:177:qat_mod_exp -QAT_F_QAT_PKEY_ECX_DERIVE25519:178:qat_pkey_ecx_derive25519 -QAT_F_QAT_PKEY_ECX_DERIVE448:179:qat_pkey_ecx_derive448 -QAT_F_QAT_PKEY_ECX_KEYGEN:180:qat_pkey_ecx_keygen -QAT_F_QAT_PRF_PMETH:181:qat_prf_pmeth -QAT_F_QAT_PRF_TLS_DERIVE:182:qat_prf_tls_derive -QAT_F_QAT_REMAP_INSTANCES:183:qat_remap_instances -QAT_F_QAT_RSA_DECRYPT:184:qat_rsa_decrypt -QAT_F_QAT_RSA_DECRYPT_CRT:185:qat_rsa_decrypt_CRT -QAT_F_QAT_RSA_ENCRYPT:186:qat_rsa_encrypt -QAT_F_QAT_RSA_PRIV_DEC:187:qat_rsa_priv_dec -QAT_F_QAT_RSA_PRIV_ENC:188:qat_rsa_priv_enc -QAT_F_QAT_RSA_PUB_DEC:189:qat_rsa_pub_dec -QAT_F_QAT_RSA_PUB_ENC:190:qat_rsa_pub_enc -QAT_F_QAT_SESSION_DATA_INIT:191:qat_session_data_init -QAT_F_QAT_SETUP_OP_PARAMS:192:qat_setup_op_params -QAT_F_QAT_SET_INSTANCE_FOR_THREAD:193:qat_set_instance_for_thread -QAT_F_QAT_SHA3_CLEANUP:194:qat_sha3_cleanup -QAT_F_QAT_SHA3_CTRL:195:qat_sha3_ctrl -QAT_F_QAT_SHA3_FINAL:196:qat_sha3_final -QAT_F_QAT_SHA3_SESSION_DATA_INIT:197:qat_sha3_session_data_init -QAT_F_QAT_SHA3_SETUP_PARAM:198:qat_sha3_setup_param -QAT_F_QAT_SHA3_UPDATE:199:qat_sha3_update -QAT_F_QAT_SM4_CBC_CLEANUP:200:qat_sm4_cbc_cleanup -QAT_F_QAT_SM4_CBC_DO_CIPHER:201:qat_sm4_cbc_do_cipher -QAT_F_QAT_SM4_CBC_INIT:202:qat_sm4_cbc_init -QAT_F_QAT_SW_INIT:203:qat_sw_init -QAT_F_QAT_SW_SM3_FINAL:204:qat_sw_sm3_final -QAT_F_QAT_SW_SM3_INIT:205:qat_sw_sm3_init -QAT_F_QAT_SW_SM3_UPDATE:206:qat_sw_sm3_update -QAT_F_QAT_SW_SM4_CBC_CIPHER:207:qat_sw_sm4_cbc_cipher -QAT_F_QAT_SW_SM4_CBC_CLEANUP:208:qat_sw_sm4_cbc_cleanup -QAT_F_QAT_SW_SM4_CBC_KEY_INIT:209:qat_sw_sm4_cbc_key_init -QAT_F_QAT_SW_SM4_CCM_CLEANUP:210:qat_sw_sm4_ccm_cleanup -QAT_F_QAT_SW_SM4_CCM_CTRL:211:qat_sw_sm4_ccm_ctrl -QAT_F_QAT_SW_SM4_CCM_DECRYPT:212:qat_sw_sm4_ccm_decrypt -QAT_F_QAT_SW_SM4_CCM_DO_CIPHER:213:qat_sw_sm4_ccm_do_cipher -QAT_F_QAT_SW_SM4_CCM_ENCRYPT:214:qat_sw_sm4_ccm_encrypt -QAT_F_QAT_SW_SM4_CCM_INIT:215:qat_sw_sm4_ccm_init -QAT_F_QAT_SW_SM4_GCM_CIPHER:216:qat_sw_sm4_gcm_cipher -QAT_F_QAT_SW_SM4_GCM_CLEANUP:217:qat_sw_sm4_gcm_cleanup -QAT_F_QAT_SW_SM4_GCM_CTRL:218:qat_sw_sm4_gcm_ctrl -QAT_F_QAT_SW_SM4_GCM_DECRYPT:219:qat_sw_sm4_gcm_decrypt -QAT_F_QAT_SW_SM4_GCM_ENCRYPT:220:qat_sw_sm4_gcm_encrypt -QAT_F_QAT_SW_SM4_GCM_INIT:221:qat_sw_sm4_gcm_init -QAT_F_QAT_SW_SM4_GCM_TLS_CIPHER:222:qat_sw_sm4_gcm_tls_cipher -QAT_F_QAT_SYM_PERFORM_OP:223:qat_sym_perform_op -QAT_F_QAT_VALIDATE_ECX_DERIVE:224:qat_validate_ecx_derive -QAT_F_QAT_X25519_PMETH:225:qat_x25519_pmeth -QAT_F_QAT_X448_PMETH:226:qat_x448_pmeth -QAT_F_VAESGCM_CIPHERS_CTRL:227:vaesgcm_ciphers_ctrl -QAT_F_VAESGCM_CIPHERS_DO_CIPHER:228:vaesgcm_ciphers_do_cipher -QAT_F_VAESGCM_CIPHERS_INIT:229:vaesgcm_ciphers_init -QAT_F_VAESGCM_INIT_GCM:230:vaesgcm_init_gcm -QAT_F_VAESGCM_INIT_IPSEC_MB_MGR:231:vaesgcm_init_ipsec_mb_mgr -QAT_F_VAESGCM_INIT_KEY:232:vaesgcm_init_key +QAT_F_QAT_HW_CREATE_SM3_METH:171:qat_hw_create_sm3_meth +QAT_F_QAT_HW_FINISH_INT:172:qat_hw_finish_int +QAT_F_QAT_HW_INIT:173:qat_hw_init +QAT_F_QAT_HW_SHA3_OFFLOAD:174:qat_hw_sha3_offload +QAT_F_QAT_HW_SM3_CLEANUP:175:qat_hw_sm3_cleanup +QAT_F_QAT_HW_SM3_COPY:176:qat_hw_sm3_copy +QAT_F_QAT_HW_SM3_DO_OFFLOAD:177:qat_hw_sm3_do_offload +QAT_F_QAT_HW_SM3_FINAL:178:qat_hw_sm3_final +QAT_F_QAT_HW_SM3_SETUP_PARAM:179:qat_hw_sm3_setup_param +QAT_F_QAT_HW_SM3_UPDATE:180:qat_hw_sm3_update +QAT_F_QAT_INIT_OP_DONE:181:qat_init_op_done +QAT_F_QAT_INIT_OP_DONE_PIPE:182:qat_init_op_done_pipe +QAT_F_QAT_INIT_OP_DONE_RSA_CRT:183:qat_init_op_done_rsa_crt +QAT_F_QAT_MOD_EXP:184:qat_mod_exp +QAT_F_QAT_PKEY_ECX_DERIVE25519:185:qat_pkey_ecx_derive25519 +QAT_F_QAT_PKEY_ECX_DERIVE448:186:qat_pkey_ecx_derive448 +QAT_F_QAT_PKEY_ECX_KEYGEN:187:qat_pkey_ecx_keygen +QAT_F_QAT_PRF_PMETH:188:qat_prf_pmeth +QAT_F_QAT_PRF_TLS_DERIVE:189:qat_prf_tls_derive +QAT_F_QAT_REMAP_INSTANCES:190:qat_remap_instances +QAT_F_QAT_RSA_DECRYPT:191:qat_rsa_decrypt +QAT_F_QAT_RSA_DECRYPT_CRT:192:qat_rsa_decrypt_CRT +QAT_F_QAT_RSA_ENCRYPT:193:qat_rsa_encrypt +QAT_F_QAT_RSA_PRIV_DEC:194:qat_rsa_priv_dec +QAT_F_QAT_RSA_PRIV_ENC:195:qat_rsa_priv_enc +QAT_F_QAT_RSA_PUB_DEC:196:qat_rsa_pub_dec +QAT_F_QAT_RSA_PUB_ENC:197:qat_rsa_pub_enc +QAT_F_QAT_SESSION_DATA_INIT:198:qat_session_data_init +QAT_F_QAT_SETUP_OP_PARAMS:199:qat_setup_op_params +QAT_F_QAT_SET_INSTANCE_FOR_THREAD:200:qat_set_instance_for_thread +QAT_F_QAT_SHA3_CLEANUP:201:qat_sha3_cleanup +QAT_F_QAT_SHA3_CTRL:202:qat_sha3_ctrl +QAT_F_QAT_SHA3_FINAL:203:qat_sha3_final +QAT_F_QAT_SHA3_SESSION_DATA_INIT:204:qat_sha3_session_data_init +QAT_F_QAT_SHA3_SETUP_PARAM:205:qat_sha3_setup_param +QAT_F_QAT_SHA3_UPDATE:206:qat_sha3_update +QAT_F_QAT_SM4_CBC_CLEANUP:207:qat_sm4_cbc_cleanup +QAT_F_QAT_SM4_CBC_DO_CIPHER:208:qat_sm4_cbc_do_cipher +QAT_F_QAT_SM4_CBC_INIT:209:qat_sm4_cbc_init +QAT_F_QAT_SW_INIT:210:qat_sw_init +QAT_F_QAT_SW_SM3_FINAL:211:qat_sw_sm3_final +QAT_F_QAT_SW_SM3_INIT:212:qat_sw_sm3_init +QAT_F_QAT_SW_SM3_UPDATE:213:qat_sw_sm3_update +QAT_F_QAT_SW_SM4_CBC_CIPHER:214:qat_sw_sm4_cbc_cipher +QAT_F_QAT_SW_SM4_CBC_CLEANUP:215:qat_sw_sm4_cbc_cleanup +QAT_F_QAT_SW_SM4_CBC_KEY_INIT:216:qat_sw_sm4_cbc_key_init +QAT_F_QAT_SW_SM4_CCM_CLEANUP:217:qat_sw_sm4_ccm_cleanup +QAT_F_QAT_SW_SM4_CCM_CTRL:218:qat_sw_sm4_ccm_ctrl +QAT_F_QAT_SW_SM4_CCM_DECRYPT:219:qat_sw_sm4_ccm_decrypt +QAT_F_QAT_SW_SM4_CCM_DO_CIPHER:220:qat_sw_sm4_ccm_do_cipher +QAT_F_QAT_SW_SM4_CCM_ENCRYPT:221:qat_sw_sm4_ccm_encrypt +QAT_F_QAT_SW_SM4_CCM_INIT:222:qat_sw_sm4_ccm_init +QAT_F_QAT_SW_SM4_GCM_CIPHER:223:qat_sw_sm4_gcm_cipher +QAT_F_QAT_SW_SM4_GCM_CLEANUP:224:qat_sw_sm4_gcm_cleanup +QAT_F_QAT_SW_SM4_GCM_CTRL:225:qat_sw_sm4_gcm_ctrl +QAT_F_QAT_SW_SM4_GCM_DECRYPT:226:qat_sw_sm4_gcm_decrypt +QAT_F_QAT_SW_SM4_GCM_ENCRYPT:227:qat_sw_sm4_gcm_encrypt +QAT_F_QAT_SW_SM4_GCM_INIT:228:qat_sw_sm4_gcm_init +QAT_F_QAT_SW_SM4_GCM_TLS_CIPHER:229:qat_sw_sm4_gcm_tls_cipher +QAT_F_QAT_SYM_PERFORM_OP:230:qat_sym_perform_op +QAT_F_QAT_VALIDATE_ECX_DERIVE:231:qat_validate_ecx_derive +QAT_F_QAT_X25519_PMETH:232:qat_x25519_pmeth +QAT_F_QAT_X448_PMETH:233:qat_x448_pmeth +QAT_F_VAESGCM_CIPHERS_CTRL:234:vaesgcm_ciphers_ctrl +QAT_F_VAESGCM_CIPHERS_DO_CIPHER:235:vaesgcm_ciphers_do_cipher +QAT_F_VAESGCM_CIPHERS_INIT:236:vaesgcm_ciphers_init +QAT_F_VAESGCM_INIT_GCM:237:vaesgcm_init_gcm +QAT_F_VAESGCM_INIT_IPSEC_MB_MGR:238:vaesgcm_init_ipsec_mb_mgr +QAT_F_VAESGCM_INIT_KEY:239:vaesgcm_init_key #Reason codes QAT_R_AAD_INVALID_PTR:100:aad invalid ptr @@ -399,44 +406,45 @@ QAT_R_SET_TAG_INVALID_OP:344:set tag invalid op QAT_R_SHA3_CTX_NULL:345:sha3 ctx null QAT_R_SIG_GET_R_S_FAILURE:346:sig get r s failure QAT_R_SIG_MALLOC_FAILURE:347:sig malloc failure -QAT_R_SM3_FINAL_FAILURE:348:sm3 final failure -QAT_R_SM3_INIT_FAILURE:349:sm3 init failure -QAT_R_SM3_UPDATE_FAILURE:350:sm3 update failure -QAT_R_SM4_CCM_DECRYPT_FAILURE:351:sm4 ccm decrypt failure -QAT_R_SM4_GCM_DECRYPT_FAILURE:352:sm4 gcm decrypt failure -QAT_R_SM4_GCM_ENCRYPT_FAILURE:353:sm4 gcm encrypt failure -QAT_R_SM4_GET_INSTANCE_FAILED:354:sm4 get instance failed -QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED:355:sm4 get sessionctx size failed -QAT_R_SM4_MALLOC_FAILED:356:sm4 malloc failed -QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE:357:sm4 no qat instance available -QAT_R_SM4_NULL_CKEY:358:sm4 null ckey -QAT_R_SM4_NULL_CTX_OR_KEY:359:sm4 null ctx or key -QAT_R_SM4_NULL_POINTER:360:sm4 null pointer -QAT_R_SM4_NULL_QCTX:361:sm4 null qctx -QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED:362:sm4 qat context not initialised -QAT_R_SM4_QAT_INITSESSION_FAILED:363:sm4 qat initsession failed -QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED:364:sm4 qat submit request failed -QAT_R_SM4_REMOVE_SESSION_FAILED:365:sm4 remove session failed -QAT_R_SM4_SETUP_META_DATA_FAILED:366:sm4 setup meta data failed -QAT_R_SM4_SET_METHODS_FAILED:367:sm4 set methods failed -QAT_R_SSD_MALLOC_FAILURE:368:ssd malloc failure -QAT_R_SSD_NULL:369:ssd null -QAT_R_START_INSTANCE_FAILURE:370:start instance failure -QAT_R_STOP_INSTANCE_FAILURE:371:stop instance failure -QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL:372:sw get compute key pfunc null -QAT_R_SW_GET_KEYGEN_PFUNC_NULL:373:sw get keygen pfunc null -QAT_R_SW_GET_SIGN_PFUNC_NULL:374:sw get sign pfunc null -QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL:375:sw get sign setup pfunc null -QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL:376:sw get sign sig pfunc null -QAT_R_SW_GET_VERIFY_PFUNC_NULL:377:sw get verify pfunc null -QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL:378:sw get verify sig pfunc null -QAT_R_SW_METHOD_NULL:379:sw method null -QAT_R_S_NULL:380:s null -QAT_R_S_Q_COMPARE_FAILURE:381:s q compare failure -QAT_R_TAG_NOTSET:382:tag notset -QAT_R_UNKNOWN_PADDING:383:unknown padding -QAT_R_UNKNOWN_PADDING_TYPE:384:unknown padding type -QAT_R_WAKE_PAUSE_JOB_FAILURE:385:wake pause job failure -QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE:386:x y tx ty bn malloc failure -QAT_R_X_Y_Z_MALLOC_FAILURE:387:x y z malloc failure -QAT_R_Z_ALLOCATE_FAILURE:388:z allocate failure +QAT_R_SM3_CTX_NULL:348:sm3 ctx null +QAT_R_SM3_FINAL_FAILURE:349:sm3 final failure +QAT_R_SM3_INIT_FAILURE:350:sm3 init failure +QAT_R_SM3_UPDATE_FAILURE:351:sm3 update failure +QAT_R_SM4_CCM_DECRYPT_FAILURE:352:sm4 ccm decrypt failure +QAT_R_SM4_GCM_DECRYPT_FAILURE:353:sm4 gcm decrypt failure +QAT_R_SM4_GCM_ENCRYPT_FAILURE:354:sm4 gcm encrypt failure +QAT_R_SM4_GET_INSTANCE_FAILED:355:sm4 get instance failed +QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED:356:sm4 get sessionctx size failed +QAT_R_SM4_MALLOC_FAILED:357:sm4 malloc failed +QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE:358:sm4 no qat instance available +QAT_R_SM4_NULL_CKEY:359:sm4 null ckey +QAT_R_SM4_NULL_CTX_OR_KEY:360:sm4 null ctx or key +QAT_R_SM4_NULL_POINTER:361:sm4 null pointer +QAT_R_SM4_NULL_QCTX:362:sm4 null qctx +QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED:363:sm4 qat context not initialised +QAT_R_SM4_QAT_INITSESSION_FAILED:364:sm4 qat initsession failed +QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED:365:sm4 qat submit request failed +QAT_R_SM4_REMOVE_SESSION_FAILED:366:sm4 remove session failed +QAT_R_SM4_SETUP_META_DATA_FAILED:367:sm4 setup meta data failed +QAT_R_SM4_SET_METHODS_FAILED:368:sm4 set methods failed +QAT_R_SSD_MALLOC_FAILURE:369:ssd malloc failure +QAT_R_SSD_NULL:370:ssd null +QAT_R_START_INSTANCE_FAILURE:371:start instance failure +QAT_R_STOP_INSTANCE_FAILURE:372:stop instance failure +QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL:373:sw get compute key pfunc null +QAT_R_SW_GET_KEYGEN_PFUNC_NULL:374:sw get keygen pfunc null +QAT_R_SW_GET_SIGN_PFUNC_NULL:375:sw get sign pfunc null +QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL:376:sw get sign setup pfunc null +QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL:377:sw get sign sig pfunc null +QAT_R_SW_GET_VERIFY_PFUNC_NULL:378:sw get verify pfunc null +QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL:379:sw get verify sig pfunc null +QAT_R_SW_METHOD_NULL:380:sw method null +QAT_R_S_NULL:381:s null +QAT_R_S_Q_COMPARE_FAILURE:382:s q compare failure +QAT_R_TAG_NOTSET:383:tag notset +QAT_R_UNKNOWN_PADDING:384:unknown padding +QAT_R_UNKNOWN_PADDING_TYPE:385:unknown padding type +QAT_R_WAKE_PAUSE_JOB_FAILURE:386:wake pause job failure +QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE:387:x y tx ty bn malloc failure +QAT_R_X_Y_Z_MALLOC_FAILURE:388:x y z malloc failure +QAT_R_Z_ALLOCATE_FAILURE:389:z allocate failure diff --git a/e_qat_err.c b/e_qat_err.c index a69cb1a6..34086cc0 100644 --- a/e_qat_err.c +++ b/e_qat_err.c @@ -105,9 +105,16 @@ static ERR_STRING_DATA QAT_str_functs[] = { {ERR_PACK(0, QAT_F_QAT_HKDF_DERIVE, 0), "qat_hkdf_derive"}, {ERR_PACK(0, QAT_F_QAT_HKDF_INIT, 0), "qat_hkdf_init"}, {ERR_PACK(0, QAT_F_QAT_HKDF_PMETH, 0), "qat_hkdf_pmeth"}, + {ERR_PACK(0, QAT_F_QAT_HW_CREATE_SM3_METH, 0), "qat_hw_create_sm3_meth"}, {ERR_PACK(0, QAT_F_QAT_HW_FINISH_INT, 0), "qat_hw_finish_int"}, {ERR_PACK(0, QAT_F_QAT_HW_INIT, 0), "qat_hw_init"}, {ERR_PACK(0, QAT_F_QAT_HW_SHA3_OFFLOAD, 0), "qat_hw_sha3_offload"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_CLEANUP, 0), "qat_hw_sm3_cleanup"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_COPY, 0), "qat_hw_sm3_copy"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_DO_OFFLOAD, 0), "qat_hw_sm3_do_offload"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_FINAL, 0), "qat_hw_sm3_final"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_SETUP_PARAM, 0), "qat_hw_sm3_setup_param"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_UPDATE, 0), "qat_hw_sm3_update"}, {ERR_PACK(0, QAT_F_QAT_INIT_OP_DONE, 0), "qat_init_op_done"}, {ERR_PACK(0, QAT_F_QAT_INIT_OP_DONE_PIPE, 0), "qat_init_op_done_pipe"}, {ERR_PACK(0, QAT_F_QAT_INIT_OP_DONE_RSA_CRT, 0), @@ -520,6 +527,7 @@ static ERR_STRING_DATA QAT_str_reasons[] = { {ERR_PACK(0, 0, QAT_R_SHA3_CTX_NULL), "sha3 ctx null"}, {ERR_PACK(0, 0, QAT_R_SIG_GET_R_S_FAILURE), "sig get r s failure"}, {ERR_PACK(0, 0, QAT_R_SIG_MALLOC_FAILURE), "sig malloc failure"}, + {ERR_PACK(0, 0, QAT_R_SM3_CTX_NULL), "sm3 ctx null"}, {ERR_PACK(0, 0, QAT_R_SM3_FINAL_FAILURE), "sm3 final failure"}, {ERR_PACK(0, 0, QAT_R_SM3_INIT_FAILURE), "sm3 init failure"}, {ERR_PACK(0, 0, QAT_R_SM3_UPDATE_FAILURE), "sm3 update failure"}, diff --git a/e_qat_err.h b/e_qat_err.h index 2e8dbbcc..bf178a28 100644 --- a/e_qat_err.h +++ b/e_qat_err.h @@ -100,68 +100,75 @@ void ERR_QAT_error(int function, int reason, char *file, int line); # define QAT_F_QAT_HKDF_DERIVE 168 # define QAT_F_QAT_HKDF_INIT 169 # define QAT_F_QAT_HKDF_PMETH 170 -# define QAT_F_QAT_HW_FINISH_INT 171 -# define QAT_F_QAT_HW_INIT 172 -# define QAT_F_QAT_HW_SHA3_OFFLOAD 173 -# define QAT_F_QAT_INIT_OP_DONE 174 -# define QAT_F_QAT_INIT_OP_DONE_PIPE 175 -# define QAT_F_QAT_INIT_OP_DONE_RSA_CRT 176 -# define QAT_F_QAT_MOD_EXP 177 -# define QAT_F_QAT_PKEY_ECX_DERIVE25519 178 -# define QAT_F_QAT_PKEY_ECX_DERIVE448 179 -# define QAT_F_QAT_PKEY_ECX_KEYGEN 180 -# define QAT_F_QAT_PRF_PMETH 181 -# define QAT_F_QAT_PRF_TLS_DERIVE 182 -# define QAT_F_QAT_REMAP_INSTANCES 183 -# define QAT_F_QAT_RSA_DECRYPT 184 -# define QAT_F_QAT_RSA_DECRYPT_CRT 185 -# define QAT_F_QAT_RSA_ENCRYPT 186 -# define QAT_F_QAT_RSA_PRIV_DEC 187 -# define QAT_F_QAT_RSA_PRIV_ENC 188 -# define QAT_F_QAT_RSA_PUB_DEC 189 -# define QAT_F_QAT_RSA_PUB_ENC 190 -# define QAT_F_QAT_SESSION_DATA_INIT 191 -# define QAT_F_QAT_SETUP_OP_PARAMS 192 -# define QAT_F_QAT_SET_INSTANCE_FOR_THREAD 193 -# define QAT_F_QAT_SHA3_CLEANUP 194 -# define QAT_F_QAT_SHA3_CTRL 195 -# define QAT_F_QAT_SHA3_FINAL 196 -# define QAT_F_QAT_SHA3_SESSION_DATA_INIT 197 -# define QAT_F_QAT_SHA3_SETUP_PARAM 198 -# define QAT_F_QAT_SHA3_UPDATE 199 -# define QAT_F_QAT_SM4_CBC_CLEANUP 200 -# define QAT_F_QAT_SM4_CBC_DO_CIPHER 201 -# define QAT_F_QAT_SM4_CBC_INIT 202 -# define QAT_F_QAT_SW_INIT 203 -# define QAT_F_QAT_SW_SM3_FINAL 204 -# define QAT_F_QAT_SW_SM3_INIT 205 -# define QAT_F_QAT_SW_SM3_UPDATE 206 -# define QAT_F_QAT_SW_SM4_CBC_CIPHER 207 -# define QAT_F_QAT_SW_SM4_CBC_CLEANUP 208 -# define QAT_F_QAT_SW_SM4_CBC_KEY_INIT 209 -# define QAT_F_QAT_SW_SM4_CCM_CLEANUP 210 -# define QAT_F_QAT_SW_SM4_CCM_CTRL 211 -# define QAT_F_QAT_SW_SM4_CCM_DECRYPT 212 -# define QAT_F_QAT_SW_SM4_CCM_DO_CIPHER 213 -# define QAT_F_QAT_SW_SM4_CCM_ENCRYPT 214 -# define QAT_F_QAT_SW_SM4_CCM_INIT 215 -# define QAT_F_QAT_SW_SM4_GCM_CIPHER 216 -# define QAT_F_QAT_SW_SM4_GCM_CLEANUP 217 -# define QAT_F_QAT_SW_SM4_GCM_CTRL 218 -# define QAT_F_QAT_SW_SM4_GCM_DECRYPT 219 -# define QAT_F_QAT_SW_SM4_GCM_ENCRYPT 220 -# define QAT_F_QAT_SW_SM4_GCM_INIT 221 -# define QAT_F_QAT_SW_SM4_GCM_TLS_CIPHER 222 -# define QAT_F_QAT_SYM_PERFORM_OP 223 -# define QAT_F_QAT_VALIDATE_ECX_DERIVE 224 -# define QAT_F_QAT_X25519_PMETH 225 -# define QAT_F_QAT_X448_PMETH 226 -# define QAT_F_VAESGCM_CIPHERS_CTRL 227 -# define QAT_F_VAESGCM_CIPHERS_DO_CIPHER 228 -# define QAT_F_VAESGCM_CIPHERS_INIT 229 -# define QAT_F_VAESGCM_INIT_GCM 230 -# define QAT_F_VAESGCM_INIT_IPSEC_MB_MGR 231 -# define QAT_F_VAESGCM_INIT_KEY 232 +# define QAT_F_QAT_HW_CREATE_SM3_METH 171 +# define QAT_F_QAT_HW_FINISH_INT 172 +# define QAT_F_QAT_HW_INIT 173 +# define QAT_F_QAT_HW_SHA3_OFFLOAD 174 +# define QAT_F_QAT_HW_SM3_CLEANUP 175 +# define QAT_F_QAT_HW_SM3_COPY 176 +# define QAT_F_QAT_HW_SM3_DO_OFFLOAD 177 +# define QAT_F_QAT_HW_SM3_FINAL 178 +# define QAT_F_QAT_HW_SM3_SETUP_PARAM 179 +# define QAT_F_QAT_HW_SM3_UPDATE 180 +# define QAT_F_QAT_INIT_OP_DONE 181 +# define QAT_F_QAT_INIT_OP_DONE_PIPE 182 +# define QAT_F_QAT_INIT_OP_DONE_RSA_CRT 183 +# define QAT_F_QAT_MOD_EXP 184 +# define QAT_F_QAT_PKEY_ECX_DERIVE25519 185 +# define QAT_F_QAT_PKEY_ECX_DERIVE448 186 +# define QAT_F_QAT_PKEY_ECX_KEYGEN 187 +# define QAT_F_QAT_PRF_PMETH 188 +# define QAT_F_QAT_PRF_TLS_DERIVE 189 +# define QAT_F_QAT_REMAP_INSTANCES 190 +# define QAT_F_QAT_RSA_DECRYPT 191 +# define QAT_F_QAT_RSA_DECRYPT_CRT 192 +# define QAT_F_QAT_RSA_ENCRYPT 193 +# define QAT_F_QAT_RSA_PRIV_DEC 194 +# define QAT_F_QAT_RSA_PRIV_ENC 195 +# define QAT_F_QAT_RSA_PUB_DEC 196 +# define QAT_F_QAT_RSA_PUB_ENC 197 +# define QAT_F_QAT_SESSION_DATA_INIT 198 +# define QAT_F_QAT_SETUP_OP_PARAMS 199 +# define QAT_F_QAT_SET_INSTANCE_FOR_THREAD 200 +# define QAT_F_QAT_SHA3_CLEANUP 201 +# define QAT_F_QAT_SHA3_CTRL 202 +# define QAT_F_QAT_SHA3_FINAL 203 +# define QAT_F_QAT_SHA3_SESSION_DATA_INIT 204 +# define QAT_F_QAT_SHA3_SETUP_PARAM 205 +# define QAT_F_QAT_SHA3_UPDATE 206 +# define QAT_F_QAT_SM4_CBC_CLEANUP 207 +# define QAT_F_QAT_SM4_CBC_DO_CIPHER 208 +# define QAT_F_QAT_SM4_CBC_INIT 209 +# define QAT_F_QAT_SW_INIT 210 +# define QAT_F_QAT_SW_SM3_FINAL 211 +# define QAT_F_QAT_SW_SM3_INIT 212 +# define QAT_F_QAT_SW_SM3_UPDATE 213 +# define QAT_F_QAT_SW_SM4_CBC_CIPHER 214 +# define QAT_F_QAT_SW_SM4_CBC_CLEANUP 215 +# define QAT_F_QAT_SW_SM4_CBC_KEY_INIT 216 +# define QAT_F_QAT_SW_SM4_CCM_CLEANUP 217 +# define QAT_F_QAT_SW_SM4_CCM_CTRL 218 +# define QAT_F_QAT_SW_SM4_CCM_DECRYPT 219 +# define QAT_F_QAT_SW_SM4_CCM_DO_CIPHER 220 +# define QAT_F_QAT_SW_SM4_CCM_ENCRYPT 221 +# define QAT_F_QAT_SW_SM4_CCM_INIT 222 +# define QAT_F_QAT_SW_SM4_GCM_CIPHER 223 +# define QAT_F_QAT_SW_SM4_GCM_CLEANUP 224 +# define QAT_F_QAT_SW_SM4_GCM_CTRL 225 +# define QAT_F_QAT_SW_SM4_GCM_DECRYPT 226 +# define QAT_F_QAT_SW_SM4_GCM_ENCRYPT 227 +# define QAT_F_QAT_SW_SM4_GCM_INIT 228 +# define QAT_F_QAT_SW_SM4_GCM_TLS_CIPHER 229 +# define QAT_F_QAT_SYM_PERFORM_OP 230 +# define QAT_F_QAT_VALIDATE_ECX_DERIVE 231 +# define QAT_F_QAT_X25519_PMETH 232 +# define QAT_F_QAT_X448_PMETH 233 +# define QAT_F_VAESGCM_CIPHERS_CTRL 234 +# define QAT_F_VAESGCM_CIPHERS_DO_CIPHER 235 +# define QAT_F_VAESGCM_CIPHERS_INIT 236 +# define QAT_F_VAESGCM_INIT_GCM 237 +# define QAT_F_VAESGCM_INIT_IPSEC_MB_MGR 238 +# define QAT_F_VAESGCM_INIT_KEY 239 /* * QAT reason codes. @@ -414,46 +421,47 @@ void ERR_QAT_error(int function, int reason, char *file, int line); # define QAT_R_SHA3_CTX_NULL 345 # define QAT_R_SIG_GET_R_S_FAILURE 346 # define QAT_R_SIG_MALLOC_FAILURE 347 -# define QAT_R_SM3_FINAL_FAILURE 348 -# define QAT_R_SM3_INIT_FAILURE 349 -# define QAT_R_SM3_UPDATE_FAILURE 350 -# define QAT_R_SM4_CCM_DECRYPT_FAILURE 351 -# define QAT_R_SM4_GCM_DECRYPT_FAILURE 352 -# define QAT_R_SM4_GCM_ENCRYPT_FAILURE 353 -# define QAT_R_SM4_GET_INSTANCE_FAILED 354 -# define QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED 355 -# define QAT_R_SM4_MALLOC_FAILED 356 -# define QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE 357 -# define QAT_R_SM4_NULL_CKEY 358 -# define QAT_R_SM4_NULL_CTX_OR_KEY 359 -# define QAT_R_SM4_NULL_POINTER 360 -# define QAT_R_SM4_NULL_QCTX 361 -# define QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED 362 -# define QAT_R_SM4_QAT_INITSESSION_FAILED 363 -# define QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED 364 -# define QAT_R_SM4_REMOVE_SESSION_FAILED 365 -# define QAT_R_SM4_SETUP_META_DATA_FAILED 366 -# define QAT_R_SM4_SET_METHODS_FAILED 367 -# define QAT_R_SSD_MALLOC_FAILURE 368 -# define QAT_R_SSD_NULL 369 -# define QAT_R_START_INSTANCE_FAILURE 370 -# define QAT_R_STOP_INSTANCE_FAILURE 371 -# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 372 -# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 373 -# define QAT_R_SW_GET_SIGN_PFUNC_NULL 374 -# define QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL 375 -# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 376 -# define QAT_R_SW_GET_VERIFY_PFUNC_NULL 377 -# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 378 -# define QAT_R_SW_METHOD_NULL 379 -# define QAT_R_S_NULL 380 -# define QAT_R_S_Q_COMPARE_FAILURE 381 -# define QAT_R_TAG_NOTSET 382 -# define QAT_R_UNKNOWN_PADDING 383 -# define QAT_R_UNKNOWN_PADDING_TYPE 384 -# define QAT_R_WAKE_PAUSE_JOB_FAILURE 385 -# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 386 -# define QAT_R_X_Y_Z_MALLOC_FAILURE 387 -# define QAT_R_Z_ALLOCATE_FAILURE 388 +# define QAT_R_SM3_CTX_NULL 348 +# define QAT_R_SM3_FINAL_FAILURE 349 +# define QAT_R_SM3_INIT_FAILURE 350 +# define QAT_R_SM3_UPDATE_FAILURE 351 +# define QAT_R_SM4_CCM_DECRYPT_FAILURE 352 +# define QAT_R_SM4_GCM_DECRYPT_FAILURE 353 +# define QAT_R_SM4_GCM_ENCRYPT_FAILURE 354 +# define QAT_R_SM4_GET_INSTANCE_FAILED 355 +# define QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED 356 +# define QAT_R_SM4_MALLOC_FAILED 357 +# define QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE 358 +# define QAT_R_SM4_NULL_CKEY 359 +# define QAT_R_SM4_NULL_CTX_OR_KEY 360 +# define QAT_R_SM4_NULL_POINTER 361 +# define QAT_R_SM4_NULL_QCTX 362 +# define QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED 363 +# define QAT_R_SM4_QAT_INITSESSION_FAILED 364 +# define QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED 365 +# define QAT_R_SM4_REMOVE_SESSION_FAILED 366 +# define QAT_R_SM4_SETUP_META_DATA_FAILED 367 +# define QAT_R_SM4_SET_METHODS_FAILED 368 +# define QAT_R_SSD_MALLOC_FAILURE 369 +# define QAT_R_SSD_NULL 370 +# define QAT_R_START_INSTANCE_FAILURE 371 +# define QAT_R_STOP_INSTANCE_FAILURE 372 +# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 373 +# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 374 +# define QAT_R_SW_GET_SIGN_PFUNC_NULL 375 +# define QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL 376 +# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 377 +# define QAT_R_SW_GET_VERIFY_PFUNC_NULL 378 +# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 379 +# define QAT_R_SW_METHOD_NULL 380 +# define QAT_R_S_NULL 381 +# define QAT_R_S_Q_COMPARE_FAILURE 382 +# define QAT_R_TAG_NOTSET 383 +# define QAT_R_UNKNOWN_PADDING 384 +# define QAT_R_UNKNOWN_PADDING_TYPE 385 +# define QAT_R_WAKE_PAUSE_JOB_FAILURE 386 +# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 387 +# define QAT_R_X_Y_Z_MALLOC_FAILURE 388 +# define QAT_R_Z_ALLOCATE_FAILURE 389 #endif diff --git a/qat_bssl_err.c b/qat_bssl_err.c index 8484a2ff..66c9200b 100644 --- a/qat_bssl_err.c +++ b/qat_bssl_err.c @@ -105,9 +105,16 @@ static ERR_STRING_DATA QAT_str_functs[] = { {ERR_PACK(0, QAT_F_QAT_HKDF_DERIVE, 0), "qat_hkdf_derive"}, {ERR_PACK(0, QAT_F_QAT_HKDF_INIT, 0), "qat_hkdf_init"}, {ERR_PACK(0, QAT_F_QAT_HKDF_PMETH, 0), "qat_hkdf_pmeth"}, + {ERR_PACK(0, QAT_F_QAT_HW_CREATE_SM3_METH, 0), "qat_hw_create_sm3_meth"}, {ERR_PACK(0, QAT_F_QAT_HW_FINISH_INT, 0), "qat_hw_finish_int"}, {ERR_PACK(0, QAT_F_QAT_HW_INIT, 0), "qat_hw_init"}, {ERR_PACK(0, QAT_F_QAT_HW_SHA3_OFFLOAD, 0), "qat_hw_sha3_offload"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_CLEANUP, 0), "qat_hw_sm3_cleanup"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_COPY, 0), "qat_hw_sm3_copy"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_DO_OFFLOAD, 0), "qat_hw_sm3_do_offload"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_FINAL, 0), "qat_hw_sm3_final"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_SETUP_PARAM, 0), "qat_hw_sm3_setup_param"}, + {ERR_PACK(0, QAT_F_QAT_HW_SM3_UPDATE, 0), "qat_hw_sm3_update"}, {ERR_PACK(0, QAT_F_QAT_INIT_OP_DONE, 0), "qat_init_op_done"}, {ERR_PACK(0, QAT_F_QAT_INIT_OP_DONE_PIPE, 0), "qat_init_op_done_pipe"}, {ERR_PACK(0, QAT_F_QAT_INIT_OP_DONE_RSA_CRT, 0), @@ -520,6 +527,7 @@ static ERR_STRING_DATA QAT_str_reasons[] = { {ERR_PACK(0, 0, QAT_R_SHA3_CTX_NULL), "sha3 ctx null"}, {ERR_PACK(0, 0, QAT_R_SIG_GET_R_S_FAILURE), "sig get r s failure"}, {ERR_PACK(0, 0, QAT_R_SIG_MALLOC_FAILURE), "sig malloc failure"}, + {ERR_PACK(0, 0, QAT_R_SM3_CTX_NULL), "sm3 ctx null"}, {ERR_PACK(0, 0, QAT_R_SM3_FINAL_FAILURE), "sm3 final failure"}, {ERR_PACK(0, 0, QAT_R_SM3_INIT_FAILURE), "sm3 init failure"}, {ERR_PACK(0, 0, QAT_R_SM3_UPDATE_FAILURE), "sm3 update failure"}, diff --git a/qat_bssl_err.h b/qat_bssl_err.h index a54dd830..2a350747 100644 --- a/qat_bssl_err.h +++ b/qat_bssl_err.h @@ -97,68 +97,75 @@ void ERR_QAT_error(int function, int reason, char *file, int line); # define QAT_F_QAT_HKDF_DERIVE 168 # define QAT_F_QAT_HKDF_INIT 169 # define QAT_F_QAT_HKDF_PMETH 170 -# define QAT_F_QAT_HW_FINISH_INT 171 -# define QAT_F_QAT_HW_INIT 172 -# define QAT_F_QAT_HW_SHA3_OFFLOAD 173 -# define QAT_F_QAT_INIT_OP_DONE 174 -# define QAT_F_QAT_INIT_OP_DONE_PIPE 175 -# define QAT_F_QAT_INIT_OP_DONE_RSA_CRT 176 -# define QAT_F_QAT_MOD_EXP 177 -# define QAT_F_QAT_PKEY_ECX_DERIVE25519 178 -# define QAT_F_QAT_PKEY_ECX_DERIVE448 179 -# define QAT_F_QAT_PKEY_ECX_KEYGEN 180 -# define QAT_F_QAT_PRF_PMETH 181 -# define QAT_F_QAT_PRF_TLS_DERIVE 182 -# define QAT_F_QAT_REMAP_INSTANCES 183 -# define QAT_F_QAT_RSA_DECRYPT 184 -# define QAT_F_QAT_RSA_DECRYPT_CRT 185 -# define QAT_F_QAT_RSA_ENCRYPT 186 -# define QAT_F_QAT_RSA_PRIV_DEC 187 -# define QAT_F_QAT_RSA_PRIV_ENC 188 -# define QAT_F_QAT_RSA_PUB_DEC 189 -# define QAT_F_QAT_RSA_PUB_ENC 190 -# define QAT_F_QAT_SESSION_DATA_INIT 191 -# define QAT_F_QAT_SETUP_OP_PARAMS 192 -# define QAT_F_QAT_SET_INSTANCE_FOR_THREAD 193 -# define QAT_F_QAT_SHA3_CLEANUP 194 -# define QAT_F_QAT_SHA3_CTRL 195 -# define QAT_F_QAT_SHA3_FINAL 196 -# define QAT_F_QAT_SHA3_SESSION_DATA_INIT 197 -# define QAT_F_QAT_SHA3_SETUP_PARAM 198 -# define QAT_F_QAT_SHA3_UPDATE 199 -# define QAT_F_QAT_SM4_CBC_CLEANUP 200 -# define QAT_F_QAT_SM4_CBC_DO_CIPHER 201 -# define QAT_F_QAT_SM4_CBC_INIT 202 -# define QAT_F_QAT_SW_INIT 203 -# define QAT_F_QAT_SW_SM3_FINAL 204 -# define QAT_F_QAT_SW_SM3_INIT 205 -# define QAT_F_QAT_SW_SM3_UPDATE 206 -# define QAT_F_QAT_SW_SM4_CBC_CIPHER 207 -# define QAT_F_QAT_SW_SM4_CBC_CLEANUP 208 -# define QAT_F_QAT_SW_SM4_CBC_KEY_INIT 209 -# define QAT_F_QAT_SW_SM4_CCM_CLEANUP 210 -# define QAT_F_QAT_SW_SM4_CCM_CTRL 211 -# define QAT_F_QAT_SW_SM4_CCM_DECRYPT 212 -# define QAT_F_QAT_SW_SM4_CCM_DO_CIPHER 213 -# define QAT_F_QAT_SW_SM4_CCM_ENCRYPT 214 -# define QAT_F_QAT_SW_SM4_CCM_INIT 215 -# define QAT_F_QAT_SW_SM4_GCM_CIPHER 216 -# define QAT_F_QAT_SW_SM4_GCM_CLEANUP 217 -# define QAT_F_QAT_SW_SM4_GCM_CTRL 218 -# define QAT_F_QAT_SW_SM4_GCM_DECRYPT 219 -# define QAT_F_QAT_SW_SM4_GCM_ENCRYPT 220 -# define QAT_F_QAT_SW_SM4_GCM_INIT 221 -# define QAT_F_QAT_SW_SM4_GCM_TLS_CIPHER 222 -# define QAT_F_QAT_SYM_PERFORM_OP 223 -# define QAT_F_QAT_VALIDATE_ECX_DERIVE 224 -# define QAT_F_QAT_X25519_PMETH 225 -# define QAT_F_QAT_X448_PMETH 226 -# define QAT_F_VAESGCM_CIPHERS_CTRL 227 -# define QAT_F_VAESGCM_CIPHERS_DO_CIPHER 228 -# define QAT_F_VAESGCM_CIPHERS_INIT 229 -# define QAT_F_VAESGCM_INIT_GCM 230 -# define QAT_F_VAESGCM_INIT_IPSEC_MB_MGR 231 -# define QAT_F_VAESGCM_INIT_KEY 232 +# define QAT_F_QAT_HW_CREATE_SM3_METH 171 +# define QAT_F_QAT_HW_FINISH_INT 172 +# define QAT_F_QAT_HW_INIT 173 +# define QAT_F_QAT_HW_SHA3_OFFLOAD 174 +# define QAT_F_QAT_HW_SM3_CLEANUP 175 +# define QAT_F_QAT_HW_SM3_COPY 176 +# define QAT_F_QAT_HW_SM3_DO_OFFLOAD 177 +# define QAT_F_QAT_HW_SM3_FINAL 178 +# define QAT_F_QAT_HW_SM3_SETUP_PARAM 179 +# define QAT_F_QAT_HW_SM3_UPDATE 180 +# define QAT_F_QAT_INIT_OP_DONE 181 +# define QAT_F_QAT_INIT_OP_DONE_PIPE 182 +# define QAT_F_QAT_INIT_OP_DONE_RSA_CRT 183 +# define QAT_F_QAT_MOD_EXP 184 +# define QAT_F_QAT_PKEY_ECX_DERIVE25519 185 +# define QAT_F_QAT_PKEY_ECX_DERIVE448 186 +# define QAT_F_QAT_PKEY_ECX_KEYGEN 187 +# define QAT_F_QAT_PRF_PMETH 188 +# define QAT_F_QAT_PRF_TLS_DERIVE 189 +# define QAT_F_QAT_REMAP_INSTANCES 190 +# define QAT_F_QAT_RSA_DECRYPT 191 +# define QAT_F_QAT_RSA_DECRYPT_CRT 192 +# define QAT_F_QAT_RSA_ENCRYPT 193 +# define QAT_F_QAT_RSA_PRIV_DEC 194 +# define QAT_F_QAT_RSA_PRIV_ENC 195 +# define QAT_F_QAT_RSA_PUB_DEC 196 +# define QAT_F_QAT_RSA_PUB_ENC 197 +# define QAT_F_QAT_SESSION_DATA_INIT 198 +# define QAT_F_QAT_SETUP_OP_PARAMS 199 +# define QAT_F_QAT_SET_INSTANCE_FOR_THREAD 200 +# define QAT_F_QAT_SHA3_CLEANUP 201 +# define QAT_F_QAT_SHA3_CTRL 202 +# define QAT_F_QAT_SHA3_FINAL 203 +# define QAT_F_QAT_SHA3_SESSION_DATA_INIT 204 +# define QAT_F_QAT_SHA3_SETUP_PARAM 205 +# define QAT_F_QAT_SHA3_UPDATE 206 +# define QAT_F_QAT_SM4_CBC_CLEANUP 207 +# define QAT_F_QAT_SM4_CBC_DO_CIPHER 208 +# define QAT_F_QAT_SM4_CBC_INIT 209 +# define QAT_F_QAT_SW_INIT 210 +# define QAT_F_QAT_SW_SM3_FINAL 211 +# define QAT_F_QAT_SW_SM3_INIT 212 +# define QAT_F_QAT_SW_SM3_UPDATE 213 +# define QAT_F_QAT_SW_SM4_CBC_CIPHER 214 +# define QAT_F_QAT_SW_SM4_CBC_CLEANUP 215 +# define QAT_F_QAT_SW_SM4_CBC_KEY_INIT 216 +# define QAT_F_QAT_SW_SM4_CCM_CLEANUP 217 +# define QAT_F_QAT_SW_SM4_CCM_CTRL 218 +# define QAT_F_QAT_SW_SM4_CCM_DECRYPT 219 +# define QAT_F_QAT_SW_SM4_CCM_DO_CIPHER 220 +# define QAT_F_QAT_SW_SM4_CCM_ENCRYPT 221 +# define QAT_F_QAT_SW_SM4_CCM_INIT 222 +# define QAT_F_QAT_SW_SM4_GCM_CIPHER 223 +# define QAT_F_QAT_SW_SM4_GCM_CLEANUP 224 +# define QAT_F_QAT_SW_SM4_GCM_CTRL 225 +# define QAT_F_QAT_SW_SM4_GCM_DECRYPT 226 +# define QAT_F_QAT_SW_SM4_GCM_ENCRYPT 227 +# define QAT_F_QAT_SW_SM4_GCM_INIT 228 +# define QAT_F_QAT_SW_SM4_GCM_TLS_CIPHER 229 +# define QAT_F_QAT_SYM_PERFORM_OP 230 +# define QAT_F_QAT_VALIDATE_ECX_DERIVE 231 +# define QAT_F_QAT_X25519_PMETH 232 +# define QAT_F_QAT_X448_PMETH 233 +# define QAT_F_VAESGCM_CIPHERS_CTRL 234 +# define QAT_F_VAESGCM_CIPHERS_DO_CIPHER 235 +# define QAT_F_VAESGCM_CIPHERS_INIT 236 +# define QAT_F_VAESGCM_INIT_GCM 237 +# define QAT_F_VAESGCM_INIT_IPSEC_MB_MGR 238 +# define QAT_F_VAESGCM_INIT_KEY 239 /* * QAT reason codes. @@ -411,46 +418,47 @@ void ERR_QAT_error(int function, int reason, char *file, int line); # define QAT_R_SHA3_CTX_NULL 345 # define QAT_R_SIG_GET_R_S_FAILURE 346 # define QAT_R_SIG_MALLOC_FAILURE 347 -# define QAT_R_SM3_FINAL_FAILURE 348 -# define QAT_R_SM3_INIT_FAILURE 349 -# define QAT_R_SM3_UPDATE_FAILURE 350 -# define QAT_R_SM4_CCM_DECRYPT_FAILURE 351 -# define QAT_R_SM4_GCM_DECRYPT_FAILURE 352 -# define QAT_R_SM4_GCM_ENCRYPT_FAILURE 353 -# define QAT_R_SM4_GET_INSTANCE_FAILED 354 -# define QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED 355 -# define QAT_R_SM4_MALLOC_FAILED 356 -# define QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE 357 -# define QAT_R_SM4_NULL_CKEY 358 -# define QAT_R_SM4_NULL_CTX_OR_KEY 359 -# define QAT_R_SM4_NULL_POINTER 360 -# define QAT_R_SM4_NULL_QCTX 361 -# define QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED 362 -# define QAT_R_SM4_QAT_INITSESSION_FAILED 363 -# define QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED 364 -# define QAT_R_SM4_REMOVE_SESSION_FAILED 365 -# define QAT_R_SM4_SETUP_META_DATA_FAILED 366 -# define QAT_R_SM4_SET_METHODS_FAILED 367 -# define QAT_R_SSD_MALLOC_FAILURE 368 -# define QAT_R_SSD_NULL 369 -# define QAT_R_START_INSTANCE_FAILURE 370 -# define QAT_R_STOP_INSTANCE_FAILURE 371 -# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 372 -# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 373 -# define QAT_R_SW_GET_SIGN_PFUNC_NULL 374 -# define QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL 375 -# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 376 -# define QAT_R_SW_GET_VERIFY_PFUNC_NULL 377 -# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 378 -# define QAT_R_SW_METHOD_NULL 379 -# define QAT_R_S_NULL 380 -# define QAT_R_S_Q_COMPARE_FAILURE 381 -# define QAT_R_TAG_NOTSET 382 -# define QAT_R_UNKNOWN_PADDING 383 -# define QAT_R_UNKNOWN_PADDING_TYPE 384 -# define QAT_R_WAKE_PAUSE_JOB_FAILURE 385 -# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 386 -# define QAT_R_X_Y_Z_MALLOC_FAILURE 387 -# define QAT_R_Z_ALLOCATE_FAILURE 388 +# define QAT_R_SM3_CTX_NULL 348 +# define QAT_R_SM3_FINAL_FAILURE 349 +# define QAT_R_SM3_INIT_FAILURE 350 +# define QAT_R_SM3_UPDATE_FAILURE 351 +# define QAT_R_SM4_CCM_DECRYPT_FAILURE 352 +# define QAT_R_SM4_GCM_DECRYPT_FAILURE 353 +# define QAT_R_SM4_GCM_ENCRYPT_FAILURE 354 +# define QAT_R_SM4_GET_INSTANCE_FAILED 355 +# define QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED 356 +# define QAT_R_SM4_MALLOC_FAILED 357 +# define QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE 358 +# define QAT_R_SM4_NULL_CKEY 359 +# define QAT_R_SM4_NULL_CTX_OR_KEY 360 +# define QAT_R_SM4_NULL_POINTER 361 +# define QAT_R_SM4_NULL_QCTX 362 +# define QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED 363 +# define QAT_R_SM4_QAT_INITSESSION_FAILED 364 +# define QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED 365 +# define QAT_R_SM4_REMOVE_SESSION_FAILED 366 +# define QAT_R_SM4_SETUP_META_DATA_FAILED 367 +# define QAT_R_SM4_SET_METHODS_FAILED 368 +# define QAT_R_SSD_MALLOC_FAILURE 369 +# define QAT_R_SSD_NULL 370 +# define QAT_R_START_INSTANCE_FAILURE 371 +# define QAT_R_STOP_INSTANCE_FAILURE 372 +# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 373 +# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 374 +# define QAT_R_SW_GET_SIGN_PFUNC_NULL 375 +# define QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL 376 +# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 377 +# define QAT_R_SW_GET_VERIFY_PFUNC_NULL 378 +# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 379 +# define QAT_R_SW_METHOD_NULL 380 +# define QAT_R_S_NULL 381 +# define QAT_R_S_Q_COMPARE_FAILURE 382 +# define QAT_R_TAG_NOTSET 383 +# define QAT_R_UNKNOWN_PADDING 384 +# define QAT_R_UNKNOWN_PADDING_TYPE 385 +# define QAT_R_WAKE_PAUSE_JOB_FAILURE 386 +# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 387 +# define QAT_R_X_Y_Z_MALLOC_FAILURE 388 +# define QAT_R_Z_ALLOCATE_FAILURE 389 #endif diff --git a/qat_evp.c b/qat_evp.c index 38e8a59a..2d6f05a8 100644 --- a/qat_evp.c +++ b/qat_evp.c @@ -69,6 +69,7 @@ # include "qat_hw_gcm.h" # include "qat_hw_sha3.h" # include "qat_hw_chachapoly.h" +# include "qat_hw_sm3.h" # endif /* QAT_BORINGSSL */ #endif @@ -215,7 +216,7 @@ static digest_data digest_info[] = { { NID_sha3_384, NULL, NID_RSA_SHA3_384}, { NID_sha3_512, NULL, NID_RSA_SHA3_512}, #endif -#ifdef ENABLE_QAT_SW_SM3 +#if defined(ENABLE_QAT_SW_SM3) || defined(ENABLE_QAT_HW_SM3) { NID_sm3, NULL, NID_sm3WithRSAEncryption}, #endif }; @@ -230,7 +231,7 @@ int qat_digest_nids[] = { NID_sha3_384, NID_sha3_512, # endif -#ifdef ENABLE_QAT_SW_SM3 +#if defined(ENABLE_QAT_SW_SM3) || defined(ENABLE_QAT_HW_SM3) NID_sm3, #endif }; @@ -267,6 +268,9 @@ static PKT_THRESHOLD qat_pkt_threshold_table[] = { #if defined(ENABLE_QAT_HW_SM4_CBC) || defined(ENABLE_QAT_SW_SM4_CBC) {NID_sm4_cbc, CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD_SM4_CBC}, # endif +# ifdef ENABLE_QAT_HW_SM3 + {NID_sm3, CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD_HW_SM3}, +# endif }; static int pkt_threshold_table_size = @@ -370,6 +374,14 @@ void qat_create_digest_meth(void) qat_sw_create_sm3_meth(digest_info[i].m_type , digest_info[i].pkey_type); break; #endif + +#ifdef ENABLE_QAT_HW_SM3 + case NID_sm3: + digest_info[i].md = (EVP_MD *) + qat_hw_create_sm3_meth(digest_info[i].m_type , digest_info[i].pkey_type); + break; +#endif + default: break; } @@ -402,12 +414,20 @@ void qat_free_digest_meth(void) EVP_MD_meth_free(digest_info[i].md); break; #endif + +#ifdef ENABLE_QAT_HW_SM3 + case NID_sm3: + if (qat_hw_sm3_offload) + EVP_MD_meth_free(digest_info[i].md); + break; +#endif } digest_info[i].md = NULL; } } qat_hw_sha_offload = 0; qat_sw_sm3_offload = 0; + qat_hw_sm3_offload = 0; } /****************************************************************************** diff --git a/qat_evp.h b/qat_evp.h index 817e2870..daba1657 100644 --- a/qat_evp.h +++ b/qat_evp.h @@ -169,6 +169,7 @@ const EVP_CIPHER *qat_create_gcm_cipher_meth(int nid, int keylen); # ifndef ENABLE_QAT_SMALL_PKT_OFFLOAD # define CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT 2048 # define CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD_SM4_CBC 64 +# define CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD_HW_SM3 1024 int qat_pkt_threshold_table_set_threshold(const char *cn , int threshold); int qat_pkt_threshold_table_get_threshold(int nid); # endif diff --git a/qat_hw_hkdf.c b/qat_hw_hkdf.c index d2f2c522..db59ebd4 100644 --- a/qat_hw_hkdf.c +++ b/qat_hw_hkdf.c @@ -472,6 +472,13 @@ static int qat_get_cipher_suite(QAT_HKDF_CTX * qat_hkdf_ctx, case NID_sha384: *cipher_suite = CPA_CY_HKDF_TLS_AES_256_GCM_SHA384; break; + +#if defined(QAT20_OOT) + case NID_sm3: + WARN("HKDF based on SM3 not supported\n"); + return 0; +#endif + default: WARN("Unsupported HKDF hash type\n"); return 0; @@ -667,8 +674,8 @@ int qat_hkdf_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *olen) } if (!qat_get_cipher_suite(qat_hkdf_ctx, &cipher_suite)) { - WARN("Failed to get cipher suite\n"); - QATerr(QAT_F_QAT_HKDF_DERIVE, ERR_R_INTERNAL_ERROR); + DEBUG("Failed to get cipher suite, fallback to SW\n"); + fallback = 1; goto err; } diff --git a/qat_hw_prf.c b/qat_hw_prf.c index 37be3f46..9638c223 100644 --- a/qat_hw_prf.c +++ b/qat_hw_prf.c @@ -434,6 +434,13 @@ static int qat_get_hash_algorithm(QAT_TLS1_PRF_CTX * qat_prf_ctx, case NID_md5: *hash_algorithm = CPA_CY_SYM_HASH_MD5; break; + +#if defined(QAT20_OOT) + case NID_sm3: + *hash_algorithm = CPA_CY_SYM_HASH_SM3; + break; +#endif + default: WARN("unsupported PRF hash type\n"); return 0; diff --git a/qat_hw_sm3.c b/qat_hw_sm3.c new file mode 100644 index 00000000..cd949192 --- /dev/null +++ b/qat_hw_sm3.c @@ -0,0 +1,795 @@ +/* ==================================================================== + * + * + * BSD LICENSE + * + * Copyright(c) 2023 Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * ==================================================================== + */ + +/***************************************************************************** + * @file qat_hw_sm3.c + * + * This file contains the engine implementations for SM3 Hash operations + * + *****************************************************************************/ + +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif +#include +#include +#include +#ifdef USE_QAT_CONTIG_MEM +# include "qae_mem_utils.h" +#endif +#ifdef USE_USDM_MEM +# include "qat_hw_usdm_inf.h" +#endif +#include "e_qat.h" +#include "qat_utils.h" +#include "qat_hw_callback.h" +#include "qat_hw_polling.h" +#include "qat_events.h" +#include "qat_evp.h" + +#include "cpa.h" +#include "cpa_types.h" +#include "cpa_cy_sym.h" +#include "qat_hw_sm3.h" +#include "qat_hw_ciphers.h" + +#include +#include +#include +#include +#include + +#ifdef ENABLE_QAT_HW_SM3 + +static inline QAT_SM3_CTX *qat_hw_sm3_get_ctx(EVP_MD_CTX *ctx) +{ + if (unlikely(ctx == NULL)) { + WARN("hw sm3 ctx %p is NULL\n", ctx); + return NULL; + } + + return ((QAT_SM3_CTX *) (EVP_MD_CTX_md_data(ctx) + sizeof(SM3_CTX))); +} + +/****************************************************************************** + * function: + * + * static void qat_hw_sm3_cb(void *pCallbackTag, CpaStatus status, + * const CpaCySymOp operationType, + * void *pOpData, CpaBufferList *pDstBuffer, + * CpaBoolean verifyResult) + * + * @param pCallbackTag [IN] - Opaque value provided by user while making + * individual function call. Cast to op_done_pipe_t. + * @param status [IN] - Status of the operation. + * @param operationType [IN] - Identifies the operation type requested. + * @param pOpData [IN] - Pointer to structure with input parameters. + * @param pDstBuffer [IN] - Destination buffer to hold the data output. + * @param verifyResult [IN] - Used to verify digest result. + * + * description: + Callback to indicate the completion of crypto operation + ******************************************************************************/ +static void qat_hw_sm3_cb(void *pCallbackTag, CpaStatus status, + const CpaCySymOp operationType, + void *pOpData, CpaBufferList *pDstBuffer, + CpaBoolean verifyResult) +{ + if (enable_heuristic_polling) + QAT_ATOMIC_DEC(num_cipher_pipeline_requests_in_flight); + + qat_crypto_callbackFn(pCallbackTag, status, CPA_CY_SYM_OP_HASH, pOpData, + NULL, CPA_TRUE); +} + +/****************************************************************************** +* function: +* qat_hw_sm3_setup_param(EVP_MD_CTX *ctx) +* +* @param ctx [IN] - pointer to context +* +* @retval 1 function succeeded +* @retval 0 function failed +* +* description: +* This function synchronises the initialisation of the QAT session and +* pre-allocates the necessary buffers for the session. +******************************************************************************/ +static int qat_hw_sm3_setup_param(QAT_SM3_CTX *qat_sm3_ctx) +{ + int numBuffers = 2; + Cpa32U bufferMetaSize = 0; + Cpa32U sctx_size = 0; + CpaStatus status; + CpaCySymSessionSetupData *session_data; + + session_data = OPENSSL_zalloc(sizeof(CpaCySymSessionSetupData) + + sizeof(CpaCySymOpData) + + sizeof(int)); + if (NULL == session_data) { + WARN("session setup data Malloc failure\n"); + QATerr(QAT_F_QAT_HW_SM3_SETUP_PARAM, ERR_R_MALLOC_FAILURE); + return 0; + } + qat_sm3_ctx->session_data = session_data; + qat_sm3_ctx->pOpData = (void *)session_data + + sizeof(CpaCySymSessionSetupData); + qat_sm3_ctx->rc_refs = (void *)session_data + + sizeof(CpaCySymSessionSetupData) + + sizeof(CpaCySymOpData); + + session_data->sessionPriority = CPA_CY_PRIORITY_HIGH; + /* Hash only operation on the data */ + session_data->symOperation = CPA_CY_SYM_OP_HASH; + /* Place the digest result in a buffer unrelated to srcBuffer */ + session_data->digestIsAppended = CPA_FALSE; + /* Set FALSE to generate a message digest, instead of doing digest verify */ + session_data->verifyDigest = CPA_FALSE; + + /* Set the hash mode and the length of the digest */ + session_data->hashSetupData.hashAlgorithm = CPA_CY_SYM_HASH_SM3; + session_data->hashSetupData.hashMode = CPA_CY_SYM_HASH_MODE_PLAIN; + session_data->hashSetupData.digestResultLenInBytes = QAT_SM3_DIGEST_SIZE; + session_data->hashSetupData.authModeSetupData.authKey = NULL; + session_data->hashSetupData.nestedModeSetupData.pInnerPrefixData = NULL; + session_data->hashSetupData.nestedModeSetupData.pOuterPrefixData = NULL; + + DUMP_SESSION_SETUP_DATA(qat_sm3_ctx->session_data); + + /* Allocate instance */ + qat_sm3_ctx->inst_num = get_next_inst_num(INSTANCE_TYPE_CRYPTO_SYM); + if (qat_sm3_ctx->inst_num == QAT_INVALID_INSTANCE) { + WARN("Failed to get a QAT instance.\n"); + QATerr(QAT_F_QAT_HW_SM3_SETUP_PARAM, QAT_R_GET_INSTANCE_FAILURE); + goto err; + } + + /* Determine size of session context to allocate */ + status = + cpaCySymSessionCtxGetSize(qat_instance_handles[qat_sm3_ctx->inst_num], + qat_sm3_ctx->session_data, &sctx_size); + if (status != CPA_STATUS_SUCCESS) { + WARN("Failed to get SessionCtx size.\n"); + QATerr(QAT_F_QAT_HW_SM3_SETUP_PARAM, ERR_R_INTERNAL_ERROR); + goto err; + } + DEBUG("Size of session ctx = %d\n", sctx_size); + + qat_sm3_ctx->session_ctx = + (CpaCySymSessionCtx) qaeCryptoMemAlloc(sctx_size, __FILE__, __LINE__); + if (qat_sm3_ctx->session_ctx == NULL) { + WARN("Memory alloc failed for session ctx\n"); + QATerr(QAT_F_QAT_HW_SM3_SETUP_PARAM, ERR_R_MALLOC_FAILURE); + goto err; + } + + /* Initialise Session data */ + status = cpaCySymInitSession(qat_instance_handles[qat_sm3_ctx->inst_num], + qat_hw_sm3_cb, + qat_sm3_ctx->session_data, + qat_sm3_ctx->session_ctx); + if (status != CPA_STATUS_SUCCESS) { + WARN("cpaCySymInitSession failed! Status = %d\n", status); + if (((status == CPA_STATUS_RESTARTING) || (status == CPA_STATUS_FAIL))) { + CRYPTO_QAT_LOG + ("Failed to submit request to qat inst_num %d device_id %d\n", + qat_sm3_ctx->inst_num, + qat_instance_details[qat_sm3_ctx->inst_num].qat_instance_info. + physInstId.packageId); + } + QATerr(QAT_F_QAT_HW_SM3_SETUP_PARAM, ERR_R_INTERNAL_ERROR); + goto err; + } + + /* Get buffer metasize */ + status = + cpaCyBufferListGetMetaSize(qat_instance_handles[qat_sm3_ctx->inst_num], + numBuffers, &bufferMetaSize); + if (status != CPA_STATUS_SUCCESS) { + WARN("cpaCyBufferListGetMetaSize failed for the instance id %d\n", + qat_sm3_ctx->inst_num); + QATerr(QAT_F_QAT_HW_SM3_SETUP_PARAM, ERR_R_INTERNAL_ERROR); + goto err; + } + DEBUG("Buffer MetaSize : %d\n", bufferMetaSize); + + if (bufferMetaSize) { + qat_sm3_ctx->pSrcBufferList.pPrivateMetaData = + qaeCryptoMemAlloc(bufferMetaSize, __FILE__, __LINE__); + if (qat_sm3_ctx->pSrcBufferList.pPrivateMetaData == NULL) { + WARN("QMEM alloc failed for PrivateData\n"); + QATerr(QAT_F_QAT_HW_SM3_SETUP_PARAM, ERR_R_MALLOC_FAILURE); + goto err; + } + qat_sm3_ctx->pSrcBufferList.numBuffers = 1; + + } else { + qat_sm3_ctx->pSrcBufferList.pPrivateMetaData = NULL; + qat_sm3_ctx->pSrcBufferList.numBuffers = 0; + } + + qat_sm3_ctx->context_params_set = 1; + + return 1; + + err: + qaeCryptoMemFreeNonZero(qat_sm3_ctx->pSrcBufferList.pPrivateMetaData); + qaeCryptoMemFreeNonZero(qat_sm3_ctx->session_ctx); + OPENSSL_free(session_data); + qat_sm3_ctx->session_data = NULL; + qat_sm3_ctx->pOpData = NULL; + qat_sm3_ctx->rc_refs = NULL; + + return 0; +} + +static int qat_hw_sm3_do_offload(QAT_SM3_CTX *qat_sm3_ctx, const void *in, + size_t len, int packet_type) +{ + int job_ret = 0; + int ret = 0; /* Default fail */ + CpaStatus status; + op_done_t op_done; + thread_local_variables_t *tlv = NULL; + CpaFlatBuffer src_buffer; + + if (!qat_sm3_ctx->context_params_set) { + if (!qat_hw_sm3_setup_param(qat_sm3_ctx)) { + WARN("SM3 operational params setup failed.\n"); + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_INTERNAL_ERROR); + return 0; + } + } + + /* The variables in and out remain separate */ + src_buffer.pData = + qaeCryptoMemAlloc(len + QAT_SM3_DIGEST_SIZE, __FILE__, __LINE__); + if ((src_buffer.pData) == NULL) { + WARN("Unable to allocate memory for buffer for sm3 hash.\n"); + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_MALLOC_FAILURE); + goto err; + } + + src_buffer.dataLenInBytes = len + QAT_SM3_DIGEST_SIZE; + + if (len == 0) { + DEBUG("qat hw start offload: Length 0\n"); + } else { + DUMPL("qat hw start offload", in, (len > 128) ? len : 128); + memcpy(src_buffer.pData, in, len); + } + + qat_sm3_ctx->pSrcBufferList.pBuffers = &src_buffer; + + tlv = qat_check_create_local_variables(); + if (NULL == tlv) { + WARN("could not create local variables\n"); + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_INTERNAL_ERROR); + goto err; + } + + qat_init_op_done(&op_done); + if (op_done.job != NULL) { + if (qat_setup_async_event_notification(op_done.job) == 0) { + WARN("Failed to setup async event notification\n"); + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_INTERNAL_ERROR); + qat_cleanup_op_done(&op_done); + goto err; + } + } + + qat_sm3_ctx->pSrcBufferList.pUserData = NULL; + + qat_sm3_ctx->pOpData->sessionCtx = qat_sm3_ctx->session_ctx; + + if (CPA_CY_SYM_PACKET_TYPE_LAST_PARTIAL == packet_type && + qat_sm3_ctx->qat_offloaded == 0) { + qat_sm3_ctx->pOpData->packetType = CPA_CY_SYM_PACKET_TYPE_FULL; + } else { + qat_sm3_ctx->pOpData->packetType = packet_type; + } + + /* The message length, in bytes, of the source buffer that the hash + * will be computed on. */ + qat_sm3_ctx->pOpData->messageLenToHashInBytes = len; + qat_sm3_ctx->pOpData->pDigestResult = src_buffer.pData + len; + + if (!is_instance_available(qat_sm3_ctx->inst_num)) { + WARN("QAT instance %d not available.\n", qat_sm3_ctx->inst_num); + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_INTERNAL_ERROR); + if (op_done.job != NULL) { + qat_clear_async_event_notification(op_done.job); + } + qat_cleanup_op_done(&op_done); + goto err; + } + + /* same src & dst for an in-place operation */ + status = qat_sym_perform_op(qat_sm3_ctx->inst_num, + &op_done, + qat_sm3_ctx->pOpData, + &(qat_sm3_ctx->pSrcBufferList), + &(qat_sm3_ctx->pSrcBufferList), + &(qat_sm3_ctx->session_data->verifyDigest)); + + if (status != CPA_STATUS_SUCCESS) { + if (((status == CPA_STATUS_RESTARTING) || (status == CPA_STATUS_FAIL))) { + CRYPTO_QAT_LOG + ("Failed to submit request to qat inst_num %d device_id %d - %s\n", + qat_sm3_ctx->inst_num, + qat_instance_details[qat_sm3_ctx->inst_num].qat_instance_info. + physInstId.packageId); + } + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_INTERNAL_ERROR); + if (op_done.job != NULL) + qat_clear_async_event_notification(op_done.job); + + qat_cleanup_op_done(&op_done); + goto err; + } + + QAT_INC_IN_FLIGHT_REQS(num_requests_in_flight, tlv); + if (qat_use_signals()) { + if (tlv->localOpsInFlight == 1) { + if (sem_post(&hw_polling_thread_sem) != 0) { + WARN("hw sem_post failed!, hw_polling_thread_sem address: %p.\n", &hw_polling_thread_sem); + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_INTERNAL_ERROR); + QAT_DEC_IN_FLIGHT_REQS(num_requests_in_flight, tlv); + if (op_done.job != NULL) + qat_clear_async_event_notification(op_done.job); + + qat_cleanup_op_done(&op_done); + goto err; + } + } + } + + if (enable_heuristic_polling) + QAT_ATOMIC_INC(num_cipher_pipeline_requests_in_flight); + + do { + if (op_done.job != NULL) { + /* If we get a failure on qat_pause_job then we will + not flag an error here and quit because we have + an asynchronous request in flight. + We don't want to start cleaning up data + structures that are still being used. If + qat_pause_job fails we will just yield and + loop around and try again until the request + completes and we can continue. */ + if ((job_ret = qat_pause_job(op_done.job, ASYNC_STATUS_OK)) == 0) + sched_yield(); + + } else { + sched_yield(); + } + } while (!op_done.flag || QAT_CHK_JOB_RESUMED_UNEXPECTEDLY(job_ret)); + + QAT_DEC_IN_FLIGHT_REQS(num_requests_in_flight, tlv); + + if (op_done.verifyResult != CPA_TRUE) { + WARN("Verification of result failed\n"); + QATerr(QAT_F_QAT_HW_SM3_DO_OFFLOAD, ERR_R_INTERNAL_ERROR); + if (op_done.status == CPA_STATUS_FAIL) { + CRYPTO_QAT_LOG + ("Verification of result failed for qat inst_num %d device_id %d - %s\n", + inst_num, + qat_instance_details[qat_sm3_ctx->_inst_num].qat_instance_info. + physInstId.packageId); + qat_cleanup_op_done(&op_done); + goto err; + } + } + qat_cleanup_op_done(&op_done); + + /* final partial */ + if (CPA_CY_SYM_PACKET_TYPE_LAST_PARTIAL == packet_type) { + memcpy(qat_sm3_ctx->digest_data, src_buffer.pData + len, + QAT_SM3_DIGEST_SIZE); + ret = 1; + } else { + qat_sm3_ctx->qat_offloaded = 1; + ret = 1; + } + + err: + qaeCryptoMemFreeNonZero(src_buffer.pData); + return ret; +} + +/****************************************************************************** +* function: +* qat_hw_sm3_init(EVP_MD_CTX *ctx) +* +* @param ctx [IN] - pointer to existing context +* +* @retval 1 function succeeded +* @retval 0 function failed +* +* description: +* This function initialises the hash algorithm parameters for EVP context. +* +******************************************************************************/ +static int qat_hw_sm3_init(EVP_MD_CTX *ctx) +{ + return 1; +} + +/****************************************************************************** +* function: +* qat_hw_sm3_update(EVP_MD_CTX *ctx, const void *in, size_t len) +* +* @param ctx [IN] - pointer to existing context +* @param in [IN] - input buffer +* @param len [IN] - length of input buffer +* +* @retval -1 function failed +* @retval len function succeeded +* +* description: +* This function performs the cryptographic transform according to the +* parameters setup during initialisation. +* +* +******************************************************************************/ +static int qat_hw_sm3_update(EVP_MD_CTX *ctx, const void *in, size_t len) +{ + const unsigned char *data = in; + + QAT_SM3_CTX *qat_sm3_ctx = NULL; + unsigned char *p; + size_t n; + + if (len == 0) { + DEBUG("sm3 hw update with len = 0 %p\n", ctx); + return 1; + } + + if (unlikely(in == NULL)) { + WARN("in %p is NULL\n", in); + QATerr(QAT_F_QAT_HW_SM3_UPDATE, QAT_R_INVALID_INPUT); + return 0; + } + + qat_sm3_ctx = qat_hw_sm3_get_ctx(ctx); + if (unlikely(qat_sm3_ctx == NULL)) { + WARN("SM3 context hash data is NULL.\n"); + QATerr(QAT_F_QAT_HW_SM3_UPDATE, QAT_R_SM3_CTX_NULL); + return 0; + } + + qat_sm3_ctx->rcv_count += len; + DUMPL("sm3 hw update receive", in, len); + + n = qat_sm3_ctx->num; + /* Packets left from previous process */ + if (n != 0) { + p = (unsigned char *)qat_sm3_ctx->data; + + /* Offload threshold met */ + if (len >= QAT_SM3_OFFLOAD_THRESHOLD + || len + n >= QAT_SM3_OFFLOAD_THRESHOLD) { + /* Use part of new packet filling the packet buffer */ + memcpy(p + n, data, QAT_SM3_OFFLOAD_THRESHOLD - n); + + if (!qat_hw_sm3_do_offload + (qat_sm3_ctx, p, QAT_SM3_OFFLOAD_THRESHOLD, + CPA_CY_SYM_PACKET_TYPE_PARTIAL)) + return 1; + + /* The data left of new input */ + n = QAT_SM3_OFFLOAD_THRESHOLD - n; + data += n; + len -= n; + qat_sm3_ctx->num = 0; + /* + * We use memset rather than OPENSSL_cleanse() here deliberately. + * Using OPENSSL_cleanse() here could be a performance issue. It + * will get properly cleansed on finalisation so this isn't a + * security problem. + */ + memset(p, 0, QAT_SM3_OFFLOAD_THRESHOLD); /* keep it zeroed */ + } else { + /* Append the new packets to buffer */ + memcpy(p + n, data, len); + qat_sm3_ctx->num += (unsigned int)len; + + return 1; + } + } + + n = len / QAT_SM3_OFFLOAD_THRESHOLD; + if (n > 0) { + n *= QAT_SM3_OFFLOAD_THRESHOLD; + + if (!qat_hw_sm3_do_offload(qat_sm3_ctx, in, n, + CPA_CY_SYM_PACKET_TYPE_PARTIAL)) + return 1; + + data += n; + len -= n; + } + + /* Save the bytes into buffer if there're some bytes left + after the previous update. */ + if (len != 0) { + qat_sm3_ctx->data = OPENSSL_zalloc(QAT_SM3_OFFLOAD_THRESHOLD); + qat_sm3_ctx->data_refs = OPENSSL_zalloc(sizeof(int)); + + p = (unsigned char *)qat_sm3_ctx->data; + qat_sm3_ctx->num = (unsigned int)len; + memcpy(p, data, len); + } + + return 1; +} + +static int qat_hw_sm3_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) +{ + QAT_SM3_CTX *qat_from; + + if (NULL == from) { + WARN("sm3 copy from %p is NULL\n", from); + QATerr(QAT_F_QAT_HW_SM3_COPY, QAT_R_CTX_NULL); + return 0; + } + + /* Digest-copy can be called without a md_data in some condition */ + if (EVP_MD_CTX_md_data(from) == 0) { + DEBUG("digest copy without md_data\n"); + return 1; + } + + qat_from = QAT_SM3_GET_CTX(from); + if (NULL == qat_from) { + WARN("qat_from %p is NULL\n", qat_from); + QATerr(QAT_F_QAT_HW_SM3_COPY, QAT_R_CTX_NULL); + return 0; + } + + if (qat_from->rc_refs) + (*qat_from->rc_refs)++; + + if (qat_from->data_refs) + (*qat_from->data_refs)++; + + return 1; +} + +/****************************************************************************** +* function: +* qat_hw_sm3_final(EVP_MD_CTX *ctx, unsigned char *md) +* +* @param ctx [IN] - pointer to existing context +* @param md [OUT] - output buffer for digest result +* +* @retval -1 function failed +* @retval 1 function succeeded +* +* description: +* This function performs the copy operation of digest into md buffer. +* +******************************************************************************/ +static int qat_hw_sm3_final(EVP_MD_CTX *ctx, unsigned char *md) +{ + QAT_SM3_CTX *qat_sm3_ctx = NULL; + + if (md == NULL) { + WARN("hw sm3 md is null\n"); + QATerr(QAT_F_QAT_HW_SM3_FINAL, QAT_R_INPUT_PARAM_INVALID); + return 0; + } + + qat_sm3_ctx = qat_hw_sm3_get_ctx(ctx); + if (qat_sm3_ctx == NULL) { + WARN("qat_sm3_ctx is NULL\n"); + QATerr(QAT_F_QAT_HW_SM3_FINAL, QAT_R_CTX_NULL); + return 0; + } +# ifndef ENABLE_QAT_SMALL_PKT_OFFLOAD + if (qat_sm3_ctx->rcv_count <= CRYPTO_SMALL_PACKET_OFFLOAD_THRESHOLD_HW_SM3) { + /* Software calculation can start from init, because SPO threashold will + always small than context buffer and all data are stored in context + buffer */ + int (*sw_init_ptr)(EVP_MD_CTX *); + int (*sw_update_ptr)(EVP_MD_CTX *, const void *, size_t); + int (*sw_final_ptr)(EVP_MD_CTX *, unsigned char *); + + DUMPL("Start ossl calculate", qat_sm3_ctx->data, qat_sm3_ctx->num); + + sw_init_ptr = EVP_MD_meth_get_init((EVP_MD *)EVP_sm3()); + sw_update_ptr = EVP_MD_meth_get_update((EVP_MD *)EVP_sm3()); + sw_final_ptr = EVP_MD_meth_get_final((EVP_MD *)EVP_sm3()); + + if ((*sw_init_ptr) (ctx) != 1 + || (*sw_update_ptr) (ctx, qat_sm3_ctx->data, qat_sm3_ctx->num) != 1 + || (*sw_final_ptr) (ctx, md) != 1) { + WARN("Software calculate failed %p\n", ctx); + return 0; + } + + DUMPL("DigestResult (OSSL)", md, QAT_SM3_DIGEST_SIZE); + + return 1; + } +# endif + + qat_sm3_ctx->digest_data = md; + if (!qat_hw_sm3_do_offload(qat_sm3_ctx, qat_sm3_ctx->data, qat_sm3_ctx->num, + CPA_CY_SYM_PACKET_TYPE_LAST_PARTIAL)) + return 0; + + DUMPL("DigestResult (QAT_HW)", md, QAT_SM3_DIGEST_SIZE); + + return 1; +} + +/****************************************************************************** +* function: +* qat_hw_sm3_cleanup(EVP_MD_CTX *ctx) +* +* @param ctx [IN] - pointer to existing context +* +* @retval 1 function succeeded +* @retval 0 function failed +* +* description: +* This function will cleanup all allocated resources required to perform the +* cryptographic transform. +* +******************************************************************************/ +static int qat_hw_sm3_cleanup(EVP_MD_CTX *ctx) +{ + QAT_SM3_CTX *qat_sm3_ctx; + CpaStatus status = 0; + int ret_val = 1; + CpaBoolean sessionInUse = CPA_FALSE; + + qat_sm3_ctx = qat_hw_sm3_get_ctx(ctx); + if (NULL == qat_sm3_ctx) { + WARN("qat_sm3_ctx is NULL\n"); + QATerr(QAT_F_QAT_HW_SM3_CLEANUP, QAT_R_CTX_NULL); + return 0; + } + + if (EVP_MD_CTX_md_data(ctx) == NULL) { + DEBUG("digest cleanup without md_data\n"); + return 1; + } + + if (qat_sm3_ctx->data_refs) { + if (*qat_sm3_ctx->data_refs > 0) { + (*qat_sm3_ctx->data_refs)--; + DEBUG("HW SM3 data refrence decrease to %d\n", + *qat_sm3_ctx->data_refs); + } else { + OPENSSL_free(qat_sm3_ctx->data); + OPENSSL_free(qat_sm3_ctx->data_refs); + } + } + + if (qat_sm3_ctx->context_params_set) { + if (*qat_sm3_ctx->rc_refs > 0) { + (*qat_sm3_ctx->rc_refs)--; + DEBUG("HW SM3 resource refrence decrease to %d\n", + *qat_sm3_ctx->rc_refs); + return 1; + } + + if (is_instance_available(qat_sm3_ctx->inst_num)) { + /* Wait for in-flight requests before removing session */ + do { + cpaCySymSessionInUse(qat_sm3_ctx->session_ctx, &sessionInUse); + } while (sessionInUse); + + if ((status = + cpaCySymRemoveSession(qat_instance_handles + [qat_sm3_ctx->inst_num], + qat_sm3_ctx->session_ctx)) + != CPA_STATUS_SUCCESS) { + WARN("cpaCySymRemoveSession FAILED, status= %d.!\n", status); + ret_val = 0; + } + } else { + WARN("instance no longer available\n"); + } + + qaeCryptoMemFreeNonZero(qat_sm3_ctx->session_ctx); + qat_sm3_ctx->session_ctx = NULL; + + qaeCryptoMemFreeNonZero(qat_sm3_ctx->pSrcBufferList.pPrivateMetaData); + qat_sm3_ctx->pSrcBufferList.pPrivateMetaData = NULL; + + OPENSSL_free(qat_sm3_ctx->session_data); + qat_sm3_ctx->session_data = NULL; + + qat_sm3_ctx->context_params_set = 0; + } + + return ret_val; +} + +const EVP_MD *qat_hw_create_sm3_meth(int nid, int key_type) +{ + int res = 1; + EVP_MD *qat_hw_sm3_meth = NULL; + + if (qat_hw_offload && (qat_hw_algo_enable_mask & ALGO_ENABLE_MASK_SM3)) { + if ((qat_hw_sm3_meth = EVP_MD_meth_new(nid, key_type)) == NULL) { + WARN("Failed to allocate digest methods for nid %d\n", nid); + QATerr(QAT_F_QAT_HW_CREATE_SM3_METH, QAT_R_INIT_FAILURE); + return NULL; + } + + res &= EVP_MD_meth_set_result_size(qat_hw_sm3_meth, QAT_SM3_STATE_SIZE); + res &= + EVP_MD_meth_set_input_blocksize(qat_hw_sm3_meth, + QAT_SM3_BLOCK_SIZE); + /* Totally 3 memory sections in application data, common EVP_MD, + SM3_CTX used for SM3 software, and QAT_SM3_CTX for QAT_HW */ + res &= EVP_MD_meth_set_app_datasize(qat_hw_sm3_meth, + sizeof(EVP_MD *) + sizeof(SM3_CTX) + + sizeof(QAT_SM3_CTX)); + res &= EVP_MD_meth_set_flags(qat_hw_sm3_meth, EVP_MD_CTX_FLAG_REUSE); + res &= EVP_MD_meth_set_init(qat_hw_sm3_meth, qat_hw_sm3_init); + res &= EVP_MD_meth_set_update(qat_hw_sm3_meth, qat_hw_sm3_update); + res &= EVP_MD_meth_set_final(qat_hw_sm3_meth, qat_hw_sm3_final); + res &= EVP_MD_meth_set_copy(qat_hw_sm3_meth, qat_hw_sm3_copy); + res &= EVP_MD_meth_set_cleanup(qat_hw_sm3_meth, qat_hw_sm3_cleanup); + + if (0 == res) { + WARN("Failed to set MD methods for nid %d\n", nid); + QATerr(QAT_F_QAT_HW_CREATE_SM3_METH, QAT_R_INIT_FAILURE); + EVP_MD_meth_free(qat_hw_sm3_meth); + return NULL; + } + + qat_hw_sm3_offload = 1; + DEBUG("QAT HW SM3 Registration succeeded\n"); + + return qat_hw_sm3_meth; + + } else { + qat_hw_sm3_offload = 0; + DEBUG("QAT HW SM3 is disabled, using OpenSSL SW\n"); + + return (EVP_MD *)EVP_sm3(); + } +} + +#endif /* ENABLE_QAT_HW_SM3 */ diff --git a/qat_hw_sm3.h b/qat_hw_sm3.h new file mode 100644 index 00000000..fdb17ae2 --- /dev/null +++ b/qat_hw_sm3.h @@ -0,0 +1,108 @@ +/* ==================================================================== + * + * + * BSD LICENSE + * + * Copyright(c) 2023 Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * ==================================================================== + */ + +/***************************************************************************** + * @file qat_hw_sm3.h + * + * This file provides a interface for SM3 operations + * + *****************************************************************************/ + +#ifndef QAT_HW_SM3_H +# define QAT_HW_SM3_H + +# include + +# include "cpa.h" +# include "cpa_types.h" +# include "cpa_cy_sym.h" +# include "cpa_cy_drbg.h" + +# ifdef ENABLE_QAT_HW_SM3 + +/* Digest Size */ +# define QAT_SM3_DIGEST_SIZE 32 +/*Block Size */ +# define QAT_SM3_BLOCK_SIZE 64 +/* State Size */ +# define QAT_SM3_STATE_SIZE 32 + +/* Min 260x to met 16k record offload, 16461 bytes in bulk crypto test */ +# define QAT_SM3_OFFLOAD_THRESHOLD (260 * QAT_SM3_BLOCK_SIZE) + +# define SM3_DIGEST_LENGTH 32 +# define SM3_WORD unsigned int + +# define SM3_CBLOCK 64 +# define SM3_LBLOCK (SM3_CBLOCK/4) + +typedef struct SM3state_st { + SM3_WORD A, B, C, D, E, F, G, H; + SM3_WORD Nl, Nh; + SM3_WORD data[SM3_LBLOCK]; + unsigned int num; +} SM3_CTX; + +typedef struct { + int inst_num; + int context_params_set; /* True if init called */ + int qat_offloaded; /* True if there was an offload. */ + + int *rc_refs; /* The count of the resource reference */ + + int *data_refs; /* The count of the resource reference */ + unsigned char *data; /* The buffer */ + unsigned int num; /* The data left in buffer */ + unsigned int rcv_count; /* The data recived */ + + CpaCySymSessionSetupData *session_data; + CpaCySymSessionCtx session_ctx; + CpaCySymOpData *pOpData; + CpaBufferList pSrcBufferList; /* For QAT metadata */ + unsigned char *digest_data; +} QAT_SM3_CTX; + +/* Totally 3 memory sections in application data, common EVP_MD, + SM3_CTX used for SM3 software, and QAT_SM3_CTX for QAT_HW */ +# define QAT_SM3_GET_CTX(ctx) \ + ((QAT_SM3_CTX *) (EVP_MD_CTX_md_data(ctx) + sizeof(SM3_CTX))) + +const EVP_MD *qat_hw_create_sm3_meth(int nid, int key_type); + +# endif /* ENABLE_QAT_HW_SM3 */ +#endif /* QAT_HW_SM3_H */ diff --git a/qat_prov.txt b/qat_prov.txt index 060b1efd..d7d62987 100644 --- a/qat_prov.txt +++ b/qat_prov.txt @@ -264,44 +264,45 @@ QAT_R_SET_TAG_INVALID_OP:344:set tag invalid op QAT_R_SHA3_CTX_NULL:345:sha3 ctx null QAT_R_SIG_GET_R_S_FAILURE:346:sig get r s failure QAT_R_SIG_MALLOC_FAILURE:347:sig malloc failure -QAT_R_SM3_FINAL_FAILURE:348:sm3 final failure -QAT_R_SM3_INIT_FAILURE:349:sm3 init failure -QAT_R_SM3_UPDATE_FAILURE:350:sm3 update failure -QAT_R_SM4_CCM_DECRYPT_FAILURE:351:sm4 ccm decrypt failure -QAT_R_SM4_GCM_DECRYPT_FAILURE:352:sm4 gcm decrypt failure -QAT_R_SM4_GCM_ENCRYPT_FAILURE:353:sm4 gcm encrypt failure -QAT_R_SM4_GET_INSTANCE_FAILED:354:sm4 get instance failed -QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED:355:sm4 get sessionctx size failed -QAT_R_SM4_MALLOC_FAILED:356:sm4 malloc failed -QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE:357:sm4 no qat instance available -QAT_R_SM4_NULL_CKEY:358:sm4 null ckey -QAT_R_SM4_NULL_CTX_OR_KEY:359:sm4 null ctx or key -QAT_R_SM4_NULL_POINTER:360:sm4 null pointer -QAT_R_SM4_NULL_QCTX:361:sm4 null qctx -QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED:362:sm4 qat context not initialised -QAT_R_SM4_QAT_INITSESSION_FAILED:363:sm4 qat initsession failed -QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED:364:sm4 qat submit request failed -QAT_R_SM4_REMOVE_SESSION_FAILED:365:sm4 remove session failed -QAT_R_SM4_SETUP_META_DATA_FAILED:366:sm4 setup meta data failed -QAT_R_SM4_SET_METHODS_FAILED:367:sm4 set methods failed -QAT_R_SSD_MALLOC_FAILURE:368:ssd malloc failure -QAT_R_SSD_NULL:369:ssd null -QAT_R_START_INSTANCE_FAILURE:370:start instance failure -QAT_R_STOP_INSTANCE_FAILURE:371:stop instance failure -QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL:372:sw get compute key pfunc null -QAT_R_SW_GET_KEYGEN_PFUNC_NULL:373:sw get keygen pfunc null -QAT_R_SW_GET_SIGN_PFUNC_NULL:374:sw get sign pfunc null -QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL:375:sw get sign setup pfunc null -QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL:376:sw get sign sig pfunc null -QAT_R_SW_GET_VERIFY_PFUNC_NULL:377:sw get verify pfunc null -QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL:378:sw get verify sig pfunc null -QAT_R_SW_METHOD_NULL:379:sw method null -QAT_R_S_NULL:380:s null -QAT_R_S_Q_COMPARE_FAILURE:381:s q compare failure -QAT_R_TAG_NOTSET:382:tag notset -QAT_R_UNKNOWN_PADDING:383:unknown padding -QAT_R_UNKNOWN_PADDING_TYPE:384:unknown padding type -QAT_R_WAKE_PAUSE_JOB_FAILURE:385:wake pause job failure -QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE:386:x y tx ty bn malloc failure -QAT_R_X_Y_Z_MALLOC_FAILURE:387:x y z malloc failure -QAT_R_Z_ALLOCATE_FAILURE:388:z allocate failure +QAT_R_SM3_CTX_NULL:348:sm3 ctx null +QAT_R_SM3_FINAL_FAILURE:349:sm3 final failure +QAT_R_SM3_INIT_FAILURE:350:sm3 init failure +QAT_R_SM3_UPDATE_FAILURE:351:sm3 update failure +QAT_R_SM4_CCM_DECRYPT_FAILURE:352:sm4 ccm decrypt failure +QAT_R_SM4_GCM_DECRYPT_FAILURE:353:sm4 gcm decrypt failure +QAT_R_SM4_GCM_ENCRYPT_FAILURE:354:sm4 gcm encrypt failure +QAT_R_SM4_GET_INSTANCE_FAILED:355:sm4 get instance failed +QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED:356:sm4 get sessionctx size failed +QAT_R_SM4_MALLOC_FAILED:357:sm4 malloc failed +QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE:358:sm4 no qat instance available +QAT_R_SM4_NULL_CKEY:359:sm4 null ckey +QAT_R_SM4_NULL_CTX_OR_KEY:360:sm4 null ctx or key +QAT_R_SM4_NULL_POINTER:361:sm4 null pointer +QAT_R_SM4_NULL_QCTX:362:sm4 null qctx +QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED:363:sm4 qat context not initialised +QAT_R_SM4_QAT_INITSESSION_FAILED:364:sm4 qat initsession failed +QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED:365:sm4 qat submit request failed +QAT_R_SM4_REMOVE_SESSION_FAILED:366:sm4 remove session failed +QAT_R_SM4_SETUP_META_DATA_FAILED:367:sm4 setup meta data failed +QAT_R_SM4_SET_METHODS_FAILED:368:sm4 set methods failed +QAT_R_SSD_MALLOC_FAILURE:369:ssd malloc failure +QAT_R_SSD_NULL:370:ssd null +QAT_R_START_INSTANCE_FAILURE:371:start instance failure +QAT_R_STOP_INSTANCE_FAILURE:372:stop instance failure +QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL:373:sw get compute key pfunc null +QAT_R_SW_GET_KEYGEN_PFUNC_NULL:374:sw get keygen pfunc null +QAT_R_SW_GET_SIGN_PFUNC_NULL:375:sw get sign pfunc null +QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL:376:sw get sign setup pfunc null +QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL:377:sw get sign sig pfunc null +QAT_R_SW_GET_VERIFY_PFUNC_NULL:378:sw get verify pfunc null +QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL:379:sw get verify sig pfunc null +QAT_R_SW_METHOD_NULL:380:sw method null +QAT_R_S_NULL:381:s null +QAT_R_S_Q_COMPARE_FAILURE:382:s q compare failure +QAT_R_TAG_NOTSET:383:tag notset +QAT_R_UNKNOWN_PADDING:384:unknown padding +QAT_R_UNKNOWN_PADDING_TYPE:385:unknown padding type +QAT_R_WAKE_PAUSE_JOB_FAILURE:386:wake pause job failure +QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE:387:x y tx ty bn malloc failure +QAT_R_X_Y_Z_MALLOC_FAILURE:388:x y z malloc failure +QAT_R_Z_ALLOCATE_FAILURE:389:z allocate failure diff --git a/qat_prov_err.c b/qat_prov_err.c index 3d30312c..409e5e6b 100644 --- a/qat_prov_err.c +++ b/qat_prov_err.c @@ -355,6 +355,7 @@ static ERR_STRING_DATA QAT_str_reasons[] = { {ERR_PACK(0, 0, QAT_R_SHA3_CTX_NULL), "sha3 ctx null"}, {ERR_PACK(0, 0, QAT_R_SIG_GET_R_S_FAILURE), "sig get r s failure"}, {ERR_PACK(0, 0, QAT_R_SIG_MALLOC_FAILURE), "sig malloc failure"}, + {ERR_PACK(0, 0, QAT_R_SM3_CTX_NULL), "sm3 ctx null"}, {ERR_PACK(0, 0, QAT_R_SM3_FINAL_FAILURE), "sm3 final failure"}, {ERR_PACK(0, 0, QAT_R_SM3_INIT_FAILURE), "sm3 init failure"}, {ERR_PACK(0, 0, QAT_R_SM3_UPDATE_FAILURE), "sm3 update failure"}, diff --git a/qat_prov_err.h b/qat_prov_err.h index 4b3fef54..d79beef9 100644 --- a/qat_prov_err.h +++ b/qat_prov_err.h @@ -280,46 +280,47 @@ void ERR_QAT_error(int function, int reason, const char *file, int line); # define QAT_R_SHA3_CTX_NULL 345 # define QAT_R_SIG_GET_R_S_FAILURE 346 # define QAT_R_SIG_MALLOC_FAILURE 347 -# define QAT_R_SM3_FINAL_FAILURE 348 -# define QAT_R_SM3_INIT_FAILURE 349 -# define QAT_R_SM3_UPDATE_FAILURE 350 -# define QAT_R_SM4_CCM_DECRYPT_FAILURE 351 -# define QAT_R_SM4_GCM_DECRYPT_FAILURE 352 -# define QAT_R_SM4_GCM_ENCRYPT_FAILURE 353 -# define QAT_R_SM4_GET_INSTANCE_FAILED 354 -# define QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED 355 -# define QAT_R_SM4_MALLOC_FAILED 356 -# define QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE 357 -# define QAT_R_SM4_NULL_CKEY 358 -# define QAT_R_SM4_NULL_CTX_OR_KEY 359 -# define QAT_R_SM4_NULL_POINTER 360 -# define QAT_R_SM4_NULL_QCTX 361 -# define QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED 362 -# define QAT_R_SM4_QAT_INITSESSION_FAILED 363 -# define QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED 364 -# define QAT_R_SM4_REMOVE_SESSION_FAILED 365 -# define QAT_R_SM4_SETUP_META_DATA_FAILED 366 -# define QAT_R_SM4_SET_METHODS_FAILED 367 -# define QAT_R_SSD_MALLOC_FAILURE 368 -# define QAT_R_SSD_NULL 369 -# define QAT_R_START_INSTANCE_FAILURE 370 -# define QAT_R_STOP_INSTANCE_FAILURE 371 -# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 372 -# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 373 -# define QAT_R_SW_GET_SIGN_PFUNC_NULL 374 -# define QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL 375 -# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 376 -# define QAT_R_SW_GET_VERIFY_PFUNC_NULL 377 -# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 378 -# define QAT_R_SW_METHOD_NULL 379 -# define QAT_R_S_NULL 380 -# define QAT_R_S_Q_COMPARE_FAILURE 381 -# define QAT_R_TAG_NOTSET 382 -# define QAT_R_UNKNOWN_PADDING 383 -# define QAT_R_UNKNOWN_PADDING_TYPE 384 -# define QAT_R_WAKE_PAUSE_JOB_FAILURE 385 -# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 386 -# define QAT_R_X_Y_Z_MALLOC_FAILURE 387 -# define QAT_R_Z_ALLOCATE_FAILURE 388 +# define QAT_R_SM3_CTX_NULL 348 +# define QAT_R_SM3_FINAL_FAILURE 349 +# define QAT_R_SM3_INIT_FAILURE 350 +# define QAT_R_SM3_UPDATE_FAILURE 351 +# define QAT_R_SM4_CCM_DECRYPT_FAILURE 352 +# define QAT_R_SM4_GCM_DECRYPT_FAILURE 353 +# define QAT_R_SM4_GCM_ENCRYPT_FAILURE 354 +# define QAT_R_SM4_GET_INSTANCE_FAILED 355 +# define QAT_R_SM4_GET_SESSIONCTX_SIZE_FAILED 356 +# define QAT_R_SM4_MALLOC_FAILED 357 +# define QAT_R_SM4_NO_QAT_INSTANCE_AVAILABLE 358 +# define QAT_R_SM4_NULL_CKEY 359 +# define QAT_R_SM4_NULL_CTX_OR_KEY 360 +# define QAT_R_SM4_NULL_POINTER 361 +# define QAT_R_SM4_NULL_QCTX 362 +# define QAT_R_SM4_QAT_CONTEXT_NOT_INITIALISED 363 +# define QAT_R_SM4_QAT_INITSESSION_FAILED 364 +# define QAT_R_SM4_QAT_SUBMIT_REQUEST_FAILED 365 +# define QAT_R_SM4_REMOVE_SESSION_FAILED 366 +# define QAT_R_SM4_SETUP_META_DATA_FAILED 367 +# define QAT_R_SM4_SET_METHODS_FAILED 368 +# define QAT_R_SSD_MALLOC_FAILURE 369 +# define QAT_R_SSD_NULL 370 +# define QAT_R_START_INSTANCE_FAILURE 371 +# define QAT_R_STOP_INSTANCE_FAILURE 372 +# define QAT_R_SW_GET_COMPUTE_KEY_PFUNC_NULL 373 +# define QAT_R_SW_GET_KEYGEN_PFUNC_NULL 374 +# define QAT_R_SW_GET_SIGN_PFUNC_NULL 375 +# define QAT_R_SW_GET_SIGN_SETUP_PFUNC_NULL 376 +# define QAT_R_SW_GET_SIGN_SIG_PFUNC_NULL 377 +# define QAT_R_SW_GET_VERIFY_PFUNC_NULL 378 +# define QAT_R_SW_GET_VERIFY_SIG_PFUNC_NULL 379 +# define QAT_R_SW_METHOD_NULL 380 +# define QAT_R_S_NULL 381 +# define QAT_R_S_Q_COMPARE_FAILURE 382 +# define QAT_R_TAG_NOTSET 383 +# define QAT_R_UNKNOWN_PADDING 384 +# define QAT_R_UNKNOWN_PADDING_TYPE 385 +# define QAT_R_WAKE_PAUSE_JOB_FAILURE 386 +# define QAT_R_X_Y_TX_TY_BN_MALLOC_FAILURE 387 +# define QAT_R_X_Y_Z_MALLOC_FAILURE 388 +# define QAT_R_Z_ALLOCATE_FAILURE 389 #endif diff --git a/test/tests_sm3.c b/test/tests_sm3.c index d2966088..ec079b69 100644 --- a/test/tests_sm3.c +++ b/test/tests_sm3.c @@ -45,26 +45,22 @@ #include #include #include +#include #include "tests.h" #include "../qat_utils.h" #define SM3_DIGEST_LENGTH 32 +typedef struct DIGEST_CASE { + int len; + unsigned char expected[SM3_DIGEST_LENGTH]; +} digest_case; -/****************************************************************************** -* function: -* run_sm3_msg (void *args) -* -* @param args [IN] - the test parameters -* -* Description: -******************************************************************************/ -static int run_sm3_msg(void *args) +static int run_sm3_msg_once(void *args, int inLen, unsigned char expected[]) { - TEST_PARAMS *temp_args = (TEST_PARAMS *)args; + TEST_PARAMS *temp_args = (TEST_PARAMS *) args; int count = *(temp_args->count); - int size = temp_args->size; /* If temp_args->explicit_engine is not set then set the engine to NULL to allow fallback to software if that engine under test does not support this operation. @@ -75,66 +71,96 @@ static int run_sm3_msg(void *args) int verify = temp_args->verify; int i = 0; - int inLen = size; int ret = 1; + unsigned char md[SM3_DIGEST_LENGTH]; + unsigned char *inData = NULL; - /* Use default input size in verify mode. */ - if (verify) - inLen = 1024; + if (inLen) { + inData = OPENSSL_malloc(inLen); + memset(inData, 0xaa, inLen); + } - unsigned char md[SM3_DIGEST_LENGTH]; - unsigned char *inData = OPENSSL_malloc(inLen); + /* Setup the input and output data. */ + memset(md, 0x00, SM3_DIGEST_LENGTH); - unsigned char expected[] = { - 0x69, 0xA5, 0xCF, 0x23, 0x25, 0x4A, 0x38, 0x54, - 0x03, 0xA6, 0xA8, 0x98, 0x88, 0xCC, 0x3F, 0x9E, - 0xC7, 0x03, 0x11, 0x7E, 0xD9, 0xFC, 0x06, 0xDE, - 0x77, 0x1B, 0x31, 0x86, 0x02, 0x28, 0xA6, 0x69, - }; + for (i = 0; i < count; i++) { + ret = EVP_Digest(inData, /* Input data pointer. */ + inLen, /* Input data length. */ + md, /* Output hash pointer. */ + NULL, EVP_sm3(), /* Hash algorithm indicator. */ + e); /* Engine indicator. */ + if (ret != 1 || verify) { + /* Compare the digest results with the expected results. */ + if (memcmp(md, expected, SM3_DIGEST_LENGTH)) { + fprintf(stderr, "# FAIL verify for SM3.\n"); + ret = 0; + tests_hexdump("SM3 actual :", md, SM3_DIGEST_LENGTH); + tests_hexdump("SM3 expected:", expected, SM3_DIGEST_LENGTH); + break; + } else { + fprintf(stderr, "# PASS verify for SM3 dgst %d bytes.\n", + inLen); + } + } + } /* count for-loop */ + if (print_output) + tests_hexdump("SM3 digest text:", md, SM3_DIGEST_LENGTH); - unsigned char expected_res[] = { - 0x9F, 0xEF, 0xD6, 0x3A, 0xE0, 0x52, 0x54, 0x08, - 0x5E, 0x48, 0x3E, 0xF0, 0x41, 0xAD, 0x81, 0xC6, - 0x72, 0x1E, 0xEB, 0x7E, 0x34, 0xC8, 0xF2, 0x9B, - 0xBA, 0xF7, 0x59, 0x41, 0xA1, 0x6F, 0x0A, 0x26, - }; + if (inData) + OPENSSL_free(inData); + return ret; +} - if (inData == NULL) - { - fprintf(stderr,"# FAIL: [%s] --- inData malloc failed! \n", __func__); - exit(EXIT_FAILURE); +static int run_sm3_hmac_once(void *args, int inLen, unsigned char expected[]) +{ + TEST_PARAMS *temp_args = (TEST_PARAMS *) args; + int count = *(temp_args->count); + int print_output = temp_args->print_output; + int verify = temp_args->verify; + + int i = 0; + int ret = 1; + unsigned char *result = NULL; + + unsigned char md[SM3_DIGEST_LENGTH]; + unsigned char *inData = NULL; + unsigned int md_len = 0; + + static const unsigned char dummy_key[1] = { '\0' }; + + if (inLen) { + inData = OPENSSL_malloc(inLen); + memset(inData, 0xaa, inLen); } /* Setup the input and output data. */ - memset(inData, 0xaa, inLen); memset(md, 0x00, SM3_DIGEST_LENGTH); - for (i = 0; i < count; i++) - { - DEBUG("\n----- SM3 digest msg ----- \n\n"); + for (i = 0; i < count; i++) { + result = HMAC(EVP_sm3(), /* Hash function */ + dummy_key, /* Key */ + 0, /* Key length */ + inData, /* Input data */ + inLen, /* Input data length */ + md, /* HMAC result */ + &md_len /* HMAC result length */ + ); - ret = EVP_Digest(inData, /* Input data pointer. */ - inLen, /* Input data length. */ - md, /* Output hash pointer. */ - NULL, EVP_sm3(), /* Hash algorithm indicator. */ - e); /* Engine indicator. */ - if (ret != 1 || verify) - { + if (result == NULL || verify) { /* Compare the digest results with the expected results. */ - if ((memcmp(md, expected, SM3_DIGEST_LENGTH)) && - (memcmp(md, expected_res, SM3_DIGEST_LENGTH))) - { - fprintf(stderr,"# FAIL verify for SM3.\n"); + if (memcmp(md, expected, SM3_DIGEST_LENGTH)) { + fprintf(stderr, "# FAIL verify for SM3.\n"); ret = 0; tests_hexdump("SM3 actual :", md, SM3_DIGEST_LENGTH); tests_hexdump("SM3 expected:", expected, SM3_DIGEST_LENGTH); break; + } else { + fprintf(stderr, "# PASS verify for SM3 HMAC %d bytes.\n", + inLen); } - else - fprintf(stderr,"# PASS verify for SM3.\n"); } - } /* count for-loop */ + } /* count for-loop */ if (print_output) tests_hexdump("SM3 digest text:", md, SM3_DIGEST_LENGTH); @@ -143,6 +169,137 @@ static int run_sm3_msg(void *args) return ret; } +/****************************************************************************** +* function: +* run_sm3_msg (void *args) +* +* @param args [IN] - the test parameters +* +* Description: +******************************************************************************/ +static int run_sm3_msg(void *args) +{ + digest_case cases[] = { + {0, /* length = 0 */ + { + 0x1A, 0xB2, 0x1D, 0x83, 0x55, 0xCF, 0xA1, 0x7F, + 0x8E, 0x61, 0x19, 0x48, 0x31, 0xE8, 0x1A, 0x8F, + 0x22, 0xBE, 0xC8, 0xC7, 0x28, 0xFE, 0xFB, 0x74, + 0x7E, 0xD0, 0x35, 0xEB, 0x50, 0x82, 0xAA, 0x2B, + } + }, + + {1024, /* length = 1024 */ + { + 0x69, 0xA5, 0xCF, 0x23, 0x25, 0x4A, 0x38, 0x54, + 0x03, 0xA6, 0xA8, 0x98, 0x88, 0xCC, 0x3F, 0x9E, + 0xC7, 0x03, 0x11, 0x7E, 0xD9, 0xFC, 0x06, 0xDE, + 0x77, 0x1B, 0x31, 0x86, 0x02, 0x28, 0xA6, 0x69, + } + }, + + {1 * 1024 * 1024, /* length = 1M */ + { + 0x47, 0x8D, 0xA3, 0x3C, 0x71, 0xED, 0xC9, 0x50, + 0x6D, 0x75, 0xE9, 0xDF, 0xA1, 0xD3, 0xDB, 0xA2, + 0x8B, 0x12, 0x48, 0x7A, 0x38, 0x37, 0xEC, 0xC5, + 0xA9, 0x58, 0xFE, 0x3B, 0xD2, 0x00, 0x06, 0x8D, + } + }, + + {-1, {}} /* end */ + }; + + TEST_PARAMS *temp_args = (TEST_PARAMS *) args; + int verify = temp_args->verify; + int inLen = temp_args->size; + int ret = 1; + + DEBUG("\n----- SM3 digest msg ----- \n\n"); + + if (verify) { + int i; + for (i = 0; /* */ ; i++) { + if (cases[i].len == -1) + break; + + ret = run_sm3_msg_once(args, cases[i].len, cases[i].expected); + + if (ret != 1) + break; + } + } else { + ret = run_sm3_msg_once(args, inLen, NULL); + } + + return ret; +} + +/****************************************************************************** +* function: +* run_sm3_hmac (void *args) +* +* @param args [IN] - the test parameters +* +* Description: +******************************************************************************/ +static int run_sm3_hmac(void *args) +{ + digest_case cases[] = { + {0, /* length = 0 */ + { + 0x0D, 0x23, 0xF7, 0x2B, 0xA1, 0x5E, 0x9C, 0x18, + 0x9A, 0x87, 0x9A, 0xEF, 0xC7, 0x09, 0x96, 0xB0, + 0x60, 0x91, 0xDE, 0x6E, 0x64, 0xD3, 0x1B, 0x7A, + 0x84, 0x00, 0x43, 0x56, 0xDD, 0x91, 0x52, 0x61, + } + }, + + {1024, /* length = 1024 */ + { + 0x3C, 0xC4, 0xDA, 0x4C, 0xED, 0x9C, 0xD9, 0x71, + 0xFE, 0x9C, 0x08, 0x4B, 0x43, 0x49, 0x02, 0x61, + 0x4E, 0x21, 0xC7, 0x3F, 0x8D, 0xFF, 0x61, 0x51, + 0x1F, 0x6F, 0x6B, 0x31, 0xC1, 0xE8, 0xBD, 0x55, + } + }, + + {1 * 1024 * 1024, /* length = 1M */ + { + 0x95, 0xC9, 0x06, 0xBE, 0x01, 0x21, 0x14, 0xA4, + 0x0D, 0x3F, 0xFA, 0x9B, 0x1E, 0x50, 0x26, 0x6F, + 0xDE, 0x2B, 0x30, 0x26, 0x81, 0x53, 0x98, 0x75, + 0xC8, 0x47, 0x91, 0x1E, 0x74, 0x8A, 0x17, 0xC3, + } + }, + + {-1, {}} /* end */ + }; + + TEST_PARAMS *temp_args = (TEST_PARAMS *) args; + int verify = temp_args->verify; + int inLen = temp_args->size; + int ret = 1; + + DEBUG("\n----- SM3 HMAC msg ----- \n\n"); + + if (verify) { + int i; + for (i = 0; /* */ ; i++) { + if (cases[i].len == -1) + break; + + ret = run_sm3_hmac_once(args, cases[i].len, cases[i].expected); + + if (ret != 1) + break; + } + } else { + ret = run_sm3_hmac_once(args, inLen, NULL); + } + + return ret; +} /****************************************************************************** * function: @@ -161,9 +318,11 @@ void tests_run_sm3(TEST_PARAMS *args) { args->additional_args = NULL; - if (!args->enable_async) + if (!args->enable_async) { run_sm3_msg(args); - else { + run_sm3_hmac(args); + } else { start_async_job(args, run_sm3_msg); + start_async_job(args, run_sm3_hmac); } }