sha2.h (f66d273d) sha2.h (734b6a94)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
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, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * 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 http://www.opensolaris.org/os/licensing.
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/*
7 *
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.
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/*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef _SYS_SHA2_H
28#define _SYS_SHA2_H
29
30#pragma ident "%Z%%M% %I% %E% SMI"
31
32#include <sys/types.h> /* for uint_* */
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
23 * Use is subject to license terms.
24 */
25
26#ifndef _SYS_SHA2_H
27#define _SYS_SHA2_H
28
29#pragma ident "%Z%%M% %I% %E% SMI"
30
31#include <sys/types.h> /* for uint_* */
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
38#define SHA256 0
39#define SHA256_HMAC 1
40#define SHA256_HMAC_GEN 2
41#define SHA384 3
42#define SHA384_HMAC 4
43#define SHA384_HMAC_GEN 5
44#define SHA512 6
45#define SHA512_HMAC 7
46#define SHA512_HMAC_GEN 8
47
48#define SHA2_HMAC_MIN_KEY_LEN 8 /* SHA2-HMAC min key length in bits */
49#define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bits */
50
51#define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */
52#define SHA384_DIGEST_LENGTH 48 /* SHA384 digest length in bytes */
53#define SHA512_DIGEST_LENGTH 64 /* SHA512 digest length in bytes */
54
55#define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */
56#define SHA512_HMAC_BLOCK_SIZE 128 /* SHA512-HMAC block size */
57
37#define SHA2_HMAC_MIN_KEY_LEN 8 /* SHA2-HMAC min key length in bits */
38#define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bits */
39
40#define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */
41#define SHA384_DIGEST_LENGTH 48 /* SHA384 digest length in bytes */
42#define SHA512_DIGEST_LENGTH 64 /* SHA512 digest length in bytes */
43
44#define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */
45#define SHA512_HMAC_BLOCK_SIZE 128 /* SHA512-HMAC block size */
46
47#define SHA256 0
48#define SHA256_HMAC 1
49#define SHA256_HMAC_GEN 2
50#define SHA384 3
51#define SHA384_HMAC 4
52#define SHA384_HMAC_GEN 5
53#define SHA512 6
54#define SHA512_HMAC 7
55#define SHA512_HMAC_GEN 8
58
56
59/* SHA2 context. */
57/*
58 * SHA2 context.
59 * The contents of this structure are a private interface between the
60 * Init/Update/Final calls of the functions defined below.
61 * Callers must never attempt to read or write any of the fields
62 * in this strucutre directly.
63 */
60typedef struct {
61 uint32_t algotype; /* Algorithm Type */
62
63 /* state (ABCDEFGH) */
64 union {
65 uint32_t s32[8]; /* for SHA256 */
66 uint64_t s64[8]; /* for SHA384/512 */
67 } state;

--- 4 unchanged lines hidden (view full) ---

72 } count;
73 union {
74 uint8_t buf8[128]; /* undigested input */
75 uint32_t buf32[32]; /* realigned input */
76 uint64_t buf64[16]; /* realigned input */
77 } buf_un;
78} SHA2_CTX;
79
64typedef struct {
65 uint32_t algotype; /* Algorithm Type */
66
67 /* state (ABCDEFGH) */
68 union {
69 uint32_t s32[8]; /* for SHA256 */
70 uint64_t s64[8]; /* for SHA384/512 */
71 } state;

--- 4 unchanged lines hidden (view full) ---

76 } count;
77 union {
78 uint8_t buf8[128]; /* undigested input */
79 uint32_t buf32[32]; /* realigned input */
80 uint64_t buf64[16]; /* realigned input */
81 } buf_un;
82} SHA2_CTX;
83
84typedef SHA2_CTX SHA256_CTX;
85typedef SHA2_CTX SHA384_CTX;
86typedef SHA2_CTX SHA512_CTX;
87
80extern void SHA2Init(uint64_t mech, SHA2_CTX *);
81
88extern void SHA2Init(uint64_t mech, SHA2_CTX *);
89
82extern void SHA2Update(SHA2_CTX *, const uint8_t *, uint32_t);
90extern void SHA2Update(SHA2_CTX *, const void *, size_t);
83
91
84extern void SHA2Final(uint8_t *, SHA2_CTX *);
92extern void SHA2Final(void *, SHA2_CTX *);
85
93
94extern void SHA256Init(SHA256_CTX *);
95
96extern void SHA256Update(SHA256_CTX *, const void *, size_t);
97
98extern void SHA256Final(void *, SHA256_CTX *);
99
100extern void SHA384Init(SHA384_CTX *);
101
102extern void SHA384Update(SHA384_CTX *, const void *, size_t);
103
104extern void SHA384Final(void *, SHA384_CTX *);
105
106extern void SHA512Init(SHA512_CTX *);
107
108extern void SHA512Update(SHA512_CTX *, const void *, size_t);
109
110extern void SHA512Final(void *, SHA512_CTX *);
111
112#ifdef _SHA2_IMPL
113/*
114 * The following types/functions are all private to the implementation
115 * of the SHA2 functions and must not be used by consumers of the interface
116 */
117
118/*
119 * List of support mechanisms in this module.
120 *
121 * It is important to note that in the module, division or modulus calculations
122 * are used on the enumerated type to determine which mechanism is being used;
123 * therefore, changing the order or additional mechanisms should be done
124 * carefully
125 */
126typedef enum sha2_mech_type {
127 SHA256_MECH_INFO_TYPE, /* SUN_CKM_SHA256 */
128 SHA256_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC */
129 SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */
130 SHA384_MECH_INFO_TYPE, /* SUN_CKM_SHA384 */
131 SHA384_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC */
132 SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */
133 SHA512_MECH_INFO_TYPE, /* SUN_CKM_SHA512 */
134 SHA512_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC */
135 SHA512_HMAC_GEN_MECH_INFO_TYPE /* SUN_CKM_SHA512_HMAC_GENERAL */
136} sha2_mech_type_t;
137
138#endif /* _SHA2_IMPL */
139
86#ifdef __cplusplus
87}
88#endif
89
90#endif /* _SYS_SHA2_H */
140#ifdef __cplusplus
141}
142#endif
143
144#endif /* _SYS_SHA2_H */