1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
From 12fad710349bb72b7f95ee30b40c2e6dfbb5d373 Mon Sep 17 00:00:00 2001
From: Cristian Stoica <cristian.stoica@nxp.com>
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 <cristian.stoica@nxp.com>
---
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 dc27b55..30713e5 100644
--- a/crypto/engine/eng_cryptodev.c
+++ b/crypto/engine/eng_cryptodev.c
@@ -1533,37 +1533,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);
}
@@ -1574,11 +1568,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,
@@ -1668,7 +1660,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;
@@ -1677,11 +1669,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.0
|