*** BLURB HERE ***
Chenghai Huang (3): uadk/uadk_tool - merges two similar algorithm structures uadk - modify error report information of pool management functions uadk - modify the error report and error code
Longfang Liu (1): uadk: update declaration of unsigned data types
Qi Tao (1): uadk_tool: fix zip optype configuration error
Weili Qian (1): uadk/v1: check queue status before sending doorbells
Wenkai Lin (1): uadk/sec: fix for length limit of aead stream mode
Zhiqi Song (3): uadk_tool/v1: bugfix hpre async send logic uadk/v1: cleanup put cookie operation uadk/isa_ce: cleanup header file
Makefile.am | 1 - drv/hisi_sec.c | 123 +++++----- include/wd.h | 5 +- uadk_tool/benchmark/hpre_wd_benchmark.c | 56 +++-- uadk_tool/benchmark/uadk_benchmark.c | 276 ++++++++--------------- uadk_tool/benchmark/zip_uadk_benchmark.c | 4 +- v1/drv/hisi_hpre_udrv.c | 10 +- v1/drv/hisi_qm_udrv.c | 60 +++-- v1/drv/hisi_qm_udrv.h | 4 +- v1/wd.h | 4 +- v1/wd_comp.h | 4 - v1/wd_util.c | 4 +- v1/wd_util.h | 8 +- wd_aead.c | 10 +- wd_cipher.c | 2 +- wd_comp.c | 2 +- wd_digest.c | 2 +- wd_ecc.c | 2 +- wd_rsa.c | 2 +- 19 files changed, 266 insertions(+), 313 deletions(-)
From: Chenghai Huang huangchenghai2@huawei.com
The alg options and alg name structure are duplicated and combined into one.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- uadk_tool/benchmark/uadk_benchmark.c | 276 +++++++++------------------ 1 file changed, 92 insertions(+), 184 deletions(-)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 1262a2a..1bf9fee 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -60,195 +60,103 @@ static struct acc_sva_item sys_name_item[] = { };
struct acc_alg_item { + char *type; char *name; int alg; };
static struct acc_alg_item alg_options[] = { - {"zlib", ZLIB}, - {"gzip", GZIP}, - {"deflate", DEFLATE}, - {"lz77_zstd", LZ77_ZSTD}, - {"rsa-1024", RSA_1024}, - {"rsa-2048", RSA_2048}, - {"rsa-3072", RSA_3072}, - {"rsa-4096", RSA_4096}, - {"rsa-1024-crt", RSA_1024_CRT}, - {"rsa-2048-crt", RSA_2048_CRT}, - {"rsa-3072-crt", RSA_3072_CRT}, - {"rsa-4096-crt", RSA_4096_CRT}, - {"dh-768", DH_768}, - {"dh-1024", DH_1024}, - {"dh-1536", DH_1536}, - {"dh-2048", DH_2048}, - {"dh-3072", DH_3072}, - {"dh-4096", DH_4096}, - {"ecdh-256", ECDH_256}, - {"ecdh-384", ECDH_384}, - {"ecdh-521", ECDH_521}, - {"ecdsa-256", ECDSA_256}, - {"ecdsa-384", ECDSA_384}, - {"ecdsa-521", ECDSA_521}, - {"sm2", SM2_ALG}, - {"x25519", X25519_ALG}, - {"x448", X448_ALG}, - {"aes-128-ecb", AES_128_ECB}, - {"aes-192-ecb", AES_192_ECB}, - {"aes-256-ecb", AES_256_ECB}, - {"aes-128-cbc", AES_128_CBC}, - {"aes-192-cbc", AES_192_CBC}, - {"aes-256-cbc", AES_256_CBC}, - {"aes-128-cbc-cs1", AES_128_CBC_CS1}, - {"aes-128-cbc-cs2", AES_128_CBC_CS2}, - {"aes-128-cbc-cs3", AES_128_CBC_CS3}, - {"aes-192-cbc-cs1", AES_192_CBC_CS1}, - {"aes-192-cbc-cs2", AES_192_CBC_CS2}, - {"aes-192-cbc-cs3", AES_192_CBC_CS3}, - {"aes-256-cbc-cs1", AES_256_CBC_CS1}, - {"aes-256-cbc-cs2", AES_256_CBC_CS2}, - {"aes-256-cbc-cs3", AES_256_CBC_CS3}, - {"aes-128-ctr", AES_128_CTR}, - {"aes-192-ctr", AES_192_CTR}, - {"aes-256-ctr", AES_256_CTR}, - {"aes-128-ofb", AES_128_OFB}, - {"aes-192-ofb", AES_192_OFB}, - {"aes-256-ofb", AES_256_OFB}, - {"aes-128-cfb", AES_128_CFB}, - {"aes-192-cfb", AES_192_CFB}, - {"aes-256-cfb", AES_256_CFB}, - {"aes-256-xts", AES_256_XTS}, - {"aes-512-xts", AES_512_XTS}, - {"3des-128-ecb", DES3_128_ECB}, - {"3des-192-ecb", DES3_192_ECB}, - {"3des-128-cbc", DES3_128_CBC}, - {"3des-192-cbc", DES3_192_CBC}, - {"sm4-128-ecb", SM4_128_ECB}, - {"sm4-128-cbc", SM4_128_CBC}, - {"sm4-128-cbc-cs1", SM4_128_CBC_CS1}, - {"sm4-128-cbc-cs2", SM4_128_CBC_CS2}, - {"sm4-128-cbc-cs3", SM4_128_CBC_CS3}, - {"sm4-128-ctr", SM4_128_CTR}, - {"sm4-128-ofb", SM4_128_OFB}, - {"sm4-128-cfb", SM4_128_CFB}, - {"sm4-128-xts", SM4_128_XTS}, - {"sm4-128-xts-gb", SM4_128_XTS_GB}, - {"aes-128-ccm", AES_128_CCM}, - {"aes-192-ccm", AES_192_CCM}, - {"aes-256-ccm", AES_256_CCM}, - {"aes-128-gcm", AES_128_GCM}, - {"aes-192-gcm", AES_192_GCM}, - {"aes-256-gcm", AES_256_GCM}, - {"aes-128-cbc-sha256-hmac", AES_128_CBC_SHA256_HMAC}, - {"aes-192-cbc-sha256-hmac", AES_192_CBC_SHA256_HMAC}, - {"aes-256-cbc-sha256-hmac", AES_256_CBC_SHA256_HMAC}, - {"sm4-128-ccm", SM4_128_CCM}, - {"sm4-128-gcm", SM4_128_GCM}, - {"sm3", SM3_ALG}, - {"md5", MD5_ALG}, - {"sha1", SHA1_ALG}, - {"sha256", SHA256_ALG}, - {"sha224", SHA224_ALG}, - {"sha384", SHA384_ALG}, - {"sha512", SHA512_ALG}, - {"sha512-224", SHA512_224}, - {"sha512-256", SHA512_256}, - {"trng", TRNG}, - {"", ALG_MAX} + {"zlib", "zlib", ZLIB}, + {"gzip", "gzip", GZIP}, + {"deflate", "deflate", DEFLATE}, + {"lz77_zstd", "lz77_zstd", LZ77_ZSTD}, + {"rsa", "rsa-1024", RSA_1024}, + {"rsa", "rsa-2048", RSA_2048}, + {"rsa", "rsa-3072", RSA_3072}, + {"rsa", "rsa-4096", RSA_4096}, + {"rsa", "rsa-1024-crt", RSA_1024_CRT}, + {"rsa", "rsa-2048-crt", RSA_2048_CRT}, + {"rsa", "rsa-3072-crt", RSA_3072_CRT}, + {"rsa", "rsa-4096-crt", RSA_4096_CRT}, + {"dh", "dh-768", DH_768}, + {"dh", "dh-1024", DH_1024}, + {"dh", "dh-1536", DH_1536}, + {"dh", "dh-2048", DH_2048}, + {"dh", "dh-3072", DH_3072}, + {"dh", "dh-4096", DH_4096}, + {"ecdh", "ecdh-256", ECDH_256}, + {"ecdh", "ecdh-384", ECDH_384}, + {"ecdh", "ecdh-521", ECDH_521}, + {"ecdsa", "ecdsa-256", ECDSA_256}, + {"ecdsa", "ecdsa-384", ECDSA_384}, + {"ecdsa", "ecdsa-521", ECDSA_521}, + {"sm2", "sm2", SM2_ALG}, + {"x25519", "x25519", X25519_ALG}, + {"x448", "x448", X448_ALG}, + {"ecb(aes)", "aes-128-ecb", AES_128_ECB}, + {"ecb(aes)", "aes-192-ecb", AES_192_ECB}, + {"ecb(aes)", "aes-256-ecb", AES_256_ECB}, + {"cbc(aes)", "aes-128-cbc", AES_128_CBC}, + {"cbc(aes)", "aes-192-cbc", AES_192_CBC}, + {"cbc(aes)", "aes-256-cbc", AES_256_CBC}, + {"cbc-cs1(aes)", "aes-128-cbc-cs1", AES_128_CBC_CS1}, + {"cbc-cs2(aes)", "aes-128-cbc-cs2", AES_128_CBC_CS2}, + {"cbc-cs3(aes)", "aes-128-cbc-cs3", AES_128_CBC_CS3}, + {"cbc-cs1(aes)", "aes-192-cbc-cs1", AES_192_CBC_CS1}, + {"cbc-cs2(aes)", "aes-192-cbc-cs2", AES_192_CBC_CS2}, + {"cbc-cs3(aes)", "aes-192-cbc-cs3", AES_192_CBC_CS3}, + {"cbc-cs1(aes)", "aes-256-cbc-cs1", AES_256_CBC_CS1}, + {"cbc-cs2(aes)", "aes-256-cbc-cs2", AES_256_CBC_CS2}, + {"cbc-cs3(aes)", "aes-256-cbc-cs3", AES_256_CBC_CS3}, + {"ctr(aes)", "aes-128-ctr", AES_128_CTR}, + {"ctr(aes)", "aes-192-ctr", AES_192_CTR}, + {"ctr(aes)", "aes-256-ctr", AES_256_CTR}, + {"ofb(aes)", "aes-128-ofb", AES_128_OFB}, + {"ofb(aes)", "aes-192-ofb", AES_192_OFB}, + {"ofb(aes)", "aes-256-ofb", AES_256_OFB}, + {"cfb(aes)", "aes-128-cfb", AES_128_CFB}, + {"cfb(aes)", "aes-192-cfb", AES_192_CFB}, + {"cfb(aes)", "aes-256-cfb", AES_256_CFB}, + {"xts(aes)", "aes-256-xts", AES_256_XTS}, + {"xts(aes)", "aes-512-xts", AES_512_XTS}, + {"ecb(des3_ede)", "3des-128-ecb", DES3_128_ECB}, + {"ecb(des3_ede)", "3des-192-ecb", DES3_192_ECB}, + {"cbc(des3_ede)", "3des-128-cbc", DES3_128_CBC}, + {"cbc(des3_ede)", "3des-192-cbc", DES3_192_CBC}, + {"ecb(sm4)", "sm4-128-ecb", SM4_128_ECB}, + {"cbc(sm4)", "sm4-128-cbc", SM4_128_CBC}, + {"cbc-cs1(sm4)", "sm4-128-cbc-cs1", SM4_128_CBC_CS1}, + {"cbc-cs2(sm4)", "sm4-128-cbc-cs2", SM4_128_CBC_CS2}, + {"cbc-cs3(sm4)", "sm4-128-cbc-cs3", SM4_128_CBC_CS3}, + {"ctr(sm4)", "sm4-128-ctr", SM4_128_CTR}, + {"ofb(sm4)", "sm4-128-ofb", SM4_128_OFB}, + {"cfb(sm4)", "sm4-128-cfb", SM4_128_CFB}, + {"xts(sm4)", "sm4-128-xts", SM4_128_XTS}, + {"xts(sm4)", "sm4-128-xts-gb", SM4_128_XTS_GB}, + {"ccm(aes)", "aes-128-ccm", AES_128_CCM}, + {"ccm(aes)", "aes-192-ccm", AES_192_CCM}, + {"ccm(aes)", "aes-256-ccm", AES_256_CCM}, + {"gcm(aes)", "aes-128-gcm", AES_128_GCM}, + {"gcm(aes)", "aes-192-gcm", AES_192_GCM}, + {"gcm(aes)", "aes-256-gcm", AES_256_GCM}, + {"authenc(hmac(sha256),cbc(aes))", "aes-128-cbc-sha256-hmac", AES_128_CBC_SHA256_HMAC}, + {"authenc(hmac(sha256),cbc(aes))", "aes-192-cbc-sha256-hmac", AES_192_CBC_SHA256_HMAC}, + {"authenc(hmac(sha256),cbc(aes))", "aes-256-cbc-sha256-hmac", AES_256_CBC_SHA256_HMAC}, + {"ccm(sm4)", "sm4-128-ccm", SM4_128_CCM}, + {"gcm(sm4)", "sm4-128-gcm", SM4_128_GCM}, + {"sm3", "sm3", SM3_ALG}, + {"md5", "md5", MD5_ALG}, + {"sha1", "sha1", SHA1_ALG}, + {"sha256", "sha256", SHA256_ALG}, + {"sha224", "sha224", SHA224_ALG}, + {"sha384", "sha384", SHA384_ALG}, + {"sha512", "sha512", SHA512_ALG}, + {"sha512-224", "sha512-224", SHA512_224}, + {"sha512-256", "sha512-256", SHA512_256}, + {"trng", "trng", TRNG}, + {"", "", ALG_MAX} };
-static struct acc_alg_item alg_name_options[] = { - {"zlib", ZLIB}, - {"gzip", GZIP}, - {"deflate", DEFLATE}, - {"lz77_zstd", LZ77_ZSTD}, - {"rsa", RSA_1024}, - {"rsa", RSA_2048}, - {"rsa", RSA_3072}, - {"rsa", RSA_4096}, - {"rsa", RSA_1024_CRT}, - {"rsa", RSA_2048_CRT}, - {"rsa", RSA_3072_CRT}, - {"rsa", RSA_4096_CRT}, - {"dh", DH_768}, - {"dh", DH_1024}, - {"dh", DH_1536}, - {"dh", DH_2048}, - {"dh", DH_3072}, - {"dh", DH_4096}, - {"ecdh", ECDH_256}, - {"ecdh", ECDH_384}, - {"ecdh", ECDH_521}, - {"ecdsa", ECDSA_256}, - {"ecdsa", ECDSA_384}, - {"ecdsa", ECDSA_521}, - {"sm2", SM2_ALG}, - {"x25519", X25519_ALG}, - {"x448", X448_ALG}, - {"ecb(aes)", AES_128_ECB}, - {"ecb(aes)", AES_192_ECB}, - {"ecb(aes)", AES_256_ECB}, - {"cbc(aes)", AES_128_CBC}, - {"cbc(aes)", AES_192_CBC}, - {"cbc(aes)", AES_256_CBC}, - {"cbc-cs1(aes)", AES_128_CBC_CS1}, - {"cbc-cs2(aes)", AES_128_CBC_CS2}, - {"cbc-cs3(aes)", AES_128_CBC_CS3}, - {"cbc-cs1(aes)", AES_192_CBC_CS1}, - {"cbc-cs2(aes)", AES_192_CBC_CS2}, - {"cbc-cs3(aes)", AES_192_CBC_CS3}, - {"cbc-cs1(aes)", AES_256_CBC_CS1}, - {"cbc-cs2(aes)", AES_256_CBC_CS2}, - {"cbc-cs3(aes)", AES_256_CBC_CS3}, - {"ctr(aes)", AES_128_CTR}, - {"ctr(aes)", AES_192_CTR}, - {"ctr(aes)", AES_256_CTR}, - {"ofb(aes)", AES_128_OFB}, - {"ofb(aes)", AES_192_OFB}, - {"ofb(aes)", AES_256_OFB}, - {"cfb(aes)", AES_128_CFB}, - {"cfb(aes)", AES_192_CFB}, - {"cfb(aes)", AES_256_CFB}, - {"xts(aes)", AES_256_XTS}, - {"xts(aes)", AES_512_XTS}, - {"ecb(des3_ede)", DES3_128_ECB}, - {"ecb(des3_ede)", DES3_192_ECB}, - {"cbc(des3_ede)", DES3_128_CBC}, - {"cbc(des3_ede)", DES3_192_CBC}, - {"ecb(sm4)", SM4_128_ECB}, - {"cbc(sm4)", SM4_128_CBC}, - {"cbc-cs1(sm4)", SM4_128_CBC_CS1}, - {"cbc-cs2(sm4)", SM4_128_CBC_CS2}, - {"cbc-cs3(sm4)", SM4_128_CBC_CS3}, - {"ctr(sm4)", SM4_128_CTR}, - {"ofb(sm4)", SM4_128_OFB}, - {"cfb(sm4)", SM4_128_CFB}, - {"xts(sm4)", SM4_128_XTS}, - {"xts(sm4)", SM4_128_XTS_GB}, - {"ccm(aes)", AES_128_CCM}, - {"ccm(aes)", AES_192_CCM}, - {"ccm(aes)", AES_256_CCM}, - {"gcm(aes)", AES_128_GCM}, - {"gcm(aes)", AES_192_GCM}, - {"gcm(aes)", AES_256_GCM}, - {"authenc(hmac(sha256),cbc(aes))", AES_128_CBC_SHA256_HMAC}, - {"authenc(hmac(sha256),cbc(aes))", AES_192_CBC_SHA256_HMAC}, - {"authenc(hmac(sha256),cbc(aes))", AES_256_CBC_SHA256_HMAC}, - {"ccm(sm4)", SM4_128_CCM}, - {"gcm(sm4)", SM4_128_GCM}, - {"sm3", SM3_ALG}, - {"md5", MD5_ALG}, - {"sha1", SHA1_ALG}, - {"sha256", SHA256_ALG}, - {"sha224", SHA224_ALG}, - {"sha384", SHA384_ALG}, - {"sha512", SHA512_ALG}, - {"sha512-224", SHA512_224}, - {"sha512-256", SHA512_256}, - {"trng", TRNG}, - {"", ALG_MAX} -}; - - /*-------------------------------------tool code------------------------------------------------------*/ void add_send_complete(void) { @@ -311,8 +219,8 @@ int get_alg_name(int alg, char *alg_name) int i;
for (i = 0; i < ALG_MAX; i++) { - if (alg == alg_name_options[i].alg) { - strcpy(alg_name, alg_name_options[i].name); + if (alg == alg_options[i].alg) { + strcpy(alg_name, alg_options[i].type); return 0; } }
In zip device, different operation types are corresponding to different algorithm cores. So, we need to specify the operation type of the ctx requested from zip device.
Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/benchmark/zip_uadk_benchmark.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index e2876a9..ecb688f 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -372,7 +372,7 @@ static int specified_device_request_ctx(struct acc_option *options) ret = -ENOMEM; goto free_ctx; } - g_ctx_cfg.ctxs[i].op_type = 0; + g_ctx_cfg.ctxs[i].op_type = options->optype % WD_DIR_MAX; g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; }
@@ -414,7 +414,7 @@ static int non_specified_device_request_ctx(struct acc_option *options) if (!g_ctx_cfg.ctxs[i].ctx) break;
- g_ctx_cfg.ctxs[i].op_type = 0; + g_ctx_cfg.ctxs[i].op_type = options->optype % WD_DIR_MAX; g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; }
From: Zhiqi Song songzhiqi1@huawei.com
As the async send thread will free ctx resources when the sending is complete. If the async poll thread is still recv the msg from hardware when the async send thread ends, the error address will be accessed.
Fix wait logic, make async send thread wait until the async poll thread has finished.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/benchmark/hpre_wd_benchmark.c | 56 +++++++++++++++---------- 1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c index 6dc1269..5545ad8 100644 --- a/uadk_tool/benchmark/hpre_wd_benchmark.c +++ b/uadk_tool/benchmark/hpre_wd_benchmark.c @@ -18,6 +18,7 @@ #define SM2_DG_SZ 1024 #define SEND_USLEEP 100 #define ALIGN_SIZE 128 +#define WAIT_POLL_USLEEP 1000
static char rsa_m[8] = {0x54, 0x85, 0x9b, 0x34, 0x2c, 0x49, 0xea, 0x2a};
@@ -115,6 +116,28 @@ static const char* const alg_operations[] = { "GenKey", "ShareKey", "Encrypt", "Decrypt", "Sign", "Verify", };
+static void hpre_wait_recv_complete(void) +{ + int i = 0; + + while (get_run_state() != 0) { + if (i++ >= MAX_TRY_CNT) { + HPRE_TST_PRT("failed to get run state!\n"); + break; + } + usleep(WAIT_POLL_USLEEP); + } + + i = 0; + while (get_recv_time() != g_thread_num) { + if (i++ >= MAX_TRY_CNT) { + HPRE_TST_PRT("failed to wait poll thread finish!\n"); + break; + } + usleep(WAIT_POLL_USLEEP); + } +} + static void get_rsa_param(u32 algtype, u32 *keysize, u32 *mode) { switch(algtype) { @@ -543,7 +566,6 @@ void *hpre_wd_poll(void *data) } count += recv; recv = 0; - if (get_run_state() == 0) last_time--; } @@ -1037,6 +1059,9 @@ static void *rsa_wd_async_run(void *arg) count++; } while(true);
+ /* Wait async mode finish recv */ + hpre_wait_recv_complete(); + /* clean output buffer remainings in the last time operation */ if (opdata.op_type == WCRYPTO_RSA_GENKEY) { char *data; @@ -1067,12 +1092,6 @@ sample_release: free(rsa_key_in); key_release: free(key_info); - - while (1) { - if (get_recv_time() > 0) // wait Async mode finish recv - break; - usleep(SEND_USLEEP); - } wcrypto_del_rsa_ctx(ctx);
add_send_complete(); @@ -1396,6 +1415,9 @@ static void *dh_wd_async_run(void *arg) count++; } while(true);
+ /* Wait async mode finish recv */ + hpre_wait_recv_complete(); + tag_release: free(tag); param_release: @@ -1403,12 +1425,6 @@ param_release: wd_free_blk(pool, opdata.pv); wd_free_blk(pool, opdata.pri); ctx_release: - while (1) { - if (get_recv_time() > 0) // wait Async mode finish recv - break; - usleep(SEND_USLEEP); - } - wcrypto_del_dh_ctx(ctx); add_send_complete();
@@ -1450,7 +1466,7 @@ static int get_ecc_curve(struct hpre_ecc_setup *setup, u32 cid) return 0; }
-static int get_ecc_key_param(struct wcrypto_ecc_curve *param, u32 key_bits) +static int get_ecc_key_param(struct wcrypto_ecc_curve *param, u32 key_bits) { u32 key_size = (key_bits + 7) / 8;
@@ -1568,7 +1584,8 @@ static int get_ecc_param_from_sample(struct hpre_ecc_setup *setup, return -1; memset(setup->msg, 0xFF, len);
- if (true) { // for msg_sigest mode + /* for msg_digest mode */ + if (true) { memcpy(setup->msg, sm2_digest, sizeof(sm2_digest)); setup->msg_size = sizeof(sm2_digest); } else { @@ -2380,6 +2397,9 @@ static void *ecc_wd_async_run(void *arg) count++; } while(true);
+ /* Wait async mode finish recv */ + hpre_wait_recv_complete(); + tag_release: free(tag); src_release: @@ -2388,12 +2408,6 @@ src_release: if (opdata.out) (void)wcrypto_del_ecc_out(ctx, opdata.out); sess_release: - while (1) { - if (get_recv_time() > 0) // wait Async mode finish recv - break; - usleep(SEND_USLEEP); - } - wcrypto_del_ecc_ctx(ctx); msg_release: if (subtype == SM2_TYPE)
From: Chenghai Huang huangchenghai2@huawei.com
The wd_find_msg_in_pool function and the wd_get_msg_from_pool function report the same error information, which affects code search during fault locating.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- wd_aead.c | 2 +- wd_cipher.c | 2 +- wd_comp.c | 2 +- wd_digest.c | 2 +- wd_ecc.c | 2 +- wd_rsa.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/wd_aead.c b/wd_aead.c index 0e59768..c0a7cfc 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -873,7 +873,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_aead_setting.pool, idx, resp_msg.tag); if (!msg) { - WD_ERR("failed to get msg from pool!\n"); + WD_ERR("failed to find msg from pool!\n"); return -WD_EINVAL; }
diff --git a/wd_cipher.c b/wd_cipher.c index f34a47e..4799213 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -808,7 +808,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_cipher_setting.pool, idx, resp_msg.tag); if (!msg) { - WD_ERR("failed to get msg from pool!\n"); + WD_ERR("failed to find msg from pool!\n"); return -WD_EINVAL; }
diff --git a/wd_comp.c b/wd_comp.c index 459223e..34ddbcf 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -389,7 +389,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_comp_setting.pool, idx, resp_msg.tag); if (unlikely(!msg)) { - WD_ERR("failed to get msg from pool!\n"); + WD_ERR("failed to find msg from pool!\n"); return -WD_EINVAL; }
diff --git a/wd_digest.c b/wd_digest.c index 2e9734d..f116aec 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -769,7 +769,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_digest_setting.pool, idx, recv_msg.tag); if (!msg) { - WD_ERR("failed to get msg from pool!\n"); + WD_ERR("failed to find msg from pool!\n"); return -WD_EINVAL; }
diff --git a/wd_ecc.c b/wd_ecc.c index ec5e7ad..7c0c77a 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -2339,7 +2339,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_ecc_setting.pool, idx, recv_msg.tag); if (!msg) { - WD_ERR("failed to get msg from pool!\n"); + WD_ERR("failed to find msg from pool!\n"); return -WD_EINVAL; }
diff --git a/wd_rsa.c b/wd_rsa.c index c3709de..b858491 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -553,7 +553,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_rsa_setting.pool, idx, recv_msg.tag); if (!msg) { - WD_ERR("failed to get msg from pool!\n"); + WD_ERR("failed to find msg from pool!\n"); return -WD_EINVAL; }
From: Chenghai Huang huangchenghai2@huawei.com
The meaning of the sess parameter of the AEAD in the inspection report is incorrect.
The EACCES error code is misspelled.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- include/wd.h | 2 +- wd_aead.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/wd.h b/include/wd.h index 80982b0..bcf3aa7 100644 --- a/include/wd.h +++ b/include/wd.h @@ -83,7 +83,7 @@ typedef void (*wd_log)(const char *format, ...); #define WD_EIO EIO #define WD_EAGAIN EAGAIN #define WD_ENOMEM ENOMEM -#define WD_EACCESS EACCESS +#define WD_EACCES EACCES #define WD_EBUSY EBUSY #define WD_EEXIST EEXIST #define WD_ENODEV ENODEV diff --git a/wd_aead.c b/wd_aead.c index c0a7cfc..9c3f1ab 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -243,7 +243,7 @@ int wd_aead_set_authsize(handle_t h_sess, __u16 authsize) struct wd_aead_sess *sess = (struct wd_aead_sess *)h_sess;
if (!sess) { - WD_ERR("failed to check session parameter!\n"); + WD_ERR("invalid: aead input sess is NULL!\n"); return -WD_EINVAL; }
@@ -282,7 +282,7 @@ int wd_aead_get_authsize(handle_t h_sess) struct wd_aead_sess *sess = (struct wd_aead_sess *)h_sess;
if (!sess) { - WD_ERR("failed to check session parameter!\n"); + WD_ERR("invalid: aead input sess is NULL!\n"); return -WD_EINVAL; }
@@ -294,7 +294,7 @@ int wd_aead_get_maxauthsize(handle_t h_sess) struct wd_aead_sess *sess = (struct wd_aead_sess *)h_sess;
if (!sess || sess->dalg >= WD_DIGEST_TYPE_MAX) { - WD_ERR("failed to check session parameter!\n"); + WD_ERR("invalid: aead input sess is NULL or invalid alg type!\n"); return -WD_EINVAL; }
@@ -359,7 +359,7 @@ void wd_aead_free_sess(handle_t h_sess) struct wd_aead_sess *sess = (struct wd_aead_sess *)h_sess;
if (unlikely(!sess)) { - WD_ERR("failed to check session parameter!\n"); + WD_ERR("invalid: aead input sess is NULL!\n"); return; }
From: Zhiqi Song songzhiqi1@huawei.com
Add value type conversion for idx calculation in put_cookie() operation. And modify error log to make information clearer.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- v1/wd_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/v1/wd_util.c b/v1/wd_util.c index 35201f5..d441805 100644 --- a/v1/wd_util.c +++ b/v1/wd_util.c @@ -75,7 +75,7 @@ int wd_alloc_id(__u8 *buf, __u32 size, __u32 *id, __u32 last_id, __u32 id_max) void wd_free_id(__u8 *buf, __u32 size, __u32 id, __u32 id_max) { if (unlikely(id >= id_max)) { - WD_ERR("id error, id = %u!\n", id); + WD_ERR("id error, id(%u) >= id_max(%u)!\n", id, id_max); return; }
@@ -111,7 +111,7 @@ void wd_uninit_cookie_pool(struct wd_cookie_pool *pool)
static void put_cookie(struct wd_cookie_pool *pool, const void *cookie) { - __u32 idx = ((uintptr_t)cookie - (uintptr_t)pool->cookies) / + __u32 idx = (__u32)((uintptr_t)cookie - (uintptr_t)pool->cookies) / pool->cookies_size;
wd_free_id(pool->cstatus, pool->cookies_num, idx, pool->cookies_num);
From: Weili Qian qianweili@huawei.com
When the device needs to be reset, the queue status is set to disable before resetting. The user process checks the queue status before sending the doorbell. If the queue is disable, the user process returns failure.
Currently, the task execution order in user mode is as follows: 1. check the queue status. 2. fill in or parse the BD. 3. send the doorbell to the hardware.
To reduce the possibility of sending doorbells during reset, the task execution order is modified as follows: 1. fill in or parse the BD. 2. check the queue status. 3. send the doorbell to the hardware.
In addition, a rmb() is added before the doorbell is sent to ensure that the queue status check is complete.
rmb() and wmb() can be replaced by mb() in hisi_qm_send(). Therefore, the barrier on the wd_reg_read() and wd_reg_write() can be deleted.
Signed-off-by: Weili Qian qianweili@huawei.com --- v1/drv/hisi_hpre_udrv.c | 10 ++++--- v1/drv/hisi_qm_udrv.c | 60 +++++++++++++++++++++++++---------------- v1/drv/hisi_qm_udrv.h | 4 +-- v1/wd_util.h | 8 +----- 4 files changed, 46 insertions(+), 36 deletions(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c index 0b2bdd5..84ec710 100644 --- a/v1/drv/hisi_hpre_udrv.c +++ b/v1/drv/hisi_hpre_udrv.c @@ -1938,10 +1938,10 @@ static int fill_sm2_enc_sqe(void *msg, struct qm_queue_info *info, __u16 idx) goto fail_fill_sqe; }
- /* make sure the request is all in memory before doorbell */ - mb(); info->sq_tail_index = i; - qm_tx_update(info, 1); + ret = qm_tx_update(info, 1); + if (unlikely(ret)) + goto fail_fill_sqe;
return ret;
@@ -2091,7 +2091,9 @@ static int parse_first_sqe(void *hw_msg, struct qm_queue_info *info, __u16 idx, WD_ERR("first BD error = %u\n", msg->result);
info->cq_head_index = i; - qm_rx_update(info, 1); + ret = qm_rx_update(info, 1); + if (unlikely(ret)) + return ret;
return 1; } diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c index ea4b199..175a5c4 100644 --- a/v1/drv/hisi_qm_udrv.c +++ b/v1/drv/hisi_qm_udrv.c @@ -582,10 +582,20 @@ void qm_uninit_queue(struct wd_queue *q) qinfo->priv = NULL; }
-void qm_tx_update(struct qm_queue_info *info, __u32 num) +int qm_tx_update(struct qm_queue_info *info, __u32 num) { + if (unlikely(wd_reg_read(info->ds_tx_base) == 1)) { + WD_ERR("wd queue hw error happened before qm send!\n"); + return -WD_HW_EACCESS; + } + + /* make sure the request is all in memory before doorbell */ + mb(); + info->db(info, DOORBELL_CMD_SQ, info->sq_tail_index, 0); __atomic_add_fetch(&info->used, num, __ATOMIC_RELAXED); + + return WD_SUCCESS; }
int qm_send(struct wd_queue *q, void **req, __u32 num) @@ -595,11 +605,6 @@ int qm_send(struct wd_queue *q, void **req, __u32 num) int ret; __u32 i;
- if (unlikely(wd_reg_read(info->ds_tx_base) == 1)) { - WD_ERR("wd queue hw error happened before qm send!\n"); - return -WD_HW_EACCESS; - } - wd_spinlock(&info->sd_lock); if (unlikely((__u32)__atomic_load_n(&info->used, __ATOMIC_RELAXED) > info->sq_depth - num - 1)) { @@ -623,19 +628,10 @@ int qm_send(struct wd_queue *q, void **req, __u32 num) info->sq_tail_index++; }
- /* make sure the request is all in memory before doorbell */ - mb(); - qm_tx_update(info, num); + ret = qm_tx_update(info, num); wd_unspinlock(&info->sd_lock);
- return WD_SUCCESS; -} - -void qm_rx_update(struct qm_queue_info *info, __u32 num) -{ - /* set c_flag to enable interrupt when use poll */ - info->db(info, DOORBELL_CMD_CQ, info->cq_head_index, info->is_poll); - __atomic_sub_fetch(&info->used, num, __ATOMIC_RELAXED); + return ret; }
void qm_rx_from_cache(struct qm_queue_info *info, void **resp, __u32 num) @@ -677,6 +673,24 @@ static int check_ds_rx_base(struct qm_queue_info *info, return -WD_HW_EACCESS; }
+int qm_rx_update(struct qm_queue_info *info, __u32 num) +{ + int ret; + + ret = check_ds_rx_base(info, NULL, 0, 0); + if (unlikely(ret)) + return ret; + + /* make sure queue status check is complete. */ + rmb(); + + /* set c_flag to enable interrupt when use poll */ + info->db(info, DOORBELL_CMD_CQ, info->cq_head_index, info->is_poll); + __atomic_sub_fetch(&info->used, num, __ATOMIC_RELAXED); + + return WD_SUCCESS; +} + int qm_recv(struct wd_queue *q, void **resp, __u32 num) { struct q_info *qinfo = q->qinfo; @@ -727,15 +741,15 @@ int qm_recv(struct wd_queue *q, void **resp, __u32 num) } }
- if (i) - qm_rx_update(info, i); + if (i) { + ret = qm_rx_update(info, i); + if (!ret) + ret = i; + }
wd_unspinlock(&info->rc_lock); - ret = check_ds_rx_base(info, resp, num, 0); - if (unlikely(ret)) - return ret;
- return i; + return ret; }
static int hw_type_check(struct wd_queue *q, const char *hw_type) diff --git a/v1/drv/hisi_qm_udrv.h b/v1/drv/hisi_qm_udrv.h index 542d20d..4d54cf6 100644 --- a/v1/drv/hisi_qm_udrv.h +++ b/v1/drv/hisi_qm_udrv.h @@ -191,8 +191,8 @@ int qm_init_hwsgl_mem(struct wd_queue *q, void *pool, struct wd_sgl *sgl); int qm_uninit_hwsgl_mem(struct wd_queue *q, void *pool, struct wd_sgl *sgl); int qm_merge_hwsgl(struct wd_queue *q, void *pool, struct wd_sgl *dst_sgl, struct wd_sgl *src_sgl); -void qm_tx_update(struct qm_queue_info *info, __u32 num); -void qm_rx_update(struct qm_queue_info *info, __u32 num); +int qm_tx_update(struct qm_queue_info *info, __u32 num); +int qm_rx_update(struct qm_queue_info *info, __u32 num); void qm_rx_from_cache(struct qm_queue_info *info, void **resp, __u32 num);
#define HISI_QM_API_VER_BASE "hisi_qm_v1" diff --git a/v1/wd_util.h b/v1/wd_util.h index 9180fc1..21137d2 100644 --- a/v1/wd_util.h +++ b/v1/wd_util.h @@ -383,17 +383,11 @@ struct wcrypto_ecc_out { static inline void wd_reg_write(void *reg_addr, uint32_t value) { *((uint32_t *)reg_addr) = value; - wmb(); /* load fence */ }
static inline uint32_t wd_reg_read(void *reg_addr) { - uint32_t temp; - - temp = *((uint32_t *)reg_addr); - rmb(); /* load fence */ - - return temp; + return *((uint32_t *)reg_addr); }
void wd_spinlock(struct wd_lock *lock);
From: Longfang Liu liulongfang@huawei.com
In order to ensure that all applications using the uadk interface can use the corresponding unsigned data type normally. Their declarations need to be placed in the public header file.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- include/wd.h | 3 +++ v1/wd.h | 4 +++- v1/wd_comp.h | 4 ---- 3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/wd.h b/include/wd.h index bcf3aa7..21e5e06 100644 --- a/include/wd.h +++ b/include/wd.h @@ -32,6 +32,9 @@ extern "C" { #define WD_IPC_KEY 0x500011 #define CRYPTO_MAX_ALG_NAME 128
+typedef unsigned char __u8; +typedef unsigned int __u32; +typedef unsigned long long __u64; /* Required compiler attributes */ #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) diff --git a/v1/wd.h b/v1/wd.h index 0a32182..4618a8c 100644 --- a/v1/wd.h +++ b/v1/wd.h @@ -61,8 +61,10 @@ extern "C" { #define WD_IN_EPARA 67 #define WD_ENOPROC 68
+typedef unsigned char __u8; +typedef unsigned int __u32; +typedef unsigned long long __u64; typedef void (*wcrypto_cb)(const void *msg, void *tag); - typedef void (*wd_log)(const char *format, ...);
struct wcrypto_cb_tag { diff --git a/v1/wd_comp.h b/v1/wd_comp.h index 580b968..4c84ea3 100644 --- a/v1/wd_comp.h +++ b/v1/wd_comp.h @@ -25,10 +25,6 @@ extern "C" { #endif
-typedef unsigned char __u8; -typedef unsigned int __u32; -typedef unsigned long long __u64; - #define ZIP_LOG(format, args...) fprintf(stderr, format, ##args)
#define MAX_CTX_RSV_SIZE 65536
From: Zhiqi Song songzhiqi1@huawei.com
Cleanup redundant header file in compile file.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- Makefile.am | 1 - 1 file changed, 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am index 1049639..46cf933 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,7 +77,6 @@ libwd_crypto_la_SOURCES=wd_cipher.c wd_cipher.h wd_cipher_drv.h \ wd_rsa.c wd_rsa.h wd_rsa_drv.h \ wd_dh.c wd_dh.h wd_dh_drv.h \ wd_ecc.c wd_ecc.h wd_ecc_drv.h \ - arm_arch_ce.h isa_ce_sm3.h isa_ce_sm4.h \ wd_digest.c wd_digest.h wd_digest_drv.h \ wd_util.c wd_util.h \ wd_sched.c wd_sched.h \
From: Wenkai Lin linwenkai6@hisilicon.com
Due to the hardware limitation, the correct mac cannot be obtained if the total data length exceeds 16 MB. The total data length is used to calculate the mac at the final stage, therefore, only the final message needs to be processed by software.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_sec.c | 123 +++++++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 51 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index aba4185..d9bb7e4 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -72,6 +72,7 @@ #define GCM_FULL_MAC_LEN 16 #define GCM_AUTH_MAC_OFFSET 47 #define GCM_BLOCK_SIZE AES_BLOCK_SIZE +#define GCM_BLOCK_OFFSET (AES_BLOCK_SIZE - 1) #define AKEY_LEN(c_key_len) (2 * (c_key_len) + 0x4) #define MAC_LEN 4 #define LONG_AUTH_DATA_OFFSET 24 @@ -2340,33 +2341,17 @@ static void fill_gcm_middle_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sq sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->ckey; }
-static void fill_gcm_final_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe) -{ - sqe->ai_apd_cs = AI_GEN_IVIN_ADDR; - sqe->ai_apd_cs |= AUTHPAD_PAD << AUTHPAD_OFFSET; - sqe->type_auth_cipher |= NO_AUTH << AUTHTYPE_OFFSET; - sqe->type2.cipher_src_offset = 0; - sqe->type2.auth_src_offset = 0; - fill_gcm_akey_len(msg, sqe, BD_TYPE2); - sqe->type2.alen_ivllen = 0; - sqe->type2.long_a_data_len = msg->assoc_bytes; - sqe->type2.long_a_data_len |= msg->long_data_len << LONG_AUTH_DATA_OFFSET; - sqe->type2.c_ivin_addr = (__u64)(uintptr_t)msg->iv; - sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->ckey; - sqe->type2.a_ivin_addr = (__u64)(uintptr_t)msg->aiv_stream; -} - static void get_galois_vector_s(struct wd_aead_msg *msg, __u8 *s) { - unsigned int aad_len, cipher_len; __u8 a_c[GCM_BLOCK_SIZE] = {0}; + __u64 cipher_len, aad_len; __u32 i;
aad_len = msg->assoc_bytes * BYTE_BITS; - memcpy(&a_c[BYTE_BITS], &aad_len, sizeof(unsigned int)); + memcpy(&a_c[BYTE_BITS], &aad_len, sizeof(__u64));
cipher_len = msg->long_data_len * BYTE_BITS; - memcpy(&a_c[0], &cipher_len, sizeof(unsigned int)); + memcpy(&a_c[0], &cipher_len, sizeof(__u64));
/* Based the little-endian operation */ for (i = 0; i < GCM_BLOCK_SIZE; i++) @@ -2378,12 +2363,44 @@ static int gcm_do_soft_mac(struct wd_aead_msg *msg) __u8 ctr_r[GCM_BLOCK_SIZE] = {0}; __u8 data[GCM_BLOCK_SIZE] = {0}; __u8 H[GCM_BLOCK_SIZE] = {0}; + __u8 K[GCM_BLOCK_SIZE] = {0}; __u8 S[GCM_BLOCK_SIZE] = {0}; __u8 g[GCM_BLOCK_SIZE] = {0}; - int i, ret; + __u8 G[GCM_BLOCK_SIZE] = {0}; + __u32 i, len, block, offset; + __u8 *out; + int ret;
aes_encrypt(msg->ckey, msg->ckey_bytes, data, H);
+ len = msg->in_bytes; + offset = 0; + while (len) { + memset(data, 0, GCM_BLOCK_SIZE); + block = len >= GCM_BLOCK_SIZE ? GCM_BLOCK_SIZE : len; + memcpy(data, msg->in + offset, block); + ctr_iv_inc(msg->iv, GCM_BLOCK_SIZE >> CTR_MODE_LEN_SHIFT); + aes_encrypt(msg->ckey, msg->ckey_bytes, msg->iv, K); + out = msg->out + offset; + for (i = 0; i < block; i++) + out[i] = K[i] ^ data[i]; + + if (msg->op_type == WD_CIPHER_ENCRYPTION_DIGEST) + memcpy(data, out, block); + + /* + * Mac and data is based on big-endian, the first argument of galois_compute + * must be converted to little-endian. + */ + for (i = 0; i < GCM_BLOCK_SIZE; i++) + G[i] = data[GCM_BLOCK_OFFSET - i] ^ + msg->aiv_stream[(__u8)(GCM_AUTH_MAC_OFFSET - i)]; + + galois_compute(G, H, msg->aiv_stream + GCM_STREAM_MAC_OFFSET, GCM_BLOCK_SIZE); + len -= block; + offset += block; + } + get_galois_vector_s(msg, S);
galois_compute(S, H, g, GCM_BLOCK_SIZE); @@ -2406,7 +2423,7 @@ static int gcm_do_soft_mac(struct wd_aead_msg *msg)
msg->result = WD_SUCCESS;
- return 0; + return WD_SOFT_COMPUTING; }
static int fill_stream_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe) @@ -2415,19 +2432,17 @@ static int fill_stream_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe)
switch (msg->msg_state) { case AEAD_MSG_FIRST: - fill_gcm_first_bd2(msg, sqe); + if (msg->cmode == WD_CIPHER_GCM) + fill_gcm_first_bd2(msg, sqe); break; case AEAD_MSG_MIDDLE: - fill_gcm_middle_bd2(msg, sqe); + if (msg->cmode == WD_CIPHER_GCM) + fill_gcm_middle_bd2(msg, sqe); break; case AEAD_MSG_END: - gcm_auth_ivin(msg); - if (msg->in_bytes) { - fill_gcm_final_bd2(msg, sqe); - } else { + if (msg->cmode == WD_CIPHER_GCM) { + gcm_auth_ivin(msg); ret = gcm_do_soft_mac(msg); - if (!ret) - ret = WD_SOFT_COMPUTING; } break; default: @@ -2565,15 +2580,16 @@ static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_
static void update_stream_counter(struct wd_aead_msg *recv_msg) { - /* - * The counter of the first middle BD is set to 1. - * Other middle BDs and tail BD are set based on - * cipher_len and the counter of the previous BD. - */ - if (recv_msg->msg_state == AEAD_MSG_FIRST) { - recv_msg->iv[MAX_IV_SIZE - 1] = 0x1; - } else if (recv_msg->msg_state == AEAD_MSG_MIDDLE) { - ctr_iv_inc(recv_msg->iv, recv_msg->in_bytes >> CTR_MODE_LEN_SHIFT); + if (recv_msg->cmode == WD_CIPHER_GCM) { + /* + * The counter of the first middle BD is set to 1. + * Other middle BDs and tail BD are set based on + * cipher_len and the counter of the previous BD. + */ + if (recv_msg->msg_state == AEAD_MSG_FIRST) + recv_msg->iv[MAX_IV_SIZE - 1] = 0x1; + else if (recv_msg->msg_state == AEAD_MSG_MIDDLE) + ctr_iv_inc(recv_msg->iv, recv_msg->in_bytes >> CTR_MODE_LEN_SHIFT); } }
@@ -2622,8 +2638,10 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, static bool soft_compute_check(struct hisi_qp *qp, struct wd_aead_msg *msg) { /* Asynchronous mode does not use the sent message, so ignores it */ - return (msg->msg_state == AEAD_MSG_END) && !msg->in_bytes && - qp->q_info.qp_mode == CTX_MODE_SYNC; + if (msg->cmode == WD_CIPHER_GCM) + return (msg->msg_state == AEAD_MSG_END) && qp->q_info.qp_mode == CTX_MODE_SYNC; + + return false; }
static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) @@ -2814,25 +2832,28 @@ static void fill_gcm_final_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sq sqe->auth_ivin.a_ivin_addr = (__u64)(uintptr_t)msg->aiv_stream; }
-static int fill_stream_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe) +static int fill_stream_bd3(handle_t h_qp, struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe) { + struct hisi_qp *qp = (struct hisi_qp *)h_qp; int ret = 0;
switch (msg->msg_state) { case AEAD_MSG_FIRST: - fill_gcm_first_bd3(msg, sqe); + if (msg->cmode == WD_CIPHER_GCM) + fill_gcm_first_bd3(msg, sqe); break; case AEAD_MSG_MIDDLE: - fill_gcm_middle_bd3(msg, sqe); + if (msg->cmode == WD_CIPHER_GCM) + fill_gcm_middle_bd3(msg, sqe); break; case AEAD_MSG_END: - gcm_auth_ivin(msg); - if (msg->in_bytes) { - fill_gcm_final_bd3(msg, sqe); - } else { - ret = gcm_do_soft_mac(msg); - if (!ret) - ret = WD_SOFT_COMPUTING; + if (msg->cmode == WD_CIPHER_GCM) { + gcm_auth_ivin(msg); + /* Due to hardware limitations, software compute is required. */ + if (qp->q_info.hw_type <= HISI_QM_API_VER3_BASE || !msg->in_bytes) + ret = gcm_do_soft_mac(msg); + else + fill_gcm_final_bd3(msg, sqe); } break; default: @@ -2924,7 +2945,7 @@ static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void * }
fill_aead_bd3_addr(msg, &sqe); - ret = fill_stream_bd3(msg, &sqe); + ret = fill_stream_bd3(h_qp, msg, &sqe); if (ret == WD_SOFT_COMPUTING) return 0; else if (unlikely(ret))