Skip to content

Commit

Permalink
Fix QAT_SW EC registration issue in non ICX platforms
Browse files Browse the repository at this point in the history
In a non ICX platform which doesnt support QAT_SW the
expected behaviour is to fallback to use OpenSSL SW. The
pkey method and ec method share a common reg function
between QAT_HW and QAT_SW seperated using conditional
compilation which is not registering any function.
Refactored it with global variables fix register issue.

Signed-off-by: Yogaraj Alamenda <[email protected]>
  • Loading branch information
Yogaraj-Alamenda committed Oct 20, 2021
1 parent 8513468 commit 4915c97
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 388 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.68])
AC_INIT([qatengine], [0.6.8], [])
AC_INIT([qatengine], [0.6.9], [])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([.])
Expand Down
37 changes: 20 additions & 17 deletions e_qat.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@
const char *engine_qat_id = STR(QAT_ENGINE_ID);
#if defined(QAT_HW) && defined(QAT_SW)
const char *engine_qat_name =
"Reference implementation of QAT crypto engine(qat_hw & qat_sw) v0.6.8";
"Reference implementation of QAT crypto engine(qat_hw & qat_sw) v0.6.9";
#elif QAT_HW
const char *engine_qat_name =
"Reference implementation of QAT crypto engine(qat_hw) v0.6.8";
"Reference implementation of QAT crypto engine(qat_hw) v0.6.9";
#else
const char *engine_qat_name =
"Reference implementation of QAT crypto engine(qat_sw) v0.6.8";
"Reference implementation of QAT crypto engine(qat_sw) v0.6.9";
#endif
unsigned int engine_inited = 0;

Expand All @@ -170,6 +170,12 @@ int qat_hw_rsa_offload = 0;
int qat_hw_ecx_offload = 0;
int qat_hw_ecdh_offload = 0;
int qat_hw_ecdsa_offload = 0;
int qat_hw_prf_offload = 0;
int qat_hw_hkdf_offload = 0;
int qat_sw_rsa_offload = 0;
int qat_sw_ecx_offload = 0;
int qat_sw_ecdh_offload = 0;
int qat_sw_ecdsa_offload = 0;
int qat_keep_polling = 1;
int multibuff_keep_polling = 1;
int enable_external_polling = 0;
Expand Down Expand Up @@ -508,6 +514,13 @@ int qat_engine_finish_int(ENGINE *e, int reset_globals)
qat_hw_ecx_offload = 0;
qat_hw_ecdh_offload = 0;
qat_hw_ecdsa_offload = 0;
qat_hw_prf_offload = 0;
qat_hw_hkdf_offload = 0;
qat_sw_rsa_offload = 0;
qat_sw_ecx_offload = 0;
qat_sw_ecdh_offload = 0;
qat_sw_ecdsa_offload = 0;

}
qat_pthread_mutex_unlock();
CRYPTO_CLOSE_QAT_LOG();
Expand Down Expand Up @@ -929,15 +942,18 @@ static int bind_qat(ENGINE *e, const char *id)
}

#ifdef QAT_SW
# if defined(ENABLE_QAT_SW_RSA) || defined(ENABLE_QAT_SW_ECX) \
|| defined(ENABLE_QAT_SW_ECDH) || defined(ENABLE_QAT_SW_ECDSA)
DEBUG("Registering QAT SW supported algorithms\n");
qat_sw_offload = 1;
# endif

# ifdef ENABLE_QAT_SW_RSA
if (!qat_hw_rsa_offload &&
mbx_get_algo_info(MBX_ALGO_RSA_2K) &&
mbx_get_algo_info(MBX_ALGO_RSA_3K) &&
mbx_get_algo_info(MBX_ALGO_RSA_4K)) {
DEBUG("QAT SW RSA Supported\n");
qat_sw_offload = 1;
if (!ENGINE_set_RSA(e, multibuff_get_RSA_methods())) {
WARN("ENGINE_set_RSA QAT SW failed\n");
goto end;
Expand All @@ -963,25 +979,12 @@ static int bind_qat(ENGINE *e, const char *id)
WARN("ENGINE_set_EC failed\n");
goto end;
}
# if defined(ENABLE_QAT_SW_ECDH) || defined(ENABLE_QAT_SW_ECDSA)
if (mbx_get_algo_info(MBX_ALGO_ECDHE_NIST_P256) &&
mbx_get_algo_info(MBX_ALGO_ECDHE_NIST_P384) &&
mbx_get_algo_info(MBX_ALGO_ECDSA_NIST_P256) &&
mbx_get_algo_info(MBX_ALGO_ECDSA_NIST_P384)) {
DEBUG("QAT SW ECDSA p256/p384 & ECDH p256/p384 Supported\n");
qat_sw_offload = 1;
}
# endif

# ifndef QAT_OPENSSL_3
if (!ENGINE_set_pkey_meths(e, qat_pkey_methods)) {
WARN("ENGINE_set_pkey_meths failed\n");
goto end;
}
# if ENABLE_QAT_SW_ECX
if (mbx_get_algo_info(MBX_ALGO_X25519))
qat_sw_offload = 1;
# endif
# endif
#endif

Expand Down
6 changes: 6 additions & 0 deletions e_qat.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ extern int qat_hw_rsa_offload;
extern int qat_hw_ecx_offload;
extern int qat_hw_ecdh_offload;
extern int qat_hw_ecdsa_offload;
extern int qat_hw_prf_offload;
extern int qat_hw_hkdf_offload;
extern int qat_sw_rsa_offload;
extern int qat_sw_ecx_offload;
extern int qat_sw_ecdh_offload;
extern int qat_sw_ecdsa_offload;
extern int qat_keep_polling;
extern int multibuff_keep_polling;
extern int enable_external_polling;
Expand Down
159 changes: 79 additions & 80 deletions e_qat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,86 +31,85 @@ QAT_F_MULTIBUFF_RSA_PUB_ENC:121:multibuff_rsa_pub_enc
QAT_F_MULTIBUFF_VALIDATE_ECX_DERIVE:122:multibuff_validate_ecx_derive
QAT_F_MULTIBUFF_X25519_DERIVE:123:multibuff_x25519_derive
QAT_F_MULTIBUFF_X25519_KEYGEN:124:multibuff_x25519_keygen
QAT_F_MULTIBUFF_X25519_PMETH:125:multibuff_x25519_pmeth
QAT_F_POLL_INSTANCES:126:poll_instances
QAT_F_QAT_ADJUST_THREAD_AFFINITY:127:qat_adjust_thread_affinity
QAT_F_QAT_AES_GCM_CIPHER:128:qat_aes_gcm_cipher
QAT_F_QAT_AES_GCM_CLEANUP:129:qat_aes_gcm_cleanup
QAT_F_QAT_AES_GCM_CTRL:130:qat_aes_gcm_ctrl
QAT_F_QAT_AES_GCM_INIT:131:qat_aes_gcm_init
QAT_F_QAT_AES_GCM_SESSION_INIT:132:qat_aes_gcm_session_init
QAT_F_QAT_AES_GCM_TLS_CIPHER:133:qat_aes_gcm_tls_cipher
QAT_F_QAT_CHACHA20_POLY1305_CLEANUP:134:qat_chacha20_poly1305_cleanup
QAT_F_QAT_CHACHA20_POLY1305_CTRL:135:qat_chacha20_poly1305_ctrl
QAT_F_QAT_CHACHA20_POLY1305_DO_CIPHER:136:qat_chacha20_poly1305_do_cipher
QAT_F_QAT_CHACHA20_POLY1305_INIT:137:qat_chacha20_poly1305_init
QAT_F_QAT_CHACHA20_POLY1305_INIT_KEY_IV:138:qat_chacha20_poly1305_init_key_iv
QAT_F_QAT_CHACHA20_POLY1305_MAC_KEYGEN:139:qat_chacha20_poly1305_mac_keygen
QAT_F_QAT_CHACHA20_POLY1305_TLS_CIPHER:140:qat_chacha20_poly1305_tls_cipher
QAT_F_QAT_CHACHAPOLY_SESSION_DATA_INIT:141:qat_chachapoly_session_data_init
QAT_F_QAT_CHACHAPOLY_SETUP_OP_PARAMS:142:qat_chachapoly_setup_op_params
QAT_F_QAT_CRYPTO_CALLBACKFN:143:qat_crypto_callbackFn
QAT_F_QAT_DH_COMPUTE_KEY:144:qat_dh_compute_key
QAT_F_QAT_DH_GENERATE_KEY:145:qat_dh_generate_key
QAT_F_QAT_DSA_DO_SIGN:146:qat_dsa_do_sign
QAT_F_QAT_DSA_DO_VERIFY:147:qat_dsa_do_verify
QAT_F_QAT_DSA_SIGN_SETUP:148:qat_dsa_sign_setup
QAT_F_QAT_ECDH_COMPUTE_KEY:149:qat_ecdh_compute_key
QAT_F_QAT_ECDH_GENERATE_KEY:150:qat_ecdh_generate_key
QAT_F_QAT_ECDSA_DO_SIGN:151:qat_ecdsa_do_sign
QAT_F_QAT_ECDSA_DO_VERIFY:152:qat_ecdsa_do_verify
QAT_F_QAT_ECDSA_SIGN:153:qat_ecdsa_sign
QAT_F_QAT_ECDSA_VERIFY:154:qat_ecdsa_verify
QAT_F_QAT_ENGINE_CTRL:155:qat_engine_ctrl
QAT_F_QAT_ENGINE_ECDH_COMPUTE_KEY:156:qat_engine_ecdh_compute_key
QAT_F_QAT_FD_CLEANUP:157:qat_fd_cleanup
QAT_F_QAT_FINISH_INT:158:qat_finish_int
QAT_F_QAT_FREE_DH_METHODS:159:qat_free_DH_methods
QAT_F_QAT_FREE_DSA_METHODS:160:qat_free_DSA_methods
QAT_F_QAT_GET_DH_METHODS:161:qat_get_DH_methods
QAT_F_QAT_GET_DSA_METHODS:162:qat_get_DSA_methods
QAT_F_QAT_GET_EC_METHODS:163:qat_get_EC_methods
QAT_F_QAT_GET_RSA_METHODS:164:qat_get_RSA_methods
QAT_F_QAT_HKDF_DERIVE:165:qat_hkdf_derive
QAT_F_QAT_HKDF_INIT:166:qat_hkdf_init
QAT_F_QAT_HKDF_PMETH:167:qat_hkdf_pmeth
QAT_F_QAT_INIT:168:qat_init
QAT_F_QAT_INIT_OP_DONE:169:qat_init_op_done
QAT_F_QAT_INIT_OP_DONE_PIPE:170:qat_init_op_done_pipe
QAT_F_QAT_INIT_OP_DONE_RSA_CRT:171:qat_init_op_done_rsa_crt
QAT_F_QAT_MOD_EXP:172:qat_mod_exp
QAT_F_QAT_PKEY_ECX_DERIVE25519:173:qat_pkey_ecx_derive25519
QAT_F_QAT_PKEY_ECX_DERIVE448:174:qat_pkey_ecx_derive448
QAT_F_QAT_PKEY_ECX_KEYGEN:175:qat_pkey_ecx_keygen
QAT_F_QAT_PRF_PMETH:176:qat_prf_pmeth
QAT_F_QAT_PRF_TLS_DERIVE:177:qat_prf_tls_derive
QAT_F_QAT_RSA_DECRYPT:178:qat_rsa_decrypt
QAT_F_QAT_RSA_DECRYPT_CRT:179:qat_rsa_decrypt_CRT
QAT_F_QAT_RSA_ENCRYPT:180:qat_rsa_encrypt
QAT_F_QAT_RSA_PRIV_DEC:181:qat_rsa_priv_dec
QAT_F_QAT_RSA_PRIV_ENC:182:qat_rsa_priv_enc
QAT_F_QAT_RSA_PUB_DEC:183:qat_rsa_pub_dec
QAT_F_QAT_RSA_PUB_ENC:184:qat_rsa_pub_enc
QAT_F_QAT_SESSION_DATA_INIT:185:qat_session_data_init
QAT_F_QAT_SET_AFFINE_COORDINATES:186:qat_set_affine_coordinates
QAT_F_QAT_SET_INSTANCE_FOR_THREAD:187:qat_set_instance_for_thread
QAT_F_QAT_SHA3_CLEANUP:188:qat_sha3_cleanup
QAT_F_QAT_SHA3_CTRL:189:qat_sha3_ctrl
QAT_F_QAT_SHA3_FINAL:190:qat_sha3_final
QAT_F_QAT_SHA3_SESSION_DATA_INIT:191:qat_sha3_session_data_init
QAT_F_QAT_SHA3_SETUP_PARAM:192:qat_sha3_setup_param
QAT_F_QAT_SHA3_UPDATE:193:qat_sha3_update
QAT_F_QAT_SYM_PERFORM_OP:194:qat_sym_perform_op
QAT_F_QAT_VALIDATE_ECX_DERIVE:195:qat_validate_ecx_derive
QAT_F_QAT_X25519_PMETH:196:qat_x25519_pmeth
QAT_F_QAT_X448_PMETH:197:qat_x448_pmeth
QAT_F_VAESGCM_CIPHERS_CTRL:198:vaesgcm_ciphers_ctrl
QAT_F_VAESGCM_CIPHERS_DO_CIPHER:199:vaesgcm_ciphers_do_cipher
QAT_F_VAESGCM_CIPHERS_INIT:200:vaesgcm_ciphers_init
QAT_F_VAESGCM_CREATE_CIPHER_METH:201:vaesgcm_create_cipher_meth
QAT_F_VAESGCM_INIT_GCM:202:vaesgcm_init_gcm
QAT_F_VAESGCM_INIT_IPSEC_MB_MGR:203:vaesgcm_init_ipsec_mb_mgr
QAT_F_VAESGCM_INIT_KEY:204:vaesgcm_init_key
QAT_F_POLL_INSTANCES:125:poll_instances
QAT_F_QAT_ADJUST_THREAD_AFFINITY:126:qat_adjust_thread_affinity
QAT_F_QAT_AES_GCM_CIPHER:127:qat_aes_gcm_cipher
QAT_F_QAT_AES_GCM_CLEANUP:128:qat_aes_gcm_cleanup
QAT_F_QAT_AES_GCM_CTRL:129:qat_aes_gcm_ctrl
QAT_F_QAT_AES_GCM_INIT:130:qat_aes_gcm_init
QAT_F_QAT_AES_GCM_SESSION_INIT:131:qat_aes_gcm_session_init
QAT_F_QAT_AES_GCM_TLS_CIPHER:132:qat_aes_gcm_tls_cipher
QAT_F_QAT_CHACHA20_POLY1305_CLEANUP:133:qat_chacha20_poly1305_cleanup
QAT_F_QAT_CHACHA20_POLY1305_CTRL:134:qat_chacha20_poly1305_ctrl
QAT_F_QAT_CHACHA20_POLY1305_DO_CIPHER:135:qat_chacha20_poly1305_do_cipher
QAT_F_QAT_CHACHA20_POLY1305_INIT:136:qat_chacha20_poly1305_init
QAT_F_QAT_CHACHA20_POLY1305_INIT_KEY_IV:137:qat_chacha20_poly1305_init_key_iv
QAT_F_QAT_CHACHA20_POLY1305_MAC_KEYGEN:138:qat_chacha20_poly1305_mac_keygen
QAT_F_QAT_CHACHA20_POLY1305_TLS_CIPHER:139:qat_chacha20_poly1305_tls_cipher
QAT_F_QAT_CHACHAPOLY_SESSION_DATA_INIT:140:qat_chachapoly_session_data_init
QAT_F_QAT_CHACHAPOLY_SETUP_OP_PARAMS:141:qat_chachapoly_setup_op_params
QAT_F_QAT_CRYPTO_CALLBACKFN:142:qat_crypto_callbackFn
QAT_F_QAT_DH_COMPUTE_KEY:143:qat_dh_compute_key
QAT_F_QAT_DH_GENERATE_KEY:144:qat_dh_generate_key
QAT_F_QAT_DSA_DO_SIGN:145:qat_dsa_do_sign
QAT_F_QAT_DSA_DO_VERIFY:146:qat_dsa_do_verify
QAT_F_QAT_DSA_SIGN_SETUP:147:qat_dsa_sign_setup
QAT_F_QAT_ECDH_COMPUTE_KEY:148:qat_ecdh_compute_key
QAT_F_QAT_ECDH_GENERATE_KEY:149:qat_ecdh_generate_key
QAT_F_QAT_ECDSA_DO_SIGN:150:qat_ecdsa_do_sign
QAT_F_QAT_ECDSA_DO_VERIFY:151:qat_ecdsa_do_verify
QAT_F_QAT_ECDSA_SIGN:152:qat_ecdsa_sign
QAT_F_QAT_ECDSA_VERIFY:153:qat_ecdsa_verify
QAT_F_QAT_ENGINE_CTRL:154:qat_engine_ctrl
QAT_F_QAT_ENGINE_ECDH_COMPUTE_KEY:155:qat_engine_ecdh_compute_key
QAT_F_QAT_FD_CLEANUP:156:qat_fd_cleanup
QAT_F_QAT_FINISH_INT:157:qat_finish_int
QAT_F_QAT_FREE_DH_METHODS:158:qat_free_DH_methods
QAT_F_QAT_FREE_DSA_METHODS:159:qat_free_DSA_methods
QAT_F_QAT_GET_DH_METHODS:160:qat_get_DH_methods
QAT_F_QAT_GET_DSA_METHODS:161:qat_get_DSA_methods
QAT_F_QAT_GET_EC_METHODS:162:qat_get_EC_methods
QAT_F_QAT_GET_RSA_METHODS:163:qat_get_RSA_methods
QAT_F_QAT_HKDF_DERIVE:164:qat_hkdf_derive
QAT_F_QAT_HKDF_INIT:165:qat_hkdf_init
QAT_F_QAT_HKDF_PMETH:166:qat_hkdf_pmeth
QAT_F_QAT_INIT:167:qat_init
QAT_F_QAT_INIT_OP_DONE:168:qat_init_op_done
QAT_F_QAT_INIT_OP_DONE_PIPE:169:qat_init_op_done_pipe
QAT_F_QAT_INIT_OP_DONE_RSA_CRT:170:qat_init_op_done_rsa_crt
QAT_F_QAT_MOD_EXP:171:qat_mod_exp
QAT_F_QAT_PKEY_ECX_DERIVE25519:172:qat_pkey_ecx_derive25519
QAT_F_QAT_PKEY_ECX_DERIVE448:173:qat_pkey_ecx_derive448
QAT_F_QAT_PKEY_ECX_KEYGEN:174:qat_pkey_ecx_keygen
QAT_F_QAT_PRF_PMETH:175:qat_prf_pmeth
QAT_F_QAT_PRF_TLS_DERIVE:176:qat_prf_tls_derive
QAT_F_QAT_RSA_DECRYPT:177:qat_rsa_decrypt
QAT_F_QAT_RSA_DECRYPT_CRT:178:qat_rsa_decrypt_CRT
QAT_F_QAT_RSA_ENCRYPT:179:qat_rsa_encrypt
QAT_F_QAT_RSA_PRIV_DEC:180:qat_rsa_priv_dec
QAT_F_QAT_RSA_PRIV_ENC:181:qat_rsa_priv_enc
QAT_F_QAT_RSA_PUB_DEC:182:qat_rsa_pub_dec
QAT_F_QAT_RSA_PUB_ENC:183:qat_rsa_pub_enc
QAT_F_QAT_SESSION_DATA_INIT:184:qat_session_data_init
QAT_F_QAT_SET_AFFINE_COORDINATES:185:qat_set_affine_coordinates
QAT_F_QAT_SET_INSTANCE_FOR_THREAD:186:qat_set_instance_for_thread
QAT_F_QAT_SHA3_CLEANUP:187:qat_sha3_cleanup
QAT_F_QAT_SHA3_CTRL:188:qat_sha3_ctrl
QAT_F_QAT_SHA3_FINAL:189:qat_sha3_final
QAT_F_QAT_SHA3_SESSION_DATA_INIT:190:qat_sha3_session_data_init
QAT_F_QAT_SHA3_SETUP_PARAM:191:qat_sha3_setup_param
QAT_F_QAT_SHA3_UPDATE:192:qat_sha3_update
QAT_F_QAT_SYM_PERFORM_OP:193:qat_sym_perform_op
QAT_F_QAT_VALIDATE_ECX_DERIVE:194:qat_validate_ecx_derive
QAT_F_QAT_X25519_PMETH:195:qat_x25519_pmeth
QAT_F_QAT_X448_PMETH:196:qat_x448_pmeth
QAT_F_VAESGCM_CIPHERS_CTRL:197:vaesgcm_ciphers_ctrl
QAT_F_VAESGCM_CIPHERS_DO_CIPHER:198:vaesgcm_ciphers_do_cipher
QAT_F_VAESGCM_CIPHERS_INIT:199:vaesgcm_ciphers_init
QAT_F_VAESGCM_CREATE_CIPHER_METH:200:vaesgcm_create_cipher_meth
QAT_F_VAESGCM_INIT_GCM:201:vaesgcm_init_gcm
QAT_F_VAESGCM_INIT_IPSEC_MB_MGR:202:vaesgcm_init_ipsec_mb_mgr
QAT_F_VAESGCM_INIT_KEY:203:vaesgcm_init_key

#Reason codes
QAT_R_AAD_INVALID_PTR:100:aad invalid ptr
Expand Down
1 change: 0 additions & 1 deletion e_qat_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static ERR_STRING_DATA QAT_str_functs[] = {
"multibuff_validate_ecx_derive"},
{ERR_PACK(0, QAT_F_MULTIBUFF_X25519_DERIVE, 0), "multibuff_x25519_derive"},
{ERR_PACK(0, QAT_F_MULTIBUFF_X25519_KEYGEN, 0), "multibuff_x25519_keygen"},
{ERR_PACK(0, QAT_F_MULTIBUFF_X25519_PMETH, 0), "multibuff_x25519_pmeth"},
{ERR_PACK(0, QAT_F_POLL_INSTANCES, 0), "poll_instances"},
{ERR_PACK(0, QAT_F_QAT_ADJUST_THREAD_AFFINITY, 0),
"qat_adjust_thread_affinity"},
Expand Down
Loading

0 comments on commit 4915c97

Please sign in to comment.