@@ -148,8 +148,6 @@ struct odp_crypto_generic_session_t {
struct {
uint8_t key[EVP_MAX_KEY_LENGTH];
uint8_t iv_data[EVP_MAX_IV_LENGTH];
- uint32_t key_length;
- uint32_t bytes;
union {
const EVP_MD *evp_md;
const EVP_CIPHER *evp_cipher;
@@ -202,13 +200,30 @@ null_crypto_routine(odp_packet_t pkt ODP_UNUSED,
return ODP_CRYPTO_ALG_ERR_NONE;
}
+/* Mimic new OpenSSL 1.1.y API */
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+static HMAC_CTX *HMAC_CTX_new(void)
+{
+ HMAC_CTX *ctx = malloc(sizeof(*ctx));
+
+ HMAC_CTX_init(ctx);
+ return ctx;
+}
+
+static void HMAC_CTX_free(HMAC_CTX *ctx)
+{
+ HMAC_CTX_cleanup(ctx);
+ free(ctx);
+}
+#endif
+
static
-void packet_hmac_calculate(HMAC_CTX *ctx,
- odp_packet_t pkt,
- const odp_crypto_packet_op_param_t *param,
- odp_crypto_generic_session_t *session,
- uint8_t *hash)
+void packet_hmac(odp_packet_t pkt,
+ const odp_crypto_packet_op_param_t *param,
+ odp_crypto_generic_session_t *session,
+ uint8_t *hash)
{
+ HMAC_CTX *ctx = HMAC_CTX_new();
uint32_t offset = param->auth_range.offset;
uint32_t len = param->auth_range.length;
@@ -216,7 +231,7 @@ void packet_hmac_calculate(HMAC_CTX *ctx,
HMAC_Init_ex(ctx,
session->auth.key,
- session->auth.key_length,
+ session->p.auth_key.length,
session->auth.evp_md,
NULL);
@@ -231,42 +246,13 @@ void packet_hmac_calculate(HMAC_CTX *ctx,
}
HMAC_Final(ctx, hash, NULL);
-}
-
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
-static
-void packet_hmac(odp_packet_t pkt,
- const odp_crypto_packet_op_param_t *param,
- odp_crypto_generic_session_t *session,
- uint8_t *hash)
-{
- HMAC_CTX ctx;
-
- /* Hash it */
- HMAC_CTX_init(&ctx);
- packet_hmac_calculate(&ctx, pkt, param, session, hash);
- HMAC_CTX_cleanup(&ctx);
-}
-#else
-static
-void packet_hmac(odp_packet_t pkt,
- const odp_crypto_packet_op_param_t *param,
- odp_crypto_generic_session_t *session,
- uint8_t *hash)
-{
- HMAC_CTX *ctx;
-
- /* Hash it */
- ctx = HMAC_CTX_new();
- packet_hmac_calculate(ctx, pkt, param, session, hash);
HMAC_CTX_free(ctx);
}
-#endif
static
-odp_crypto_alg_err_t auth_gen(odp_packet_t pkt,
- const odp_crypto_packet_op_param_t *param,
- odp_crypto_generic_session_t *session)
+odp_crypto_alg_err_t auth_hmac_gen(odp_packet_t pkt,
+ const odp_crypto_packet_op_param_t *param,
+ odp_crypto_generic_session_t *session)
{
uint8_t hash[EVP_MAX_MD_SIZE];
@@ -283,9 +269,9 @@ odp_crypto_alg_err_t auth_gen(odp_packet_t pkt,
}
static
-odp_crypto_alg_err_t auth_check(odp_packet_t pkt,
- const odp_crypto_packet_op_param_t *param,
- odp_crypto_generic_session_t *session)
+odp_crypto_alg_err_t auth_hmac_check(odp_packet_t pkt,
+ const odp_crypto_packet_op_param_t *param,
+ odp_crypto_generic_session_t *session)
{
uint32_t bytes = session->p.auth_digest_len;
uint8_t hash_in[EVP_MAX_MD_SIZE];
@@ -907,15 +893,14 @@ static int process_aes_ccm_param(odp_crypto_generic_session_t *session,
return 0;
}
-static int process_auth_param(odp_crypto_generic_session_t *session,
- uint32_t key_length,
- const EVP_MD *evp_md)
+static int process_auth_hmac_param(odp_crypto_generic_session_t *session,
+ const EVP_MD *evp_md)
{
/* Set function */
if (ODP_CRYPTO_OP_ENCODE == session->p.op)
- session->auth.func = auth_gen;
+ session->auth.func = auth_hmac_gen;
else
- session->auth.func = auth_check;
+ session->auth.func = auth_hmac_check;
session->auth.evp_md = evp_md;
@@ -924,9 +909,8 @@ static int process_auth_param(odp_crypto_generic_session_t *session,
return -1;
/* Convert keys */
- session->auth.key_length = key_length;
memcpy(session->auth.key, session->p.auth_key.data,
- session->auth.key_length);
+ session->p.auth_key.length);
return 0;
}
@@ -1245,10 +1229,10 @@ odp_crypto_session_create(odp_crypto_session_param_t *param,
#endif
/* Fallthrough */
case ODP_AUTH_ALG_MD5_HMAC:
- rc = process_auth_param(session, 16, EVP_md5());
+ rc = process_auth_hmac_param(session, EVP_md5());
break;
case ODP_AUTH_ALG_SHA1_HMAC:
- rc = process_auth_param(session, 20, EVP_sha1());
+ rc = process_auth_hmac_param(session, EVP_sha1());
break;
#if ODP_DEPRECATED_API
case ODP_AUTH_ALG_SHA256_128:
@@ -1257,10 +1241,10 @@ odp_crypto_session_create(odp_crypto_session_param_t *param,
#endif
/* Fallthrough */
case ODP_AUTH_ALG_SHA256_HMAC:
- rc = process_auth_param(session, 32, EVP_sha256());
+ rc = process_auth_hmac_param(session, EVP_sha256());
break;
case ODP_AUTH_ALG_SHA512_HMAC:
- rc = process_auth_param(session, 64, EVP_sha512());
+ rc = process_auth_hmac_param(session, EVP_sha512());
break;
#if ODP_DEPRECATED_API
case ODP_AUTH_ALG_AES128_GCM: