-
Notifications
You must be signed in to change notification settings - Fork 139
[PATCH API-NEXT v1] api: crypto: deprecate per-session IV #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,14 +234,14 @@ typedef struct odp_crypto_key { | |
| /** | ||
| * Crypto API IV structure | ||
| */ | ||
| typedef struct odp_crypto_iv { | ||
| typedef struct ODP_DEPRECATE(odp_crypto_iv) { | ||
| /** IV data */ | ||
| uint8_t *data; | ||
|
|
||
| /** IV length in bytes */ | ||
| uint32_t length; | ||
|
|
||
| } odp_crypto_iv_t; | ||
| } ODP_DEPRECATE(odp_crypto_iv_t); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is really a bug correction, perhaps this should just be removed without deprecation? Why would anyone want to retain the incorrect behavior "for compatibility"?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Bill-Fischofer-Linaro I would like to hear a word from other parties. This bug might be local to linux-generic. And there might be use cases for the IV specified at session creation time (e.g. if packets should be encrypted in one continuous stream).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During today's ARCH call this was discussed briefly and Nikhil pointed out that per-session IVs are useful for many cases, so deprecation may be premature, especially as we already permit per-packet IV overrides. We can continue this discussion on Monday's ARCH call if the mailing list can't reach resolution before then. |
||
|
|
||
| /** | ||
| * Crypto API data range specifier | ||
|
|
@@ -285,8 +285,11 @@ typedef struct odp_crypto_session_param_t { | |
| */ | ||
| odp_crypto_key_t cipher_key; | ||
|
|
||
| /** Cipher Initialization Vector (IV) */ | ||
| odp_crypto_iv_t iv; | ||
| /** @deprecated use iv_length and per-packet IV instead */ | ||
| ODP_DEPRECATE(odp_crypto_iv_t) ODP_DEPRECATE(iv); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not clear why checkpatch gets confused here. It seems to think this is a cast of some sort. Another reason perhaps to simply correct this issue without deprecation. |
||
|
|
||
| /** Cipher Initialization Vector (IV) length */ | ||
| uint32_t iv_length; | ||
|
|
||
| /** Authentication algorithm | ||
| * | ||
|
|
@@ -359,8 +362,11 @@ typedef struct odp_crypto_op_param_t { | |
| */ | ||
| odp_packet_t out_pkt; | ||
|
|
||
| /** Override session IV pointer */ | ||
| uint8_t *override_iv_ptr; | ||
| /** @deprecated use iv_ptr instead */ | ||
| uint8_t *ODP_DEPRECATE(override_iv_ptr); | ||
|
|
||
| /** IV pointer */ | ||
| uint8_t *iv_ptr; | ||
|
|
||
| /** Offset from start of packet for hash result | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
| #ifndef ODP_CRYPTO_INTERNAL_H_ | ||
| #define ODP_CRYPTO_INTERNAL_H_ | ||
|
|
||
| #include <odp/api/deprecated.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
@@ -40,8 +42,10 @@ struct odp_crypto_generic_session { | |
| odp_bool_t do_cipher_first; | ||
|
|
||
| struct { | ||
| #if ODP_DEPRECATED_API | ||
| /* Copy of session IV data */ | ||
| uint8_t iv_data[MAX_IV_LEN]; | ||
| #endif | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needing an #ifdef looks ugly here and elsewhere in this series. Better to correct the code than retain "compatibility" here. |
||
|
|
||
| union { | ||
| struct { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,10 +184,14 @@ odp_crypto_alg_err_t aes_encrypt(odp_crypto_op_param_t *param, | |
| unsigned char iv_enc[AES_BLOCK_SIZE]; | ||
| void *iv_ptr; | ||
|
|
||
| if (param->override_iv_ptr) | ||
| if (param->iv_ptr) | ||
| iv_ptr = param->iv_ptr; | ||
| #if ODP_DEPRECATED_API | ||
| else if (param->override_iv_ptr) | ||
| iv_ptr = param->override_iv_ptr; | ||
| else if (session->p.iv.data) | ||
| iv_ptr = session->cipher.iv_data; | ||
| #endif | ||
| else | ||
| return ODP_CRYPTO_ALG_ERR_IV_INVALID; | ||
|
|
||
|
|
@@ -216,10 +220,14 @@ odp_crypto_alg_err_t aes_decrypt(odp_crypto_op_param_t *param, | |
| unsigned char iv_enc[AES_BLOCK_SIZE]; | ||
| void *iv_ptr; | ||
|
|
||
| if (param->override_iv_ptr) | ||
| if (param->iv_ptr) | ||
| iv_ptr = param->iv_ptr; | ||
| #if ODP_DEPRECATED_API | ||
| else if (param->override_iv_ptr) | ||
| iv_ptr = param->override_iv_ptr; | ||
| else if (session->p.iv.data) | ||
| iv_ptr = session->cipher.iv_data; | ||
| #endif | ||
| else | ||
| return ODP_CRYPTO_ALG_ERR_IV_INVALID; | ||
|
|
||
|
|
@@ -241,9 +249,14 @@ odp_crypto_alg_err_t aes_decrypt(odp_crypto_op_param_t *param, | |
|
|
||
| static int process_aes_param(odp_crypto_generic_session_t *session) | ||
| { | ||
| /* Verify IV len is either 0 or 16 */ | ||
| if (!((0 == session->p.iv.length) || (16 == session->p.iv.length))) | ||
| /* Verify IV len is 16 */ | ||
| #if ODP_DEPRECATED_API | ||
| if (!((16 == session->p.iv_length) || (16 == session->p.iv.length))) | ||
| return -1; | ||
| #else | ||
| if (16 != session->p.iv_length) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment above got deleted. Magic numbers should either be enums or at least retain a comment explaining their use/significance. |
||
| return -1; | ||
| #endif | ||
|
|
||
| /* Set function */ | ||
| if (ODP_CRYPTO_OP_ENCODE == session->p.op) { | ||
|
|
@@ -273,10 +286,14 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, | |
| void *iv_ptr; | ||
| uint8_t *tag = data + param->hash_result_offset; | ||
|
|
||
| if (param->override_iv_ptr) | ||
| if (param->iv_ptr) | ||
| iv_ptr = param->iv_ptr; | ||
| #if ODP_DEPRECATED_API | ||
| else if (param->override_iv_ptr) | ||
| iv_ptr = param->override_iv_ptr; | ||
| else if (session->p.iv.data) | ||
| iv_ptr = session->cipher.iv_data; | ||
| #endif | ||
| else | ||
| return ODP_CRYPTO_ALG_ERR_IV_INVALID; | ||
|
|
||
|
|
@@ -338,10 +355,14 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, | |
| void *iv_ptr; | ||
| uint8_t *tag = data + param->hash_result_offset; | ||
|
|
||
| if (param->override_iv_ptr) | ||
| if (param->iv_ptr) | ||
| iv_ptr = param->iv_ptr; | ||
| #if ODP_DEPRECATED_API | ||
| else if (param->override_iv_ptr) | ||
| iv_ptr = param->override_iv_ptr; | ||
| else if (session->p.iv.data) | ||
| iv_ptr = session->cipher.iv_data; | ||
| #endif | ||
| else | ||
| return ODP_CRYPTO_ALG_ERR_IV_INVALID; | ||
|
|
||
|
|
@@ -392,6 +413,13 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, | |
|
|
||
| static int process_aes_gcm_param(odp_crypto_generic_session_t *session) | ||
| { | ||
| uint32_t iv_length = session->p.iv_length; | ||
|
|
||
| #if ODP_DEPRECATED_API | ||
| if (0 != session->p.iv.length) | ||
| iv_length = session->p.iv.length; | ||
| #endif | ||
|
|
||
| /* Verify Key len is 16 */ | ||
| if (session->p.cipher_key.length != 16) | ||
| return -1; | ||
|
|
@@ -409,7 +437,7 @@ static int process_aes_gcm_param(odp_crypto_generic_session_t *session) | |
| } | ||
|
|
||
| EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, | ||
| session->p.iv.length, NULL); | ||
| iv_length, NULL); | ||
| if (ODP_CRYPTO_OP_ENCODE == session->p.op) { | ||
| EVP_EncryptInit_ex(ctx, NULL, NULL, | ||
| session->p.cipher_key.data, NULL); | ||
|
|
@@ -430,10 +458,14 @@ odp_crypto_alg_err_t des_encrypt(odp_crypto_op_param_t *param, | |
| DES_cblock iv; | ||
| void *iv_ptr; | ||
|
|
||
| if (param->override_iv_ptr) | ||
| if (param->iv_ptr) | ||
| iv_ptr = param->iv_ptr; | ||
| #if ODP_DEPRECATED_API | ||
| else if (param->override_iv_ptr) | ||
| iv_ptr = param->override_iv_ptr; | ||
| else if (session->p.iv.data) | ||
| iv_ptr = session->cipher.iv_data; | ||
| #endif | ||
| else | ||
| return ODP_CRYPTO_ALG_ERR_IV_INVALID; | ||
|
|
||
|
|
@@ -468,10 +500,14 @@ odp_crypto_alg_err_t des_decrypt(odp_crypto_op_param_t *param, | |
| DES_cblock iv; | ||
| void *iv_ptr; | ||
|
|
||
| if (param->override_iv_ptr) | ||
| if (param->iv_ptr) | ||
| iv_ptr = param->iv_ptr; | ||
| #if ODP_DEPRECATED_API | ||
| else if (param->override_iv_ptr) | ||
| iv_ptr = param->override_iv_ptr; | ||
| else if (session->p.iv.data) | ||
| iv_ptr = session->cipher.iv_data; | ||
| #endif | ||
| else | ||
| return ODP_CRYPTO_ALG_ERR_IV_INVALID; | ||
|
|
||
|
|
@@ -500,9 +536,14 @@ odp_crypto_alg_err_t des_decrypt(odp_crypto_op_param_t *param, | |
|
|
||
| static int process_des_param(odp_crypto_generic_session_t *session) | ||
| { | ||
| /* Verify IV len is either 0 or 8 */ | ||
| if (!((0 == session->p.iv.length) || (8 == session->p.iv.length))) | ||
| /* Verify IV len is 8 */ | ||
| #if ODP_DEPRECATED_API | ||
| if (!((8 == session->p.iv_length) || (8 == session->p.iv.length))) | ||
| return -1; | ||
| #else | ||
| if (8 != session->p.iv_length) | ||
| return -1; | ||
| #endif | ||
|
|
||
| /* Set function */ | ||
| if (ODP_CRYPTO_OP_ENCODE == session->p.op) | ||
|
|
@@ -679,6 +720,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, | |
| session->p = *param; | ||
|
|
||
| /* Copy IV data */ | ||
| #if ODP_DEPRECATED_API | ||
| if (session->p.iv.data) { | ||
| if (session->p.iv.length > MAX_IV_LEN) { | ||
| ODP_DBG("Maximum IV length exceeded\n"); | ||
|
|
@@ -689,6 +731,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, | |
| memcpy(session->cipher.iv_data, session->p.iv.data, | ||
| session->p.iv.length); | ||
| } | ||
| #endif | ||
|
|
||
| /* Derive order */ | ||
| if (ODP_CRYPTO_OP_ENCODE == param->op) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use enum here: ODP_RANDOM_CRYPTO