summaryrefslogtreecommitdiffstats
path: root/cryptodev.h
blob: 4d6b712e5069811867633661bb1c562fc117f21e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* This is a source compatible implementation with the original API of 
 * cryptodev by Angelos D. Keromytis, found at openbsd cryptodev.h.
 * Placed under public domain */

#ifndef L_CRYPTODEV_H
#define L_CRYPTODEV_H

#ifndef __KERNEL__
#include <inttypes.h>
#define __user
#else
#endif

/* API extensions for linux */
#define CRYPTO_HMAC_MAX_KEY_LEN		512
#define CRYPTO_CIPHER_MAX_KEY_LEN	64

/* All the supported algorithms
 */
typedef enum {
	CRYPTO_DES_CBC=1,
	CRYPTO_3DES_CBC=2,
	CRYPTO_BLF_CBC=3,
	CRYPTO_CAST_CBC=4,
	CRYPTO_SKIPJACK_CBC=5,
	CRYPTO_MD5_HMAC=6,
	CRYPTO_SHA1_HMAC=7,
	CRYPTO_RIPEMD160_HMAC=8,
	CRYPTO_MD5_KPDK=9,
	CRYPTO_SHA1_KPDK=10,
	CRYPTO_RIJNDAEL128_CBC=11,
	CRYPTO_AES_CBC=CRYPTO_RIJNDAEL128_CBC,
	CRYPTO_ARC4=12,
	CRYPTO_MD5=13,
	CRYPTO_SHA1=14,
	CRYPTO_DEFLATE_COMP=15,
	CRYPTO_NULL=16,
	CRYPTO_LZS_COMP=17,
	CRYPTO_SHA2_256_HMAC=18,
	CRYPTO_SHA2_384_HMAC=19,
	CRYPTO_SHA2_512_HMAC=20,
	CRYPTO_AES_CTR=21,
	CRYPTO_AES_XTS=22,

	CRYPTO_CAMELLIA_CBC=101,
	CRYPTO_RIPEMD160,
	CRYPTO_SHA2_256,
	CRYPTO_SHA2_384,
	CRYPTO_SHA2_512,
	CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */
} cryptodev_crypto_op_t;
#define	CRYPTO_ALGORITHM_MAX	(CRYPTO_ALGORITHM_ALL - 1)

/* Values for ciphers */
#define DES_BLOCK_LEN		8
#define DES3_BLOCK_LEN		8
#define RIJNDAEL128_BLOCK_LEN	16
#define AES_BLOCK_LEN		RIJNDAEL128_BLOCK_LEN
#define CAMELLIA_BLOCK_LEN
#define BLOWFISH_BLOCK_LEN	8
#define SKIPJACK_BLOCK_LEN	8
#define CAST128_BLOCK_LEN	8

/* the maximum of the above */
#define EALG_MAX_BLOCK_LEN	16

/* Values for hashes/MAC */
#define AALG_MAX_RESULT_LEN		64

/* input of CIOCGSESSION */
struct session_op {
	/* Specify either cipher or mac
	 */
	uint32_t	cipher;		/* cryptodev_crypto_op_t */
	uint32_t	mac;		/* cryptodev_crypto_op_t */

	uint32_t	keylen;
	uint8_t	__user *key;
	uint32_t	mackeylen;
	uint8_t	__user *mackey;

	uint32_t	ses;		/* session identifier */
};

#define	COP_ENCRYPT	0
#define COP_DECRYPT	1

/* input of CIOCCRYPT */
 struct crypt_op {
	uint32_t	ses;		/* session identifier */
	uint16_t	op;		/* COP_ENCRYPT or COP_DECRYPT */
	uint16_t	flags;		/* no usage so far, use 0 */
	uint32_t	len;		/* length of source data */
	uint8_t __user *src;		/* source data */
	uint8_t __user *dst;		/* pointer to output data */
	uint8_t	__user *mac;		/* pointer to output data for hash/MAC operations */
	uint8_t	__user *iv;		/* initialization vector for encryption operations */
};

/* Stuff for bignum arithmetic and public key
 * cryptography - not supported yet by linux
 * cryptodev.
 */

#define	CRYPTO_ALG_FLAG_SUPPORTED	1
#define	CRYPTO_ALG_FLAG_RNG_ENABLE	2
#define	CRYPTO_ALG_FLAG_DSA_SHA		4

struct crparam {
	uint8_t*	crp_p;
	uint32_t	crp_nbits;
};

#define CRK_MAXPARAM	8

/* input of CIOCKEY */
struct crypt_kop {
	uint32_t	crk_op;		/* cryptodev_crk_ot_t */
	uint32_t	crk_status;
	uint16_t	crk_iparams;
	uint16_t	crk_oparams;
	uint32_t	crk_pad1;
	struct crparam	crk_param[CRK_MAXPARAM];
};

typedef enum {
	CRK_MOD_EXP=0,
	CRK_MOD_EXP_CRT=1,
	CRK_DSA_SIGN=2,
	CRK_DSA_VERIFY=3,
	CRK_DH_COMPUTE_KEY=4,
	CRK_ALGORITHM_ALL
} cryptodev_crk_op_t;

#define CRK_ALGORITHM_MAX	CRK_ALGORITHM_ALL-1

/* features to be queried with CIOCASYMFEAT ioctl
 */
#define CRF_MOD_EXP		(1 << CRK_MOD_EXP)
#define CRF_MOD_EXP_CRT		(1 << CRK_MOD_EXP_CRT)
#define CRF_DSA_SIGN		(1 << CRK_DSA_SIGN)
#define CRF_DSA_VERIFY		(1 << CRK_DSA_VERIFY)
#define CRF_DH_COMPUTE_KEY	(1 << CRK_DH_COMPUTE_KEY)


/* ioctl's. Compatible with old linux cryptodev.h
 */
#define CRIOGET         _IOWR('c', 101, uint32_t)
#define CIOCGSESSION    _IOWR('c', 102, struct session_op)
#define CIOCFSESSION    _IOW('c', 103, uint32_t)
#define CIOCCRYPT       _IOWR('c', 104, struct crypt_op)
#define CIOCKEY         _IOWR('c', 105, struct crypt_kop)
#define CIOCASYMFEAT    _IOR('c', 106, uint32_t)

#endif /* L_CRYPTODEV_H */