From 328b2890d5a9baf9f936bd9facaf411c01931f08 Mon Sep 17 00:00:00 2001 From: Cristian Stoica Date: Wed, 13 Jan 2016 15:18:20 +0200 Subject: [PATCH 30/48] cryptodev: reduce duplicated efforts for searching inside digests table Signed-off-by: Cristian Stoica --- crypto/engine/eng_cryptodev.c | 44 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c index 4f375e0..163a37d 100644 --- a/crypto/engine/eng_cryptodev.c +++ b/crypto/engine/eng_cryptodev.c @@ -1534,37 +1534,31 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, # ifdef USE_CRYPTODEV_DIGESTS -/* convert digest type to cryptodev */ -static int digest_nid_to_cryptodev(int nid) +static int digest_nid_to_id(int nid) { int i; - for (i = 0; digests[i].id; i++) - if (digests[i].nid == nid) - return (digests[i].id); - return (0); -} - -static int digest_key_length(int nid) -{ - int i; - - for (i = 0; digests[i].id; i++) - if (digests[i].nid == nid) - return digests[i].keylen; - return (0); + for (i = 0;; i++) { + if ((digests[i].nid == nid) || (digests[i].id == 0)) { + break; + } + } + return i; } static int cryptodev_digest_init(EVP_MD_CTX *ctx) { struct dev_crypto_state *state = ctx->md_data; struct hash_op_data *hash_op = &state->hash_op; - int digest; + int id; memset(state, 0, sizeof(struct dev_crypto_state)); - digest = digest_nid_to_cryptodev(ctx->digest->type); - if (digest == NID_undef) { + id = digest_nid_to_id(ctx->digest->type); + + hash_op->mac_op = digests[id].id; + hash_op->mackeylen = digests[id].keylen; + if (hash_op->mac_op == 0) { printf("%s: Can't get digest\n", __func__); return (0); } @@ -1575,11 +1569,9 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) return (0); } - hash_op->mac_op = digest; hash_op->mackey = state->dummy_mac_key; - hash_op->mackeylen = digest_key_length(ctx->digest->type); - return (1); + return 1; } static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, @@ -1669,7 +1661,7 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) struct dev_crypto_state *fstate = from->md_data; struct dev_crypto_state *dstate = to->md_data; struct session_op *sess; - int digest; + int id; if (dstate == NULL || fstate == NULL) return 1; @@ -1678,11 +1670,11 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) sess = &dstate->d_sess; - digest = digest_nid_to_cryptodev(to->digest->type); + id = digest_nid_to_id(to->digest->type); sess->mackey = dstate->dummy_mac_key; - sess->mackeylen = digest_key_length(to->digest->type); - sess->mac = digest; + sess->mackeylen = digests[id].keylen; + sess->mac = digests[id].id; dstate->d_fd = get_dev_crypto(); -- 2.7.3