Lines Matching refs:ctx
112 static void sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) { in sha256_process_block() argument
117 uint32_t a = ctx->H[0]; in sha256_process_block()
118 uint32_t b = ctx->H[1]; in sha256_process_block()
119 uint32_t c = ctx->H[2]; in sha256_process_block()
120 uint32_t d = ctx->H[3]; in sha256_process_block()
121 uint32_t e = ctx->H[4]; in sha256_process_block()
122 uint32_t f = ctx->H[5]; in sha256_process_block()
123 uint32_t g = ctx->H[6]; in sha256_process_block()
124 uint32_t h = ctx->H[7]; in sha256_process_block()
129 ctx->total[0] += len; in sha256_process_block()
130 if (ctx->total[0] < len) { in sha256_process_block()
131 ++ctx->total[1]; in sha256_process_block()
197 ctx->H[0] = a; in sha256_process_block()
198 ctx->H[1] = b; in sha256_process_block()
199 ctx->H[2] = c; in sha256_process_block()
200 ctx->H[3] = d; in sha256_process_block()
201 ctx->H[4] = e; in sha256_process_block()
202 ctx->H[5] = f; in sha256_process_block()
203 ctx->H[6] = g; in sha256_process_block()
204 ctx->H[7] = h; in sha256_process_block()
210 static void sha256_init_ctx(struct sha256_ctx *ctx) { in sha256_init_ctx() argument
211 ctx->H[0] = 0x6a09e667; in sha256_init_ctx()
212 ctx->H[1] = 0xbb67ae85; in sha256_init_ctx()
213 ctx->H[2] = 0x3c6ef372; in sha256_init_ctx()
214 ctx->H[3] = 0xa54ff53a; in sha256_init_ctx()
215 ctx->H[4] = 0x510e527f; in sha256_init_ctx()
216 ctx->H[5] = 0x9b05688c; in sha256_init_ctx()
217 ctx->H[6] = 0x1f83d9ab; in sha256_init_ctx()
218 ctx->H[7] = 0x5be0cd19; in sha256_init_ctx()
220 ctx->total[0] = ctx->total[1] = 0; in sha256_init_ctx()
221 ctx->buflen = 0; in sha256_init_ctx()
230 static void * sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) { in sha256_finish_ctx() argument
232 uint32_t bytes = ctx->buflen; in sha256_finish_ctx()
237 ctx->total[0] += bytes; in sha256_finish_ctx()
238 if (ctx->total[0] < bytes) { in sha256_finish_ctx()
239 ++ctx->total[1]; in sha256_finish_ctx()
243 memcpy(&ctx->buffer[bytes], fillbuf, pad); in sha256_finish_ctx()
246 *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3); in sha256_finish_ctx()
247 *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) | in sha256_finish_ctx()
248 (ctx->total[0] >> 29)); in sha256_finish_ctx()
251 sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); in sha256_finish_ctx()
255 ((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]); in sha256_finish_ctx()
262 static void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx) { in sha256_process_bytes() argument
265 if (ctx->buflen != 0) { in sha256_process_bytes()
266 size_t left_over = ctx->buflen; in sha256_process_bytes()
269 memcpy(&ctx->buffer[left_over], buffer, add); in sha256_process_bytes()
270 ctx->buflen += add; in sha256_process_bytes()
272 if (ctx->buflen > 64) { in sha256_process_bytes()
273 sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); in sha256_process_bytes()
274 ctx->buflen &= 63; in sha256_process_bytes()
276 memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], ctx->buflen); in sha256_process_bytes()
294 sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); in sha256_process_bytes()
298 sha256_process_block(buffer, len & ~63, ctx); in sha256_process_bytes()
306 size_t left_over = ctx->buflen; in sha256_process_bytes()
308 memcpy(&ctx->buffer[left_over], buffer, len); in sha256_process_bytes()
311 sha256_process_block(ctx->buffer, 64, ctx); in sha256_process_bytes()
313 memcpy(ctx->buffer, &ctx->buffer[64], left_over); in sha256_process_bytes()
315 ctx->buflen = left_over; in sha256_process_bytes()
357 struct sha256_ctx ctx; in php_sha256_crypt_r() local
405 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
408 sha256_process_bytes(key, key_len, &ctx); in php_sha256_crypt_r()
413 sha256_process_bytes(salt, salt_len, &ctx); in php_sha256_crypt_r()
435 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
437 sha256_process_bytes(alt_result, cnt, &ctx); in php_sha256_crypt_r()
443 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
445 sha256_process_bytes(key, key_len, &ctx); in php_sha256_crypt_r()
450 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
492 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
496 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
498 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
503 sha256_process_bytes(s_bytes, salt_len, &ctx); in php_sha256_crypt_r()
508 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
513 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
515 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
519 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
578 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
579 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
583 memset(&ctx, '\0', sizeof(ctx)); in php_sha256_crypt_r()
702 struct sha256_ctx ctx; in main() local
712 sha256_init_ctx(&ctx); in main()
713 sha256_process_bytes(tests[cnt].input, strlen(tests[cnt].input), &ctx); in main()
714 sha256_finish_ctx(&ctx, sum); in main()
720 sha256_init_ctx(&ctx); in main()
722 sha256_process_bytes(&tests[cnt].input[i], 1, &ctx); in main()
724 sha256_finish_ctx(&ctx, sum); in main()
734 sha256_init_ctx(&ctx); in main()
736 sha256_process_bytes (buf, sizeof (buf), &ctx); in main()
739 sha256_finish_ctx(&ctx, sum); in main()