xref: /illumos-gate/usr/src/uts/common/sys/sha2_consts.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
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.
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 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SHA2_CONSTS_H
28 #define	_SYS_SHA2_CONSTS_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * Loading 32-bit constants on a sparc is expensive since it involves both
36  * a `sethi' and an `or'.  thus, we instead use `ld' to load the constants
37  * from an array called `sha2_consts'.  however, on intel (and perhaps other
38  * processors), it is cheaper to load the constant directly.  thus, the c
39  * code in SHA transform functions uses the macro SHA2_CONST() which either
40  * expands to a constant or an array reference, depending on
41  * the architecture the code is being compiled for.
42  *
43  * SHA512 constants are used for SHA384
44  */
45 
46 #include <sys/types.h>		/* uint32_t */
47 
48 extern	const uint32_t	sha256_consts[];
49 extern	const uint64_t	sha512_consts[];
50 
51 #if	defined(__sparc)
52 #define	SHA256_CONST(x)		(sha256_consts[x])
53 #define	SHA512_CONST(x)		(sha512_consts[x])
54 #else
55 #define	SHA256_CONST(x)		(SHA256_CONST_ ## x)
56 #define	SHA512_CONST(x)		(SHA512_CONST_ ## x)
57 #endif
58 
59 /* constants, as provided in FIPS 180-2 */
60 
61 #define	SHA256_CONST_0		0x428a2f98U
62 #define	SHA256_CONST_1		0x71374491U
63 #define	SHA256_CONST_2		0xb5c0fbcfU
64 #define	SHA256_CONST_3		0xe9b5dba5U
65 #define	SHA256_CONST_4		0x3956c25bU
66 #define	SHA256_CONST_5		0x59f111f1U
67 #define	SHA256_CONST_6		0x923f82a4U
68 #define	SHA256_CONST_7		0xab1c5ed5U
69 
70 #define	SHA256_CONST_8		0xd807aa98U
71 #define	SHA256_CONST_9		0x12835b01U
72 #define	SHA256_CONST_10		0x243185beU
73 #define	SHA256_CONST_11		0x550c7dc3U
74 #define	SHA256_CONST_12		0x72be5d74U
75 #define	SHA256_CONST_13		0x80deb1feU
76 #define	SHA256_CONST_14		0x9bdc06a7U
77 #define	SHA256_CONST_15		0xc19bf174U
78 
79 #define	SHA256_CONST_16		0xe49b69c1U
80 #define	SHA256_CONST_17		0xefbe4786U
81 #define	SHA256_CONST_18		0x0fc19dc6U
82 #define	SHA256_CONST_19		0x240ca1ccU
83 #define	SHA256_CONST_20		0x2de92c6fU
84 #define	SHA256_CONST_21		0x4a7484aaU
85 #define	SHA256_CONST_22		0x5cb0a9dcU
86 #define	SHA256_CONST_23		0x76f988daU
87 
88 #define	SHA256_CONST_24		0x983e5152U
89 #define	SHA256_CONST_25		0xa831c66dU
90 #define	SHA256_CONST_26		0xb00327c8U
91 #define	SHA256_CONST_27		0xbf597fc7U
92 #define	SHA256_CONST_28		0xc6e00bf3U
93 #define	SHA256_CONST_29		0xd5a79147U
94 #define	SHA256_CONST_30		0x06ca6351U
95 #define	SHA256_CONST_31		0x14292967U
96 
97 #define	SHA256_CONST_32		0x27b70a85U
98 #define	SHA256_CONST_33		0x2e1b2138U
99 #define	SHA256_CONST_34		0x4d2c6dfcU
100 #define	SHA256_CONST_35		0x53380d13U
101 #define	SHA256_CONST_36		0x650a7354U
102 #define	SHA256_CONST_37		0x766a0abbU
103 #define	SHA256_CONST_38		0x81c2c92eU
104 #define	SHA256_CONST_39		0x92722c85U
105 
106 #define	SHA256_CONST_40		0xa2bfe8a1U
107 #define	SHA256_CONST_41		0xa81a664bU
108 #define	SHA256_CONST_42		0xc24b8b70U
109 #define	SHA256_CONST_43		0xc76c51a3U
110 #define	SHA256_CONST_44		0xd192e819U
111 #define	SHA256_CONST_45		0xd6990624U
112 #define	SHA256_CONST_46		0xf40e3585U
113 #define	SHA256_CONST_47		0x106aa070U
114 
115 #define	SHA256_CONST_48		0x19a4c116U
116 #define	SHA256_CONST_49		0x1e376c08U
117 #define	SHA256_CONST_50		0x2748774cU
118 #define	SHA256_CONST_51		0x34b0bcb5U
119 #define	SHA256_CONST_52		0x391c0cb3U
120 #define	SHA256_CONST_53		0x4ed8aa4aU
121 #define	SHA256_CONST_54		0x5b9cca4fU
122 #define	SHA256_CONST_55		0x682e6ff3U
123 
124 #define	SHA256_CONST_56		0x748f82eeU
125 #define	SHA256_CONST_57		0x78a5636fU
126 #define	SHA256_CONST_58		0x84c87814U
127 #define	SHA256_CONST_59		0x8cc70208U
128 #define	SHA256_CONST_60		0x90befffaU
129 #define	SHA256_CONST_61		0xa4506cebU
130 #define	SHA256_CONST_62		0xbef9a3f7U
131 #define	SHA256_CONST_63		0xc67178f2U
132 
133 #define	SHA512_CONST_0		0x428a2f98d728ae22ULL
134 #define	SHA512_CONST_1		0x7137449123ef65cdULL
135 #define	SHA512_CONST_2		0xb5c0fbcfec4d3b2fULL
136 #define	SHA512_CONST_3		0xe9b5dba58189dbbcULL
137 #define	SHA512_CONST_4		0x3956c25bf348b538ULL
138 #define	SHA512_CONST_5		0x59f111f1b605d019ULL
139 #define	SHA512_CONST_6		0x923f82a4af194f9bULL
140 #define	SHA512_CONST_7		0xab1c5ed5da6d8118ULL
141 #define	SHA512_CONST_8		0xd807aa98a3030242ULL
142 #define	SHA512_CONST_9		0x12835b0145706fbeULL
143 #define	SHA512_CONST_10		0x243185be4ee4b28cULL
144 #define	SHA512_CONST_11		0x550c7dc3d5ffb4e2ULL
145 #define	SHA512_CONST_12		0x72be5d74f27b896fULL
146 #define	SHA512_CONST_13		0x80deb1fe3b1696b1ULL
147 #define	SHA512_CONST_14		0x9bdc06a725c71235ULL
148 #define	SHA512_CONST_15		0xc19bf174cf692694ULL
149 #define	SHA512_CONST_16		0xe49b69c19ef14ad2ULL
150 #define	SHA512_CONST_17		0xefbe4786384f25e3ULL
151 #define	SHA512_CONST_18		0x0fc19dc68b8cd5b5ULL
152 #define	SHA512_CONST_19		0x240ca1cc77ac9c65ULL
153 #define	SHA512_CONST_20		0x2de92c6f592b0275ULL
154 #define	SHA512_CONST_21		0x4a7484aa6ea6e483ULL
155 #define	SHA512_CONST_22		0x5cb0a9dcbd41fbd4ULL
156 #define	SHA512_CONST_23		0x76f988da831153b5ULL
157 #define	SHA512_CONST_24		0x983e5152ee66dfabULL
158 #define	SHA512_CONST_25		0xa831c66d2db43210ULL
159 #define	SHA512_CONST_26		0xb00327c898fb213fULL
160 #define	SHA512_CONST_27		0xbf597fc7beef0ee4ULL
161 #define	SHA512_CONST_28		0xc6e00bf33da88fc2ULL
162 #define	SHA512_CONST_29		0xd5a79147930aa725ULL
163 #define	SHA512_CONST_30		0x06ca6351e003826fULL
164 #define	SHA512_CONST_31		0x142929670a0e6e70ULL
165 #define	SHA512_CONST_32		0x27b70a8546d22ffcULL
166 #define	SHA512_CONST_33		0x2e1b21385c26c926ULL
167 #define	SHA512_CONST_34		0x4d2c6dfc5ac42aedULL
168 #define	SHA512_CONST_35		0x53380d139d95b3dfULL
169 #define	SHA512_CONST_36		0x650a73548baf63deULL
170 #define	SHA512_CONST_37		0x766a0abb3c77b2a8ULL
171 #define	SHA512_CONST_38		0x81c2c92e47edaee6ULL
172 #define	SHA512_CONST_39		0x92722c851482353bULL
173 #define	SHA512_CONST_40		0xa2bfe8a14cf10364ULL
174 #define	SHA512_CONST_41		0xa81a664bbc423001ULL
175 #define	SHA512_CONST_42		0xc24b8b70d0f89791ULL
176 #define	SHA512_CONST_43		0xc76c51a30654be30ULL
177 #define	SHA512_CONST_44		0xd192e819d6ef5218ULL
178 #define	SHA512_CONST_45		0xd69906245565a910ULL
179 #define	SHA512_CONST_46		0xf40e35855771202aULL
180 #define	SHA512_CONST_47		0x106aa07032bbd1b8ULL
181 #define	SHA512_CONST_48		0x19a4c116b8d2d0c8ULL
182 #define	SHA512_CONST_49		0x1e376c085141ab53ULL
183 #define	SHA512_CONST_50		0x2748774cdf8eeb99ULL
184 #define	SHA512_CONST_51		0x34b0bcb5e19b48a8ULL
185 #define	SHA512_CONST_52		0x391c0cb3c5c95a63ULL
186 #define	SHA512_CONST_53		0x4ed8aa4ae3418acbULL
187 #define	SHA512_CONST_54		0x5b9cca4f7763e373ULL
188 #define	SHA512_CONST_55		0x682e6ff3d6b2b8a3ULL
189 #define	SHA512_CONST_56		0x748f82ee5defb2fcULL
190 #define	SHA512_CONST_57		0x78a5636f43172f60ULL
191 #define	SHA512_CONST_58		0x84c87814a1f0ab72ULL
192 #define	SHA512_CONST_59		0x8cc702081a6439ecULL
193 #define	SHA512_CONST_60		0x90befffa23631e28ULL
194 #define	SHA512_CONST_61		0xa4506cebde82bde9ULL
195 #define	SHA512_CONST_62		0xbef9a3f7b2c67915ULL
196 #define	SHA512_CONST_63		0xc67178f2e372532bULL
197 #define	SHA512_CONST_64		0xca273eceea26619cULL
198 #define	SHA512_CONST_65		0xd186b8c721c0c207ULL
199 #define	SHA512_CONST_66		0xeada7dd6cde0eb1eULL
200 #define	SHA512_CONST_67		0xf57d4f7fee6ed178ULL
201 #define	SHA512_CONST_68		0x06f067aa72176fbaULL
202 #define	SHA512_CONST_69		0x0a637dc5a2c898a6ULL
203 #define	SHA512_CONST_70		0x113f9804bef90daeULL
204 #define	SHA512_CONST_71		0x1b710b35131c471bULL
205 #define	SHA512_CONST_72		0x28db77f523047d84ULL
206 #define	SHA512_CONST_73		0x32caab7b40c72493ULL
207 #define	SHA512_CONST_74		0x3c9ebe0a15c9bebcULL
208 #define	SHA512_CONST_75		0x431d67c49c100d4cULL
209 #define	SHA512_CONST_76		0x4cc5d4becb3e42b6ULL
210 #define	SHA512_CONST_77		0x597f299cfc657e2aULL
211 #define	SHA512_CONST_78		0x5fcb6fab3ad6faecULL
212 #define	SHA512_CONST_79		0x6c44198c4a475817ULL
213 
214 
215 #ifdef	__cplusplus
216 }
217 #endif
218 
219 #endif /* _SYS_SHA2_CONSTS_H */
220