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 http://www.opensolaris.org/os/licensing.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 /* Copyright 2013 Saso Kiselkov. All rights reserved. */
30 #include <sys/types.h> /* for uint_* */
36 #define SHA2_HMAC_MIN_KEY_LEN 1 /* SHA2-HMAC min key length in bytes */
37 #define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bytes */
39 #define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */
41 #define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */
45 #define SHA256_HMAC_GEN 2
49 * The contents of this structure are a private interface between the
50 * Init/Update/Final calls of the functions defined below.
51 * Callers must never attempt to read or write any of the fields
52 * in this structure directly.
55 uint32_t algotype
; /* Algorithm Type */
57 /* state (ABCDEFGH) */
59 uint32_t s32
[8]; /* for SHA256 */
60 uint64_t s64
[8]; /* for SHA384/512 */
64 uint32_t c32
[2]; /* for SHA256 , modulo 2^64 */
65 uint64_t c64
[2]; /* for SHA384/512, modulo 2^128 */
68 uint8_t buf8
[128]; /* undigested input */
69 uint32_t buf32
[32]; /* realigned input */
70 uint64_t buf64
[16]; /* realigned input */
74 typedef SHA2_CTX SHA256_CTX
;
75 typedef SHA2_CTX SHA384_CTX
;
76 typedef SHA2_CTX SHA512_CTX
;
78 extern void SHA2Init(uint64_t mech
, SHA2_CTX
*);
80 extern void SHA2Update(SHA2_CTX
*, const void *, size_t);
82 extern void SHA2Final(void *, SHA2_CTX
*);
84 extern void SHA256Init(SHA256_CTX
*);
86 extern void SHA256Update(SHA256_CTX
*, const void *, size_t);
88 extern void SHA256Final(void *, SHA256_CTX
*);
92 * The following types/functions are all private to the implementation
93 * of the SHA2 functions and must not be used by consumers of the interface
97 * List of support mechanisms in this module.
99 * It is important to note that in the module, division or modulus calculations
100 * are used on the enumerated type to determine which mechanism is being used;
101 * therefore, changing the order or additional mechanisms should be done
104 typedef enum sha2_mech_type
{
105 SHA256_MECH_INFO_TYPE
, /* SUN_CKM_SHA256 */
106 SHA256_HMAC_MECH_INFO_TYPE
, /* SUN_CKM_SHA256_HMAC */
107 SHA256_HMAC_GEN_MECH_INFO_TYPE
, /* SUN_CKM_SHA256_HMAC_GENERAL */
110 #endif /* _SHA2_IMPL */
116 #endif /* _SYS_SHA2_H */