1 From 12fad710349bb72b7f95ee30b40c2e6dfbb5d373 Mon Sep 17 00:00:00 2001
2 From: Cristian Stoica <cristian.stoica@nxp.com>
3 Date: Wed, 13 Jan 2016 15:18:20 +0200
4 Subject: [PATCH 30/48] cryptodev: reduce duplicated efforts for searching
7 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
9 crypto/engine/eng_cryptodev.c | 44 ++++++++++++++++++-------------------------
10 1 file changed, 18 insertions(+), 26 deletions(-)
12 diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
13 index dc27b55..30713e5 100644
14 --- a/crypto/engine/eng_cryptodev.c
15 +++ b/crypto/engine/eng_cryptodev.c
16 @@ -1533,37 +1533,31 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
18 # ifdef USE_CRYPTODEV_DIGESTS
20 -/* convert digest type to cryptodev */
21 -static int digest_nid_to_cryptodev(int nid)
22 +static int digest_nid_to_id(int nid)
26 - for (i = 0; digests[i].id; i++)
27 - if (digests[i].nid == nid)
28 - return (digests[i].id);
32 -static int digest_key_length(int nid)
36 - for (i = 0; digests[i].id; i++)
37 - if (digests[i].nid == nid)
38 - return digests[i].keylen;
41 + if ((digests[i].nid == nid) || (digests[i].id == 0)) {
48 static int cryptodev_digest_init(EVP_MD_CTX *ctx)
50 struct dev_crypto_state *state = ctx->md_data;
51 struct hash_op_data *hash_op = &state->hash_op;
55 memset(state, 0, sizeof(struct dev_crypto_state));
57 - digest = digest_nid_to_cryptodev(ctx->digest->type);
58 - if (digest == NID_undef) {
59 + id = digest_nid_to_id(ctx->digest->type);
61 + hash_op->mac_op = digests[id].id;
62 + hash_op->mackeylen = digests[id].keylen;
63 + if (hash_op->mac_op == 0) {
64 printf("%s: Can't get digest\n", __func__);
67 @@ -1574,11 +1568,9 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx)
71 - hash_op->mac_op = digest;
72 hash_op->mackey = state->dummy_mac_key;
73 - hash_op->mackeylen = digest_key_length(ctx->digest->type);
79 static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data,
80 @@ -1668,7 +1660,7 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
81 struct dev_crypto_state *fstate = from->md_data;
82 struct dev_crypto_state *dstate = to->md_data;
83 struct session_op *sess;
87 if (dstate == NULL || fstate == NULL)
89 @@ -1677,11 +1669,11 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
91 sess = &dstate->d_sess;
93 - digest = digest_nid_to_cryptodev(to->digest->type);
94 + id = digest_nid_to_id(to->digest->type);
96 sess->mackey = dstate->dummy_mac_key;
97 - sess->mackeylen = digest_key_length(to->digest->type);
99 + sess->mackeylen = digests[id].keylen;
100 + sess->mac = digests[id].id;
102 dstate->d_fd = get_dev_crypto();