documented updates
[cryptodev-linux.git] / cryptodev_int.h
blobc1d327f01feef076038c27df10b0fa441282bcbe
1 /* cipher stuff */
2 #ifndef CRYPTODEV_INT_H
3 # define CRYPTODEV_INT_H
5 #include <linux/init.h>
6 #include <linux/sched.h>
7 #include <linux/fs.h>
8 #include <linux/file.h>
9 #include <linux/fdtable.h>
10 #include <linux/miscdevice.h>
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/scatterlist.h>
14 #include <crypto/cryptodev.h>
15 #include <crypto/aead.h>
17 #define PFX "cryptodev: "
18 #define dprintk(level, severity, format, a...) \
19 do { \
20 if (level <= cryptodev_verbosity) \
21 printk(severity PFX "%s[%u] (%s:%u): " format, \
22 current->comm, current->pid, \
23 __func__, __LINE__, \
24 ##a); \
25 } while (0)
27 extern int cryptodev_verbosity;
29 struct fcrypt {
30 struct list_head list;
31 struct mutex sem;
34 /* compatibility stuff */
35 #ifdef CONFIG_COMPAT
36 #include <linux/compat.h>
38 /* input of CIOCGSESSION */
39 struct compat_session_op {
40 /* Specify either cipher or mac
42 uint32_t cipher; /* cryptodev_crypto_op_t */
43 uint32_t mac; /* cryptodev_crypto_op_t */
45 uint32_t keylen;
46 compat_uptr_t key; /* pointer to key data */
47 uint32_t mackeylen;
48 compat_uptr_t mackey; /* pointer to mac key data */
50 uint32_t ses; /* session identifier */
53 /* input of CIOCCRYPT */
54 struct compat_crypt_op {
55 uint32_t ses; /* session identifier */
56 uint16_t op; /* COP_ENCRYPT or COP_DECRYPT */
57 uint16_t flags; /* see COP_FLAG_* */
58 uint32_t len; /* length of source data */
59 compat_uptr_t src; /* source data */
60 compat_uptr_t dst; /* pointer to output data */
61 compat_uptr_t mac;/* pointer to output data for hash/MAC operations */
62 compat_uptr_t iv;/* initialization vector for encryption operations */
65 /* compat ioctls, defined for the above structs */
66 #define COMPAT_CIOCGSESSION _IOWR('c', 102, struct compat_session_op)
67 #define COMPAT_CIOCCRYPT _IOWR('c', 104, struct compat_crypt_op)
68 #define COMPAT_CIOCASYNCCRYPT _IOW('c', 107, struct compat_crypt_op)
69 #define COMPAT_CIOCASYNCFETCH _IOR('c', 108, struct compat_crypt_op)
71 #endif /* CONFIG_COMPAT */
73 /* kernel-internal extension to struct crypt_op */
74 struct kernel_crypt_op {
75 struct crypt_op cop;
77 int ivlen;
78 __u8 iv[EALG_MAX_BLOCK_LEN];
80 int digestsize;
81 uint8_t hash_output[AALG_MAX_RESULT_LEN];
83 struct task_struct *task;
84 struct mm_struct *mm;
87 struct kernel_crypt_auth_op {
88 struct crypt_auth_op caop;
90 int dst_len; /* based on src_len + pad + tag */
91 int ivlen;
92 __u8 iv[EALG_MAX_BLOCK_LEN];
94 struct task_struct *task;
95 struct mm_struct *mm;
98 /* auth */
100 int kcaop_from_user(struct kernel_crypt_auth_op *kcop,
101 struct fcrypt *fcr, void __user *arg);
102 int kcaop_to_user(struct kernel_crypt_auth_op *kcaop,
103 struct fcrypt *fcr, void __user *arg);
104 int crypto_auth_run(struct fcrypt *fcr, struct kernel_crypt_auth_op *kcaop);
105 int crypto_run(struct fcrypt *fcr, struct kernel_crypt_op *kcop);
107 #include <cryptlib.h>
109 /* other internal structs */
110 struct csession {
111 struct list_head entry;
112 struct mutex sem;
113 struct cipher_data cdata;
114 struct hash_data hdata;
115 uint32_t sid;
116 uint32_t alignmask;
118 unsigned int array_size;
119 unsigned int used_pages; /* the number of pages that are used */
120 /* the number of pages marked as writable (first are the readable) */
121 unsigned int readable_pages;
122 struct page **pages;
123 struct scatterlist *sg;
126 struct csession *crypto_get_session_by_sid(struct fcrypt *fcr, uint32_t sid);
128 inline static void crypto_put_session(struct csession * ses_ptr)
130 mutex_unlock(&ses_ptr->sem);
132 int adjust_sg_array(struct csession * ses, int pagecount);
134 #endif /* CRYPTODEV_INT_H */