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
7 Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
9 crypto/cryptodev.h | 16 ++++++++++++++++
10 ioctl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
11 2 files changed, 65 insertions(+)
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 {
21 +/* data container for CIOCHASH operations */
22 +struct hash_op_data {
23 + __u32 ses; /* session identifier */
24 + __u32 mac_op; /* cryptodev_crypto_op_t */
28 + __u16 flags; /* see COP_FLAG_* */
29 + __u32 len; /* length of source data */
30 + __u8 *src; /* source data */
34 /* In plain AEAD mode the following are required:
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)
42 +#define CIOCHASH _IOWR('c', 114, struct hash_op_data)
44 #endif /* L_CRYPTODEV_H */
45 diff --git a/ioctl.c b/ioctl.c
46 index 7adde75..3763954 100644
49 @@ -960,6 +960,7 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_)
50 void __user *arg = (void __user *)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_)
60 return kcop_to_user(&kcop, fcr, arg);
63 + if (unlikely(copy_from_user(&hash_op, arg, sizeof(struct hash_op_data)))) {
64 + pr_err("copy from user fault\n");
69 + sop.mac = hash_op.mac_op;
70 + sop.mackey = hash_op.mackey;
71 + sop.mackeylen = hash_op.mackeylen;
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");
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;
90 + kcop.digestsize = 0; /* will be updated during operation */
91 + kcop.task = current;
92 + kcop.mm = current->mm;
94 + ret = crypto_run(fcr, &kcop);
95 + if (unlikely(ret)) {
96 + dwarning(1, "Error in hash run");
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");
107 + ret = crypto_finish_session(fcr, sop.ses);
110 if (unlikely(ret = kcaop_from_user(&kcaop, fcr, arg))) {
111 dwarning(1, "Error copying from user");