bumped version to 0.7
[cryptodev-linux.git] / cryptodev_int.h
blob15eb5bf7e5669810027d3caecabb88b6d02a765c
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 "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 void release_user_pages(struct page **pg, int pagecount);
32 /* last page - first page + 1 */
33 #define PAGECOUNT(buf, buflen) \
34 ((((unsigned long)(buf + buflen - 1) & PAGE_MASK) >> PAGE_SHIFT) - \
35 (((unsigned long) buf & PAGE_MASK) >> PAGE_SHIFT) + 1)
37 #define DEFAULT_PREALLOC_PAGES 32
39 struct cipher_data {
40 int init; /* 0 uninitialized */
41 int blocksize;
42 int ivsize;
43 struct {
44 struct crypto_ablkcipher *s;
45 struct cryptodev_result *result;
46 struct ablkcipher_request *request;
47 uint8_t iv[EALG_MAX_BLOCK_LEN];
48 } async;
51 int cryptodev_cipher_init(struct cipher_data *out, const char *alg_name,
52 uint8_t *key, size_t keylen);
53 void cryptodev_cipher_deinit(struct cipher_data *cdata);
54 ssize_t cryptodev_cipher_decrypt(struct cipher_data *cdata,
55 const struct scatterlist *sg1,
56 struct scatterlist *sg2, size_t len);
57 ssize_t cryptodev_cipher_encrypt(struct cipher_data *cdata,
58 const struct scatterlist *sg1,
59 struct scatterlist *sg2, size_t len);
61 void cryptodev_cipher_set_iv(struct cipher_data *cdata,
62 void *iv, size_t iv_size);
64 /* hash stuff */
65 struct hash_data {
66 int init; /* 0 uninitialized */
67 int digestsize;
68 struct {
69 struct crypto_ahash *s;
70 struct cryptodev_result *result;
71 struct ahash_request *request;
72 } async;
75 int cryptodev_hash_final(struct hash_data *hdata, void *output);
76 ssize_t cryptodev_hash_update(struct hash_data *hdata,
77 struct scatterlist *sg, size_t len);
78 int cryptodev_hash_reset(struct hash_data *hdata);
79 void cryptodev_hash_deinit(struct hash_data *hdata);
80 int cryptodev_hash_init(struct hash_data *hdata, const char *alg_name,
81 int hmac_mode, void *mackey, size_t mackeylen);
83 /* compatibility stuff */
84 #ifdef CONFIG_COMPAT
85 #include <linux/compat.h>
87 /* input of CIOCGSESSION */
88 struct compat_session_op {
89 /* Specify either cipher or mac
91 uint32_t cipher; /* cryptodev_crypto_op_t */
92 uint32_t mac; /* cryptodev_crypto_op_t */
94 uint32_t keylen;
95 compat_uptr_t key; /* pointer to key data */
96 uint32_t mackeylen;
97 compat_uptr_t mackey; /* pointer to mac key data */
99 uint32_t ses; /* session identifier */
102 /* input of CIOCCRYPT */
103 struct compat_crypt_op {
104 uint32_t ses; /* session identifier */
105 uint16_t op; /* COP_ENCRYPT or COP_DECRYPT */
106 uint16_t flags; /* no usage so far, use 0 */
107 uint32_t len; /* length of source data */
108 compat_uptr_t src; /* source data */
109 compat_uptr_t dst; /* pointer to output data */
110 compat_uptr_t mac;/* pointer to output data for hash/MAC operations */
111 compat_uptr_t iv;/* initialization vector for encryption operations */
114 /* compat ioctls, defined for the above structs */
115 #define COMPAT_CIOCGSESSION _IOWR('c', 102, struct compat_session_op)
116 #define COMPAT_CIOCCRYPT _IOWR('c', 104, struct compat_crypt_op)
118 #endif /* CONFIG_COMPAT */
120 #endif /* CRYPTODEV_INT_H */