1*61145dc2SMartin Matuska // SPDX-License-Identifier: CDDL-1.0 2eda14cbcSMatt Macy /* 3eda14cbcSMatt Macy * CDDL HEADER START 4eda14cbcSMatt Macy * 5eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 6eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 7eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 8eda14cbcSMatt Macy * 9eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0. 11eda14cbcSMatt Macy * See the License for the specific language governing permissions 12eda14cbcSMatt Macy * and limitations under the License. 13eda14cbcSMatt Macy * 14eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 15eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 17eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 18eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 19eda14cbcSMatt Macy * 20eda14cbcSMatt Macy * CDDL HEADER END 21eda14cbcSMatt Macy */ 222a58b312SMartin Matuska 23eda14cbcSMatt Macy /* 242a58b312SMartin Matuska * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. 252a58b312SMartin Matuska * Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de> 26eda14cbcSMatt Macy */ 27eda14cbcSMatt Macy 28eda14cbcSMatt Macy #ifndef _SHA2_IMPL_H 29eda14cbcSMatt Macy #define _SHA2_IMPL_H 30eda14cbcSMatt Macy 31eda14cbcSMatt Macy #include <sys/sha2.h> 32eda14cbcSMatt Macy 33eda14cbcSMatt Macy #ifdef __cplusplus 34eda14cbcSMatt Macy extern "C" { 35eda14cbcSMatt Macy #endif 36eda14cbcSMatt Macy 372a58b312SMartin Matuska /* transform function definition */ 382a58b312SMartin Matuska typedef void (*sha256_f)(uint32_t state[8], const void *data, size_t blks); 392a58b312SMartin Matuska typedef void (*sha512_f)(uint64_t state[8], const void *data, size_t blks); 402a58b312SMartin Matuska 412a58b312SMartin Matuska /* needed for checking valid implementations */ 422a58b312SMartin Matuska typedef boolean_t (*sha2_is_supported_f)(void); 432a58b312SMartin Matuska 442a58b312SMartin Matuska typedef struct { 452a58b312SMartin Matuska const char *name; 462a58b312SMartin Matuska sha256_f transform; 472a58b312SMartin Matuska sha2_is_supported_f is_supported; 482a58b312SMartin Matuska } sha256_ops_t; 492a58b312SMartin Matuska 502a58b312SMartin Matuska typedef struct { 512a58b312SMartin Matuska const char *name; 522a58b312SMartin Matuska sha512_f transform; 532a58b312SMartin Matuska sha2_is_supported_f is_supported; 542a58b312SMartin Matuska } sha512_ops_t; 552a58b312SMartin Matuska 562a58b312SMartin Matuska extern const sha256_ops_t *sha256_get_ops(void); 572a58b312SMartin Matuska extern const sha512_ops_t *sha512_get_ops(void); 582a58b312SMartin Matuska 59eda14cbcSMatt Macy typedef enum { 60eda14cbcSMatt Macy SHA1_TYPE, 61eda14cbcSMatt Macy SHA256_TYPE, 62eda14cbcSMatt Macy SHA384_TYPE, 63eda14cbcSMatt Macy SHA512_TYPE 64eda14cbcSMatt Macy } sha2_mech_t; 65eda14cbcSMatt Macy 66eda14cbcSMatt Macy /* 67eda14cbcSMatt Macy * Context for SHA2 mechanism. 68eda14cbcSMatt Macy */ 69eda14cbcSMatt Macy typedef struct sha2_ctx { 70eda14cbcSMatt Macy sha2_mech_type_t sc_mech_type; /* type of context */ 71eda14cbcSMatt Macy SHA2_CTX sc_sha2_ctx; /* SHA2 context */ 72eda14cbcSMatt Macy } sha2_ctx_t; 73eda14cbcSMatt Macy 74eda14cbcSMatt Macy /* 75eda14cbcSMatt Macy * Context for SHA2 HMAC and HMAC GENERAL mechanisms. 76eda14cbcSMatt Macy */ 77eda14cbcSMatt Macy typedef struct sha2_hmac_ctx { 78eda14cbcSMatt Macy sha2_mech_type_t hc_mech_type; /* type of context */ 79eda14cbcSMatt Macy uint32_t hc_digest_len; /* digest len in bytes */ 80eda14cbcSMatt Macy SHA2_CTX hc_icontext; /* inner SHA2 context */ 81eda14cbcSMatt Macy SHA2_CTX hc_ocontext; /* outer SHA2 context */ 82eda14cbcSMatt Macy } sha2_hmac_ctx_t; 83eda14cbcSMatt Macy 84eda14cbcSMatt Macy #ifdef __cplusplus 85eda14cbcSMatt Macy } 86eda14cbcSMatt Macy #endif 87eda14cbcSMatt Macy 88eda14cbcSMatt Macy #endif /* _SHA2_IMPL_H */ 89