1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or https://opensource.org/licenses/CDDL-1.0. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_CRYPTO_API_H 28 #define _SYS_CRYPTO_API_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #include <sys/zfs_context.h> 35 #include <sys/crypto/common.h> 36 37 typedef void *crypto_context_t; 38 typedef void *crypto_ctx_template_t; 39 40 /* 41 * Returns the mechanism type corresponding to a mechanism name. 42 */ 43 #define CRYPTO_MECH_INVALID ((uint64_t)-1) 44 extern crypto_mech_type_t crypto_mech2id(const char *name); 45 46 /* 47 * Create and destroy context templates. 48 */ 49 extern int crypto_create_ctx_template(crypto_mechanism_t *mech, 50 crypto_key_t *key, crypto_ctx_template_t *tmpl); 51 extern void crypto_destroy_ctx_template(crypto_ctx_template_t tmpl); 52 53 /* 54 * Single and multi-part MAC operations. 55 */ 56 extern int crypto_mac(crypto_mechanism_t *mech, crypto_data_t *data, 57 crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *mac); 58 extern int crypto_mac_init(crypto_mechanism_t *mech, crypto_key_t *key, 59 crypto_ctx_template_t tmpl, crypto_context_t *ctxp); 60 extern int crypto_mac_update(crypto_context_t ctx, crypto_data_t *data); 61 extern int crypto_mac_final(crypto_context_t ctx, crypto_data_t *data); 62 63 /* 64 * Single-part encryption/decryption operations. 65 */ 66 extern int crypto_encrypt(crypto_mechanism_t *mech, crypto_data_t *plaintext, 67 crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *ciphertext); 68 extern int crypto_decrypt(crypto_mechanism_t *mech, crypto_data_t *ciphertext, 69 crypto_key_t *key, crypto_ctx_template_t tmpl, crypto_data_t *plaintext); 70 71 #ifdef __cplusplus 72 } 73 #endif 74 75 #endif /* _SYS_CRYPTO_API_H */ 76