Lines Matching +full:0 +full:- +full:5
1 // SPDX-License-Identifier: BSD-3-Clause
6 * FIPS 180-2 SHA-224/256/384/512 implementation
14 #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
15 #define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
29 *((str) + 0) = (uint8_t)((x) >> 24); \
36 ((uint32_t) * ((str) + 0) << 24); \
42 { w[i] = SHA256_F4(w[i - 2]) + w[i - 7] + SHA256_F3(w[i - 15]) + w[i - 16]; }
53 static const uint32_t sha256_h0[8] = {0x6a09e667,
54 0xbb67ae85,
55 0x3c6ef372,
56 0xa54ff53a,
57 0x510e527f,
58 0x9b05688c,
59 0x1f83d9ab,
60 0x5be0cd19};
63 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
64 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
65 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
66 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
67 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
68 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
69 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
70 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
71 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
72 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
73 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
75 /* SHA-256 implementation */
79 for (i = 0; i < 8; i++) { in avb_sha256_init()
80 ctx->h[i] = sha256_h0[i]; in avb_sha256_init()
83 ctx->h[0] = sha256_h0[0]; in avb_sha256_init()
84 ctx->h[1] = sha256_h0[1]; in avb_sha256_init()
85 ctx->h[2] = sha256_h0[2]; in avb_sha256_init()
86 ctx->h[3] = sha256_h0[3]; in avb_sha256_init()
87 ctx->h[4] = sha256_h0[4]; in avb_sha256_init()
88 ctx->h[5] = sha256_h0[5]; in avb_sha256_init()
89 ctx->h[6] = sha256_h0[6]; in avb_sha256_init()
90 ctx->h[7] = sha256_h0[7]; in avb_sha256_init()
93 ctx->len = 0; in avb_sha256_init()
94 ctx->tot_len = 0; in avb_sha256_init()
110 for (i = 0; i < (int)block_nb; i++) { in SHA256_transform()
114 for (j = 0; j < 16; j++) { in SHA256_transform()
122 for (j = 0; j < 8; j++) { in SHA256_transform()
123 wv[j] = ctx->h[j]; in SHA256_transform()
126 for (j = 0; j < 64; j++) { in SHA256_transform()
127 t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + sha256_k[j] + in SHA256_transform()
129 t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); in SHA256_transform()
131 wv[6] = wv[5]; in SHA256_transform()
132 wv[5] = wv[4]; in SHA256_transform()
136 wv[1] = wv[0]; in SHA256_transform()
137 wv[0] = t1 + t2; in SHA256_transform()
140 for (j = 0; j < 8; j++) { in SHA256_transform()
141 ctx->h[j] += wv[j]; in SHA256_transform()
144 PACK32(&sub_block[0], &w[0]); in SHA256_transform()
149 PACK32(&sub_block[20], &w[5]); in SHA256_transform()
210 wv[0] = ctx->h[0]; in SHA256_transform()
211 wv[1] = ctx->h[1]; in SHA256_transform()
212 wv[2] = ctx->h[2]; in SHA256_transform()
213 wv[3] = ctx->h[3]; in SHA256_transform()
214 wv[4] = ctx->h[4]; in SHA256_transform()
215 wv[5] = ctx->h[5]; in SHA256_transform()
216 wv[6] = ctx->h[6]; in SHA256_transform()
217 wv[7] = ctx->h[7]; in SHA256_transform()
219 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 0); in SHA256_transform()
220 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 1); in SHA256_transform()
221 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 2); in SHA256_transform()
222 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 3); in SHA256_transform()
223 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 4); in SHA256_transform()
224 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 5); in SHA256_transform()
225 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 6); in SHA256_transform()
226 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 7); in SHA256_transform()
227 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 8); in SHA256_transform()
228 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 9); in SHA256_transform()
229 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 10); in SHA256_transform()
230 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 11); in SHA256_transform()
231 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 12); in SHA256_transform()
232 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 13); in SHA256_transform()
233 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 14); in SHA256_transform()
234 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 15); in SHA256_transform()
235 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 16); in SHA256_transform()
236 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 17); in SHA256_transform()
237 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 18); in SHA256_transform()
238 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 19); in SHA256_transform()
239 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 20); in SHA256_transform()
240 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 21); in SHA256_transform()
241 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 22); in SHA256_transform()
242 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 23); in SHA256_transform()
243 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 24); in SHA256_transform()
244 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 25); in SHA256_transform()
245 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 26); in SHA256_transform()
246 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 27); in SHA256_transform()
247 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 28); in SHA256_transform()
248 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 29); in SHA256_transform()
249 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 30); in SHA256_transform()
250 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 31); in SHA256_transform()
251 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 32); in SHA256_transform()
252 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 33); in SHA256_transform()
253 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 34); in SHA256_transform()
254 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 35); in SHA256_transform()
255 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 36); in SHA256_transform()
256 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 37); in SHA256_transform()
257 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 38); in SHA256_transform()
258 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 39); in SHA256_transform()
259 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 40); in SHA256_transform()
260 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 41); in SHA256_transform()
261 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 42); in SHA256_transform()
262 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 43); in SHA256_transform()
263 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 44); in SHA256_transform()
264 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 45); in SHA256_transform()
265 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 46); in SHA256_transform()
266 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 47); in SHA256_transform()
267 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 48); in SHA256_transform()
268 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 49); in SHA256_transform()
269 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 50); in SHA256_transform()
270 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 51); in SHA256_transform()
271 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 52); in SHA256_transform()
272 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 53); in SHA256_transform()
273 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 54); in SHA256_transform()
274 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 55); in SHA256_transform()
275 SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, 56); in SHA256_transform()
276 SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, 57); in SHA256_transform()
277 SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, 58); in SHA256_transform()
278 SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, 59); in SHA256_transform()
279 SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, 60); in SHA256_transform()
280 SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, 61); in SHA256_transform()
281 SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, 62); in SHA256_transform()
282 SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, 63); in SHA256_transform()
284 ctx->h[0] += wv[0]; in SHA256_transform()
285 ctx->h[1] += wv[1]; in SHA256_transform()
286 ctx->h[2] += wv[2]; in SHA256_transform()
287 ctx->h[3] += wv[3]; in SHA256_transform()
288 ctx->h[4] += wv[4]; in SHA256_transform()
289 ctx->h[5] += wv[5]; in SHA256_transform()
290 ctx->h[6] += wv[6]; in SHA256_transform()
291 ctx->h[7] += wv[7]; in SHA256_transform()
301 tmp_len = AVB_SHA256_BLOCK_SIZE - ctx->len; in avb_sha256_update()
304 avb_memcpy(&ctx->block[ctx->len], data, rem_len); in avb_sha256_update()
306 if (ctx->len + len < AVB_SHA256_BLOCK_SIZE) { in avb_sha256_update()
307 ctx->len += len; in avb_sha256_update()
311 new_len = len - rem_len; in avb_sha256_update()
316 SHA256_transform(ctx, ctx->block, 1); in avb_sha256_update()
321 avb_memcpy(ctx->block, &shifted_data[block_nb << 6], rem_len); in avb_sha256_update()
323 ctx->len = rem_len; in avb_sha256_update()
324 ctx->tot_len += (block_nb + 1) << 6; in avb_sha256_update()
336 (1 + ((AVB_SHA256_BLOCK_SIZE - 9) < (ctx->len % AVB_SHA256_BLOCK_SIZE))); in avb_sha256_final()
338 len_b = (ctx->tot_len + ctx->len) << 3; in avb_sha256_final()
341 avb_memset(ctx->block + ctx->len, 0, pm_len - ctx->len); in avb_sha256_final()
342 ctx->block[ctx->len] = 0x80; in avb_sha256_final()
343 UNPACK32(len_b, ctx->block + pm_len - 4); in avb_sha256_final()
345 SHA256_transform(ctx, ctx->block, block_nb); in avb_sha256_final()
348 for (i = 0; i < 8; i++) { in avb_sha256_final()
349 UNPACK32(ctx->h[i], &ctx->buf[i << 2]); in avb_sha256_final()
352 UNPACK32(ctx->h[0], &ctx->buf[0]); in avb_sha256_final()
353 UNPACK32(ctx->h[1], &ctx->buf[4]); in avb_sha256_final()
354 UNPACK32(ctx->h[2], &ctx->buf[8]); in avb_sha256_final()
355 UNPACK32(ctx->h[3], &ctx->buf[12]); in avb_sha256_final()
356 UNPACK32(ctx->h[4], &ctx->buf[16]); in avb_sha256_final()
357 UNPACK32(ctx->h[5], &ctx->buf[20]); in avb_sha256_final()
358 UNPACK32(ctx->h[6], &ctx->buf[24]); in avb_sha256_final()
359 UNPACK32(ctx->h[7], &ctx->buf[28]); in avb_sha256_final()
362 return ctx->buf; in avb_sha256_final()