]> code.ossystems Code Review - meta-freescale.git/blob
995a593f85b5fde7352a7f978b9c3f26383fa77d
[meta-freescale.git] /
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
5  inside digests table
6
7 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
8 ---
9  crypto/engine/eng_cryptodev.c | 44 ++++++++++++++++++-------------------------
10  1 file changed, 18 insertions(+), 26 deletions(-)
11
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,
17  
18  # ifdef USE_CRYPTODEV_DIGESTS
19  
20 -/* convert digest type to cryptodev */
21 -static int digest_nid_to_cryptodev(int nid)
22 +static int digest_nid_to_id(int nid)
23  {
24      int i;
25  
26 -    for (i = 0; digests[i].id; i++)
27 -        if (digests[i].nid == nid)
28 -            return (digests[i].id);
29 -    return (0);
30 -}
31 -
32 -static int digest_key_length(int nid)
33 -{
34 -    int i;
35 -
36 -    for (i = 0; digests[i].id; i++)
37 -        if (digests[i].nid == nid)
38 -            return digests[i].keylen;
39 -    return (0);
40 +    for (i = 0;; i++) {
41 +        if ((digests[i].nid == nid) || (digests[i].id == 0)) {
42 +            break;
43 +        }
44 +    }
45 +    return i;
46  }
47  
48  static int cryptodev_digest_init(EVP_MD_CTX *ctx)
49  {
50      struct dev_crypto_state *state = ctx->md_data;
51      struct hash_op_data *hash_op = &state->hash_op;
52 -    int digest;
53 +    int id;
54  
55      memset(state, 0, sizeof(struct dev_crypto_state));
56  
57 -    digest = digest_nid_to_cryptodev(ctx->digest->type);
58 -    if (digest == NID_undef) {
59 +    id = digest_nid_to_id(ctx->digest->type);
60 +
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__);
65          return (0);
66      }
67 @@ -1574,11 +1568,9 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx)
68          return (0);
69      }
70  
71 -    hash_op->mac_op = digest;
72      hash_op->mackey = state->dummy_mac_key;
73 -    hash_op->mackeylen = digest_key_length(ctx->digest->type);
74  
75 -    return (1);
76 +    return 1;
77  }
78  
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;
84 -    int digest;
85 +    int id;
86  
87      if (dstate == NULL || fstate == NULL)
88          return 1;
89 @@ -1677,11 +1669,11 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
90  
91      sess = &dstate->d_sess;
92  
93 -    digest = digest_nid_to_cryptodev(to->digest->type);
94 +    id = digest_nid_to_id(to->digest->type);
95  
96      sess->mackey = dstate->dummy_mac_key;
97 -    sess->mackeylen = digest_key_length(to->digest->type);
98 -    sess->mac = digest;
99 +    sess->mackeylen = digests[id].keylen;
100 +    sess->mac = digests[id].id;
101  
102      dstate->d_fd = get_dev_crypto();
103  
104 -- 
105 2.7.0
106