aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/sha256.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/sha256.c')
-rw-r--r--src/microhttpd/sha256.c98
1 files changed, 63 insertions, 35 deletions
diff --git a/src/microhttpd/sha256.c b/src/microhttpd/sha256.c
index b03e7555..2f9edf6a 100644
--- a/src/microhttpd/sha256.c
+++ b/src/microhttpd/sha256.c
@@ -145,9 +145,7 @@ sha256_transform (uint32_t H[SHA256_DIGEST_SIZE_WORDS],
145 + (w)[((t) - 7) & 0xf] + sig0 ((w)[((t) - 15) & 0xf]) ) 145 + (w)[((t) - 7) & 0xf] + sig0 ((w)[((t) - 15) & 0xf]) )
146 146
147#ifndef MHD_FAVOR_SMALL_CODE 147#ifndef MHD_FAVOR_SMALL_CODE
148 /* During first 16 steps, before making any calculations on each step, 148
149 the W element is read from input data buffer as big-endian value and
150 stored in array of W elements. */
151 /* Note: instead of using K constants as array, all K values are specified 149 /* Note: instead of using K constants as array, all K values are specified
152 individually for each step, see FIPS PUB 180-4 paragraph 4.2.2 for 150 individually for each step, see FIPS PUB 180-4 paragraph 4.2.2 for
153 K values. */ 151 K values. */
@@ -157,38 +155,68 @@ sha256_transform (uint32_t H[SHA256_DIGEST_SIZE_WORDS],
157 SHA2STEP32(h, a, b, c, d, e, f, g, K[1], data[1]); 155 SHA2STEP32(h, a, b, c, d, e, f, g, K[1], data[1]);
158 so current 'vD' will be used as 'vE' on next step, 156 so current 'vD' will be used as 'vE' on next step,
159 current 'vH' will be used as 'vA' on next step. */ 157 current 'vH' will be used as 'vA' on next step. */
160 SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0x428a2f98), W[0] = \ 158#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
161 GET_W_FROM_DATA (data, 0)); 159 if ((const void *) W == data)
162 SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x71374491), W[1] = \ 160 {
163 GET_W_FROM_DATA (data, 1)); 161 /* The input data is already in the cyclic data buffer W[] in correct bytes
164 SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0xb5c0fbcf), W[2] = \ 162 order. */
165 GET_W_FROM_DATA (data, 2)); 163 SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0x428a2f98), W[0]);
166 SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0xe9b5dba5), W[3] = \ 164 SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x71374491), W[1]);
167 GET_W_FROM_DATA (data, 3)); 165 SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0xb5c0fbcf), W[2]);
168 SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x3956c25b), W[4] = \ 166 SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0xe9b5dba5), W[3]);
169 GET_W_FROM_DATA (data, 4)); 167 SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x3956c25b), W[4]);
170 SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x59f111f1), W[5] = \ 168 SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x59f111f1), W[5]);
171 GET_W_FROM_DATA (data, 5)); 169 SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x923f82a4), W[6]);
172 SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x923f82a4), W[6] = \ 170 SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xab1c5ed5), W[7]);
173 GET_W_FROM_DATA (data, 6)); 171 SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0xd807aa98), W[8]);
174 SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xab1c5ed5), W[7] = \ 172 SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x12835b01), W[9]);
175 GET_W_FROM_DATA (data, 7)); 173 SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0x243185be), W[10]);
176 SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0xd807aa98), W[8] = \ 174 SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0x550c7dc3), W[11]);
177 GET_W_FROM_DATA (data, 8)); 175 SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x72be5d74), W[12]);
178 SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x12835b01), W[9] = \ 176 SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x80deb1fe), W[13]);
179 GET_W_FROM_DATA (data, 9)); 177 SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x9bdc06a7), W[14]);
180 SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0x243185be), W[10] = \ 178 SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xc19bf174), W[15]);
181 GET_W_FROM_DATA (data, 10)); 179 }
182 SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0x550c7dc3), W[11] = \ 180 else /* Combined with the next 'if' */
183 GET_W_FROM_DATA (data, 11)); 181#endif /* _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN */
184 SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x72be5d74), W[12] = \ 182 if (1)
185 GET_W_FROM_DATA (data, 12)); 183 {
186 SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x80deb1fe), W[13] = \ 184 /* During first 16 steps, before making any calculations on each step,
187 GET_W_FROM_DATA (data, 13)); 185 the W element is read from input data buffer as big-endian value and
188 SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x9bdc06a7), W[14] = \ 186 stored in array of W elements. */
189 GET_W_FROM_DATA (data, 14)); 187 SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0x428a2f98), W[0] = \
190 SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xc19bf174), W[15] = \ 188 GET_W_FROM_DATA (data, 0));
191 GET_W_FROM_DATA (data, 15)); 189 SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x71374491), W[1] = \
190 GET_W_FROM_DATA (data, 1));
191 SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0xb5c0fbcf), W[2] = \
192 GET_W_FROM_DATA (data, 2));
193 SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0xe9b5dba5), W[3] = \
194 GET_W_FROM_DATA (data, 3));
195 SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x3956c25b), W[4] = \
196 GET_W_FROM_DATA (data, 4));
197 SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x59f111f1), W[5] = \
198 GET_W_FROM_DATA (data, 5));
199 SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x923f82a4), W[6] = \
200 GET_W_FROM_DATA (data, 6));
201 SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xab1c5ed5), W[7] = \
202 GET_W_FROM_DATA (data, 7));
203 SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0xd807aa98), W[8] = \
204 GET_W_FROM_DATA (data, 8));
205 SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x12835b01), W[9] = \
206 GET_W_FROM_DATA (data, 9));
207 SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0x243185be), W[10] = \
208 GET_W_FROM_DATA (data, 10));
209 SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0x550c7dc3), W[11] = \
210 GET_W_FROM_DATA (data, 11));
211 SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x72be5d74), W[12] = \
212 GET_W_FROM_DATA (data, 12));
213 SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x80deb1fe), W[13] = \
214 GET_W_FROM_DATA (data, 13));
215 SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x9bdc06a7), W[14] = \
216 GET_W_FROM_DATA (data, 14));
217 SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xc19bf174), W[15] = \
218 GET_W_FROM_DATA (data, 15));
219 }
192 220
193 /* During last 48 steps, before making any calculations on each step, 221 /* During last 48 steps, before making any calculations on each step,
194 current W element is generated from other W elements of the cyclic buffer 222 current W element is generated from other W elements of the cyclic buffer