]> git.proxmox.com Git - mirror_zfs.git/blame - include/sys/crypto/api.h
module/*.ko: prune .data, global .rodata
[mirror_zfs.git] / include / sys / crypto / api.h
CommitLineData
0b04990a
TC
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef _SYS_CRYPTO_API_H
27#define _SYS_CRYPTO_API_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <sys/zfs_context.h>
34#include <sys/crypto/common.h>
35
36typedef long crypto_req_id_t;
37typedef void *crypto_bc_t;
38typedef void *crypto_context_t;
39typedef void *crypto_ctx_template_t;
40
41typedef uint32_t crypto_call_flag_t;
42
43/* crypto_call_flag's values */
44#define CRYPTO_ALWAYS_QUEUE 0x00000001 /* ALWAYS queue the req. */
45#define CRYPTO_NOTIFY_OPDONE 0x00000002 /* Notify intermediate steps */
46#define CRYPTO_SKIP_REQID 0x00000004 /* Skip request ID generation */
47#define CRYPTO_RESTRICTED 0x00000008 /* cannot use restricted prov */
48
49typedef struct {
50 crypto_call_flag_t cr_flag;
51 void (*cr_callback_func)(void *, int);
52 void *cr_callback_arg;
53 crypto_req_id_t cr_reqid;
54} crypto_call_req_t;
55
56/*
57 * Returns the mechanism type corresponding to a mechanism name.
58 */
59
60#define CRYPTO_MECH_INVALID ((uint64_t)-1)
18168da7 61extern crypto_mech_type_t crypto_mech2id(const char *name);
0b04990a
TC
62
63/*
64 * Create and destroy context templates.
65 */
66extern int crypto_create_ctx_template(crypto_mechanism_t *mech,
67 crypto_key_t *key, crypto_ctx_template_t *tmpl, int kmflag);
68extern void crypto_destroy_ctx_template(crypto_ctx_template_t tmpl);
69
70/*
71 * Single and multi-part digest operations.
72 */
73extern int crypto_digest(crypto_mechanism_t *mech, crypto_data_t *data,
74 crypto_data_t *digest, crypto_call_req_t *cr);
75extern int crypto_digest_prov(crypto_provider_t, crypto_session_id_t,
76 crypto_mechanism_t *, crypto_data_t *, crypto_data_t *,
77 crypto_call_req_t *);
78extern int crypto_digest_init(crypto_mechanism_t *mech, crypto_context_t *ctxp,
79 crypto_call_req_t *cr);
80extern int crypto_digest_init_prov(crypto_provider_t, crypto_session_id_t,
81 crypto_mechanism_t *, crypto_context_t *, crypto_call_req_t *);
82extern int crypto_digest_update(crypto_context_t ctx, crypto_data_t *data,
83 crypto_call_req_t *cr);
84extern int crypto_digest_final(crypto_context_t ctx, crypto_data_t *digest,
85 crypto_call_req_t *cr);
86
87/*
88 * Single and multi-part MAC operations.
89 */
90extern int crypto_mac(crypto_mechanism_t *mech, crypto_data_t *data,
91 crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *mac,
92 crypto_call_req_t *cr);
93extern int crypto_mac_prov(crypto_provider_t, crypto_session_id_t,
94 crypto_mechanism_t *, crypto_data_t *, crypto_key_t *,
95 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
96extern int crypto_mac_verify(crypto_mechanism_t *mech, crypto_data_t *data,
97 crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *mac,
98 crypto_call_req_t *cr);
99extern int crypto_mac_verify_prov(crypto_provider_t, crypto_session_id_t,
100 crypto_mechanism_t *, crypto_data_t *, crypto_key_t *,
101 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
102extern int crypto_mac_init(crypto_mechanism_t *mech, crypto_key_t *key,
103 crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *cr);
104extern int crypto_mac_init_prov(crypto_provider_t, crypto_session_id_t,
105 crypto_mechanism_t *, crypto_key_t *, crypto_ctx_template_t,
106 crypto_context_t *, crypto_call_req_t *);
107extern int crypto_mac_update(crypto_context_t ctx, crypto_data_t *data,
108 crypto_call_req_t *cr);
109extern int crypto_mac_final(crypto_context_t ctx, crypto_data_t *data,
110 crypto_call_req_t *cr);
111
112/*
113 * Single and multi-part sign with private key operations.
114 */
115extern int crypto_sign(crypto_mechanism_t *mech, crypto_key_t *key,
116 crypto_data_t *data, crypto_ctx_template_t tmpl,
117 crypto_data_t *signature, crypto_call_req_t *cr);
118extern int crypto_sign_prov(crypto_provider_t, crypto_session_id_t,
119 crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
120 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
121extern int crypto_sign_init(crypto_mechanism_t *mech, crypto_key_t *key,
122 crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *cr);
123extern int crypto_sign_init_prov(crypto_provider_t, crypto_session_id_t,
124 crypto_mechanism_t *, crypto_key_t *, crypto_ctx_template_t,
125 crypto_context_t *, crypto_call_req_t *);
126extern int crypto_sign_update(crypto_context_t ctx, crypto_data_t *data,
127 crypto_call_req_t *cr);
128extern int crypto_sign_final(crypto_context_t ctx, crypto_data_t *signature,
129 crypto_call_req_t *cr);
130extern int crypto_sign_recover_init_prov(crypto_provider_t,
131 crypto_session_id_t, crypto_mechanism_t *, crypto_key_t *,
132 crypto_ctx_template_t tmpl, crypto_context_t *, crypto_call_req_t *);
133extern int crypto_sign_recover(crypto_mechanism_t *mech, crypto_key_t *key,
134 crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
135 crypto_call_req_t *cr);
136extern int crypto_sign_recover_prov(crypto_provider_t, crypto_session_id_t,
137 crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
138 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
139
140/*
141 * Single and multi-part verify with public key operations.
142 */
143extern int crypto_verify(crypto_mechanism_t *mech, crypto_key_t *key,
144 crypto_data_t *data, crypto_ctx_template_t tmpl, crypto_data_t *signature,
145 crypto_call_req_t *cr);
146extern int crypto_verify_prov(crypto_provider_t, crypto_session_id_t,
147 crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
148 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
149extern int crypto_verify_init(crypto_mechanism_t *mech, crypto_key_t *key,
150 crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *cr);
151extern int crypto_verify_init_prov(crypto_provider_t, crypto_session_id_t,
152 crypto_mechanism_t *, crypto_key_t *, crypto_ctx_template_t,
153 crypto_context_t *, crypto_call_req_t *);
154extern int crypto_verify_update(crypto_context_t ctx, crypto_data_t *data,
155 crypto_call_req_t *cr);
156extern int crypto_verify_final(crypto_context_t ctx, crypto_data_t *signature,
157 crypto_call_req_t *cr);
158extern int crypto_verify_recover_init_prov(crypto_provider_t,
159 crypto_session_id_t, crypto_mechanism_t *, crypto_key_t *,
160 crypto_ctx_template_t tmpl, crypto_context_t *, crypto_call_req_t *);
161extern int crypto_verify_recover(crypto_mechanism_t *mech, crypto_key_t *key,
162 crypto_data_t *signature, crypto_ctx_template_t tmpl, crypto_data_t *data,
163 crypto_call_req_t *cr);
164extern int crypto_verify_recover_prov(crypto_provider_t, crypto_session_id_t,
165 crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
166 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
167
168/*
169 * Single and multi-part encryption operations.
170 */
171extern int crypto_encrypt(crypto_mechanism_t *mech, crypto_data_t *plaintext,
172 crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *ciphertext,
173 crypto_call_req_t *cr);
174extern int crypto_encrypt_prov(crypto_provider_t, crypto_session_id_t,
175 crypto_mechanism_t *, crypto_data_t *, crypto_key_t *,
176 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
177extern int crypto_encrypt_init(crypto_mechanism_t *mech, crypto_key_t *key,
178 crypto_ctx_template_t tmpl, crypto_context_t *ctxp, crypto_call_req_t *cr);
179extern int crypto_encrypt_init_prov(crypto_provider_t, crypto_session_id_t,
180 crypto_mechanism_t *, crypto_key_t *, crypto_ctx_template_t,
181 crypto_context_t *, crypto_call_req_t *);
182extern int crypto_encrypt_update(crypto_context_t ctx,
183 crypto_data_t *plaintext, crypto_data_t *ciphertext,
184 crypto_call_req_t *cr);
185extern int crypto_encrypt_final(crypto_context_t ctx,
186 crypto_data_t *ciphertext, crypto_call_req_t *cr);
187
188/*
189 * Single and multi-part decryption operations.
190 */
191extern int crypto_decrypt(crypto_mechanism_t *mech, crypto_data_t *ciphertext,
192 crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *plaintext,
193 crypto_call_req_t *cr);
194extern int crypto_decrypt_prov(crypto_provider_t, crypto_session_id_t,
195 crypto_mechanism_t *, crypto_data_t *, crypto_key_t *,
196 crypto_ctx_template_t, crypto_data_t *, crypto_call_req_t *);
197extern int crypto_decrypt_init(crypto_mechanism_t *mech, crypto_key_t *key,
198 crypto_ctx_template_t tmpl, crypto_context_t *ctxp,
199 crypto_call_req_t *cr);
200extern int crypto_decrypt_init_prov(crypto_provider_t, crypto_session_id_t,
201 crypto_mechanism_t *, crypto_key_t *, crypto_ctx_template_t,
202 crypto_context_t *, crypto_call_req_t *);
203extern int crypto_decrypt_update(crypto_context_t ctx,
204 crypto_data_t *ciphertext, crypto_data_t *plaintext,
205 crypto_call_req_t *cr);
206extern int crypto_decrypt_final(crypto_context_t ctx, crypto_data_t *plaintext,
207 crypto_call_req_t *cr);
208
209/*
210 * Single and multi-part encrypt/MAC dual operations.
211 */
212extern int crypto_encrypt_mac(crypto_mechanism_t *encr_mech,
213 crypto_mechanism_t *mac_mech, crypto_data_t *pt,
214 crypto_key_t *encr_key, crypto_key_t *mac_key,
215 crypto_ctx_template_t encr_tmpl, crypto_ctx_template_t mac_tmpl,
216 crypto_dual_data_t *ct, crypto_data_t *mac, crypto_call_req_t *cr);
217extern int crypto_encrypt_mac_prov(crypto_provider_t, crypto_session_id_t,
218 crypto_mechanism_t *, crypto_mechanism_t *, crypto_data_t *,
219 crypto_key_t *, crypto_key_t *, crypto_ctx_template_t,
220 crypto_ctx_template_t, crypto_dual_data_t *, crypto_data_t *,
221 crypto_call_req_t *);
222extern int crypto_encrypt_mac_init(crypto_mechanism_t *encr_mech,
223 crypto_mechanism_t *mac_mech, crypto_key_t *encr_key,
224 crypto_key_t *mac_key, crypto_ctx_template_t encr_tmpl,
225 crypto_ctx_template_t mac_tmpl, crypto_context_t *ctxp,
226 crypto_call_req_t *cr);
227extern int crypto_encrypt_mac_init_prov(crypto_provider_t, crypto_session_id_t,
228 crypto_mechanism_t *, crypto_mechanism_t *, crypto_key_t *, crypto_key_t *,
229 crypto_ctx_template_t, crypto_ctx_template_t, crypto_context_t *,
230 crypto_call_req_t *);
231extern int crypto_encrypt_mac_update(crypto_context_t ctx,
232 crypto_data_t *pt, crypto_dual_data_t *ct, crypto_call_req_t *cr);
233extern int crypto_encrypt_mac_final(crypto_context_t ctx,
234 crypto_dual_data_t *ct, crypto_data_t *mac, crypto_call_req_t *cr);
235
236/*
237 * Single and multi-part MAC/decrypt dual operations.
238 */
239extern int crypto_mac_decrypt(crypto_mechanism_t *mac_mech,
240 crypto_mechanism_t *decr_mech, crypto_dual_data_t *ct,
241 crypto_key_t *mac_key, crypto_key_t *decr_key,
242 crypto_ctx_template_t mac_tmpl, crypto_ctx_template_t decr_tmpl,
243 crypto_data_t *mac, crypto_data_t *pt, crypto_call_req_t *cr);
244extern int crypto_mac_decrypt_prov(crypto_provider_t, crypto_session_id_t,
245 crypto_mechanism_t *mac_mech, crypto_mechanism_t *decr_mech,
246 crypto_dual_data_t *ct, crypto_key_t *mac_key, crypto_key_t *decr_key,
247 crypto_ctx_template_t mac_tmpl, crypto_ctx_template_t decr_tmpl,
248 crypto_data_t *mac, crypto_data_t *pt, crypto_call_req_t *cr);
249extern int crypto_mac_verify_decrypt(crypto_mechanism_t *mac_mech,
250 crypto_mechanism_t *decr_mech, crypto_dual_data_t *ct,
251 crypto_key_t *mac_key, crypto_key_t *decr_key,
252 crypto_ctx_template_t mac_tmpl, crypto_ctx_template_t decr_tmpl,
253 crypto_data_t *mac, crypto_data_t *pt, crypto_call_req_t *cr);
254extern int crypto_mac_verify_decrypt_prov(crypto_provider_t,
255 crypto_session_id_t, crypto_mechanism_t *mac_mech,
256 crypto_mechanism_t *decr_mech, crypto_dual_data_t *ct,
257 crypto_key_t *mac_key, crypto_key_t *decr_key,
258 crypto_ctx_template_t mac_tmpl, crypto_ctx_template_t decr_tmpl,
259 crypto_data_t *mac, crypto_data_t *pt, crypto_call_req_t *cr);
260extern int crypto_mac_decrypt_init(crypto_mechanism_t *mac_mech,
261 crypto_mechanism_t *decr_mech, crypto_key_t *mac_key,
262 crypto_key_t *decr_key, crypto_ctx_template_t mac_tmpl,
263 crypto_ctx_template_t decr_tmpl, crypto_context_t *ctxp,
264 crypto_call_req_t *cr);
265extern int crypto_mac_decrypt_init_prov(crypto_provider_t,
266 crypto_session_id_t, crypto_mechanism_t *mac_mech,
267 crypto_mechanism_t *decr_mech, crypto_key_t *mac_key,
268 crypto_key_t *decr_key, crypto_ctx_template_t mac_tmpl,
269 crypto_ctx_template_t decr_tmpl, crypto_context_t *ctxp,
270 crypto_call_req_t *cr);
271extern int crypto_mac_decrypt_update(crypto_context_t ctx,
272 crypto_dual_data_t *ct, crypto_data_t *pt, crypto_call_req_t *cr);
273extern int crypto_mac_decrypt_final(crypto_context_t ctx, crypto_data_t *mac,
274 crypto_data_t *pt, crypto_call_req_t *cr);
275
276/* Session Management */
277extern int crypto_session_open(crypto_provider_t, crypto_session_id_t *,
278 crypto_call_req_t *);
279extern int crypto_session_close(crypto_provider_t, crypto_session_id_t,
280 crypto_call_req_t *);
281extern int crypto_session_login(crypto_provider_t, crypto_session_id_t,
282 crypto_user_type_t, char *, size_t, crypto_call_req_t *);
283extern int crypto_session_logout(crypto_provider_t, crypto_session_id_t,
284 crypto_call_req_t *);
285
286/* Object Management */
287extern int crypto_object_copy(crypto_provider_t, crypto_session_id_t,
288 crypto_object_id_t, crypto_object_attribute_t *, uint_t,
289 crypto_object_id_t *, crypto_call_req_t *);
290extern int crypto_object_create(crypto_provider_t, crypto_session_id_t,
291 crypto_object_attribute_t *, uint_t, crypto_object_id_t *,
292 crypto_call_req_t *);
293extern int crypto_object_destroy(crypto_provider_t, crypto_session_id_t,
294 crypto_object_id_t, crypto_call_req_t *);
295extern int crypto_object_get_attribute_value(crypto_provider_t,
296 crypto_session_id_t, crypto_object_id_t, crypto_object_attribute_t *,
297 uint_t, crypto_call_req_t *);
298extern int crypto_object_get_size(crypto_provider_t, crypto_session_id_t,
299 crypto_object_id_t, size_t *, crypto_call_req_t *);
300extern int crypto_object_find_final(crypto_provider_t, void *,
301 crypto_call_req_t *);
302extern int crypto_object_find_init(crypto_provider_t, crypto_session_id_t,
303 crypto_object_attribute_t *, uint_t, void **, crypto_call_req_t *);
304extern int crypto_object_find(crypto_provider_t, void *, crypto_object_id_t *,
305 uint_t *, uint_t, crypto_call_req_t *);
306extern int crypto_object_set_attribute_value(crypto_provider_t,
307 crypto_session_id_t, crypto_object_id_t, crypto_object_attribute_t *,
308 uint_t, crypto_call_req_t *);
309
310/* Key Management */
311extern int crypto_key_derive(crypto_provider_t, crypto_session_id_t,
312 crypto_mechanism_t *, crypto_key_t *, crypto_object_attribute_t *,
313 uint_t, crypto_object_id_t *, crypto_call_req_t *);
314extern int crypto_key_generate(crypto_provider_t, crypto_session_id_t,
315 crypto_mechanism_t *, crypto_object_attribute_t *, uint_t,
316 crypto_object_id_t *, crypto_call_req_t *);
317extern int crypto_key_generate_pair(crypto_provider_t, crypto_session_id_t,
318 crypto_mechanism_t *, crypto_object_attribute_t *, uint_t,
319 crypto_object_attribute_t *, uint_t, crypto_object_id_t *,
320 crypto_object_id_t *, crypto_call_req_t *);
321extern int crypto_key_unwrap(crypto_provider_t, crypto_session_id_t,
322 crypto_mechanism_t *, crypto_key_t *, uchar_t *, size_t *,
323 crypto_object_attribute_t *, uint_t, crypto_object_id_t *,
324 crypto_call_req_t *);
325extern int crypto_key_wrap(crypto_provider_t, crypto_session_id_t,
326 crypto_mechanism_t *, crypto_key_t *, crypto_object_id_t *, uchar_t *,
327 size_t *, crypto_call_req_t *);
328extern int crypto_key_check_prov(crypto_provider_t, crypto_mechanism_t *mech,
329 crypto_key_t *key);
330extern int crypto_key_check(crypto_mechanism_t *mech, crypto_key_t *key);
331
332
333/*
334 * Routines to cancel a single asynchronous request or all asynchronous
335 * requests associated with a particular context.
336 */
337extern void crypto_cancel_req(crypto_req_id_t req);
338extern void crypto_cancel_ctx(crypto_context_t ctx);
339
340/*
341 * crypto_get_mech_list(9F) allocates and returns the list of currently
342 * supported cryptographic mechanisms.
343 */
344extern crypto_mech_name_t *crypto_get_mech_list(uint_t *count, int kmflag);
345extern void crypto_free_mech_list(crypto_mech_name_t *mech_names,
346 uint_t count);
347
348extern crypto_provider_t crypto_get_provider(char *, char *, char *);
349extern int crypto_get_provinfo(crypto_provider_t, crypto_provider_ext_info_t *);
350extern void crypto_release_provider(crypto_provider_t);
351
352/*
353 * A kernel consumer can request to be notified when some particular event
354 * occurs. The valid events, callback function type, and functions to
355 * be called to register or unregister for notification are defined below.
356 */
357
358#define CRYPTO_EVENT_MECHS_CHANGED 0x00000001
359#define CRYPTO_EVENT_PROVIDER_REGISTERED 0x00000002
360#define CRYPTO_EVENT_PROVIDER_UNREGISTERED 0x00000004
361
362typedef enum {
363 CRYPTO_MECH_ADDED = 1,
364 CRYPTO_MECH_REMOVED
365} crypto_event_change_t;
366
367/* The event_arg argument structure for CRYPTO_EVENT_PROVIDERS_CHANGE event */
368typedef struct crypto_notify_event_change {
369 crypto_mech_name_t ec_mech_name;
370 crypto_provider_type_t ec_provider_type;
371 crypto_event_change_t ec_change;
372} crypto_notify_event_change_t;
373
374typedef void *crypto_notify_handle_t;
375typedef void (*crypto_notify_callback_t)(uint32_t event_mask, void *event_arg);
376
377extern crypto_notify_handle_t crypto_notify_events(
378 crypto_notify_callback_t nf, uint32_t event_mask);
379extern void crypto_unnotify_events(crypto_notify_handle_t);
380
381/*
382 * crypto_bufcall(9F) group of routines.
383 */
384extern crypto_bc_t crypto_bufcall_alloc(void);
385extern int crypto_bufcall_free(crypto_bc_t bc);
386extern int crypto_bufcall(crypto_bc_t bc, void (*func)(void *arg), void *arg);
387extern int crypto_unbufcall(crypto_bc_t bc);
388
389/*
390 * To obtain the list of key size ranges supported by a mechanism.
391 */
392
393#define CRYPTO_MECH_USAGE_ENCRYPT 0x00000001
394#define CRYPTO_MECH_USAGE_DECRYPT 0x00000002
395#define CRYPTO_MECH_USAGE_MAC 0x00000004
396
397typedef uint32_t crypto_mech_usage_t;
398
399typedef struct crypto_mechanism_info {
400 size_t mi_min_key_size;
401 size_t mi_max_key_size;
402 crypto_keysize_unit_t mi_keysize_unit; /* for mi_xxx_key_size */
403 crypto_mech_usage_t mi_usage;
404} crypto_mechanism_info_t;
405
406#ifdef _SYSCALL32
407
408typedef struct crypto_mechanism_info32 {
409 size32_t mi_min_key_size;
410 size32_t mi_max_key_size;
411 crypto_keysize_unit_t mi_keysize_unit; /* for mi_xxx_key_size */
412 crypto_mech_usage_t mi_usage;
413} crypto_mechanism_info32_t;
414
415#endif /* _SYSCALL32 */
416
417extern int crypto_get_all_mech_info(crypto_mech_type_t,
418 crypto_mechanism_info_t **, uint_t *, int);
419extern void crypto_free_all_mech_info(crypto_mechanism_info_t *, uint_t);
420
421#ifdef __cplusplus
422}
423#endif
424
425#endif /* _SYS_CRYPTO_API_H */