]> code.ossystems Code Review - meta-freescale.git/blob
3a1f0c0572957d91bd0e2c969dd03543f166b06d
[meta-freescale.git] /
1 From c43fa74b9ed11f0183d25b21486b71fe02d84de7 Mon Sep 17 00:00:00 2001
2 From: Cristian Stoica <cristian.stoica@nxp.com>
3 Date: Tue, 15 Dec 2015 15:31:47 +0200
4 Subject: [PATCH 34/38] extend API with CIOCHASH to support direct hash
5  operations
6
7 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
8 ---
9  crypto/cryptodev.h | 16 ++++++++++++++++
10  ioctl.c            | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
11  2 files changed, 65 insertions(+)
12
13 diff --git a/crypto/cryptodev.h b/crypto/cryptodev.h
14 index f6058ca..c6083f7 100644
15 --- a/crypto/cryptodev.h
16 +++ b/crypto/cryptodev.h
17 @@ -167,6 +167,19 @@ struct crypt_auth_op {
18         __u32   iv_len;
19  };
20  
21 +/* data container for CIOCHASH operations */
22 +struct hash_op_data {
23 +       __u32   ses;            /* session identifier */
24 +       __u32   mac_op;         /* cryptodev_crypto_op_t */
25 +       __u8    *mackey;
26 +       __u32   mackeylen;
27 +
28 +       __u16   flags;          /* see COP_FLAG_* */
29 +       __u32   len;            /* length of source data */
30 +       __u8    *src;           /* source data */
31 +       __u8    *mac_result;
32 +};
33 +
34  /* In plain AEAD mode the following are required:
35   *  flags   : 0
36   *  iv      : the initialization vector (12 bytes)
37 @@ -325,4 +338,7 @@ enum cryptodev_crk_op_t {
38  /* additional ioctls for asynchronous  operation for asymmetric ciphers*/
39  #define CIOCASYMASYNCRYPT    _IOW('c', 112, struct crypt_kop)
40  #define CIOCASYMFETCHCOOKIE    _IOR('c', 113, struct pkc_cookie_list_s)
41 +
42 +#define CIOCHASH       _IOWR('c', 114, struct hash_op_data)
43 +
44  #endif /* L_CRYPTODEV_H */
45 diff --git a/ioctl.c b/ioctl.c
46 index 7adde75..3763954 100644
47 --- a/ioctl.c
48 +++ b/ioctl.c
49 @@ -960,6 +960,7 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_)
50         void __user *arg = (void __user *)arg_;
51         int __user *p = arg;
52         struct session_op sop;
53 +       struct hash_op_data hash_op;
54         struct kernel_crypt_op kcop;
55         struct kernel_crypt_auth_op kcaop;
56         struct crypt_priv *pcr = filp->private_data;
57 @@ -1049,6 +1050,54 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_)
58                 }
59  
60                 return kcop_to_user(&kcop, fcr, arg);
61 +       case CIOCHASH:
62 +               /* get session */
63 +               if (unlikely(copy_from_user(&hash_op, arg, sizeof(struct hash_op_data)))) {
64 +                       pr_err("copy from user fault\n");
65 +                       return -EFAULT;
66 +               }
67 +
68 +               sop.cipher = 0;
69 +               sop.mac = hash_op.mac_op;
70 +               sop.mackey = hash_op.mackey;
71 +               sop.mackeylen = hash_op.mackeylen;
72 +
73 +               /* writes sop.ses as a side-effect */
74 +               ret = crypto_create_session(fcr, &sop);
75 +               if (unlikely(ret)) {
76 +                       pr_err("can't get session\n");
77 +                       return ret;
78 +               }
79 +
80 +               /* do hashing */
81 +               kcop.cop.ses = sop.ses;
82 +               kcop.cop.flags = hash_op.flags;
83 +               kcop.cop.len = hash_op.len;
84 +               kcop.cop.src = hash_op.src;
85 +               kcop.cop.mac = hash_op.mac_result;
86 +               kcop.cop.dst = 0;
87 +               kcop.cop.op = 0;
88 +               kcop.cop.iv = 0;
89 +               kcop.ivlen = 0;
90 +               kcop.digestsize = 0; /* will be updated during operation */
91 +               kcop.task = current;
92 +               kcop.mm = current->mm;
93 +
94 +               ret = crypto_run(fcr, &kcop);
95 +               if (unlikely(ret)) {
96 +                       dwarning(1, "Error in hash run");
97 +                       return ret;
98 +               }
99 +
100 +               ret = copy_to_user(kcop.cop.mac, kcop.hash_output, kcop.digestsize);
101 +               if (unlikely(ret)) {
102 +                       dwarning(1, "Error in copy to user");
103 +                       return ret;
104 +               }
105 +
106 +               /* put session */
107 +               ret = crypto_finish_session(fcr, sop.ses);
108 +               return 0;
109         case CIOCAUTHCRYPT:
110                 if (unlikely(ret = kcaop_from_user(&kcaop, fcr, arg))) {
111                         dwarning(1, "Error copying from user");
112 -- 
113 2.7.0
114