From 85f5a09334a77abafdadca58c5063e55a1fea419 Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Mon, 9 Oct 2023 09:50:14 +0300 Subject: [PATCH] linux-gen: crypto: implement ODP_CRYPTO_TYPE_BASIC_AND_OOP Implement the BASIC_AND_OOP crypto op type which allows both basic and out-of-place operations with the same session. Add the support only for the openssl crypto module as that is now the only one which supports out-of-place crypto. Signed-off-by: Janne Peltonen Reviewed-by: Petri Savolainen --- .../arch/aarch64/odp_crypto_armv8.c | 3 +- platform/linux-generic/odp_crypto_ipsecmb.c | 3 +- platform/linux-generic/odp_crypto_null.c | 3 +- platform/linux-generic/odp_crypto_openssl.c | 33 +++++++++++++++---- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/platform/linux-generic/arch/aarch64/odp_crypto_armv8.c b/platform/linux-generic/arch/aarch64/odp_crypto_armv8.c index 7bbaa04081c..52936dacf2e 100644 --- a/platform/linux-generic/arch/aarch64/odp_crypto_armv8.c +++ b/platform/linux-generic/arch/aarch64/odp_crypto_armv8.c @@ -534,7 +534,8 @@ odp_crypto_session_create(const odp_crypto_session_param_t *param, *session_out = ODP_CRYPTO_SESSION_INVALID; return -1; } - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) { + if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP || + param->op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP) { *status = ODP_CRYPTO_SES_ERR_PARAMS; *session_out = ODP_CRYPTO_SESSION_INVALID; return -1; diff --git a/platform/linux-generic/odp_crypto_ipsecmb.c b/platform/linux-generic/odp_crypto_ipsecmb.c index 6a847cc6f38..e5884409855 100644 --- a/platform/linux-generic/odp_crypto_ipsecmb.c +++ b/platform/linux-generic/odp_crypto_ipsecmb.c @@ -555,7 +555,8 @@ odp_crypto_session_create(const odp_crypto_session_param_t *param, *session_out = ODP_CRYPTO_SESSION_INVALID; return -1; } - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) { + if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP || + param->op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP) { *status = ODP_CRYPTO_SES_ERR_PARAMS; *session_out = ODP_CRYPTO_SESSION_INVALID; return -1; diff --git a/platform/linux-generic/odp_crypto_null.c b/platform/linux-generic/odp_crypto_null.c index 5e3a4e8373c..6eda0f45586 100644 --- a/platform/linux-generic/odp_crypto_null.c +++ b/platform/linux-generic/odp_crypto_null.c @@ -219,7 +219,8 @@ odp_crypto_session_create(const odp_crypto_session_param_t *param, *session_out = ODP_CRYPTO_SESSION_INVALID; return -1; } - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) { + if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP || + param->op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP) { *status = ODP_CRYPTO_SES_ERR_PARAMS; *session_out = ODP_CRYPTO_SESSION_INVALID; return -1; diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index 13b027f3ed6..879ce0b97a6 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -2592,6 +2592,9 @@ int crypto_int(odp_packet_t pkt_in, if (odp_likely(session->p.op_type == ODP_CRYPTO_OP_TYPE_BASIC)) { out_pkt = pkt_in; + } else if (session->p.op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP && + *pkt_out == ODP_PACKET_INVALID) { + out_pkt = pkt_in; } else { out_pkt = get_output_packet(session, pkt_in, *pkt_out); if (odp_unlikely(out_pkt == ODP_PACKET_INVALID)) @@ -2762,10 +2765,19 @@ int odp_crypto_op(const odp_packet_t pkt_in[], session = (odp_crypto_generic_session_t *)(intptr_t)param[i].session; _ODP_ASSERT(ODP_CRYPTO_SYNC == session->p.op_mode); - if (odp_unlikely(session->p.op_type == ODP_CRYPTO_OP_TYPE_OOP)) + if (odp_likely(session->p.op_type == ODP_CRYPTO_OP_TYPE_BASIC)) { + rc = crypto_int(pkt_in[i], &pkt_out[i], ¶m[i]); + } else if (session->p.op_type == ODP_CRYPTO_OP_TYPE_OOP) { rc = crypto_int_oop(pkt_in[i], &pkt_out[i], ¶m[i]); - else + } else if (session->p.op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP) { + if (pkt_out[i] == ODP_PACKET_INVALID) /* basic */ + rc = crypto_int(pkt_in[i], &pkt_out[i], ¶m[i]); + else /* oop */ + rc = crypto_int_oop(pkt_in[i], &pkt_out[i], ¶m[i]); + } else { + _ODP_ASSERT(session->p.op_type == ODP_CRYPTO_OP_TYPE_LEGACY); rc = crypto_int(pkt_in[i], &pkt_out[i], ¶m[i]); + } if (rc < 0) break; } @@ -2788,13 +2800,22 @@ int odp_crypto_op_enq(const odp_packet_t pkt_in[], _ODP_ASSERT(ODP_CRYPTO_ASYNC == session->p.op_mode); _ODP_ASSERT(ODP_QUEUE_INVALID != session->p.compl_queue); - if (session->p.op_type != ODP_CRYPTO_OP_TYPE_BASIC) + if (odp_likely(session->p.op_type == ODP_CRYPTO_OP_TYPE_BASIC)) { + rc = crypto_int(pkt_in[i], &pkt, ¶m[i]); + } else if (session->p.op_type == ODP_CRYPTO_OP_TYPE_OOP) { pkt = pkt_out[i]; - - if (odp_unlikely(session->p.op_type == ODP_CRYPTO_OP_TYPE_OOP)) rc = crypto_int_oop(pkt_in[i], &pkt, ¶m[i]); - else + } else if (session->p.op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP) { + pkt = pkt_out[i]; + if (pkt_out[i] == ODP_PACKET_INVALID) /* basic */ + rc = crypto_int(pkt_in[i], &pkt, ¶m[i]); + else /* oop */ + rc = crypto_int_oop(pkt_in[i], &pkt, ¶m[i]); + } else { + _ODP_ASSERT(session->p.op_type == ODP_CRYPTO_OP_TYPE_LEGACY); + pkt = pkt_out[i]; rc = crypto_int(pkt_in[i], &pkt, ¶m[i]); + } if (rc < 0) break;