Lines Matching refs:ctx

97 static void sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) {  in sha256_process_block()  argument
102 uint32_t a = ctx->H[0]; in sha256_process_block()
103 uint32_t b = ctx->H[1]; in sha256_process_block()
104 uint32_t c = ctx->H[2]; in sha256_process_block()
105 uint32_t d = ctx->H[3]; in sha256_process_block()
106 uint32_t e = ctx->H[4]; in sha256_process_block()
107 uint32_t f = ctx->H[5]; in sha256_process_block()
108 uint32_t g = ctx->H[6]; in sha256_process_block()
109 uint32_t h = ctx->H[7]; in sha256_process_block()
114 ctx->total[0] += (uint32_t)len; in sha256_process_block()
115 if (ctx->total[0] < len) { in sha256_process_block()
116 ++ctx->total[1]; in sha256_process_block()
182 ctx->H[0] = a; in sha256_process_block()
183 ctx->H[1] = b; in sha256_process_block()
184 ctx->H[2] = c; in sha256_process_block()
185 ctx->H[3] = d; in sha256_process_block()
186 ctx->H[4] = e; in sha256_process_block()
187 ctx->H[5] = f; in sha256_process_block()
188 ctx->H[6] = g; in sha256_process_block()
189 ctx->H[7] = h; in sha256_process_block()
195 static void sha256_init_ctx(struct sha256_ctx *ctx) { in sha256_init_ctx() argument
196 ctx->H[0] = 0x6a09e667; in sha256_init_ctx()
197 ctx->H[1] = 0xbb67ae85; in sha256_init_ctx()
198 ctx->H[2] = 0x3c6ef372; in sha256_init_ctx()
199 ctx->H[3] = 0xa54ff53a; in sha256_init_ctx()
200 ctx->H[4] = 0x510e527f; in sha256_init_ctx()
201 ctx->H[5] = 0x9b05688c; in sha256_init_ctx()
202 ctx->H[6] = 0x1f83d9ab; in sha256_init_ctx()
203 ctx->H[7] = 0x5be0cd19; in sha256_init_ctx()
205 ctx->total[0] = ctx->total[1] = 0; in sha256_init_ctx()
206 ctx->buflen = 0; in sha256_init_ctx()
215 static void * sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) { in sha256_finish_ctx() argument
217 uint32_t bytes = ctx->buflen; in sha256_finish_ctx()
222 ctx->total[0] += bytes; in sha256_finish_ctx()
223 if (ctx->total[0] < bytes) { in sha256_finish_ctx()
224 ++ctx->total[1]; in sha256_finish_ctx()
228 memcpy(&ctx->buffer[bytes], fillbuf, pad); in sha256_finish_ctx()
231 *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3); in sha256_finish_ctx()
232 *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) | in sha256_finish_ctx()
233 (ctx->total[0] >> 29)); in sha256_finish_ctx()
236 sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); in sha256_finish_ctx()
240 ((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]); in sha256_finish_ctx()
247 static void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx) { in sha256_process_bytes() argument
250 if (ctx->buflen != 0) { in sha256_process_bytes()
251 size_t left_over = ctx->buflen; in sha256_process_bytes()
254 memcpy(&ctx->buffer[left_over], buffer, add); in sha256_process_bytes()
255 ctx->buflen += (uint32_t)add; in sha256_process_bytes()
257 if (ctx->buflen > 64) { in sha256_process_bytes()
258 sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); in sha256_process_bytes()
259 ctx->buflen &= 63; in sha256_process_bytes()
261 memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], ctx->buflen); in sha256_process_bytes()
279 sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); in sha256_process_bytes()
283 sha256_process_block(buffer, len & ~63, ctx); in sha256_process_bytes()
291 size_t left_over = ctx->buflen; in sha256_process_bytes()
293 memcpy(&ctx->buffer[left_over], buffer, len); in sha256_process_bytes()
296 sha256_process_block(ctx->buffer, 64, ctx); in sha256_process_bytes()
298 memcpy(ctx->buffer, &ctx->buffer[64], left_over); in sha256_process_bytes()
300 ctx->buflen = (uint32_t)left_over; in sha256_process_bytes()
335 struct sha256_ctx ctx; in php_sha256_crypt_r() local
383 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
386 sha256_process_bytes(key, key_len, &ctx); in php_sha256_crypt_r()
391 sha256_process_bytes(salt, salt_len, &ctx); in php_sha256_crypt_r()
413 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
415 sha256_process_bytes(alt_result, cnt, &ctx); in php_sha256_crypt_r()
421 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
423 sha256_process_bytes(key, key_len, &ctx); in php_sha256_crypt_r()
428 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
470 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
474 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
476 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
481 sha256_process_bytes(s_bytes, salt_len, &ctx); in php_sha256_crypt_r()
486 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
491 sha256_process_bytes(alt_result, 32, &ctx); in php_sha256_crypt_r()
493 sha256_process_bytes(p_bytes, key_len, &ctx); in php_sha256_crypt_r()
497 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
556 sha256_init_ctx(&ctx); in php_sha256_crypt_r()
557 sha256_finish_ctx(&ctx, alt_result); in php_sha256_crypt_r()
561 ZEND_SECURE_ZERO(&ctx, sizeof(ctx)); in php_sha256_crypt_r()
679 struct sha256_ctx ctx; in main() local
689 sha256_init_ctx(&ctx); in main()
690 sha256_process_bytes(tests[cnt].input, strlen(tests[cnt].input), &ctx); in main()
691 sha256_finish_ctx(&ctx, sum); in main()
697 sha256_init_ctx(&ctx); in main()
699 sha256_process_bytes(&tests[cnt].input[i], 1, &ctx); in main()
701 sha256_finish_ctx(&ctx, sum); in main()
711 sha256_init_ctx(&ctx); in main()
713 sha256_process_bytes (buf, sizeof (buf), &ctx); in main()
716 sha256_finish_ctx(&ctx, sum); in main()