Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/qat/qat_api/common/crypto/sym/qat/lac_sym_qat_cipher.c
Show All 23 Lines | |||||
#include "lac_sym_qat_cipher.h" | #include "lac_sym_qat_cipher.h" | ||||
#include "lac_mem.h" | #include "lac_mem.h" | ||||
#include "lac_common.h" | #include "lac_common.h" | ||||
#include "cpa_cy_sym.h" | #include "cpa_cy_sym.h" | ||||
#include "lac_sym_qat.h" | #include "lac_sym_qat.h" | ||||
#include "lac_sym_cipher_defs.h" | #include "lac_sym_cipher_defs.h" | ||||
#include "icp_qat_hw.h" | #include "icp_qat_hw.h" | ||||
#include "icp_qat_fw_la.h" | #include "icp_qat_fw_la.h" | ||||
#include "sal_hw_gen.h" | |||||
#define LAC_UNUSED_POS_MASK 0x3 | |||||
/***************************************************************************** | /***************************************************************************** | ||||
* Internal data | * Internal data | ||||
*****************************************************************************/ | *****************************************************************************/ | ||||
typedef enum _icp_qat_hw_key_depend { | typedef enum _icp_qat_hw_key_depend { | ||||
IS_KEY_DEP_NO = 0, | IS_KEY_DEP_NO = 0, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
} icp_qat_hw_key_depend; | } icp_qat_hw_key_depend; | ||||
Show All 27 Lines | static const uint8_t key_size_xts[] = { | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, // ICP_QAT_HW_AES_128_XTS_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES128, /* ICP_QAT_HW_AES_128_XTS_KEY_SZ */ | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
Show All 15 Lines | static const uint8_t key_size_xts[] = { | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES256 // ICP_QAT_HW_AES_256_XTS_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES256 /* ICP_QAT_HW_AES_256_XTS_KEY_SZ */ | ||||
}; | }; | ||||
/* LAC_CIPHER_IS_AES */ | /* LAC_CIPHER_IS_AES */ | ||||
static const uint8_t key_size_aes[] = { | static const uint8_t key_size_aes[] = { | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, // ICP_QAT_HW_AES_128_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES128, /* ICP_QAT_HW_AES_128_KEY_SZ */ | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES192, // ICP_QAT_HW_AES_192_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES192, /* ICP_QAT_HW_AES_192_KEY_SZ */ | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES256 // ICP_QAT_HW_AES_256_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES256 /* ICP_QAT_HW_AES_256_KEY_SZ */ | ||||
}; | }; | ||||
/* LAC_CIPHER_IS_AES_F8 */ | /* LAC_CIPHER_IS_AES_F8 */ | ||||
static const uint8_t key_size_f8[] = { | static const uint8_t key_size_f8[] = { | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
Show All 19 Lines | static const uint8_t key_size_f8[] = { | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, // ICP_QAT_HW_AES_128_F8_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES128, /* ICP_QAT_HW_AES_128_F8_KEY_SZ */ | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES192, // ICP_QAT_HW_AES_192_F8_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES192, /* ICP_QAT_HW_AES_192_F8_KEY_SZ */ | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
0, | 0, | ||||
ICP_QAT_HW_CIPHER_ALGO_AES256 // ICP_QAT_HW_AES_256_F8_KEY_SZ | ICP_QAT_HW_CIPHER_ALGO_AES256 /* ICP_QAT_HW_AES_256_F8_KEY_SZ */ | ||||
}; | }; | ||||
/* LAC_CIPHER_IS_SM4 */ | |||||
static const uint8_t key_size_sm4[] = { | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
0, | |||||
ICP_QAT_HW_CIPHER_ALGO_SM4 // ICP_QAT_HW_SM4_KEY_SZ | |||||
}; | |||||
typedef struct _icp_qat_hw_cipher_info { | typedef struct _icp_qat_hw_cipher_info { | ||||
icp_qat_hw_cipher_algo_t algorithm; | icp_qat_hw_cipher_algo_t algorithm; | ||||
icp_qat_hw_cipher_mode_t mode; | icp_qat_hw_cipher_mode_t mode; | ||||
icp_qat_hw_cipher_convert_t key_convert[2]; | icp_qat_hw_cipher_convert_t key_convert[2]; | ||||
icp_qat_hw_cipher_dir_t dir[2]; | icp_qat_hw_cipher_dir_t dir[2]; | ||||
icp_qat_hw_key_depend isKeyLenDepend; | icp_qat_hw_key_depend isKeyLenDepend; | ||||
const uint8_t *pAlgByKeySize; | const uint8_t *pAlgByKeySize; | ||||
} icp_qat_hw_cipher_info; | } icp_qat_hw_cipher_info; | ||||
static const icp_qat_hw_cipher_info icp_qat_alg_info[] = | static const icp_qat_hw_cipher_info icp_qat_alg_info[] = { | ||||
{ | |||||
/* CPA_CY_SYM_CIPHER_NULL */ | /* CPA_CY_SYM_CIPHER_NULL */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_NULL, | ICP_QAT_HW_CIPHER_ALGO_NULL, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_ARC4 */ | /* CPA_CY_SYM_CIPHER_ARC4 */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_ARC4, | ICP_QAT_HW_CIPHER_ALGO_ARC4, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt */ | /* Streaming ciphers are a special case. Decrypt = encrypt */ | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_AES_ECB */ | /* CPA_CY_SYM_CIPHER_AES_ECB */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, | ICP_QAT_HW_CIPHER_ALGO_AES128, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
/* AES decrypt key needs to be reversed. Instead of reversing the key | /* AES decrypt key needs to be reversed. Instead of reversing the | ||||
* at session registration, it is instead reversed on-the-fly by | * key at session registration, it is instead reversed on-the-fly by | ||||
* setting the KEY_CONVERT bit here | * setting the KEY_CONVERT bit here | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
key_size_aes, | key_size_aes, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_AES_CBC */ | /* CPA_CY_SYM_CIPHER_AES_CBC */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, | ICP_QAT_HW_CIPHER_ALGO_AES128, | ||||
ICP_QAT_HW_CIPHER_CBC_MODE, | ICP_QAT_HW_CIPHER_CBC_MODE, | ||||
/* AES decrypt key needs to be reversed. Instead of reversing the key | /* AES decrypt key needs to be reversed. Instead of reversing the | ||||
* at session registration, it is instead reversed on-the-fly by | * key at session registration, it is instead reversed on-the-fly by | ||||
* setting the KEY_CONVERT bit here | * setting the KEY_CONVERT bit here | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
key_size_aes, | key_size_aes, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_AES_CTR */ | /* CPA_CY_SYM_CIPHER_AES_CTR */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, | ICP_QAT_HW_CIPHER_ALGO_AES128, | ||||
ICP_QAT_HW_CIPHER_CTR_MODE, | ICP_QAT_HW_CIPHER_CTR_MODE, | ||||
/* AES decrypt key needs to be reversed. Instead of reversing the key | /* AES decrypt key needs to be reversed. Instead of reversing the | ||||
* at session registration, it is instead reversed on-the-fly by | * key at session registration, it is instead reversed on-the-fly by | ||||
* setting the KEY_CONVERT bit here | * setting the KEY_CONVERT bit here | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt | /* Streaming ciphers are a special case. Decrypt = encrypt | ||||
* Overriding default values previously set for AES | * Overriding default values previously set for AES | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
key_size_aes, | key_size_aes, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_AES_CCM */ | /* CPA_CY_SYM_CIPHER_AES_CCM */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, | ICP_QAT_HW_CIPHER_ALGO_AES128, | ||||
ICP_QAT_HW_CIPHER_CTR_MODE, | ICP_QAT_HW_CIPHER_CTR_MODE, | ||||
/* AES decrypt key needs to be reversed. Instead of reversing the key | /* AES decrypt key needs to be reversed. Instead of reversing the | ||||
* at session registration, it is instead reversed on-the-fly by | * key at session registration, it is instead reversed on-the-fly by | ||||
* setting the KEY_CONVERT bit here | * setting the KEY_CONVERT bit here | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt | /* Streaming ciphers are a special case. Decrypt = encrypt | ||||
* Overriding default values previously set for AES | * Overriding default values previously set for AES | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
key_size_aes, | key_size_aes, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_AES_GCM */ | /* CPA_CY_SYM_CIPHER_AES_GCM */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, | ICP_QAT_HW_CIPHER_ALGO_AES128, | ||||
ICP_QAT_HW_CIPHER_CTR_MODE, | ICP_QAT_HW_CIPHER_CTR_MODE, | ||||
/* AES decrypt key needs to be reversed. Instead of reversing the key | /* AES decrypt key needs to be reversed. Instead of reversing the | ||||
* at session registration, it is instead reversed on-the-fly by | * key at session registration, it is instead reversed on-the-fly by | ||||
* setting the KEY_CONVERT bit here | * setting the KEY_CONVERT bit here | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt | /* Streaming ciphers are a special case. Decrypt = encrypt | ||||
* Overriding default values previously set for AES | * Overriding default values previously set for AES | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
key_size_aes, | key_size_aes, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_DES_ECB */ | /* CPA_CY_SYM_CIPHER_DES_ECB */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_DES, | ICP_QAT_HW_CIPHER_ALGO_DES, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_DES_CBC */ | /* CPA_CY_SYM_CIPHER_DES_CBC */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_DES, | ICP_QAT_HW_CIPHER_ALGO_DES, | ||||
ICP_QAT_HW_CIPHER_CBC_MODE, | ICP_QAT_HW_CIPHER_CBC_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_3DES_ECB */ | /* CPA_CY_SYM_CIPHER_3DES_ECB */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_3DES, | ICP_QAT_HW_CIPHER_ALGO_3DES, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_3DES_CBC */ | /* CPA_CY_SYM_CIPHER_3DES_CBC */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_3DES, | ICP_QAT_HW_CIPHER_ALGO_3DES, | ||||
ICP_QAT_HW_CIPHER_CBC_MODE, | ICP_QAT_HW_CIPHER_CBC_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_3DES_CTR */ | /* CPA_CY_SYM_CIPHER_3DES_CTR */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_3DES, | ICP_QAT_HW_CIPHER_ALGO_3DES, | ||||
ICP_QAT_HW_CIPHER_CTR_MODE, | ICP_QAT_HW_CIPHER_CTR_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt | /* Streaming ciphers are a special case. Decrypt = encrypt | ||||
* Overriding default values previously set for AES | * Overriding default values previously set for AES | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_KASUMI_F8 */ | /* CPA_CY_SYM_CIPHER_KASUMI_F8 */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_KASUMI, | ICP_QAT_HW_CIPHER_ALGO_KASUMI, | ||||
ICP_QAT_HW_CIPHER_F8_MODE, | ICP_QAT_HW_CIPHER_F8_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt */ | /* Streaming ciphers are a special case. Decrypt = encrypt */ | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_SNOW3G_UEA2 */ | /* CPA_CY_SYM_CIPHER_SNOW3G_UEA2 */ | ||||
{ | { | ||||
/* The KEY_CONVERT bit has to be set for Snow_3G operation */ | /* The KEY_CONVERT bit has to be set for Snow_3G operation */ | ||||
ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2, | ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
{ ICP_QAT_HW_CIPHER_KEY_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_KEY_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_AES_F8 */ | /* CPA_CY_SYM_CIPHER_AES_F8 */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, | ICP_QAT_HW_CIPHER_ALGO_AES128, | ||||
ICP_QAT_HW_CIPHER_F8_MODE, | ICP_QAT_HW_CIPHER_F8_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt */ | /* Streaming ciphers are a special case. Decrypt = encrypt */ | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
key_size_f8, | key_size_f8, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_AES_XTS */ | /* CPA_CY_SYM_CIPHER_AES_XTS */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_AES128, | ICP_QAT_HW_CIPHER_ALGO_AES128, | ||||
ICP_QAT_HW_CIPHER_XTS_MODE, | ICP_QAT_HW_CIPHER_XTS_MODE, | ||||
/* AES decrypt key needs to be reversed. Instead of reversing the key | /* AES decrypt key needs to be reversed. Instead of reversing the | ||||
* at session registration, it is instead reversed on-the-fly by | * key at session registration, it is instead reversed on-the-fly by | ||||
* setting the KEY_CONVERT bit here | * setting the KEY_CONVERT bit here | ||||
*/ | */ | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_YES, | ||||
key_size_xts, | key_size_xts, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_ZUC_EEA3 */ | /* CPA_CY_SYM_CIPHER_ZUC_EEA3 */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3, | ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
{ ICP_QAT_HW_CIPHER_KEY_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_KEY_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_CHACHA */ | /* CPA_CY_SYM_CIPHER_CHACHA */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_CHACHA20_POLY1305, | ICP_QAT_HW_CIPHER_ALGO_CHACHA20_POLY1305, | ||||
ICP_QAT_HW_CIPHER_CTR_MODE, | ICP_QAT_HW_CIPHER_CTR_MODE, | ||||
{ ICP_QAT_HW_CIPHER_KEY_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_NO, | IS_KEY_DEP_NO, | ||||
NULL, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_SM4_ECB */ | /* CPA_CY_SYM_CIPHER_SM4_ECB */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_SM4, | ICP_QAT_HW_CIPHER_ALGO_SM4, | ||||
ICP_QAT_HW_CIPHER_ECB_MODE, | ICP_QAT_HW_CIPHER_ECB_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_NO, | ||||
key_size_sm4, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_SM4_CBC */ | /* CPA_CY_SYM_CIPHER_SM4_CBC */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_SM4, | ICP_QAT_HW_CIPHER_ALGO_SM4, | ||||
ICP_QAT_HW_CIPHER_CBC_MODE, | ICP_QAT_HW_CIPHER_CBC_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, | ||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_NO, | ||||
key_size_sm4, | NULL, | ||||
}, | }, | ||||
/* CPA_CY_SYM_CIPHER_SM4_CTR */ | /* CPA_CY_SYM_CIPHER_SM4_CTR */ | ||||
{ | { | ||||
ICP_QAT_HW_CIPHER_ALGO_SM4, | ICP_QAT_HW_CIPHER_ALGO_SM4, | ||||
ICP_QAT_HW_CIPHER_CTR_MODE, | ICP_QAT_HW_CIPHER_CTR_MODE, | ||||
{ ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | { ICP_QAT_HW_CIPHER_NO_CONVERT, ICP_QAT_HW_CIPHER_NO_CONVERT }, | ||||
/* Streaming ciphers are a special case. Decrypt = encrypt */ | |||||
{ ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_ENCRYPT }, | ||||
IS_KEY_DEP_YES, | IS_KEY_DEP_NO, | ||||
key_size_sm4, | NULL, | ||||
}, | }, | ||||
}; | }; | ||||
/***************************************************************************** | /***************************************************************************** | ||||
* Internal functions | * Internal functions | ||||
*****************************************************************************/ | *****************************************************************************/ | ||||
void | void | ||||
LacSymQat_CipherCtrlBlockWrite(icp_qat_la_bulk_req_ftr_t *pMsg, | LacSymQat_CipherCtrlBlockWrite(icp_qat_la_bulk_req_ftr_t *pMsg, | ||||
Cpa32U cipherAlgorithm, | Cpa32U cipherAlgorithm, | ||||
Cpa32U targetKeyLenInBytes, | Cpa32U targetKeyLenInBytes, | ||||
Cpa32U sliceType, | |||||
icp_qat_fw_slice_t nextSlice, | icp_qat_fw_slice_t nextSlice, | ||||
Cpa8U cipherCfgOffsetInQuadWord) | Cpa8U cipherCfgOffsetInQuadWord) | ||||
{ | { | ||||
icp_qat_fw_cipher_cd_ctrl_hdr_t *cd_ctrl = | icp_qat_fw_cipher_cd_ctrl_hdr_t *cd_ctrl = | ||||
(icp_qat_fw_cipher_cd_ctrl_hdr_t *)&(pMsg->cd_ctrl); | (icp_qat_fw_cipher_cd_ctrl_hdr_t *)&(pMsg->cd_ctrl); | ||||
/* state_padding_sz is nonzero for f8 mode only */ | /* state_padding_sz is nonzero for f8 mode only */ | ||||
cd_ctrl->cipher_padding_sz = 0; | cd_ctrl->cipher_padding_sz = 0; | ||||
/* Special handling of AES 192 key for UCS slice. | |||||
UCS requires it to have 32 bytes - set is as targetKeyLen | |||||
in this case, and add padding. It makes no sense | |||||
to force applications to provide such key length for couple reasons: | |||||
1. It won't be possible to distinguish between AES 192 and 256 based | |||||
on key lenght only | |||||
2. Only some modes of AES will use UCS slice, then application will | |||||
have to know which ones */ | |||||
if (ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE == sliceType && | |||||
ICP_QAT_HW_AES_192_KEY_SZ == targetKeyLenInBytes) { | |||||
targetKeyLenInBytes = ICP_QAT_HW_UCS_AES_192_KEY_SZ; | |||||
} | |||||
switch (cipherAlgorithm) { | |||||
/* Base Key is not passed down to QAT in the case of ARC4 or NULL */ | /* Base Key is not passed down to QAT in the case of ARC4 or NULL */ | ||||
if (LAC_CIPHER_IS_ARC4(cipherAlgorithm) || | case CPA_CY_SYM_CIPHER_ARC4: | ||||
LAC_CIPHER_IS_NULL(cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_NULL: | ||||
cd_ctrl->cipher_key_sz = 0; | cd_ctrl->cipher_key_sz = 0; | ||||
} else if (LAC_CIPHER_IS_KASUMI(cipherAlgorithm)) { | break; | ||||
case CPA_CY_SYM_CIPHER_KASUMI_F8: | |||||
cd_ctrl->cipher_key_sz = | cd_ctrl->cipher_key_sz = | ||||
LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_KASUMI_F8_KEY_SZ); | LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_KASUMI_F8_KEY_SZ); | ||||
cd_ctrl->cipher_padding_sz = | cd_ctrl->cipher_padding_sz = | ||||
ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR; | ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR; | ||||
} else if (LAC_CIPHER_IS_SNOW3G_UEA2(cipherAlgorithm)) { | break; | ||||
/* For Snow3G UEA2 content descriptor key size is | /* For Snow3G UEA2 content descriptor key size is | ||||
key size plus iv size */ | key size plus iv size */ | ||||
case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: | |||||
cd_ctrl->cipher_key_sz = | cd_ctrl->cipher_key_sz = | ||||
LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_SNOW_3G_UEA2_KEY_SZ + | LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_SNOW_3G_UEA2_KEY_SZ + | ||||
ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ); | ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ); | ||||
} else if (LAC_CIPHER_IS_AES_F8(cipherAlgorithm)) { | break; | ||||
case CPA_CY_SYM_CIPHER_AES_F8: | |||||
cd_ctrl->cipher_key_sz = | cd_ctrl->cipher_key_sz = | ||||
LAC_BYTES_TO_QUADWORDS(targetKeyLenInBytes); | LAC_BYTES_TO_QUADWORDS(targetKeyLenInBytes); | ||||
cd_ctrl->cipher_padding_sz = | cd_ctrl->cipher_padding_sz = | ||||
2 * ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR; | (2 * ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR); | ||||
} else if (LAC_CIPHER_IS_ZUC_EEA3(cipherAlgorithm)) { | break; | ||||
/* For ZUC EEA3 content descriptor key size is | /* For ZUC EEA3 content descriptor key size is | ||||
key size plus iv size */ | key size plus iv size */ | ||||
case CPA_CY_SYM_CIPHER_ZUC_EEA3: | |||||
cd_ctrl->cipher_key_sz = | cd_ctrl->cipher_key_sz = | ||||
LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ + | LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ + | ||||
ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ); | ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ); | ||||
} else { | break; | ||||
default: | |||||
cd_ctrl->cipher_key_sz = | cd_ctrl->cipher_key_sz = | ||||
LAC_BYTES_TO_QUADWORDS(targetKeyLenInBytes); | LAC_BYTES_TO_QUADWORDS(targetKeyLenInBytes); | ||||
} | } | ||||
cd_ctrl->cipher_state_sz = LAC_BYTES_TO_QUADWORDS( | cd_ctrl->cipher_state_sz = LAC_BYTES_TO_QUADWORDS( | ||||
LacSymQat_CipherIvSizeBytesGet(cipherAlgorithm)); | LacSymQat_CipherIvSizeBytesGet(cipherAlgorithm)); | ||||
cd_ctrl->cipher_cfg_offset = cipherCfgOffsetInQuadWord; | cd_ctrl->cipher_cfg_offset = cipherCfgOffsetInQuadWord; | ||||
ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl, nextSlice); | ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl, nextSlice); | ||||
ICP_QAT_FW_COMN_CURR_ID_SET(cd_ctrl, ICP_QAT_FW_SLICE_CIPHER); | ICP_QAT_FW_COMN_CURR_ID_SET(cd_ctrl, ICP_QAT_FW_SLICE_CIPHER); | ||||
} | } | ||||
void | void | ||||
LacSymQat_CipherGetCfgData(lac_session_desc_t *pSession, | LacSymQat_CipherGetCfgData(lac_session_desc_t *pSession, | ||||
icp_qat_hw_cipher_algo_t *pAlgorithm, | icp_qat_hw_cipher_algo_t *pAlgorithm, | ||||
icp_qat_hw_cipher_mode_t *pMode, | icp_qat_hw_cipher_mode_t *pMode, | ||||
icp_qat_hw_cipher_dir_t *pDir, | icp_qat_hw_cipher_dir_t *pDir, | ||||
icp_qat_hw_cipher_convert_t *pKey_convert) | icp_qat_hw_cipher_convert_t *pKey_convert) | ||||
{ | { | ||||
sal_crypto_service_t *pService = | |||||
(sal_crypto_service_t *)pSession->pInstance; | |||||
CpaCySymCipherAlgorithm cipherAlgorithm = 0; | CpaCySymCipherAlgorithm cipherAlgorithm = 0; | ||||
icp_qat_hw_cipher_dir_t cipherDirection = 0; | icp_qat_hw_cipher_dir_t cipherDirection = 0; | ||||
/* Set defaults */ | /* Set defaults */ | ||||
*pKey_convert = ICP_QAT_HW_CIPHER_NO_CONVERT; | *pKey_convert = ICP_QAT_HW_CIPHER_NO_CONVERT; | ||||
*pAlgorithm = ICP_QAT_HW_CIPHER_ALGO_NULL; | *pAlgorithm = ICP_QAT_HW_CIPHER_ALGO_NULL; | ||||
*pMode = ICP_QAT_HW_CIPHER_ECB_MODE; | *pMode = ICP_QAT_HW_CIPHER_ECB_MODE; | ||||
*pDir = ICP_QAT_HW_CIPHER_ENCRYPT; | *pDir = ICP_QAT_HW_CIPHER_ENCRYPT; | ||||
/* decrease since it's numbered from 1 instead of 0 */ | /* decrease since it's numbered from 1 instead of 0 */ | ||||
cipherAlgorithm = pSession->cipherAlgorithm - 1; | cipherAlgorithm = pSession->cipherAlgorithm - 1; | ||||
cipherDirection = | cipherDirection = | ||||
pSession->cipherDirection == CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT ? | pSession->cipherDirection == CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT ? | ||||
ICP_QAT_HW_CIPHER_ENCRYPT : | ICP_QAT_HW_CIPHER_ENCRYPT : | ||||
ICP_QAT_HW_CIPHER_DECRYPT; | ICP_QAT_HW_CIPHER_DECRYPT; | ||||
*pAlgorithm = icp_qat_alg_info[cipherAlgorithm].algorithm; | *pAlgorithm = icp_qat_alg_info[cipherAlgorithm].algorithm; | ||||
*pMode = icp_qat_alg_info[cipherAlgorithm].mode; | *pMode = icp_qat_alg_info[cipherAlgorithm].mode; | ||||
*pDir = icp_qat_alg_info[cipherAlgorithm].dir[cipherDirection]; | *pDir = icp_qat_alg_info[cipherAlgorithm].dir[cipherDirection]; | ||||
*pKey_convert = | *pKey_convert = | ||||
icp_qat_alg_info[cipherAlgorithm].key_convert[cipherDirection]; | icp_qat_alg_info[cipherAlgorithm].key_convert[cipherDirection]; | ||||
if (IS_KEY_DEP_NO != icp_qat_alg_info[cipherAlgorithm].isKeyLenDepend) { | if (IS_KEY_DEP_NO != icp_qat_alg_info[cipherAlgorithm].isKeyLenDepend) { | ||||
*pAlgorithm = icp_qat_alg_info[cipherAlgorithm] | *pAlgorithm = icp_qat_alg_info[cipherAlgorithm] | ||||
.pAlgByKeySize[pSession->cipherKeyLenInBytes]; | .pAlgByKeySize[pSession->cipherKeyLenInBytes]; | ||||
} | } | ||||
/* Set the mode */ | |||||
if (LAC_CIPHER_IS_CTR_MODE(pSession->cipherAlgorithm)) { | /* CCP and AES_GCM single pass, despite being limited to CTR/AEAD mode, | ||||
*pMode = ICP_QAT_HW_CIPHER_CTR_MODE; | |||||
*pKey_convert = ICP_QAT_HW_CIPHER_NO_CONVERT; | |||||
/* CCP and AES_GCM single pass, despite being limited to | |||||
* CTR/AEAD mode, | |||||
* support both Encrypt/Decrypt modes - this is because of the | * support both Encrypt/Decrypt modes - this is because of the | ||||
* differences in the hash computation/verification paths in | * differences in the hash computation/verification paths in | ||||
* encrypt/decrypt modes respectively. | * encrypt/decrypt modes respectively. | ||||
* By default CCP is set as CTR Mode.Set AEAD Mode for AES_GCM. | * By default CCP is set as CTR Mode.Set AEAD Mode for AES_GCM. | ||||
*/ | */ | ||||
if (pSession->isSinglePass) { | if (SPC == pSession->singlePassState) { | ||||
if (LAC_CIPHER_IS_GCM(pSession->cipherAlgorithm)) | if (LAC_CIPHER_IS_GCM(pSession->cipherAlgorithm)) | ||||
*pMode = ICP_QAT_HW_CIPHER_AEAD_MODE; | *pMode = ICP_QAT_HW_CIPHER_AEAD_MODE; | ||||
else if (isCyGen4x(pService) && | |||||
LAC_CIPHER_IS_CCM(pSession->cipherAlgorithm)) | |||||
*pMode = ICP_QAT_HW_CIPHER_CCM_MODE; | |||||
if (cipherDirection == ICP_QAT_HW_CIPHER_DECRYPT) | if (cipherDirection == ICP_QAT_HW_CIPHER_DECRYPT) | ||||
*pDir = ICP_QAT_HW_CIPHER_DECRYPT; | *pDir = ICP_QAT_HW_CIPHER_DECRYPT; | ||||
} | } | ||||
} | } | ||||
} | |||||
void | void | ||||
LacSymQat_CipherHwBlockPopulateCfgData(lac_session_desc_t *pSession, | LacSymQat_CipherHwBlockPopulateCfgData(lac_session_desc_t *pSession, | ||||
const void *pCipherHwBlock, | const void *pCipherHwBlock, | ||||
Cpa32U *pSizeInBytes) | Cpa32U *pSizeInBytes) | ||||
{ | { | ||||
icp_qat_hw_cipher_algo_t algorithm = ICP_QAT_HW_CIPHER_ALGO_NULL; | icp_qat_hw_cipher_algo_t algorithm = ICP_QAT_HW_CIPHER_ALGO_NULL; | ||||
icp_qat_hw_cipher_mode_t mode = ICP_QAT_HW_CIPHER_ECB_MODE; | icp_qat_hw_cipher_mode_t mode = ICP_QAT_HW_CIPHER_ECB_MODE; | ||||
icp_qat_hw_cipher_dir_t dir = ICP_QAT_HW_CIPHER_ENCRYPT; | icp_qat_hw_cipher_dir_t dir = ICP_QAT_HW_CIPHER_ENCRYPT; | ||||
icp_qat_hw_cipher_convert_t key_convert; | icp_qat_hw_cipher_convert_t key_convert; | ||||
icp_qat_hw_cipher_config_t *pCipherConfig = | icp_qat_hw_cipher_config_t *pCipherConfig = | ||||
(icp_qat_hw_cipher_config_t *)pCipherHwBlock; | (icp_qat_hw_cipher_config_t *)pCipherHwBlock; | ||||
icp_qat_hw_ucs_cipher_config_t *pUCSCipherConfig = | |||||
(icp_qat_hw_ucs_cipher_config_t *)pCipherHwBlock; | |||||
Cpa32U val, reserved; | |||||
Cpa32U aed_hash_cmp_length = 0; | Cpa32U aed_hash_cmp_length = 0; | ||||
*pSizeInBytes = 0; | *pSizeInBytes = 0; | ||||
LacSymQat_CipherGetCfgData( | LacSymQat_CipherGetCfgData( | ||||
pSession, &algorithm, &mode, &dir, &key_convert); | pSession, &algorithm, &mode, &dir, &key_convert); | ||||
/* Build the cipher config into the hardware setup block */ | /* Build the cipher config into the hardware setup block */ | ||||
if (pSession->isSinglePass) { | if (SPC == pSession->singlePassState) { | ||||
aed_hash_cmp_length = pSession->hashResultSize; | aed_hash_cmp_length = pSession->hashResultSize; | ||||
pCipherConfig->reserved = ICP_QAT_HW_CIPHER_CONFIG_BUILD_UPPER( | reserved = ICP_QAT_HW_CIPHER_CONFIG_BUILD_UPPER( | ||||
pSession->aadLenInBytes); | pSession->aadLenInBytes); | ||||
} else { | } else { | ||||
pCipherConfig->reserved = 0; | reserved = 0; | ||||
} | } | ||||
pCipherConfig->val = ICP_QAT_HW_CIPHER_CONFIG_BUILD( | val = ICP_QAT_HW_CIPHER_CONFIG_BUILD( | ||||
mode, algorithm, key_convert, dir, aed_hash_cmp_length); | mode, algorithm, key_convert, dir, aed_hash_cmp_length); | ||||
/* UCS slice has 128-bit configuration register. | |||||
Leacy cipher slice has 64-bit config register */ | |||||
if (ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE == pSession->cipherSliceType) { | |||||
pUCSCipherConfig->val = val; | |||||
pUCSCipherConfig->reserved[0] = reserved; | |||||
pUCSCipherConfig->reserved[1] = 0; | |||||
pUCSCipherConfig->reserved[2] = 0; | |||||
*pSizeInBytes = sizeof(icp_qat_hw_ucs_cipher_config_t); | |||||
} else { | |||||
pCipherConfig->val = val; | |||||
pCipherConfig->reserved = reserved; | |||||
*pSizeInBytes = sizeof(icp_qat_hw_cipher_config_t); | *pSizeInBytes = sizeof(icp_qat_hw_cipher_config_t); | ||||
} | } | ||||
} | |||||
void | void | ||||
LacSymQat_CipherHwBlockPopulateKeySetup( | LacSymQat_CipherHwBlockPopulateKeySetup( | ||||
lac_session_desc_t *pSessionDesc, | |||||
const CpaCySymCipherSetupData *pCipherSetupData, | const CpaCySymCipherSetupData *pCipherSetupData, | ||||
Cpa32U targetKeyLenInBytes, | Cpa32U targetKeyLenInBytes, | ||||
Cpa32U sliceType, | |||||
const void *pCipherHwBlock, | const void *pCipherHwBlock, | ||||
Cpa32U *pSizeInBytes) | Cpa32U *pSizeInBytes) | ||||
{ | { | ||||
Cpa8U *pCipherKey = (Cpa8U *)pCipherHwBlock; | Cpa8U *pCipherKey = (Cpa8U *)pCipherHwBlock; | ||||
Cpa32U actualKeyLenInBytes = pCipherSetupData->cipherKeyLenInBytes; | Cpa32U actualKeyLenInBytes = pCipherSetupData->cipherKeyLenInBytes; | ||||
*pSizeInBytes = 0; | *pSizeInBytes = 0; | ||||
/* Key is copied into content descriptor for all cases except for | /* Key is copied into content descriptor for all cases except for | ||||
* Arc4 and Null cipher */ | * Arc4 and Null cipher */ | ||||
if (!(LAC_CIPHER_IS_ARC4(pCipherSetupData->cipherAlgorithm) || | if (!(LAC_CIPHER_IS_ARC4(pCipherSetupData->cipherAlgorithm) || | ||||
LAC_CIPHER_IS_NULL(pCipherSetupData->cipherAlgorithm))) { | LAC_CIPHER_IS_NULL(pCipherSetupData->cipherAlgorithm))) { | ||||
/* Special handling of AES 192 key for UCS slice. | |||||
UCS requires it to have 32 bytes - set is as targetKeyLen | |||||
in this case, and add padding. It makes no sense | |||||
to force applications to provide such key length for couple | |||||
reasons: | |||||
1. It won't be possible to distinguish between AES 192 and | |||||
256 based on key lenght only | |||||
2. Only some modes of AES will use UCS slice, then | |||||
application will have to know which ones */ | |||||
if (ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE == sliceType && | |||||
ICP_QAT_HW_AES_192_KEY_SZ == targetKeyLenInBytes) { | |||||
targetKeyLenInBytes = ICP_QAT_HW_UCS_AES_192_KEY_SZ; | |||||
} | |||||
/* Set the Cipher key field in the cipher block */ | /* Set the Cipher key field in the cipher block */ | ||||
memcpy(pCipherKey, | memcpy(pCipherKey, | ||||
pCipherSetupData->pCipherKey, | pCipherSetupData->pCipherKey, | ||||
actualKeyLenInBytes); | actualKeyLenInBytes); | ||||
/* Pad the key with 0's if required */ | /* Pad the key with 0's if required */ | ||||
if (0 < (targetKeyLenInBytes - actualKeyLenInBytes)) { | if (0 < (targetKeyLenInBytes - actualKeyLenInBytes)) { | ||||
LAC_OS_BZERO(pCipherKey + actualKeyLenInBytes, | LAC_OS_BZERO(pCipherKey + actualKeyLenInBytes, | ||||
targetKeyLenInBytes - actualKeyLenInBytes); | targetKeyLenInBytes - actualKeyLenInBytes); | ||||
} | } | ||||
*pSizeInBytes += targetKeyLenInBytes; | *pSizeInBytes += targetKeyLenInBytes; | ||||
switch (pCipherSetupData->cipherAlgorithm) { | |||||
/* For Kasumi in F8 mode Cipher Key is concatenated with | /* For Kasumi in F8 mode Cipher Key is concatenated with | ||||
* Cipher Key XOR-ed with Key Modifier (CK||CK^KM) */ | * Cipher Key XOR-ed with Key Modifier (CK||CK^KM) */ | ||||
if (LAC_CIPHER_IS_KASUMI(pCipherSetupData->cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_KASUMI_F8: { | ||||
Cpa32U wordIndex = 0; | Cpa32U wordIndex = 0; | ||||
Cpa32U *pu32CipherKey = | Cpa32U *pu32CipherKey = | ||||
(Cpa32U *)pCipherSetupData->pCipherKey; | (Cpa32U *)pCipherSetupData->pCipherKey; | ||||
Cpa32U *pTempKey = | Cpa32U *pTempKey = | ||||
(Cpa32U *)(pCipherKey + targetKeyLenInBytes); | (Cpa32U *)(pCipherKey + targetKeyLenInBytes); | ||||
/* XOR Key with KASUMI F8 key modifier at 4 bytes level | /* XOR Key with KASUMI F8 key modifier at 4 bytes level | ||||
*/ | */ | ||||
for (wordIndex = 0; wordIndex < | for (wordIndex = 0; wordIndex < | ||||
LAC_BYTES_TO_LONGWORDS(targetKeyLenInBytes); | LAC_BYTES_TO_LONGWORDS(targetKeyLenInBytes); | ||||
wordIndex++) { | wordIndex++) { | ||||
pTempKey[wordIndex] = pu32CipherKey[wordIndex] ^ | pTempKey[wordIndex] = pu32CipherKey[wordIndex] ^ | ||||
LAC_CIPHER_KASUMI_F8_KEY_MODIFIER_4_BYTES; | LAC_CIPHER_KASUMI_F8_KEY_MODIFIER_4_BYTES; | ||||
} | } | ||||
*pSizeInBytes += targetKeyLenInBytes; | *pSizeInBytes += targetKeyLenInBytes; | ||||
/* also add padding for F8 */ | /* also add padding for F8 */ | ||||
*pSizeInBytes += LAC_QUADWORDS_TO_BYTES( | *pSizeInBytes += LAC_QUADWORDS_TO_BYTES( | ||||
ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR); | ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR); | ||||
LAC_OS_BZERO((Cpa8U *)pTempKey + targetKeyLenInBytes, | LAC_OS_BZERO((Cpa8U *)pTempKey + targetKeyLenInBytes, | ||||
LAC_QUADWORDS_TO_BYTES( | LAC_QUADWORDS_TO_BYTES( | ||||
ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR)); | ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR)); | ||||
} | } break; | ||||
/* For AES in F8 mode Cipher Key is concatenated with | /* For AES in F8 mode Cipher Key is concatenated with | ||||
* Cipher Key XOR-ed with Key Mask (CK||CK^KM) */ | * Cipher Key XOR-ed with Key Mask (CK||CK^KM) */ | ||||
else if (LAC_CIPHER_IS_AES_F8( | case CPA_CY_SYM_CIPHER_AES_F8: { | ||||
pCipherSetupData->cipherAlgorithm)) { | |||||
Cpa32U index = 0; | Cpa32U index = 0; | ||||
Cpa8U *pTempKey = | Cpa8U *pTempKey = | ||||
pCipherKey + (targetKeyLenInBytes / 2); | pCipherKey + (targetKeyLenInBytes / 2); | ||||
*pSizeInBytes += targetKeyLenInBytes; | *pSizeInBytes += targetKeyLenInBytes; | ||||
/* XOR Key with key Mask */ | /* XOR Key with key Mask */ | ||||
for (index = 0; index < targetKeyLenInBytes; index++) { | for (index = 0; index < targetKeyLenInBytes; index++) { | ||||
pTempKey[index] = | pTempKey[index] = | ||||
pCipherKey[index] ^ pTempKey[index]; | pCipherKey[index] ^ pTempKey[index]; | ||||
} | } | ||||
pTempKey = (pCipherKey + targetKeyLenInBytes); | pTempKey = (pCipherKey + targetKeyLenInBytes); | ||||
/* also add padding for AES F8 */ | /* also add padding for AES F8 */ | ||||
*pSizeInBytes += 2 * targetKeyLenInBytes; | *pSizeInBytes += 2 * targetKeyLenInBytes; | ||||
LAC_OS_BZERO(pTempKey, 2 * targetKeyLenInBytes); | LAC_OS_BZERO(pTempKey, 2 * targetKeyLenInBytes); | ||||
} else if (LAC_CIPHER_IS_SNOW3G_UEA2( | } break; | ||||
pCipherSetupData->cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: { | ||||
/* For Snow3G zero area after the key for FW */ | /* For Snow3G zero area after the key for FW */ | ||||
LAC_OS_BZERO(pCipherKey + targetKeyLenInBytes, | LAC_OS_BZERO(pCipherKey + targetKeyLenInBytes, | ||||
ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ); | ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ); | ||||
*pSizeInBytes += ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; | *pSizeInBytes += ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; | ||||
} else if (LAC_CIPHER_IS_ZUC_EEA3( | } break; | ||||
pCipherSetupData->cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_ZUC_EEA3: { | ||||
/* For ZUC zero area after the key for FW */ | /* For ZUC zero area after the key for FW */ | ||||
LAC_OS_BZERO(pCipherKey + targetKeyLenInBytes, | LAC_OS_BZERO(pCipherKey + targetKeyLenInBytes, | ||||
ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ); | ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ); | ||||
*pSizeInBytes += ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ; | *pSizeInBytes += ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ; | ||||
} break; | |||||
case CPA_CY_SYM_CIPHER_AES_XTS: { | |||||
/* For AES in XTS mode Cipher Key is concatenated with | |||||
* second Cipher Key which is used for tweak calculation | |||||
* (CK1||CK2). For decryption Cipher Key needs to be | |||||
* converted to reverse key.*/ | |||||
if (ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE == sliceType) { | |||||
Cpa32U key_len = | |||||
pCipherSetupData->cipherKeyLenInBytes / 2; | |||||
memcpy(pSessionDesc->cipherAesXtsKey1Forward, | |||||
pCipherSetupData->pCipherKey, | |||||
key_len); | |||||
qatUtilsAESKeyExpansionForward( | |||||
pSessionDesc->cipherAesXtsKey1Forward, | |||||
key_len, | |||||
(uint32_t *) | |||||
pSessionDesc->cipherAesXtsKey1Reverse); | |||||
memcpy(pSessionDesc->cipherAesXtsKey2, | |||||
pCipherSetupData->pCipherKey + key_len, | |||||
key_len); | |||||
if (CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT == | |||||
pCipherSetupData->cipherDirection) { | |||||
memcpy(pCipherKey, | |||||
pSessionDesc | |||||
->cipherAesXtsKey1Reverse, | |||||
key_len); | |||||
} else { | |||||
memcpy(pCipherKey, | |||||
pSessionDesc | |||||
->cipherAesXtsKey1Forward, | |||||
key_len); | |||||
} | } | ||||
} | } | ||||
} break; | |||||
default: | |||||
break; | |||||
} | } | ||||
} | |||||
} | |||||
/***************************************************************************** | /***************************************************************************** | ||||
* External functions | * External functions | ||||
*****************************************************************************/ | *****************************************************************************/ | ||||
Cpa8U | Cpa8U | ||||
LacSymQat_CipherBlockSizeBytesGet(CpaCySymCipherAlgorithm cipherAlgorithm) | LacSymQat_CipherBlockSizeBytesGet(CpaCySymCipherAlgorithm cipherAlgorithm) | ||||
{ | { | ||||
if (LAC_CIPHER_IS_ARC4(cipherAlgorithm)) { | Cpa8U blockSize = 0; | ||||
return LAC_CIPHER_ARC4_BLOCK_LEN_BYTES; | switch (cipherAlgorithm) { | ||||
} else if (LAC_CIPHER_IS_AES(cipherAlgorithm) || | case CPA_CY_SYM_CIPHER_ARC4: | ||||
LAC_CIPHER_IS_AES_F8(cipherAlgorithm)) { | blockSize = LAC_CIPHER_ARC4_BLOCK_LEN_BYTES; | ||||
return ICP_QAT_HW_AES_BLK_SZ; | break; | ||||
} else if (LAC_CIPHER_IS_DES(cipherAlgorithm)) { | /* Handle AES or AES_F8 */ | ||||
return ICP_QAT_HW_DES_BLK_SZ; | case CPA_CY_SYM_CIPHER_AES_ECB: | ||||
} else if (LAC_CIPHER_IS_TRIPLE_DES(cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_AES_CBC: | ||||
return ICP_QAT_HW_3DES_BLK_SZ; | case CPA_CY_SYM_CIPHER_AES_CTR: | ||||
} else if (LAC_CIPHER_IS_KASUMI(cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_AES_CCM: | ||||
return ICP_QAT_HW_KASUMI_BLK_SZ; | case CPA_CY_SYM_CIPHER_AES_GCM: | ||||
} else if (LAC_CIPHER_IS_SNOW3G_UEA2(cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_AES_XTS: | ||||
return ICP_QAT_HW_SNOW_3G_BLK_SZ; | case CPA_CY_SYM_CIPHER_AES_F8: | ||||
} else if (LAC_CIPHER_IS_ZUC_EEA3(cipherAlgorithm)) { | blockSize = ICP_QAT_HW_AES_BLK_SZ; | ||||
return ICP_QAT_HW_ZUC_3G_BLK_SZ; | break; | ||||
} else if (LAC_CIPHER_IS_NULL(cipherAlgorithm)) { | /* Handle DES */ | ||||
return LAC_CIPHER_NULL_BLOCK_LEN_BYTES; | case CPA_CY_SYM_CIPHER_DES_ECB: | ||||
} else if (LAC_CIPHER_IS_CHACHA(cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_DES_CBC: | ||||
return ICP_QAT_HW_CHACHAPOLY_BLK_SZ; | blockSize = ICP_QAT_HW_DES_BLK_SZ; | ||||
} else if (LAC_CIPHER_IS_SM4(cipherAlgorithm)) { | break; | ||||
return ICP_QAT_HW_SM4_BLK_SZ; | /* Handle TRIPLE DES */ | ||||
} else { | case CPA_CY_SYM_CIPHER_3DES_ECB: | ||||
QAT_UTILS_LOG("Algorithm not supported in Cipher\n"); | case CPA_CY_SYM_CIPHER_3DES_CBC: | ||||
return 0; | case CPA_CY_SYM_CIPHER_3DES_CTR: | ||||
blockSize = ICP_QAT_HW_3DES_BLK_SZ; | |||||
break; | |||||
case CPA_CY_SYM_CIPHER_KASUMI_F8: | |||||
blockSize = ICP_QAT_HW_KASUMI_BLK_SZ; | |||||
break; | |||||
case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: | |||||
blockSize = ICP_QAT_HW_SNOW_3G_BLK_SZ; | |||||
break; | |||||
case CPA_CY_SYM_CIPHER_ZUC_EEA3: | |||||
blockSize = ICP_QAT_HW_ZUC_3G_BLK_SZ; | |||||
break; | |||||
case CPA_CY_SYM_CIPHER_NULL: | |||||
blockSize = LAC_CIPHER_NULL_BLOCK_LEN_BYTES; | |||||
break; | |||||
case CPA_CY_SYM_CIPHER_CHACHA: | |||||
blockSize = ICP_QAT_HW_CHACHAPOLY_BLK_SZ; | |||||
break; | |||||
case CPA_CY_SYM_CIPHER_SM4_ECB: | |||||
case CPA_CY_SYM_CIPHER_SM4_CBC: | |||||
case CPA_CY_SYM_CIPHER_SM4_CTR: | |||||
blockSize = ICP_QAT_HW_SM4_BLK_SZ; | |||||
break; | |||||
default: | |||||
QAT_UTILS_LOG("Algorithm not supported in Cipher"); | |||||
} | } | ||||
return blockSize; | |||||
} | } | ||||
Cpa32U | Cpa32U | ||||
LacSymQat_CipherIvSizeBytesGet(CpaCySymCipherAlgorithm cipherAlgorithm) | LacSymQat_CipherIvSizeBytesGet(CpaCySymCipherAlgorithm cipherAlgorithm) | ||||
{ | { | ||||
if (CPA_CY_SYM_CIPHER_ARC4 == cipherAlgorithm) { | Cpa32U ivSize = 0; | ||||
return LAC_CIPHER_ARC4_STATE_LEN_BYTES; | switch (cipherAlgorithm) { | ||||
} else if (LAC_CIPHER_IS_KASUMI(cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_ARC4: | ||||
return ICP_QAT_HW_KASUMI_BLK_SZ; | ivSize = LAC_CIPHER_ARC4_STATE_LEN_BYTES; | ||||
} else if (LAC_CIPHER_IS_SNOW3G_UEA2(cipherAlgorithm)) { | break; | ||||
return ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; | case CPA_CY_SYM_CIPHER_KASUMI_F8: | ||||
} else if (LAC_CIPHER_IS_ZUC_EEA3(cipherAlgorithm)) { | ivSize = ICP_QAT_HW_KASUMI_BLK_SZ; | ||||
return ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ; | break; | ||||
} else if (LAC_CIPHER_IS_CHACHA(cipherAlgorithm)) { | case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: | ||||
return ICP_QAT_HW_CHACHAPOLY_IV_SZ; | ivSize = ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; | ||||
} else if (LAC_CIPHER_IS_ECB_MODE(cipherAlgorithm)) { | break; | ||||
return 0; | case CPA_CY_SYM_CIPHER_ZUC_EEA3: | ||||
} else { | ivSize = ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ; | ||||
return (Cpa32U)LacSymQat_CipherBlockSizeBytesGet( | break; | ||||
cipherAlgorithm); | case CPA_CY_SYM_CIPHER_CHACHA: | ||||
ivSize = ICP_QAT_HW_CHACHAPOLY_IV_SZ; | |||||
break; | |||||
case CPA_CY_SYM_CIPHER_AES_ECB: | |||||
case CPA_CY_SYM_CIPHER_DES_ECB: | |||||
case CPA_CY_SYM_CIPHER_3DES_ECB: | |||||
case CPA_CY_SYM_CIPHER_SM4_ECB: | |||||
case CPA_CY_SYM_CIPHER_NULL: | |||||
/* for all ECB Mode IV size is 0 */ | |||||
break; | |||||
default: | |||||
ivSize = LacSymQat_CipherBlockSizeBytesGet(cipherAlgorithm); | |||||
} | } | ||||
return ivSize; | |||||
} | } | ||||
inline CpaStatus | inline CpaStatus | ||||
LacSymQat_CipherRequestParamsPopulate(icp_qat_fw_la_bulk_req_t *pReq, | LacSymQat_CipherRequestParamsPopulate(lac_session_desc_t *pSessionDesc, | ||||
icp_qat_fw_la_bulk_req_t *pReq, | |||||
Cpa32U cipherOffsetInBytes, | Cpa32U cipherOffsetInBytes, | ||||
Cpa32U cipherLenInBytes, | Cpa32U cipherLenInBytes, | ||||
Cpa64U ivBufferPhysAddr, | Cpa64U ivBufferPhysAddr, | ||||
Cpa8U *pIvBufferVirt) | Cpa8U *pIvBufferVirt) | ||||
{ | { | ||||
icp_qat_fw_la_cipher_req_params_t *pCipherReqParams; | icp_qat_fw_la_cipher_req_params_t *pCipherReqParams; | ||||
icp_qat_fw_cipher_cd_ctrl_hdr_t *pCipherCdCtrlHdr; | icp_qat_fw_cipher_cd_ctrl_hdr_t *pCipherCdCtrlHdr; | ||||
icp_qat_fw_serv_specif_flags *pCipherSpecificFlags; | icp_qat_fw_serv_specif_flags *pCipherSpecificFlags; | ||||
Cpa32U usedBufSize = 0; | |||||
Cpa32U totalBufSize = 0; | |||||
pCipherReqParams = (icp_qat_fw_la_cipher_req_params_t | pCipherReqParams = (icp_qat_fw_la_cipher_req_params_t | ||||
*)((Cpa8U *)&(pReq->serv_specif_rqpars) + | *)((Cpa8U *)&(pReq->serv_specif_rqpars) + | ||||
ICP_QAT_FW_CIPHER_REQUEST_PARAMETERS_OFFSET); | ICP_QAT_FW_CIPHER_REQUEST_PARAMETERS_OFFSET); | ||||
pCipherCdCtrlHdr = (icp_qat_fw_cipher_cd_ctrl_hdr_t *)&(pReq->cd_ctrl); | pCipherCdCtrlHdr = (icp_qat_fw_cipher_cd_ctrl_hdr_t *)&(pReq->cd_ctrl); | ||||
pCipherSpecificFlags = &(pReq->comn_hdr.serv_specif_flags); | pCipherSpecificFlags = &(pReq->comn_hdr.serv_specif_flags); | ||||
pCipherReqParams->cipher_offset = cipherOffsetInBytes; | pCipherReqParams->cipher_offset = cipherOffsetInBytes; | ||||
Show All 16 Lines | if ((pCipherCdCtrlHdr->cipher_state_sz > | ||||
pCipherReqParams->u.s.cipher_IV_ptr = ivBufferPhysAddr; | pCipherReqParams->u.s.cipher_IV_ptr = ivBufferPhysAddr; | ||||
pCipherReqParams->u.s.resrvd1 = 0; | pCipherReqParams->u.s.resrvd1 = 0; | ||||
/* Set the flag indicating the field format */ | /* Set the flag indicating the field format */ | ||||
ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET( | ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET( | ||||
*pCipherSpecificFlags, ICP_QAT_FW_CIPH_IV_64BIT_PTR); | *pCipherSpecificFlags, ICP_QAT_FW_CIPH_IV_64BIT_PTR); | ||||
} else { | } else { | ||||
/* Populate the field with the contents of the buffer, | /* Populate the field with the contents of the buffer, | ||||
* zero field first as data may be smaller than the field */ | * zero field first as data may be smaller than the field */ | ||||
/* In case of XTS mode using UCS slice always embedd IV. | |||||
* IV provided by user needs to be encrypted to calculate | |||||
* initial tweak, use pCipherReqParams->u.cipher_IV_array as | |||||
* destination buffer for tweak value */ | |||||
if (ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE == | |||||
pSessionDesc->cipherSliceType && | |||||
LAC_CIPHER_IS_XTS_MODE(pSessionDesc->cipherAlgorithm)) { | |||||
memset(pCipherReqParams->u.cipher_IV_array, | memset(pCipherReqParams->u.cipher_IV_array, | ||||
0, | 0, | ||||
LAC_LONGWORDS_TO_BYTES(ICP_QAT_FW_NUM_LONGWORDS_4)); | LAC_LONGWORDS_TO_BYTES( | ||||
ICP_QAT_FW_NUM_LONGWORDS_4)); | |||||
/* We force a specific compiler optimisation here. The length | qatUtilsAESEncrypt( | ||||
* to | pSessionDesc->cipherAesXtsKey2, | ||||
* be copied turns out to be always 16, and by coding a memcpy | pSessionDesc->cipherKeyLenInBytes / 2, | ||||
* with | |||||
* a literal value the compiler will compile inline code (in | |||||
* fact, | |||||
* only two vector instructions) to effect the copy. This gives | |||||
* us | |||||
* a huge performance increase. | |||||
*/ | |||||
unsigned long cplen = | |||||
LAC_QUADWORDS_TO_BYTES(pCipherCdCtrlHdr->cipher_state_sz); | |||||
if (cplen == 16) | |||||
memcpy(pCipherReqParams->u.cipher_IV_array, | |||||
pIvBufferVirt, | pIvBufferVirt, | ||||
16); | (Cpa8U *)pCipherReqParams->u.cipher_IV_array); | ||||
else | } else { | ||||
totalBufSize = | |||||
LAC_LONGWORDS_TO_BYTES(ICP_QAT_FW_NUM_LONGWORDS_4); | |||||
usedBufSize = LAC_QUADWORDS_TO_BYTES( | |||||
pCipherCdCtrlHdr->cipher_state_sz); | |||||
/* Only initialise unused buffer if applicable*/ | |||||
if (usedBufSize < totalBufSize) { | |||||
memset( | |||||
(&pCipherReqParams->u.cipher_IV_array | |||||
[usedBufSize & LAC_UNUSED_POS_MASK]), | |||||
0, | |||||
totalBufSize - usedBufSize); | |||||
} | |||||
memcpy(pCipherReqParams->u.cipher_IV_array, | memcpy(pCipherReqParams->u.cipher_IV_array, | ||||
pIvBufferVirt, | pIvBufferVirt, | ||||
cplen); | usedBufSize); | ||||
} | |||||
/* Set the flag indicating the field format */ | /* Set the flag indicating the field format */ | ||||
ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET( | ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET( | ||||
*pCipherSpecificFlags, ICP_QAT_FW_CIPH_IV_16BYTE_DATA); | *pCipherSpecificFlags, ICP_QAT_FW_CIPH_IV_16BYTE_DATA); | ||||
} | } | ||||
return CPA_STATUS_SUCCESS; | return CPA_STATUS_SUCCESS; | ||||
} | } | ||||
void | void | ||||
LacSymQat_CipherArc4StateInit(const Cpa8U *pKey, | LacSymQat_CipherArc4StateInit(const Cpa8U *pKey, | ||||
Cpa32U keyLenInBytes, | Cpa32U keyLenInBytes, | ||||
Cpa8U *pArc4CipherState) | Cpa8U *pArc4CipherState) | ||||
{ | { | ||||
Cpa32U i = 0; | Cpa32U i = 0; | ||||
Cpa32U j = 0; | Cpa32U j = 0; | ||||
Cpa32U k = 0; | Cpa32U k = 0; | ||||
for (i = 0; i < LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES; ++i) { | for (i = 0; i < LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES; ++i) { | ||||
pArc4CipherState[i] = (Cpa8U)i; | pArc4CipherState[i] = (Cpa8U)i; | ||||
} | } | ||||
for (i = 0; i < LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES; ++i) { | for (i = 0, k = 0; i < LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES; ++i, ++k) { | ||||
Cpa8U swap = 0; | Cpa8U swap = 0; | ||||
if (k >= keyLenInBytes) | if (k >= keyLenInBytes) | ||||
k -= keyLenInBytes; | k -= keyLenInBytes; | ||||
j = (j + pArc4CipherState[i] + pKey[k]); | j = (j + pArc4CipherState[i] + pKey[k]); | ||||
if (j >= LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES) | if (j >= LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES) | ||||
j %= LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES; | j %= LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES; | ||||
++k; | |||||
/* Swap state[i] & state[j] */ | /* Swap state[i] & state[j] */ | ||||
swap = pArc4CipherState[i]; | swap = pArc4CipherState[i]; | ||||
pArc4CipherState[i] = pArc4CipherState[j]; | pArc4CipherState[i] = pArc4CipherState[j]; | ||||
pArc4CipherState[j] = swap; | pArc4CipherState[j] = swap; | ||||
} | } | ||||
/* Initialise i & j values for QAT */ | /* Initialise i & j values for QAT */ | ||||
Show All 18 Lines |