From: Cristian Stoica <cristian.sto...@freescale.com>

This refactorization is necessary for next patches that add support for
aead composite ciphers where the aead key is the sum of cipher and hmac
keys.

Without this patch, the hmac and cipher keys can't be combined in the
same ioctl.

Signed-off-by: Cristian Stoica <cristian.sto...@freescale.com>
Reviewed-by: Mircea Pop <mircea....@freescale.com>
Reviewed-by: Alexandru Porosanu <alexandru.poros...@freescale.com>
Reviewed-by: Horia Ioan Geanta Neag <horia.gea...@freescale.com>
Tested-by: Horia Ioan Geanta Neag <horia.gea...@freescale.com>
Signed-off-by: Horia Geanta <horia.gea...@freescale.com>
---
 ioctl.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/ioctl.c b/ioctl.c
index 7a69e5a..1ba10bb 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -109,6 +109,8 @@ crypto_create_session(struct fcrypt *fcr, struct session_op 
*sop)
        const char *alg_name = NULL;
        const char *hash_name = NULL;
        int hmac_mode = 1, stream = 0, aead = 0;
+       uint8_t enckey[CRYPTO_CIPHER_MAX_KEY_LEN];
+       uint8_t mackey[CRYPTO_HMAC_MAX_KEY_LEN];
 
        /* Does the request make sense? */
        if (unlikely(!sop->cipher && !sop->mac)) {
@@ -222,8 +224,6 @@ crypto_create_session(struct fcrypt *fcr, struct session_op 
*sop)
 
        /* Set-up crypto transform. */
        if (alg_name) {
-               uint8_t keyp[CRYPTO_CIPHER_MAX_KEY_LEN];
-
                if (unlikely(sop->keylen > CRYPTO_CIPHER_MAX_KEY_LEN)) {
                        dprintk(1, KERN_DEBUG,
                                "Setting key failed for %s-%zu.\n",
@@ -232,12 +232,12 @@ crypto_create_session(struct fcrypt *fcr, struct 
session_op *sop)
                        goto error_cipher;
                }
 
-               if (unlikely(copy_from_user(keyp, sop->key, sop->keylen))) {
+               if (unlikely(copy_from_user(enckey, sop->key, sop->keylen))) {
                        ret = -EFAULT;
                        goto error_cipher;
                }
 
-               ret = cryptodev_cipher_init(&ses_new->cdata, alg_name, keyp,
+               ret = cryptodev_cipher_init(&ses_new->cdata, alg_name, enckey,
                                                sop->keylen, stream, aead);
                if (ret < 0) {
                        dprintk(1, KERN_DEBUG,
@@ -248,8 +248,6 @@ crypto_create_session(struct fcrypt *fcr, struct session_op 
*sop)
        }
 
        if (hash_name && aead == 0) {
-               uint8_t keyp[CRYPTO_HMAC_MAX_KEY_LEN];
-
                if (unlikely(sop->mackeylen > CRYPTO_HMAC_MAX_KEY_LEN)) {
                        dprintk(1, KERN_DEBUG,
                                "Setting key failed for %s-%zu.\n",
@@ -258,14 +256,14 @@ crypto_create_session(struct fcrypt *fcr, struct 
session_op *sop)
                        goto error_hash;
                }
 
-               if (sop->mackey && unlikely(copy_from_user(keyp, sop->mackey,
+               if (sop->mackey && unlikely(copy_from_user(mackey, sop->mackey,
                                            sop->mackeylen))) {
                        ret = -EFAULT;
                        goto error_hash;
                }
 
                ret = cryptodev_hash_init(&ses_new->hdata, hash_name, hmac_mode,
-                                                       keyp, sop->mackeylen);
+                                                       mackey, sop->mackeylen);
                if (ret != 0) {
                        dprintk(1, KERN_DEBUG, "Failed to load hash for %s\n", 
hash_name);
                        ret = -EINVAL;
-- 
1.7.7.6



_______________________________________________
Cryptodev-linux-devel mailing list
Cryptodev-linux-devel@gna.org
https://mail.gna.org/listinfo/cryptodev-linux-devel

Reply via email to