updated NEWS for 1.0
[cryptodev-linux.git] / cryptodev_int.h
blob4690398102157e44808a0ebd671fbf8df2f6f17c
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>
16 #define PFX "cryptodev: "
17 #define dprintk(level, severity, format, a...) \
18 do { \
19 if (level <= cryptodev_verbosity) \
20 printk(severity PFX "%s[%u]: " format, \
21 current->comm, current->pid, \
22 ##a); \
23 } while (0)
25 extern int cryptodev_verbosity;
27 /* For zero copy */
28 int __get_userbuf(uint8_t __user *addr, uint32_t len, int write,
29 int pgcount, struct page **pg, struct scatterlist *sg,
30 struct task_struct *task, struct mm_struct *mm);
31 void release_user_pages(struct page **pg, int pagecount);
33 /* last page - first page + 1 */
34 #define PAGECOUNT(buf, buflen) \
35 ((((unsigned long)(buf + buflen - 1) & PAGE_MASK) >> PAGE_SHIFT) - \
36 (((unsigned long) buf & PAGE_MASK) >> PAGE_SHIFT) + 1)
38 #define DEFAULT_PREALLOC_PAGES 32
40 struct cipher_data {
41 int init; /* 0 uninitialized */
42 int blocksize;
43 int ivsize;
44 int alignmask;
45 struct {
46 struct crypto_ablkcipher *s;
47 struct cryptodev_result *result;
48 struct ablkcipher_request *request;
49 uint8_t iv[EALG_MAX_BLOCK_LEN];
50 } async;
53 int cryptodev_cipher_init(struct cipher_data *out, const char *alg_name,
54 uint8_t *key, size_t keylen);
55 void cryptodev_cipher_deinit(struct cipher_data *cdata);
56 ssize_t cryptodev_cipher_decrypt(struct cipher_data *cdata,
57 const struct scatterlist *sg1,
58 struct scatterlist *sg2, size_t len);
59 ssize_t cryptodev_cipher_encrypt(struct cipher_data *cdata,
60 const struct scatterlist *sg1,
61 struct scatterlist *sg2, size_t len);
63 inline static void cryptodev_cipher_set_iv(struct cipher_data *cdata,
64 void *iv, size_t iv_size)
66 memcpy(cdata->async.iv, iv, min(iv_size, sizeof(cdata->async.iv)));
69 inline static void cryptodev_cipher_get_iv(struct cipher_data *cdata,
70 void *iv, size_t iv_size)
72 memcpy(iv, cdata->async.iv, min(iv_size, sizeof(cdata->async.iv)));
75 /* hash stuff */
76 struct hash_data {
77 int init; /* 0 uninitialized */
78 int digestsize;
79 int alignmask;
80 struct {
81 struct crypto_ahash *s;
82 struct cryptodev_result *result;
83 struct ahash_request *request;
84 } async;
87 int cryptodev_hash_final(struct hash_data *hdata, void *output);
88 ssize_t cryptodev_hash_update(struct hash_data *hdata,
89 struct scatterlist *sg, size_t len);
90 int cryptodev_hash_reset(struct hash_data *hdata);
91 void cryptodev_hash_deinit(struct hash_data *hdata);
92 int cryptodev_hash_init(struct hash_data *hdata, const char *alg_name,
93 int hmac_mode, void *mackey, size_t mackeylen);
95 /* compatibility stuff */
96 #ifdef CONFIG_COMPAT
97 #include <linux/compat.h>
99 /* input of CIOCGSESSION */
100 struct compat_session_op {
101 /* Specify either cipher or mac
103 uint32_t cipher; /* cryptodev_crypto_op_t */
104 uint32_t mac; /* cryptodev_crypto_op_t */
106 uint32_t keylen;
107 compat_uptr_t key; /* pointer to key data */
108 uint32_t mackeylen;
109 compat_uptr_t mackey; /* pointer to mac key data */
111 uint32_t ses; /* session identifier */
114 /* input of CIOCCRYPT */
115 struct compat_crypt_op {
116 uint32_t ses; /* session identifier */
117 uint16_t op; /* COP_ENCRYPT or COP_DECRYPT */
118 uint16_t flags; /* see COP_FLAG_* */
119 uint32_t len; /* length of source data */
120 compat_uptr_t src; /* source data */
121 compat_uptr_t dst; /* pointer to output data */
122 compat_uptr_t mac;/* pointer to output data for hash/MAC operations */
123 compat_uptr_t iv;/* initialization vector for encryption operations */
126 /* compat ioctls, defined for the above structs */
127 #define COMPAT_CIOCGSESSION _IOWR('c', 102, struct compat_session_op)
128 #define COMPAT_CIOCCRYPT _IOWR('c', 104, struct compat_crypt_op)
129 #define COMPAT_CIOCASYNCCRYPT _IOW('c', 107, struct compat_crypt_op)
130 #define COMPAT_CIOCASYNCFETCH _IOR('c', 108, struct compat_crypt_op)
132 #endif /* CONFIG_COMPAT */
134 /* kernel-internal extension to struct crypt_op */
135 struct kernel_crypt_op {
136 struct crypt_op cop;
138 int ivlen;
139 __u8 iv[EALG_MAX_BLOCK_LEN];
141 int digestsize;
142 uint8_t hash_output[AALG_MAX_RESULT_LEN];
144 struct task_struct *task;
145 struct mm_struct *mm;
148 #endif /* CRYPTODEV_INT_H */