Lines Matching +full:1 +full:- +full:4

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)))
28 *((str) + 1) = (uint8_t)((x) >> 16); \
35 ((uint32_t) * ((str) + 1) << 16) | \
42 { w[i] = SHA256_F4(w[i - 2]) + w[i - 7] + SHA256_F3(w[i - 15]) + w[i - 16]; }
75 /* SHA-256 implementation */
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()
123 wv[j] = ctx->h[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()
132 wv[5] = wv[4]; in SHA256_transform()
133 wv[4] = wv[3] + t1; in SHA256_transform()
135 wv[2] = wv[1]; in SHA256_transform()
136 wv[1] = wv[0]; in SHA256_transform()
141 ctx->h[j] += wv[j]; in SHA256_transform()
145 PACK32(&sub_block[4], &w[1]); in SHA256_transform()
148 PACK32(&sub_block[16], &w[4]); 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()
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()