aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalakrishna Garapati <balakrishna.garapati@linaro.org>2017-07-13 07:55:57 +0200
committerBalakrishna Garapati <balakrishna.garapati@linaro.org>2017-07-26 08:42:38 +0200
commitc2c3ed55057e1a8032da4cff3ef0b61d38b33d58 (patch)
tree352355b176993600ad840f612b854e981213b58b
parentd0eb8f2e9610cd61131f9e2e9e3f78ca68c8706f (diff)
downloadodp-dpdk-c2c3ed55057e1a8032da4cff3ef0b61d38b33d58.tar.gz
linux-dpdk:porting "update AES-GCM support to reflect aad and auth_digest_len"
Signed-off-by: Balakrishna Garapati <balakrishna.garapati@linaro.org> Reviewed-and-tested-by: Matias Elo <matias.elo@nokia.com>
-rw-r--r--platform/linux-dpdk/odp_crypto.c113
1 files changed, 57 insertions, 56 deletions
diff --git a/platform/linux-dpdk/odp_crypto.c b/platform/linux-dpdk/odp_crypto.c
index 9533d18b..443314a3 100644
--- a/platform/linux-dpdk/odp_crypto.c
+++ b/platform/linux-dpdk/odp_crypto.c
@@ -156,8 +156,10 @@ static crypto_session_entry_t *alloc_session(void)
odp_spinlock_lock(&global->lock);
session = global->free;
- if (session)
+ if (session) {
global->free = session->next;
+ session->next = NULL;
+ }
odp_spinlock_unlock(&global->lock);
return session;
@@ -755,7 +757,7 @@ static int get_crypto_dev(struct rte_crypto_sym_xform *cipher_xform,
return -1;
}
-int odp_crypto_session_create(odp_crypto_session_params_t *params,
+int odp_crypto_session_create(odp_crypto_session_param_t *param,
odp_crypto_session_t *session_out,
odp_crypto_ses_create_err_t *status)
{
@@ -786,7 +788,7 @@ int odp_crypto_session_create(odp_crypto_session_params_t *params,
/* Cipher Data */
cipher_xform.cipher.key.data = rte_malloc("crypto key",
- params->cipher_key.length, 0);
+ param->cipher_key.length, 0);
if (cipher_xform.cipher.key.data == NULL) {
ODP_ERR("Failed to allocate memory for cipher key\n");
/* remove the crypto_session_entry_t */
@@ -797,14 +799,14 @@ int odp_crypto_session_create(odp_crypto_session_params_t *params,
cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
cipher_xform.next = NULL;
- cipher_xform.cipher.key.length = params->cipher_key.length;
+ cipher_xform.cipher.key.length = param->cipher_key.length;
memcpy(cipher_xform.cipher.key.data,
- params->cipher_key.data,
- params->cipher_key.length);
+ param->cipher_key.data,
+ param->cipher_key.length);
/* Authentication Data */
auth_xform.auth.key.data = rte_malloc("auth key",
- params->auth_key.length, 0);
+ param->auth_key.length, 0);
if (auth_xform.auth.key.data == NULL) {
ODP_ERR("Failed to allocate memory for auth key\n");
/* remove the crypto_session_entry_t */
@@ -814,16 +816,16 @@ int odp_crypto_session_create(odp_crypto_session_params_t *params,
}
auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
auth_xform.next = NULL;
- auth_xform.auth.key.length = params->auth_key.length;
+ auth_xform.auth.key.length = param->auth_key.length;
memcpy(auth_xform.auth.key.data,
- params->auth_key.data,
- params->auth_key.length);
+ param->auth_key.data,
+ param->auth_key.length);
/* Derive order */
- if (ODP_CRYPTO_OP_ENCODE == params->op)
- entry->do_cipher_first = params->auth_cipher_text;
+ if (ODP_CRYPTO_OP_ENCODE == param->op)
+ entry->do_cipher_first = param->auth_cipher_text;
else
- entry->do_cipher_first = !params->auth_cipher_text;
+ entry->do_cipher_first = !param->auth_cipher_text;
/* Process based on cipher */
/* Derive order */
@@ -839,7 +841,7 @@ int odp_crypto_session_create(odp_crypto_session_params_t *params,
first_xform->next = &cipher_xform;
}
- rc = cipher_alg_odp_to_rte(params->cipher_alg, &cipher_xform);
+ rc = cipher_alg_odp_to_rte(param->cipher_alg, &cipher_xform);
/* Check result */
if (rc) {
@@ -847,7 +849,7 @@ int odp_crypto_session_create(odp_crypto_session_params_t *params,
return -1;
}
- rc = auth_alg_odp_to_rte(params->auth_alg, &auth_xform);
+ rc = auth_alg_odp_to_rte(param->auth_alg, &auth_xform);
/* Check result */
if (rc) {
@@ -860,7 +862,7 @@ int odp_crypto_session_create(odp_crypto_session_params_t *params,
rc = get_crypto_dev(&cipher_xform,
&auth_xform,
- params->iv.length,
+ param->iv.length,
&cdev_id);
if (rc) {
@@ -883,10 +885,10 @@ int odp_crypto_session_create(odp_crypto_session_params_t *params,
entry->rte_session = (intptr_t)session;
entry->cipher_xform = cipher_xform;
entry->auth_xform = auth_xform;
- entry->iv.length = params->iv.length;
- entry->iv.data = params->iv.data;
- entry->output_pool = params->output_pool;
- entry->compl_queue = params->compl_queue;
+ entry->iv.length = param->iv.length;
+ entry->iv.data = param->iv.data;
+ entry->output_pool = param->output_pool;
+ entry->compl_queue = param->compl_queue;
/* We're happy */
*session_out = (intptr_t)entry;
@@ -918,7 +920,7 @@ int odp_crypto_session_destroy(odp_crypto_session_t session)
return 0;
}
-int odp_crypto_operation(odp_crypto_op_params_t *params,
+int odp_crypto_operation(odp_crypto_op_param_t *param,
odp_bool_t *posted,
odp_crypto_op_result_t *result)
{
@@ -932,10 +934,10 @@ int odp_crypto_operation(odp_crypto_op_params_t *params,
uint8_t *data_addr, *aad_head;
struct rte_crypto_op *op;
uint16_t rc;
- uint32_t plain_len, aad_len;
+ uint32_t aad_len;
odp_bool_t allocated = false;
- entry = (crypto_session_entry_t *)(intptr_t)params->session;
+ entry = (crypto_session_entry_t *)(intptr_t)param->session;
if (entry == NULL)
return -1;
@@ -950,32 +952,32 @@ int odp_crypto_operation(odp_crypto_op_params_t *params,
auth_xform = entry->auth_xform;
/* Resolve output buffer */
- if (ODP_PACKET_INVALID == params->out_pkt &&
+ if (ODP_PACKET_INVALID == param->out_pkt &&
ODP_POOL_INVALID != entry->output_pool) {
- params->out_pkt = odp_packet_alloc(entry->output_pool,
- odp_packet_len(params->pkt));
+ param->out_pkt = odp_packet_alloc(entry->output_pool,
+ odp_packet_len(param->pkt));
allocated = true;
}
- if (params->pkt != params->out_pkt) {
- if (odp_unlikely(ODP_PACKET_INVALID == params->out_pkt))
+ if (param->pkt != param->out_pkt) {
+ if (odp_unlikely(ODP_PACKET_INVALID == param->out_pkt))
ODP_ABORT();
int ret;
- ret = odp_packet_copy_from_pkt(params->out_pkt,
+ ret = odp_packet_copy_from_pkt(param->out_pkt,
0,
- params->pkt,
+ param->pkt,
0,
- odp_packet_len(params->pkt));
+ odp_packet_len(param->pkt));
if (odp_unlikely(ret < 0))
goto err;
- _odp_packet_copy_md_to_packet(params->pkt, params->out_pkt);
- odp_packet_free(params->pkt);
- params->pkt = ODP_PACKET_INVALID;
+ _odp_packet_copy_md_to_packet(param->pkt, param->out_pkt);
+ odp_packet_free(param->pkt);
+ param->pkt = ODP_PACKET_INVALID;
}
- data_addr = odp_packet_data(params->out_pkt);
+ data_addr = odp_packet_data(param->out_pkt);
odp_spinlock_init(&global->lock);
odp_spinlock_lock(&global->lock);
@@ -990,25 +992,24 @@ int odp_crypto_operation(odp_crypto_op_params_t *params,
/* Set crypto operation data parameters */
rte_crypto_op_attach_sym_session(op, rte_session);
- op->sym->auth.digest.data = data_addr + params->hash_result_offset;
+ op->sym->auth.digest.data = data_addr + param->hash_result_offset;
op->sym->auth.digest.phys_addr =
- rte_pktmbuf_mtophys_offset((struct rte_mbuf *)params->out_pkt,
- odp_packet_len(params->out_pkt) -
+ rte_pktmbuf_mtophys_offset((struct rte_mbuf *)param->out_pkt,
+ odp_packet_len(param->out_pkt) -
auth_xform.auth.digest_length);
op->sym->auth.digest.length = auth_xform.auth.digest_length;
/* For SNOW3G algorithms, offset/length must be in bits */
if (auth_xform.auth.algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
- op->sym->auth.data.offset = params->auth_range.offset << 3;
- op->sym->auth.data.length = params->auth_range.length << 3;
+ op->sym->auth.data.offset = param->auth_range.offset << 3;
+ op->sym->auth.data.length = param->auth_range.length << 3;
} else {
- op->sym->auth.data.offset = params->auth_range.offset;
- op->sym->auth.data.length = params->auth_range.length;
+ op->sym->auth.data.offset = param->auth_range.offset;
+ op->sym->auth.data.length = param->auth_range.length;
}
- aad_head = data_addr + params->auth_range.offset;
- plain_len = params->cipher_range.length;
- aad_len = params->auth_range.length - plain_len;
+ aad_head = param->aad.ptr;
+ aad_len = param->aad.length;
if (aad_len > 0) {
op->sym->auth.aad.data = rte_malloc("aad", aad_len, 0);
@@ -1037,9 +1038,9 @@ int odp_crypto_operation(odp_crypto_op_params_t *params,
goto err;
}
- if (params->override_iv_ptr) {
+ if (param->override_iv_ptr) {
memcpy(op->sym->cipher.iv.data,
- params->override_iv_ptr,
+ param->override_iv_ptr,
entry->iv.length);
} else if (entry->iv.data) {
memcpy(op->sym->cipher.iv.data,
@@ -1055,19 +1056,19 @@ int odp_crypto_operation(odp_crypto_op_params_t *params,
/* For SNOW3G algorithms, offset/length must be in bits */
if (cipher_xform.cipher.algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2) {
- op->sym->cipher.data.offset = params->cipher_range.offset << 3;
- op->sym->cipher.data.length = params->cipher_range.length << 3;
+ op->sym->cipher.data.offset = param->cipher_range.offset << 3;
+ op->sym->cipher.data.length = param->cipher_range.length << 3;
} else {
- op->sym->cipher.data.offset = params->cipher_range.offset;
- op->sym->cipher.data.length = params->cipher_range.length;
+ op->sym->cipher.data.offset = param->cipher_range.offset;
+ op->sym->cipher.data.length = param->cipher_range.length;
}
if (rc_cipher == ODP_CRYPTO_ALG_ERR_NONE &&
rc_auth == ODP_CRYPTO_ALG_ERR_NONE) {
int queue_pair = odp_cpu_id();
- op->sym->m_src = (struct rte_mbuf *)params->out_pkt;
+ op->sym->m_src = (struct rte_mbuf *)param->out_pkt;
rc = rte_cryptodev_enqueue_burst(rte_session->dev_id,
queue_pair, &op, 1);
if (rc == 0) {
@@ -1085,12 +1086,12 @@ int odp_crypto_operation(odp_crypto_op_params_t *params,
goto err;
}
- params->out_pkt = (odp_packet_t)op->sym->m_src;
+ param->out_pkt = (odp_packet_t)op->sym->m_src;
}
/* Fill in result */
- local_result.ctx = params->ctx;
- local_result.pkt = params->out_pkt;
+ local_result.ctx = param->ctx;
+ local_result.pkt = param->out_pkt;
local_result.cipher_status.alg_err = rc_cipher;
local_result.cipher_status.hw_err = ODP_CRYPTO_HW_ERR_NONE;
local_result.auth_status.alg_err = rc_auth;
@@ -1106,7 +1107,7 @@ int odp_crypto_operation(odp_crypto_op_params_t *params,
odp_event_t completion_event;
odp_crypto_generic_op_result_t *op_result;
- completion_event = odp_packet_to_event(params->out_pkt);
+ completion_event = odp_packet_to_event(param->out_pkt);
_odp_buffer_event_type_set(
odp_buffer_from_event(completion_event),
ODP_EVENT_CRYPTO_COMPL);