1 /*
2  * Copyright (c) 2018 Richard Palethorpe <rpalethorpe@suse.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef CRYPTOUSER_H__
19 #define CRYPTOUSER_H__
20 
21 #ifdef HAVE_LINUX_CRYPTOUSER_H
22 #  include <linux/cryptouser.h>
23 #else
24 #  include <stdint.h>
25 #  define CRYPTO_MAX_NAME 64
26 
27 enum {
28 	CRYPTO_MSG_BASE = 0x10,
29 	CRYPTO_MSG_NEWALG = 0x10,
30 	CRYPTO_MSG_DELALG,
31 	CRYPTO_MSG_UPDATEALG,
32 	CRYPTO_MSG_GETALG,
33 	CRYPTO_MSG_DELRNG,
34 	__CRYPTO_MSG_MAX
35 };
36 
37 enum crypto_attr_type_t {
38 	CRYPTOCFGA_UNSPEC,
39 	CRYPTOCFGA_PRIORITY_VAL,	/* uint32_t */
40 	CRYPTOCFGA_REPORT_LARVAL,	/* struct crypto_report_larval */
41 	CRYPTOCFGA_REPORT_HASH,		/* struct crypto_report_hash */
42 	CRYPTOCFGA_REPORT_BLKCIPHER,	/* struct crypto_report_blkcipher */
43 	CRYPTOCFGA_REPORT_AEAD,		/* struct crypto_report_aead */
44 	CRYPTOCFGA_REPORT_COMPRESS,	/* struct crypto_report_comp */
45 	CRYPTOCFGA_REPORT_RNG,		/* struct crypto_report_rng */
46 	CRYPTOCFGA_REPORT_CIPHER,	/* struct crypto_report_cipher */
47 	CRYPTOCFGA_REPORT_AKCIPHER,	/* struct crypto_report_akcipher */
48 	CRYPTOCFGA_REPORT_KPP,		/* struct crypto_report_kpp */
49 	CRYPTOCFGA_REPORT_ACOMP,	/* struct crypto_report_acomp */
50 	__CRYPTOCFGA_MAX
51 
52 #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1)
53 };
54 
55 struct crypto_user_alg {
56 	char cru_name[CRYPTO_MAX_NAME];
57 	char cru_driver_name[CRYPTO_MAX_NAME];
58 	char cru_module_name[CRYPTO_MAX_NAME];
59 	uint32_t cru_type;
60 	uint32_t cru_mask;
61 	uint32_t cru_refcnt;
62 	uint32_t cru_flags;
63 };
64 
65 struct crypto_report_larval {
66 	char type[CRYPTO_MAX_NAME];
67 };
68 
69 struct crypto_report_hash {
70 	char type[CRYPTO_MAX_NAME];
71 	unsigned int blocksize;
72 	unsigned int digestsize;
73 };
74 
75 struct crypto_report_cipher {
76 	char type[CRYPTO_MAX_NAME];
77 	unsigned int blocksize;
78 	unsigned int min_keysize;
79 	unsigned int max_keysize;
80 };
81 
82 struct crypto_report_blkcipher {
83 	char type[CRYPTO_MAX_NAME];
84 	char geniv[CRYPTO_MAX_NAME];
85 	unsigned int blocksize;
86 	unsigned int min_keysize;
87 	unsigned int max_keysize;
88 	unsigned int ivsize;
89 };
90 
91 struct crypto_report_aead {
92 	char type[CRYPTO_MAX_NAME];
93 	char geniv[CRYPTO_MAX_NAME];
94 	unsigned int blocksize;
95 	unsigned int maxauthsize;
96 	unsigned int ivsize;
97 };
98 
99 struct crypto_report_comp {
100 	char type[CRYPTO_MAX_NAME];
101 };
102 
103 struct crypto_report_rng {
104 	char type[CRYPTO_MAX_NAME];
105 	unsigned int seedsize;
106 };
107 
108 struct crypto_report_akcipher {
109 	char type[CRYPTO_MAX_NAME];
110 };
111 
112 struct crypto_report_kpp {
113 	char type[CRYPTO_MAX_NAME];
114 };
115 
116 struct crypto_report_acomp {
117 	char type[CRYPTO_MAX_NAME];
118 };
119 
120 #endif	/* HAVE_LINUX_CRYPTOUSER_H */
121 
122 /* These are taken from include/crypto.h in the kernel tree. They are not
123  * currently included in the user API.
124  */
125 #ifndef CRYPTO_MAX_ALG_NAME
126 #  define CRYPTO_MAX_ALG_NAME		128
127 #endif
128 
129 #ifndef CRYPTO_ALG_TYPE_MASK
130 #  define CRYPTO_ALG_TYPE_MASK		0x0000000f
131 #endif
132 #ifndef CRYPTO_ALG_TYPE_CIPHER
133 #  define CRYPTO_ALG_TYPE_CIPHER	0x00000001
134 #endif
135 #ifndef CRYPTO_ALG_TYPE_COMPRESS
136 #  define CRYPTO_ALG_TYPE_COMPRESS	0x00000002
137 #endif
138 #ifndef CRYPTO_ALG_TYPE_AEAD
139 #  define CRYPTO_ALG_TYPE_AEAD		0x00000003
140 #endif
141 #ifndef CRYPTO_ALG_TYPE_BLKCIPHER
142 #  define CRYPTO_ALG_TYPE_BLKCIPHER	0x00000004
143 #endif
144 #ifndef CRYPTO_ALG_TYPE_ABLKCIPHER
145 #  define CRYPTO_ALG_TYPE_ABLKCIPHER	0x00000005
146 #endif
147 #ifndef CRYPTO_ALG_TYPE_SKCIPHER
148 #  define CRYPTO_ALG_TYPE_SKCIPHER	0x00000005
149 #endif
150 #ifndef CRYPTO_ALG_TYPE_GIVCIPHER
151 #  define CRYPTO_ALG_TYPE_GIVCIPHER	0x00000006
152 #endif
153 #ifndef CRYPTO_ALG_TYPE_KPP
154 #  define CRYPTO_ALG_TYPE_KPP		0x00000008
155 #endif
156 #ifndef CRYPTO_ALG_TYPE_ACOMPRESS
157 #  define CRYPTO_ALG_TYPE_ACOMPRESS	0x0000000a
158 #endif
159 #ifndef CRYPTO_ALG_TYPE_SCOMPRESS
160 #  define CRYPTO_ALG_TYPE_SCOMPRESS	0x0000000b
161 #endif
162 #ifndef CRYPTO_ALG_TYPE_RNG
163 #  define CRYPTO_ALG_TYPE_RNG		0x0000000c
164 #endif
165 #ifndef CRYPTO_ALG_TYPE_AKCIPHER
166 #  define CRYPTO_ALG_TYPE_AKCIPHER	0x0000000d
167 #endif
168 #ifndef CRYPTO_ALG_TYPE_DIGEST
169 #  define CRYPTO_ALG_TYPE_DIGEST	0x0000000e
170 #endif
171 #ifndef CRYPTO_ALG_TYPE_HASH
172 #  define CRYPTO_ALG_TYPE_HASH		0x0000000e
173 #endif
174 #ifndef CRYPTO_ALG_TYPE_SHASH
175 #  define CRYPTO_ALG_TYPE_SHASH		0x0000000e
176 #endif
177 #ifndef CRYPTO_ALG_TYPE_AHASH
178 #  define CRYPTO_ALG_TYPE_AHASH		0x0000000f
179 #endif
180 
181 #ifndef CRYPTO_ALG_TYPE_HASH_MASK
182 #  define CRYPTO_ALG_TYPE_HASH_MASK	0x0000000e
183 #endif
184 #ifndef CRYPTO_ALG_TYPE_AHASH_MASK
185 #  define CRYPTO_ALG_TYPE_AHASH_MASK	0x0000000e
186 #endif
187 #ifndef CRYPTO_ALG_TYPE_BLKCIPHER_MASK
188 #  define CRYPTO_ALG_TYPE_BLKCIPHER_MASK	0x0000000c
189 #endif
190 #ifndef CRYPTO_ALG_TYPE_ACOMPRESS_MASK
191 #  define CRYPTO_ALG_TYPE_ACOMPRESS_MASK	0x0000000e
192 #endif
193 
194 #endif	/* CRYPTOUSER_H__ */
195