Lines Matching +full:- +full:p

2  * FIPS-180-2 compliant SHA-256 implementation
4 * Copyright (C) 2001-2003 Christophe Devine
6 * SPDX-License-Identifier: GPL-2.0+
17 #include <u-boot/sha256.h>
33 * 32-bit integer manipulation macros (big endian)
59 ctx->cdev = NULL; in sha256_starts()
60 if (ctx->length) { in sha256_starts()
61 ctx->cdev = crypto_get_device(algo); in sha256_starts()
62 if (ctx->cdev) { in sha256_starts()
64 cctx.length = ctx->length; in sha256_starts()
65 crypto_sha_init(ctx->cdev, &cctx); in sha256_starts()
71 ctx->total[0] = 0; in sha256_starts()
72 ctx->total[1] = 0; in sha256_starts()
74 ctx->state[0] = 0x6A09E667; in sha256_starts()
75 ctx->state[1] = 0xBB67AE85; in sha256_starts()
76 ctx->state[2] = 0x3C6EF372; in sha256_starts()
77 ctx->state[3] = 0xA54FF53A; in sha256_starts()
78 ctx->state[4] = 0x510E527F; in sha256_starts()
79 ctx->state[5] = 0x9B05688C; in sha256_starts()
80 ctx->state[6] = 0x1F83D9AB; in sha256_starts()
81 ctx->state[7] = 0x5BE0CD19; in sha256_starts()
108 #define ROTR(x,n) (SHR(x,n) | (x << (32 - n))) in sha256_process_one()
121 W[t] = S1(W[t - 2]) + W[t - 7] + \ in sha256_process_one()
122 S0(W[t - 15]) + W[t - 16] \ in sha256_process_one()
125 #define P(a,b,c,d,e,f,g,h,x,K) { \ in sha256_process_one() macro
131 A = ctx->state[0]; in sha256_process_one()
132 B = ctx->state[1]; in sha256_process_one()
133 C = ctx->state[2]; in sha256_process_one()
134 D = ctx->state[3]; in sha256_process_one()
135 E = ctx->state[4]; in sha256_process_one()
136 F = ctx->state[5]; in sha256_process_one()
137 G = ctx->state[6]; in sha256_process_one()
138 H = ctx->state[7]; in sha256_process_one()
140 P(A, B, C, D, E, F, G, H, W[0], 0x428A2F98); in sha256_process_one()
141 P(H, A, B, C, D, E, F, G, W[1], 0x71374491); in sha256_process_one()
142 P(G, H, A, B, C, D, E, F, W[2], 0xB5C0FBCF); in sha256_process_one()
143 P(F, G, H, A, B, C, D, E, W[3], 0xE9B5DBA5); in sha256_process_one()
144 P(E, F, G, H, A, B, C, D, W[4], 0x3956C25B); in sha256_process_one()
145 P(D, E, F, G, H, A, B, C, W[5], 0x59F111F1); in sha256_process_one()
146 P(C, D, E, F, G, H, A, B, W[6], 0x923F82A4); in sha256_process_one()
147 P(B, C, D, E, F, G, H, A, W[7], 0xAB1C5ED5); in sha256_process_one()
148 P(A, B, C, D, E, F, G, H, W[8], 0xD807AA98); in sha256_process_one()
149 P(H, A, B, C, D, E, F, G, W[9], 0x12835B01); in sha256_process_one()
150 P(G, H, A, B, C, D, E, F, W[10], 0x243185BE); in sha256_process_one()
151 P(F, G, H, A, B, C, D, E, W[11], 0x550C7DC3); in sha256_process_one()
152 P(E, F, G, H, A, B, C, D, W[12], 0x72BE5D74); in sha256_process_one()
153 P(D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE); in sha256_process_one()
154 P(C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7); in sha256_process_one()
155 P(B, C, D, E, F, G, H, A, W[15], 0xC19BF174); in sha256_process_one()
156 P(A, B, C, D, E, F, G, H, R(16), 0xE49B69C1); in sha256_process_one()
157 P(H, A, B, C, D, E, F, G, R(17), 0xEFBE4786); in sha256_process_one()
158 P(G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6); in sha256_process_one()
159 P(F, G, H, A, B, C, D, E, R(19), 0x240CA1CC); in sha256_process_one()
160 P(E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F); in sha256_process_one()
161 P(D, E, F, G, H, A, B, C, R(21), 0x4A7484AA); in sha256_process_one()
162 P(C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC); in sha256_process_one()
163 P(B, C, D, E, F, G, H, A, R(23), 0x76F988DA); in sha256_process_one()
164 P(A, B, C, D, E, F, G, H, R(24), 0x983E5152); in sha256_process_one()
165 P(H, A, B, C, D, E, F, G, R(25), 0xA831C66D); in sha256_process_one()
166 P(G, H, A, B, C, D, E, F, R(26), 0xB00327C8); in sha256_process_one()
167 P(F, G, H, A, B, C, D, E, R(27), 0xBF597FC7); in sha256_process_one()
168 P(E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3); in sha256_process_one()
169 P(D, E, F, G, H, A, B, C, R(29), 0xD5A79147); in sha256_process_one()
170 P(C, D, E, F, G, H, A, B, R(30), 0x06CA6351); in sha256_process_one()
171 P(B, C, D, E, F, G, H, A, R(31), 0x14292967); in sha256_process_one()
172 P(A, B, C, D, E, F, G, H, R(32), 0x27B70A85); in sha256_process_one()
173 P(H, A, B, C, D, E, F, G, R(33), 0x2E1B2138); in sha256_process_one()
174 P(G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC); in sha256_process_one()
175 P(F, G, H, A, B, C, D, E, R(35), 0x53380D13); in sha256_process_one()
176 P(E, F, G, H, A, B, C, D, R(36), 0x650A7354); in sha256_process_one()
177 P(D, E, F, G, H, A, B, C, R(37), 0x766A0ABB); in sha256_process_one()
178 P(C, D, E, F, G, H, A, B, R(38), 0x81C2C92E); in sha256_process_one()
179 P(B, C, D, E, F, G, H, A, R(39), 0x92722C85); in sha256_process_one()
180 P(A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1); in sha256_process_one()
181 P(H, A, B, C, D, E, F, G, R(41), 0xA81A664B); in sha256_process_one()
182 P(G, H, A, B, C, D, E, F, R(42), 0xC24B8B70); in sha256_process_one()
183 P(F, G, H, A, B, C, D, E, R(43), 0xC76C51A3); in sha256_process_one()
184 P(E, F, G, H, A, B, C, D, R(44), 0xD192E819); in sha256_process_one()
185 P(D, E, F, G, H, A, B, C, R(45), 0xD6990624); in sha256_process_one()
186 P(C, D, E, F, G, H, A, B, R(46), 0xF40E3585); in sha256_process_one()
187 P(B, C, D, E, F, G, H, A, R(47), 0x106AA070); in sha256_process_one()
188 P(A, B, C, D, E, F, G, H, R(48), 0x19A4C116); in sha256_process_one()
189 P(H, A, B, C, D, E, F, G, R(49), 0x1E376C08); in sha256_process_one()
190 P(G, H, A, B, C, D, E, F, R(50), 0x2748774C); in sha256_process_one()
191 P(F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5); in sha256_process_one()
192 P(E, F, G, H, A, B, C, D, R(52), 0x391C0CB3); in sha256_process_one()
193 P(D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A); in sha256_process_one()
194 P(C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F); in sha256_process_one()
195 P(B, C, D, E, F, G, H, A, R(55), 0x682E6FF3); in sha256_process_one()
196 P(A, B, C, D, E, F, G, H, R(56), 0x748F82EE); in sha256_process_one()
197 P(H, A, B, C, D, E, F, G, R(57), 0x78A5636F); in sha256_process_one()
198 P(G, H, A, B, C, D, E, F, R(58), 0x84C87814); in sha256_process_one()
199 P(F, G, H, A, B, C, D, E, R(59), 0x8CC70208); in sha256_process_one()
200 P(E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA); in sha256_process_one()
201 P(D, E, F, G, H, A, B, C, R(61), 0xA4506CEB); in sha256_process_one()
202 P(C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7); in sha256_process_one()
203 P(B, C, D, E, F, G, H, A, R(63), 0xC67178F2); in sha256_process_one()
205 ctx->state[0] += A; in sha256_process_one()
206 ctx->state[1] += B; in sha256_process_one()
207 ctx->state[2] += C; in sha256_process_one()
208 ctx->state[3] += D; in sha256_process_one()
209 ctx->state[4] += E; in sha256_process_one()
210 ctx->state[5] += F; in sha256_process_one()
211 ctx->state[6] += G; in sha256_process_one()
212 ctx->state[7] += H; in sha256_process_one()
221 while (blocks--) { in sha256_process()
236 if (ctx->cdev) { in sha256_update()
237 crypto_sha_update(ctx->cdev, (void *)input, length); in sha256_update()
242 left = ctx->total[0] & 0x3F; in sha256_update()
243 fill = 64 - left; in sha256_update()
245 ctx->total[0] += length; in sha256_update()
246 ctx->total[0] &= 0xFFFFFFFF; in sha256_update()
248 if (ctx->total[0] < length) in sha256_update()
249 ctx->total[1]++; in sha256_update()
252 memcpy((void *) (ctx->buffer + left), (void *) input, fill); in sha256_update()
253 sha256_process(ctx, ctx->buffer, 1); in sha256_update()
254 length -= fill; in sha256_update()
264 memcpy((void *) (ctx->buffer + left), (void *) input, length); in sha256_update()
284 if (ctx->cdev) { in sha256_finish()
286 cctx.length = ctx->length; in sha256_finish()
287 crypto_sha_final(ctx->cdev, &cctx, digest); in sha256_finish()
292 high = ((ctx->total[0] >> 29) in sha256_finish()
293 | (ctx->total[1] << 3)); in sha256_finish()
294 low = (ctx->total[0] << 3); in sha256_finish()
299 last = ctx->total[0] & 0x3F; in sha256_finish()
300 padn = (last < 56) ? (56 - last) : (120 - last); in sha256_finish()
305 PUT_UINT32_BE(ctx->state[0], digest, 0); in sha256_finish()
306 PUT_UINT32_BE(ctx->state[1], digest, 4); in sha256_finish()
307 PUT_UINT32_BE(ctx->state[2], digest, 8); in sha256_finish()
308 PUT_UINT32_BE(ctx->state[3], digest, 12); in sha256_finish()
309 PUT_UINT32_BE(ctx->state[4], digest, 16); in sha256_finish()
310 PUT_UINT32_BE(ctx->state[5], digest, 20); in sha256_finish()
311 PUT_UINT32_BE(ctx->state[6], digest, 24); in sha256_finish()
312 PUT_UINT32_BE(ctx->state[7], digest, 28); in sha256_finish()
316 * Output = SHA-256( input buffer ).
334 * Output = SHA-256( input buffer ). Trigger the watchdog every 'chunk_sz'
358 chunk = end - curr; in sha256_csum_wd()