Lines Matching refs:ctx
96 static void sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) { in sha256_process_block() argument
101 uint32_t a = ctx->H[0]; in sha256_process_block()
102 uint32_t b = ctx->H[1]; in sha256_process_block()
103 uint32_t c = ctx->H[2]; in sha256_process_block()
104 uint32_t d = ctx->H[3]; in sha256_process_block()
105 uint32_t e = ctx->H[4]; in sha256_process_block()
106 uint32_t f = ctx->H[5]; in sha256_process_block()
107 uint32_t g = ctx->H[6]; in sha256_process_block()
108 uint32_t h = ctx->H[7]; in sha256_process_block()
113 ctx->total[0] += (uint32_t)len; in sha256_process_block()
114 if (ctx->total[0] < len) { in sha256_process_block()
115 ++ctx->total[1]; in sha256_process_block()
181 ctx->H[0] = a; in sha256_process_block()
182 ctx->H[1] = b; in sha256_process_block()
183 ctx->H[2] = c; in sha256_process_block()
184 ctx->H[3] = d; in sha256_process_block()
185 ctx->H[4] = e; in sha256_process_block()
186 ctx->H[5] = f; in sha256_process_block()
187 ctx->H[6] = g; in sha256_process_block()
188 ctx->H[7] = h; in sha256_process_block()
194 static void sha256_init_ctx(struct sha256_ctx *ctx) { in sha256_init_ctx() argument
195 ctx->H[0] = 0x6a09e667; in sha256_init_ctx()
196 ctx->H[1] = 0xbb67ae85; in sha256_init_ctx()
197 ctx->H[2] = 0x3c6ef372; in sha256_init_ctx()
198 ctx->H[3] = 0xa54ff53a; in sha256_init_ctx()
199 ctx->H[4] = 0x510e527f; in sha256_init_ctx()
200 ctx->H[5] = 0x9b05688c; in sha256_init_ctx()
201 ctx->H[6] = 0x1f83d9ab; in sha256_init_ctx()
202 ctx->H[7] = 0x5be0cd19; in sha256_init_ctx()
204 ctx->total[0] = ctx->total[1] = 0; in sha256_init_ctx()
205 ctx->buflen = 0; in sha256_init_ctx()
214 static void * sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) { in sha256_finish_ctx() argument
216 uint32_t bytes = ctx->buflen; in sha256_finish_ctx()
221 ctx->total[0] += bytes; in sha256_finish_ctx()
222 if (ctx->total[0] < bytes) { in sha256_finish_ctx()
223 ++ctx->total[1]; in sha256_finish_ctx()
227 memcpy(&ctx->buffer[bytes], fillbuf, pad); in sha256_finish_ctx()
230 *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3); in sha256_finish_ctx()
231 *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) | in sha256_finish_ctx()
232 (ctx->total[0] >> 29)); in sha256_finish_ctx()
235 sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); in sha256_finish_ctx()
239 ((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]); in sha256_finish_ctx()
246 static void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx) { in sha256_process_bytes() argument
249 if (ctx->buflen != 0) { in sha256_process_bytes()
250 size_t left_over = ctx->buflen; in sha256_process_bytes()
253 memcpy(&ctx->buffer[left_over], buffer, add); in sha256_process_bytes()
254 ctx->buflen += (uint32_t)add; in sha256_process_bytes()
256 if (ctx->buflen > 64) { in sha256_process_bytes()
257 sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); in sha256_process_bytes()
258 ctx->buflen &= 63; in sha256_process_bytes()
260 memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], ctx->buflen); in sha256_process_bytes()
278 sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); in sha256_process_bytes()
282 sha256_process_block(buffer, len & ~63, ctx); in sha256_process_bytes()
290 size_t left_over = ctx->buflen; in sha256_process_bytes()
292 memcpy(&ctx->buffer[left_over], buffer, len); in sha256_process_bytes()
295 sha256_process_block(ctx->buffer, 64, ctx); in sha256_process_bytes()
297 memcpy(ctx->buffer, &ctx->buffer[64], left_over); in sha256_process_bytes()
299 ctx->buflen = (uint32_t)left_over; in sha256_process_bytes()
334 struct sha256_ctx ctx; in php_sha256_crypt_r() local
393 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
396 sha256_process_bytes(key, key_len, &ctx); in php_sha256_crypt_r()
401 sha256_process_bytes(salt, salt_len, &ctx); in php_sha256_crypt_r()
423 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
425 sha256_process_bytes(alt_result, cnt, &ctx); in php_sha256_crypt_r()
431 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
433 sha256_process_bytes(key, key_len, &ctx); in php_sha256_crypt_r()
438 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
482 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
486 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
488 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
493 sha256_process_bytes(s_bytes, salt_len, &ctx); in php_sha256_crypt_r()
498 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
503 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
505 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
509 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
568 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
569 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
573 ZEND_SECURE_ZERO(&ctx, sizeof(ctx)); in php_sha256_crypt_r()
699 struct sha256_ctx ctx; in main() local
709 sha256_init_ctx(&ctx); in main()
710 sha256_process_bytes(tests[cnt].input, strlen(tests[cnt].input), &ctx); in main()
711 sha256_finish_ctx(&ctx, sum); in main()
717 sha256_init_ctx(&ctx); in main()
719 sha256_process_bytes(&tests[cnt].input[i], 1, &ctx); in main()
721 sha256_finish_ctx(&ctx, sum); in main()
731 sha256_init_ctx(&ctx); in main()
733 sha256_process_bytes (buf, sizeof (buf), &ctx); in main()
736 sha256_finish_ctx(&ctx, sum); in main()