PAM: support password changes even when not mounted
[zfs.git] / include / sys / sha2.h
blob81dfbbb8cea93cb5b70f56ee2e10aeb537c3b190
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
26 #ifndef _SYS_SHA2_H
27 #define _SYS_SHA2_H
29 #ifdef _KERNEL
30 #include <sys/types.h>
31 #else
32 #include <stdint.h>
33 #include <stdlib.h>
34 #endif
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
40 #define SHA224_BLOCK_LENGTH 64
41 #define SHA256_BLOCK_LENGTH 64
42 #define SHA384_BLOCK_LENGTH 128
43 #define SHA512_BLOCK_LENGTH 128
45 #define SHA224_DIGEST_LENGTH 28
46 #define SHA256_DIGEST_LENGTH 32
47 #define SHA384_DIGEST_LENGTH 48
48 #define SHA512_DIGEST_LENGTH 64
50 #define SHA512_224_DIGEST_LENGTH 28
51 #define SHA512_256_DIGEST_LENGTH 32
53 #define SHA256_HMAC_BLOCK_SIZE 64
54 #define SHA512_HMAC_BLOCK_SIZE 128
56 /* sha256 context */
57 typedef struct {
58 uint32_t state[8];
59 uint64_t count[2];
60 uint8_t wbuf[64];
62 /* const sha256_ops_t *ops */
63 const void *ops;
64 } sha256_ctx;
66 /* sha512 context */
67 typedef struct {
68 uint64_t state[8];
69 uint64_t count[2];
70 uint8_t wbuf[128];
72 /* const sha256_ops_t *ops */
73 const void *ops;
74 } sha512_ctx;
76 /* SHA2 context */
77 typedef struct {
78 union {
79 sha256_ctx sha256;
80 sha512_ctx sha512;
83 /* algorithm type */
84 int algotype;
85 } SHA2_CTX;
87 /* SHA2 algorithm types */
88 typedef enum sha2_mech_type {
89 SHA256_MECH_INFO_TYPE, /* SUN_CKM_SHA256 */
90 SHA256_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC */
91 SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */
92 SHA384_MECH_INFO_TYPE, /* SUN_CKM_SHA384 */
93 SHA384_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC */
94 SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */
95 SHA512_MECH_INFO_TYPE, /* SUN_CKM_SHA512 */
96 SHA512_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC */
97 SHA512_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC_GENERAL */
98 SHA512_224_MECH_INFO_TYPE, /* SUN_CKM_SHA512_224 */
99 SHA512_256_MECH_INFO_TYPE /* SUN_CKM_SHA512_256 */
100 } sha2_mech_type_t;
102 #define SHA256 0
103 #define SHA256_HMAC 1
104 #define SHA256_HMAC_GEN 2
105 #define SHA384 3
106 #define SHA384_HMAC 4
107 #define SHA384_HMAC_GEN 5
108 #define SHA512 6
109 #define SHA512_HMAC 7
110 #define SHA512_HMAC_GEN 8
111 #define SHA512_224 9
112 #define SHA512_256 10
114 /* SHA2 Init function */
115 extern void SHA2Init(int algotype, SHA2_CTX *ctx);
117 /* SHA2 Update function */
118 extern void SHA2Update(SHA2_CTX *ctx, const void *data, size_t len);
120 /* SHA2 Final function */
121 extern void SHA2Final(void *digest, SHA2_CTX *ctx);
123 #ifdef __cplusplus
125 #endif
127 #endif /* SYS_SHA2_H */