diff options
Diffstat (limited to 'platform/linux-generic/odp_crypto_null.c')
-rw-r--r-- | platform/linux-generic/odp_crypto_null.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/platform/linux-generic/odp_crypto_null.c b/platform/linux-generic/odp_crypto_null.c index cf9abc99f..aa8e8a2b3 100644 --- a/platform/linux-generic/odp_crypto_null.c +++ b/platform/linux-generic/odp_crypto_null.c @@ -1,4 +1,5 @@ /* Copyright (c) 2014-2018, Linaro Limited + * Copyright (c) 2021, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -13,6 +14,7 @@ #include <odp/api/align.h> #include <odp/api/shared_memory.h> #include <odp_debug_internal.h> +#include <odp_global_data.h> #include <odp/api/hints.h> #include <odp/api/random.h> #include <odp/api/plat/packet_inlines.h> @@ -113,6 +115,11 @@ void free_session(odp_crypto_generic_session_t *session) int odp_crypto_capability(odp_crypto_capability_t *capa) { + if (odp_global_ro.disable.crypto) { + ODP_ERR("Crypto is disabled\n"); + return -1; + } + if (NULL == capa) return -1; @@ -190,6 +197,15 @@ odp_crypto_session_create(const odp_crypto_session_param_t *param, int rc; odp_crypto_generic_session_t *session; + if (odp_global_ro.disable.crypto) { + ODP_ERR("Crypto is disabled\n"); + /* Dummy output to avoid compiler warning about uninitialized + * variables */ + *status = ODP_CRYPTO_SES_CREATE_ERR_ENOMEM; + *session_out = ODP_CRYPTO_SESSION_INVALID; + return -1; + } + /* Allocate memory for this session */ session = alloc_session(); if (NULL == session) { @@ -276,12 +292,18 @@ odp_crypto_operation(odp_crypto_op_param_t *param, packet_param.auth_range = param->auth_range; rc = odp_crypto_op(¶m->pkt, &out_pkt, &packet_param, 1); - if (rc < 0) - return rc; + if (rc <= 0) + return -1; rc = odp_crypto_result(&packet_result, out_pkt); - if (rc < 0) - return rc; + if (rc < 0) { + /* + * We cannot fail since odp_crypto_op() has already processed + * the packet. Let's indicate error in the result instead. + */ + packet_hdr(out_pkt)->p.flags.crypto_err = 1; + packet_result.ok = false; + } /* Indicate to caller operation was sync */ *posted = 0; @@ -312,11 +334,16 @@ _odp_crypto_init_global(void) odp_shm_t shm; int idx; + if (odp_global_ro.disable.crypto) { + ODP_PRINT("\nODP crypto is DISABLED\n"); + return 0; + } + /* Calculate the memory size we need */ mem_size = sizeof(odp_crypto_global_t); /* Allocate our globally shared memory */ - shm = odp_shm_reserve("_odp_crypto_pool_null", mem_size, + shm = odp_shm_reserve("_odp_crypto_null_global", mem_size, ODP_CACHE_LINE_SIZE, 0); if (ODP_SHM_INVALID == shm) { @@ -346,6 +373,9 @@ int _odp_crypto_term_global(void) int count = 0; odp_crypto_generic_session_t *session; + if (odp_global_ro.disable.crypto) + return 0; + for (session = global->free; session != NULL; session = session->next) count++; if (count != MAX_SESSIONS) { @@ -353,7 +383,7 @@ int _odp_crypto_term_global(void) rc = -1; } - ret = odp_shm_free(odp_shm_lookup("_odp_crypto_pool_null")); + ret = odp_shm_free(odp_shm_lookup("_odp_crypto_null_global")); if (ret < 0) { ODP_ERR("shm free failed for _odp_crypto_pool_null\n"); rc = -1; |