From: Chenghai Huang huangchenghai2@huawei.com
The sec algorithm has multiple common header files, so they are centrally stored in wd_alg_common.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- v1/drv/hisi_sec_udrv.c | 11 ++--------- v1/wd_aead.c | 15 --------------- v1/wd_cipher.c | 9 +-------- v1/wd_digest.c | 1 - v1/wd_util.h | 17 +++++++++++++++++ 5 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index 02a63c2..d046327 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -31,10 +31,6 @@ #include "config.h" #include "hisi_sec_udrv.h"
-#define DES_KEY_SIZE 8 -#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) -#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) - #define SEC_HW_TASK_DONE 1 #define SEC_HW_ICV_ERR 0x2 #define SEC_SM4_XTS_GB_V3 0x1 @@ -47,11 +43,8 @@ #define CTR_128BIT_COUNTER 16 #define CTR_128BIT_FLIP 0x2 #define DIF_VERIFY_FAIL 2 -#define AES_BLOCK_SIZE 16 #define WCRYPTO_CIPHER_THEN_DIGEST 0 #define WCRYPTO_DIGEST_THEN_CIPHER 1 -#define CBC_3DES_BLOCK_SIZE 8 -#define CBC_AES_BLOCK_SIZE 16 #define AEAD_IV_MAX_BYTES 64 #define MAX_CCM_AAD_LEN 65279 #define SEC_GMAC_IV_LEN 16 @@ -111,9 +104,9 @@ static int get_aes_c_key_len(__u8 mode, __u16 key_bytes, __u8 *c_key_len)
static int get_3des_c_key_len(struct wcrypto_cipher_msg *msg, __u8 *c_key_len) { - if (msg->key_bytes == SEC_3DES_2KEY_SIZE) + if (msg->key_bytes == DES3_2KEY_SIZE) *c_key_len = CKEY_LEN_3DES_2KEY; - else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) + else if (msg->key_bytes == DES3_3KEY_SIZE) *c_key_len = CKEY_LEN_3DES_3KEY; else { WD_ERR("Invalid 3DES key size!\n"); diff --git a/v1/wd_aead.c b/v1/wd_aead.c index 38429fc..380daf0 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -26,24 +26,9 @@ #include "wd_util.h" #include "wd_aead.h"
-#define MAX_AEAD_KEY_SIZE 64 -#define MAX_AEAD_MAC_SIZE 64 -#define MAX_CIPHER_KEY_SIZE 64 #define MAX_AEAD_AUTH_SIZE 64 -#define MAX_AEAD_ASSOC_SIZE 65536 -#define MAX_HMAC_KEY_SIZE 128 #define MAX_AEAD_RETRY_CNT 20000000
-#define DES_KEY_SIZE 8 -#define SM4_KEY_SIZE 16 -#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) -#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) - -#define AES_BLOCK_SIZE 16 -#define GCM_BLOCK_SIZE 12 - -#define MAX_BURST_NUM 16 - static int g_aead_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = { WCRYPTO_SM3_LEN, WCRYPTO_MD5_LEN, WCRYPTO_SHA1_LEN, WCRYPTO_SHA256_LEN, WCRYPTO_SHA224_LEN, diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index f95015d..0877993 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -26,17 +26,10 @@ #include "v1/wd_util.h" #include "v1/wd_cipher.h"
-#define MAX_CIPHER_KEY_SIZE 64 #define MAX_CIPHER_RETRY_CNT 20000000
#define XTS_MODE_KEY_LEN_MASK 0x1 -#define DES_KEY_SIZE 8 -#define SM4_KEY_SIZE 16 -#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) -#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE)
-#define CBC_3DES_BLOCK_SIZE 8 -#define CBC_AES_BLOCK_SIZE 16 #define DES_WEAK_KEY_NUM 4 static __u64 des_weak_key[DES_WEAK_KEY_NUM] = {0x0101010101010101, 0xFEFEFEFEFEFEFEFE, 0xE0E0E0E0F1F1F1F1, 0x1F1F1F1F0E0E0E0E}; @@ -300,7 +293,7 @@ static int cipher_key_len_check(struct wcrypto_cipher_ctx_setup *setup, ret = -WD_EINVAL; break; case WCRYPTO_CIPHER_3DES: - if ((key_len != SEC_3DES_2KEY_SIZE) && (key_len != SEC_3DES_3KEY_SIZE)) + if ((key_len != DES3_2KEY_SIZE) && (key_len != DES3_3KEY_SIZE)) ret = -WD_EINVAL; break; default: diff --git a/v1/wd_digest.c b/v1/wd_digest.c index df8a8af..cb9b6e0 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -26,7 +26,6 @@ #include "wd_util.h" #include "wd_digest.h"
-#define MAX_HMAC_KEY_SIZE 128 #define MAX_DIGEST_RETRY_CNT 20000000 #define SEC_SHA1_ALIGN_SZ 64 #define SEC_SHA512_ALIGN_SZ 128 diff --git a/v1/wd_util.h b/v1/wd_util.h index bf17058..9e5fa90 100644 --- a/v1/wd_util.h +++ b/v1/wd_util.h @@ -76,6 +76,23 @@ #define X_DH_OUT_PARAM_NUM 1 #define X_DH_HW_KEY_PARAM_NUM 3
+/* Key size and block size of aead */ +#define MAX_AEAD_KEY_SIZE 64 +#define GCM_BLOCK_SIZE 12 + +/* Key size and block size of chiper */ +#define MAX_CIPHER_KEY_SIZE 64 +#define AES_BLOCK_SIZE 16 +#define DES_KEY_SIZE 8 +#define SM4_KEY_SIZE 16 +#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) +#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) +#define CBC_AES_BLOCK_SIZE 16 +#define CBC_3DES_BLOCK_SIZE 8 + +/* Key size and block size of digest */ +#define MAX_HMAC_KEY_SIZE 128 + #define X_DH_OUT_PARAMS_SZ(hsz) ((hsz) * X_DH_OUT_PARAM_NUM) #define X_DH_HW_KEY_SZ(hsz) ((hsz) * X_DH_HW_KEY_PARAM_NUM) #define SM2_KG_OUT_PARAMS_SZ(hsz) ((hsz) * SM2_KG_OUT_PARAM_NUM)