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 https://opensource.org/licenses/CDDL-1.0.
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
30 extern "C" {
31 #endif
32 
33 #include <sys/zfs_context.h>
34 #include <sys/crypto/common.h>
35 
36 typedef void *crypto_context_t;
37 typedef void *crypto_ctx_template_t;
38 
39 /*
40  * Returns the mechanism type corresponding to a mechanism name.
41  */
42 #define	CRYPTO_MECH_INVALID	((uint64_t)-1)
43 extern crypto_mech_type_t crypto_mech2id(const char *name);
44 
45 /*
46  * Create and destroy context templates.
47  */
48 extern int crypto_create_ctx_template(crypto_mechanism_t *mech,
49     crypto_key_t *key, crypto_ctx_template_t *tmpl);
50 extern void crypto_destroy_ctx_template(crypto_ctx_template_t tmpl);
51 
52 /*
53  * Single and multi-part MAC operations.
54  */
55 extern int crypto_mac(crypto_mechanism_t *mech, crypto_data_t *data,
56     crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *mac);
57 extern int crypto_mac_init(crypto_mechanism_t *mech, crypto_key_t *key,
58     crypto_ctx_template_t tmpl, crypto_context_t *ctxp);
59 extern int crypto_mac_update(crypto_context_t ctx, crypto_data_t *data);
60 extern int crypto_mac_final(crypto_context_t ctx, crypto_data_t *data);
61 
62 /*
63  * Single-part encryption/decryption operations.
64  */
65 extern int crypto_encrypt(crypto_mechanism_t *mech, crypto_data_t *plaintext,
66     crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *ciphertext);
67 extern int crypto_decrypt(crypto_mechanism_t *mech, crypto_data_t *ciphertext,
68     crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *plaintext);
69 
70 #ifdef	__cplusplus
71 }
72 #endif
73 
74 #endif	/* _SYS_CRYPTO_API_H */
75