Print this page
6665607 Need a SHA256/SHA384/SHA512 implementation optimized for 64-bit x86
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/sha2.h
+++ new/usr/src/uts/common/sys/sha2.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 - * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22 + * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #ifndef _SYS_SHA2_H
27 27 #define _SYS_SHA2_H
28 28
29 -#pragma ident "@(#)sha2.h 1.4 06/03/28 SMI"
29 +#pragma ident "@(#)sha2.h 1.5 08/03/05 SMI"
30 30
31 31 #include <sys/types.h> /* for uint_* */
32 32
33 33 #ifdef __cplusplus
34 34 extern "C" {
35 35 #endif
36 36
37 37 #define SHA2_HMAC_MIN_KEY_LEN 8 /* SHA2-HMAC min key length in bits */
38 38 #define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bits */
39 39
40 40 #define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */
41 41 #define SHA384_DIGEST_LENGTH 48 /* SHA384 digest length in bytes */
42 42 #define SHA512_DIGEST_LENGTH 64 /* SHA512 digest length in bytes */
43 43
44 44 #define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */
45 45 #define SHA512_HMAC_BLOCK_SIZE 128 /* SHA512-HMAC block size */
46 46
47 47 #define SHA256 0
48 48 #define SHA256_HMAC 1
49 49 #define SHA256_HMAC_GEN 2
50 50 #define SHA384 3
51 51 #define SHA384_HMAC 4
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
52 52 #define SHA384_HMAC_GEN 5
53 53 #define SHA512 6
54 54 #define SHA512_HMAC 7
55 55 #define SHA512_HMAC_GEN 8
56 56
57 57 /*
58 58 * SHA2 context.
59 59 * The contents of this structure are a private interface between the
60 60 * Init/Update/Final calls of the functions defined below.
61 61 * Callers must never attempt to read or write any of the fields
62 - * in this strucutre directly.
62 + * in this structure directly.
63 63 */
64 64 typedef struct {
65 65 uint32_t algotype; /* Algorithm Type */
66 66
67 67 /* state (ABCDEFGH) */
68 68 union {
69 69 uint32_t s32[8]; /* for SHA256 */
70 70 uint64_t s64[8]; /* for SHA384/512 */
71 71 } state;
72 72 /* number of bits */
73 73 union {
74 74 uint32_t c32[2]; /* for SHA256 , modulo 2^64 */
75 75 uint64_t c64[2]; /* for SHA384/512, modulo 2^128 */
76 76 } count;
77 77 union {
78 78 uint8_t buf8[128]; /* undigested input */
79 79 uint32_t buf32[32]; /* realigned input */
80 80 uint64_t buf64[16]; /* realigned input */
81 81 } buf_un;
82 82 } SHA2_CTX;
83 83
84 84 typedef SHA2_CTX SHA256_CTX;
85 85 typedef SHA2_CTX SHA384_CTX;
86 86 typedef SHA2_CTX SHA512_CTX;
87 87
88 88 extern void SHA2Init(uint64_t mech, SHA2_CTX *);
89 89
90 90 extern void SHA2Update(SHA2_CTX *, const void *, size_t);
91 91
92 92 extern void SHA2Final(void *, SHA2_CTX *);
93 93
94 94 extern void SHA256Init(SHA256_CTX *);
95 95
96 96 extern void SHA256Update(SHA256_CTX *, const void *, size_t);
97 97
98 98 extern void SHA256Final(void *, SHA256_CTX *);
99 99
100 100 extern void SHA384Init(SHA384_CTX *);
101 101
102 102 extern void SHA384Update(SHA384_CTX *, const void *, size_t);
103 103
104 104 extern void SHA384Final(void *, SHA384_CTX *);
105 105
106 106 extern void SHA512Init(SHA512_CTX *);
107 107
108 108 extern void SHA512Update(SHA512_CTX *, const void *, size_t);
109 109
110 110 extern void SHA512Final(void *, SHA512_CTX *);
111 111
112 112 #ifdef _SHA2_IMPL
113 113 /*
114 114 * The following types/functions are all private to the implementation
115 115 * of the SHA2 functions and must not be used by consumers of the interface
116 116 */
117 117
118 118 /*
119 119 * List of support mechanisms in this module.
120 120 *
121 121 * It is important to note that in the module, division or modulus calculations
122 122 * are used on the enumerated type to determine which mechanism is being used;
123 123 * therefore, changing the order or additional mechanisms should be done
124 124 * carefully
125 125 */
126 126 typedef enum sha2_mech_type {
127 127 SHA256_MECH_INFO_TYPE, /* SUN_CKM_SHA256 */
128 128 SHA256_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC */
129 129 SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */
130 130 SHA384_MECH_INFO_TYPE, /* SUN_CKM_SHA384 */
131 131 SHA384_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC */
132 132 SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */
133 133 SHA512_MECH_INFO_TYPE, /* SUN_CKM_SHA512 */
134 134 SHA512_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC */
135 135 SHA512_HMAC_GEN_MECH_INFO_TYPE /* SUN_CKM_SHA512_HMAC_GENERAL */
136 136 } sha2_mech_type_t;
137 137
138 138 #endif /* _SHA2_IMPL */
139 139
140 140 #ifdef __cplusplus
141 141 }
142 142 #endif
143 143
144 144 #endif /* _SYS_SHA2_H */
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX