]> code.ossystems Code Review - meta-freescale.git/blob
4702fd4ffeab0cc08e79d87f9b2b029ce9752e17
[meta-freescale.git] /
1 From cc65307405a21c3b709ca6f2a6f64ff0c67c0eed Mon Sep 17 00:00:00 2001
2 From: Cristian Stoica <cristian.stoica@freescale.com>
3 Date: Wed, 18 Sep 2013 13:42:31 +0300
4 Subject: [[Patch][fsl 02/16] use function-local storage for cipher and hmac
5  keys
6
7 Upstream-status: Pending
8
9 This refactorization is necessary for next patches that add support for
10 aead composite ciphers where the aead key is the sum of cipher and hmac
11 keys.
12
13 Without this patch, the hmac and cipher keys can't be combined in the
14 same ioctl.
15
16 Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
17 Tested-by: Horia Ioan Geanta Neag <horia.geanta@freescale.com>
18 ---
19  ioctl.c |   14 ++++++--------
20  1 file changed, 6 insertions(+), 8 deletions(-)
21
22 diff --git a/ioctl.c b/ioctl.c
23 index a0f1db1..c614373 100644
24 --- a/ioctl.c
25 +++ b/ioctl.c
26 @@ -109,6 +109,8 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop)
27         const char *alg_name = NULL;
28         const char *hash_name = NULL;
29         int hmac_mode = 1, stream = 0, aead = 0;
30 +       uint8_t enckey[CRYPTO_CIPHER_MAX_KEY_LEN];
31 +       uint8_t mackey[CRYPTO_HMAC_MAX_KEY_LEN];
32  
33         /* Does the request make sense? */
34         if (unlikely(!sop->cipher && !sop->mac)) {
35 @@ -227,8 +229,6 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop)
36  
37         /* Set-up crypto transform. */
38         if (alg_name) {
39 -               uint8_t keyp[CRYPTO_CIPHER_MAX_KEY_LEN];
40 -
41                 if (unlikely(sop->keylen > CRYPTO_CIPHER_MAX_KEY_LEN)) {
42                         ddebug(1, "Setting key failed for %s-%zu.",
43                                 alg_name, (size_t)sop->keylen*8);
44 @@ -236,12 +236,12 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop)
45                         goto error_cipher;
46                 }
47  
48 -               if (unlikely(copy_from_user(keyp, sop->key, sop->keylen))) {
49 +               if (unlikely(copy_from_user(enckey, sop->key, sop->keylen))) {
50                         ret = -EFAULT;
51                         goto error_cipher;
52                 }
53  
54 -               ret = cryptodev_cipher_init(&ses_new->cdata, alg_name, keyp,
55 +               ret = cryptodev_cipher_init(&ses_new->cdata, alg_name, enckey,
56                                                 sop->keylen, stream, aead);
57                 if (ret < 0) {
58                         ddebug(1, "Failed to load cipher for %s", alg_name);
59 @@ -251,8 +251,6 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop)
60         }
61  
62         if (hash_name && aead == 0) {
63 -               uint8_t keyp[CRYPTO_HMAC_MAX_KEY_LEN];
64 -
65                 if (unlikely(sop->mackeylen > CRYPTO_HMAC_MAX_KEY_LEN)) {
66                         ddebug(1, "Setting key failed for %s-%zu.",
67                                 hash_name, (size_t)sop->mackeylen*8);
68 @@ -260,14 +258,14 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop)
69                         goto error_hash;
70                 }
71  
72 -               if (sop->mackey && unlikely(copy_from_user(keyp, sop->mackey,
73 +               if (sop->mackey && unlikely(copy_from_user(mackey, sop->mackey,
74                                             sop->mackeylen))) {
75                         ret = -EFAULT;
76                         goto error_hash;
77                 }
78  
79                 ret = cryptodev_hash_init(&ses_new->hdata, hash_name, hmac_mode,
80 -                                                       keyp, sop->mackeylen);
81 +                                                       mackey, sop->mackeylen);
82                 if (ret != 0) {
83                         ddebug(1, "Failed to load hash for %s", hash_name);
84                         ret = -EINVAL;
85 -- 
86 1.7.9.7
87