From 92364a0a3a38a02d64cca10d3153e94ee01c3969 Mon Sep 17 00:00:00 2001 From: Kai Ye Date: Tue, 25 Jan 2022 14:33:48 +0800 Subject: [PATCH 52/53] hisi-sec: add some dfx information in comments Add some dfx information in comments to improves locating efficiency. Signed-off-by: Kai Ye --- drv/hisi_sec.c | 86 ++++++++++++++++++++++++++++++-------------------- wd_aead.c | 39 ++++++++++++++--------- wd_cipher.c | 21 +++++++----- wd_digest.c | 12 ++++--- 4 files changed, 97 insertions(+), 61 deletions(-) diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index f5db7eb..14656c8 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -576,7 +576,7 @@ static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len) } else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) { *c_key_len = CKEY_LEN_3DES_3KEY; } else { - WD_ERR("invalid 3des key size!\n"); + WD_ERR("invalid 3des key size, size = %u\n", msg->key_bytes); return -WD_EINVAL; } @@ -602,7 +602,7 @@ static int get_aes_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len) *c_key_len = CKEY_LEN_256BIT; break; default: - WD_ERR("invalid AES key size!\n"); + WD_ERR("invalid AES key size, size = %u\n", len); return -WD_EINVAL; } @@ -634,7 +634,7 @@ static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg, struct hisi_sec_sqe *s sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET; break; default: - WD_ERR("invalid cipher type!\n"); + WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg); return -WD_EINVAL; } @@ -660,7 +660,7 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe * c_mode = C_MODE_XTS; break; default: - WD_ERR("invalid cipher mode type!\n"); + WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode); return -WD_EINVAL; } sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET; @@ -719,7 +719,8 @@ static int cipher_len_check(struct wd_cipher_msg *msg) { if (msg->in_bytes > MAX_INPUT_DATA_LEN || !msg->in_bytes) { - WD_ERR("input cipher length is error!\n"); + WD_ERR("input cipher length is error, size = %u\n", + msg->in_bytes); return -WD_EINVAL; } @@ -730,7 +731,8 @@ static int cipher_len_check(struct wd_cipher_msg *msg) if (msg->mode == WD_CIPHER_XTS) { if (msg->in_bytes < AES_BLOCK_SIZE) { - WD_ERR("input cipher length is too small!\n"); + WD_ERR("input cipher length is too small, size = %u\n", + msg->in_bytes); return -WD_EINVAL; } return 0; @@ -738,13 +740,15 @@ static int cipher_len_check(struct wd_cipher_msg *msg) if (msg->alg == WD_CIPHER_3DES || msg->alg == WD_CIPHER_DES) { if (msg->in_bytes & (DES3_BLOCK_SIZE - 1)) { - WD_ERR("input 3DES or DES cipher parameter is error!\n"); + WD_ERR("input 3DES or DES cipher parameter is error, size = %u\n", + msg->in_bytes); return -WD_EINVAL; } return 0; } else if (msg->alg == WD_CIPHER_AES || msg->alg == WD_CIPHER_SM4) { if (msg->in_bytes & (AES_BLOCK_SIZE - 1)) { - WD_ERR("input AES or SM4 cipher parameter is error!\n"); + WD_ERR("input AES or SM4 cipher parameter is error, size = %u\n", + msg->in_bytes); return -WD_EINVAL; } return 0; @@ -1006,7 +1010,7 @@ static int fill_cipher_bd3_alg(struct wd_cipher_msg *msg, sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3; break; default: - WD_ERR("invalid cipher type!\n"); + WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg); return -WD_EINVAL; } @@ -1041,7 +1045,7 @@ static int fill_cipher_bd3_mode(struct wd_cipher_msg *msg, c_mode = C_MODE_CFB; break; default: - WD_ERR("invalid cipher mode type!\n"); + WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode); return -WD_EINVAL; } sqe->c_mode_alg |= (__u16)c_mode; @@ -1201,7 +1205,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, struct hisi_sec_sqe *sqe) { if (msg->alg >= WD_DIGEST_TYPE_MAX) { - WD_ERR("invalid digest type!\n"); + WD_ERR("invalid digest alg type, alg = %u\n", msg->alg); return -WD_EINVAL; } @@ -1211,7 +1215,8 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, (__u32)g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET; else if (msg->mode == WD_DIGEST_HMAC) { if (msg->key_bytes & WORD_ALIGNMENT_MASK) { - WD_ERR("invalid digest key_bytes!\n"); + WD_ERR("invalid digest key_bytes, size = %u\n", + msg->key_bytes); return -WD_EINVAL; } sqe->type2.mac_key_alg |= (__u32)(msg->key_bytes / @@ -1221,7 +1226,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, sqe->type2.mac_key_alg |= (__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET; } else { - WD_ERR("invalid digest mode!\n"); + WD_ERR("invalid digest mode, mode = %u\n", msg->mode); return -WD_EINVAL; } @@ -1298,19 +1303,22 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) } if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) { - WD_ERR("digest input length is too long, size:%u!\n", msg->in_bytes); + WD_ERR("digest input length is too long, size = %u\n", + msg->in_bytes); return -WD_EINVAL; } if (unlikely(msg->out_bytes & WORD_ALIGNMENT_MASK)) { - WD_ERR("digest out length is error, size:%u!\n", msg->out_bytes); + WD_ERR("digest out length is error, size = %u\n", + msg->out_bytes); return -WD_EINVAL; } if (msg->has_next) { ret = digest_long_bd_check(msg); if (ret) { - WD_ERR("input data isn't aligned, size:%u!\n", msg->in_bytes); + WD_ERR("input data isn't aligned, size = %u\n", + msg->in_bytes); return -WD_EINVAL; } } @@ -1421,7 +1429,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, struct hisi_sec_sqe3 *sqe) { if (msg->alg >= WD_DIGEST_TYPE_MAX) { - WD_ERR("Invalid digest type!\n"); + WD_ERR("invalid digest type, alg = %u\n", msg->alg); return -WD_EINVAL; } @@ -1432,7 +1440,8 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, (__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; } else if (msg->mode == WD_DIGEST_HMAC) { if (msg->key_bytes & WORD_ALIGNMENT_MASK) { - WD_ERR("Invalid digest key_bytes!\n"); + WD_ERR("invalid digest key_bytes, size = %u\n", + msg->key_bytes); return -WD_EINVAL; } sqe->auth_mac_key |= (__u32)(msg->key_bytes / @@ -1441,7 +1450,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, sqe->auth_mac_key |= (__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; } else { - WD_ERR("Invalid digest mode!\n"); + WD_ERR("invalid digest mode, mode = %u\n", msg->mode); return -WD_EINVAL; } @@ -1601,7 +1610,8 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len) *key_len = CKEY_LEN_256BIT; break; default: - WD_ERR("failed to check AES key size!\n"); + WD_ERR("failed to check AES key size, size = %u\n", + msg->ckey_bytes); return -WD_EINVAL; } @@ -1622,7 +1632,7 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg, sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET; break; default: - WD_ERR("failed to check aead calg type!\n"); + WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg); ret = -WD_EINVAL; } @@ -1632,13 +1642,15 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg, return ret; if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) { - WD_ERR("failed to check aead auth_bytes!\n"); + WD_ERR("failed to check aead auth_bytes, size = %u\n", + msg->auth_bytes); return -WD_EINVAL; } sqe->type2.mac_key_alg = msg->auth_bytes / WORD_BYTES; if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) { - WD_ERR("failed to check aead auth key bytes!\n"); + WD_ERR("failed to check aead auth key bytes, size = %u\n", + msg->akey_bytes); return -WD_EINVAL; } sqe->type2.mac_key_alg |= (__u32)(msg->akey_bytes / @@ -1655,7 +1667,7 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg, d_alg = A_ALG_HMAC_SHA512 << AUTH_ALG_OFFSET; break; default: - WD_ERR("failed to check aead dalg type!\n"); + WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg); ret = -WD_EINVAL; } sqe->type2.mac_key_alg |= d_alg; @@ -1685,7 +1697,8 @@ static int fill_aead_bd2_mode(struct wd_aead_msg *msg, sqe->type2.icvw_kmode |= msg->auth_bytes; break; default: - WD_ERR("failed to check aead cmode type!\n"); + WD_ERR("failed to check aead cmode type, cmode = %u\n", + msg->cmode); return -WD_EINVAL; } sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET; @@ -1758,13 +1771,15 @@ static void fill_aead_bd2_addr(struct wd_aead_msg *msg, static int aead_len_check(struct wd_aead_msg *msg) { if (unlikely(msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) { - WD_ERR("aead input data length is too long!\n"); + WD_ERR("aead input data length is too long, size = %u\n", + msg->in_bytes + msg->assoc_bytes); return -WD_EINVAL; } if (unlikely(msg->cmode == WD_CIPHER_CCM && msg->assoc_bytes > MAX_CCM_AAD_LEN)) { - WD_ERR("failed to check ccm aad len, input is too long!\n"); + WD_ERR("failed to check ccm aad len, input is too long, size = %u\n", + msg->assoc_bytes); return -WD_EINVAL; } @@ -1793,7 +1808,7 @@ static int fill_aead_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe) sqe->type_auth_cipher |= AUTH_MAC_VERIFY << SEC_AUTH_OFFSET; } else { - WD_ERR("failed to check aead op type!\n"); + WD_ERR("failed to check aead op type, op = %u\n", msg->op_type); return -WD_EINVAL; } sqe->sds_sa_type |= (__u8)(de | scene); @@ -1950,12 +1965,14 @@ static int aead_bd3_msg_check(struct wd_aead_msg *msg) } if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) { - WD_ERR("failed to check aead auth_bytes!\n"); + WD_ERR("failed to check aead auth_bytes, size = %u\n", + msg->auth_bytes); return -WD_EINVAL; } if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) { - WD_ERR("failed to check aead auth key bytes!\n"); + WD_ERR("failed to check aead auth key bytes, size = %u\n", + msg->akey_bytes); return -WD_EINVAL; } @@ -1980,7 +1997,7 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg, sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3; break; default: - WD_ERR("failed to check aead calg type!\n"); + WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg); ret = -WD_EINVAL; } @@ -2009,7 +2026,7 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg, d_alg = A_ALG_HMAC_SHA512 << SEC_AUTH_ALG_OFFSET_V3; break; default: - WD_ERR("failed to check aead dalg type!\n"); + WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg); ret = -WD_EINVAL; } sqe->auth_mac_key |= d_alg; @@ -2037,7 +2054,8 @@ static int fill_aead_bd3_mode(struct wd_aead_msg *msg, sqe->c_icv_key |= msg->auth_bytes << SEC_MAC_OFFSET_V3; break; default: - WD_ERR("failed to check aead cmode type!\n"); + WD_ERR("failed to check aead cmode type, cmode = %u\n", + msg->cmode); return -WD_EINVAL; } @@ -2082,7 +2100,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe) sqe->auth_mac_key = AUTH_MAC_VERIFY; sqe->huk_iv_seq = WD_DIGEST_THEN_CIPHER << SEC_SEQ_OFFSET_V3; } else { - WD_ERR("failed to check aead op type!\n"); + WD_ERR("failed to check aead op type, op = %u\n", msg->op_type); return -WD_EINVAL; } sqe->bd_param |= (__u16)(de | scene); diff --git a/wd_aead.c b/wd_aead.c index 32d06ec..82a1f97 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -110,7 +110,7 @@ static int cipher_key_len_check(enum wd_cipher_alg alg, __u16 length) ret = aes_key_len_check(length); break; default: - WD_ERR("failed to check cipher key!\n"); + WD_ERR("failed to set the cipher alg, alg = %d\n", alg); return -WD_EINVAL; } @@ -143,7 +143,7 @@ int wd_aead_set_ckey(handle_t h_sess, const __u8 *key, __u16 key_len) int ret; if (unlikely(!key || !sess)) { - WD_ERR("failed to check cipher key inpupt param!\n"); + WD_ERR("failed to check cipher key input param!\n"); return -WD_EINVAL; } @@ -189,7 +189,7 @@ int wd_aead_set_akey(handle_t h_sess, const __u8 *key, __u16 key_len) return 0; err_key_len: - WD_ERR("failed to check authenticate key length!\n"); + WD_ERR("failed to check authenticate key length, size = %u\n", key_len); return -WD_EINVAL; } @@ -206,20 +206,23 @@ int wd_aead_set_authsize(handle_t h_sess, __u16 authsize) if (authsize < WD_AEAD_CCM_GCM_MIN || authsize > WD_AEAD_CCM_GCM_MAX || authsize % (WD_AEAD_CCM_GCM_MIN >> 1)) { - WD_ERR("failed to check aead CCM authsize!\n"); + WD_ERR("failed to check aead CCM authsize, size = %u\n", + authsize); return -WD_EINVAL; } } else if (sess->cmode == WD_CIPHER_GCM) { if (authsize < WD_AEAD_CCM_GCM_MIN << 1 || authsize > WD_AEAD_CCM_GCM_MAX) { - WD_ERR("failed to check aead GCM authsize!\n"); + WD_ERR("failed to check aead GCM authsize, size = %u\n", + authsize); return -WD_EINVAL; } } else { if (sess->dalg >= WD_DIGEST_TYPE_MAX || authsize & (WD_AEAD_CCM_GCM_MAX - 1) || authsize > g_aead_mac_len[sess->dalg]) { - WD_ERR("failed to check aead mac authsize!\n"); + WD_ERR("failed to check aead mac authsize, size = %u\n", + authsize); return -WD_EINVAL; } } @@ -313,20 +316,22 @@ static int aead_mac_param_check(struct wd_aead_sess *sess, switch (sess->cmode) { case WD_CIPHER_CBC: if (req->mac_bytes < g_aead_mac_len[sess->dalg]) { - WD_ERR("failed to check cbc-hmac mac buffer length!\n"); + WD_ERR("failed to check cbc-hmac mac buffer length, size = %u\n", + req->mac_bytes); ret = -WD_EINVAL; } break; case WD_CIPHER_CCM: case WD_CIPHER_GCM: if (req->mac_bytes < WD_AEAD_CCM_GCM_MAX) { - WD_ERR("failed to check CCM or GCM mac buffer length!\n"); + WD_ERR("failed to check CCM or GCM mac buffer length, size = %u\n", + req->mac_bytes); ret = -WD_EINVAL; } break; default: ret = -WD_EINVAL; - WD_ERR("set the aead cmode is error!\n"); + WD_ERR("set the aead cmode is error, cmode = %d\n", sess->cmode); } return ret; @@ -350,12 +355,14 @@ static int aead_param_check(struct wd_aead_sess *sess, if (unlikely(sess->cmode == WD_CIPHER_CBC && (req->in_bytes & (AES_BLOCK_SIZE - 1)))) { - WD_ERR("failed to check aead input data length!\n"); + WD_ERR("failed to check aead input data length, size = %u\n", + req->in_bytes); return -WD_EINVAL; } if (unlikely(req->iv_bytes != get_iv_block_size(sess->cmode))) { - WD_ERR("failed to check aead IV length, size:%u\n", req->iv_bytes); + WD_ERR("failed to check aead IV length, size = %u\n", + req->iv_bytes); return -WD_EINVAL; } @@ -367,13 +374,15 @@ static int aead_param_check(struct wd_aead_sess *sess, len = req->in_bytes + req->assoc_bytes; ret = wd_check_datalist(req->list_src, len); if (unlikely(ret)) { - WD_ERR("failed to check the src datalist!\n"); + WD_ERR("failed to check the src datalist, size = %u\n", + len); return -WD_EINVAL; } ret = wd_check_datalist(req->list_dst, req->out_bytes); if (unlikely(ret)) { - WD_ERR("failed to check the dst datalist!\n"); + WD_ERR("failed to check the dst datalist, size = %u\n", + req->out_bytes); return -WD_EINVAL; } } @@ -407,13 +416,13 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) ret = wd_init_ctx_config(&wd_aead_setting.config, config); if (ret) { - WD_ERR("failed to set config, ret = %d!\n", ret); + WD_ERR("failed to set config, ret = %d\n", ret); return ret; } ret = wd_init_sched(&wd_aead_setting.sched, sched); if (ret < 0) { - WD_ERR("failed to set sched, ret = %d!\n", ret); + WD_ERR("failed to set sched, ret = %d\n", ret); goto out; } diff --git a/wd_cipher.c b/wd_cipher.c index 5be3123..0b29fb5 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -126,7 +126,7 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length) int ret = 0; if (sess->mode == WD_CIPHER_XTS && length == AES_KEYSIZE_192) { - WD_ERR("unsupported XTS key length, length = %u.\n", length); + WD_ERR("unsupported XTS key length, length = %u\n", length); return -WD_EINVAL; } @@ -147,7 +147,7 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length) ret = -WD_EINVAL; break; default: - WD_ERR("cipher input alg err, alg is %d.\n", sess->alg); + WD_ERR("cipher input alg err, alg = %d\n", sess->alg); return -WD_EINVAL; } @@ -358,14 +358,16 @@ static int cipher_iv_len_check(struct wd_cipher_req *req, case WD_CIPHER_AES: case WD_CIPHER_SM4: if (req->iv_bytes != AES_BLOCK_SIZE) { - WD_ERR("AES or SM4 input iv bytes is err!\n"); + WD_ERR("AES or SM4 input iv bytes is err, size = %u\n", + req->iv_bytes); ret = -WD_EINVAL; } break; case WD_CIPHER_3DES: case WD_CIPHER_DES: if (req->iv_bytes != DES3_BLOCK_SIZE) { - WD_ERR("3DES or DES input iv bytes is err!\n"); + WD_ERR("3DES or DES input iv bytes is err, size = %u\n", + req->iv_bytes); ret = -WD_EINVAL; } break; @@ -384,7 +386,7 @@ static int wd_cipher_check_params(handle_t h_sess, int ret = 0; if (unlikely(!h_sess || !req)) { - WD_ERR("cipher input sess or req is NULL.\n"); + WD_ERR("cipher input sess or req is NULL!\n"); return -WD_EINVAL; } @@ -394,21 +396,24 @@ static int wd_cipher_check_params(handle_t h_sess, } if (unlikely(req->out_buf_bytes < req->in_bytes)) { - WD_ERR("cipher set out_buf_bytes is error!\n"); + WD_ERR("cipher set out_buf_bytes is error, size = %u\n", + req->out_buf_bytes); return -WD_EINVAL; } if (req->data_fmt == WD_SGL_BUF) { ret = wd_check_datalist(req->list_src, req->in_bytes); if (unlikely(ret)) { - WD_ERR("failed to check the src datalist!\n"); + WD_ERR("failed to check the src datalist, len = %u\n", + req->in_bytes); return -WD_EINVAL; } /* cipher dst len is equal to src len */ ret = wd_check_datalist(req->list_dst, req->in_bytes); if (unlikely(ret)) { - WD_ERR("failed to check the dst datalist!\n"); + WD_ERR("failed to check the dst datalist, len = %u\n", + req->in_bytes); return -WD_EINVAL; } } diff --git a/wd_digest.c b/wd_digest.c index 525d6a9..d4e710d 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -98,7 +98,8 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) if ((sess->alg <= WD_DIGEST_SHA224 && key_len > MAX_HMAC_KEY_SIZE >> 1) || key_len == 0 || key_len > MAX_HMAC_KEY_SIZE) { - WD_ERR("failed to check digest key length!\n"); + WD_ERR("failed to check digest key length, size = %u\n", + key_len); return -WD_EINVAL; } @@ -258,20 +259,23 @@ static int digest_param_check(struct wd_digest_sess *sess, } if (unlikely(req->out_buf_bytes < req->out_bytes)) { - WD_ERR("failed to check digest out buffer length!\n"); + WD_ERR("failed to check digest out buffer length, size = %u\n", + req->out_buf_bytes); return -WD_EINVAL; } if (unlikely(sess->alg >= WD_DIGEST_TYPE_MAX || req->out_bytes == 0 || req->out_bytes > g_digest_mac_len[sess->alg])) { - WD_ERR("failed to check digest type or mac length!\n"); + WD_ERR("failed to check digest type or mac length, alg = %d, out_bytes = %u\n", + sess->alg, req->out_bytes); return -WD_EINVAL; } if (req->data_fmt == WD_SGL_BUF) { ret = wd_check_datalist(req->list_in, req->in_bytes); if (unlikely(ret)) { - WD_ERR("failed to check the src datalist!\n"); + WD_ERR("failed to check the src datalist, size = %u\n", + req->in_bytes); return -WD_EINVAL; } } -- 2.25.1