MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / chacha_block

Function chacha_block

3rd/mimalloc-2.0.9/src/random.c:51–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51static void chacha_block(mi_random_ctx_t* ctx)
52{
53 // scramble into `x`
54 uint32_t x[16];
55 for (size_t i = 0; i < 16; i++) {
56 x[i] = ctx->input[i];
57 }
58 for (size_t i = 0; i < MI_CHACHA_ROUNDS; i += 2) {
59 qround(x, 0, 4, 8, 12);
60 qround(x, 1, 5, 9, 13);
61 qround(x, 2, 6, 10, 14);
62 qround(x, 3, 7, 11, 15);
63 qround(x, 0, 5, 10, 15);
64 qround(x, 1, 6, 11, 12);
65 qround(x, 2, 7, 8, 13);
66 qround(x, 3, 4, 9, 14);
67 }
68
69 // add scrambled data to the initial state
70 for (size_t i = 0; i < 16; i++) {
71 ctx->output[i] = x[i] + ctx->input[i];
72 }
73 ctx->output_available = 16;
74
75 // increment the counter for the next round
76 ctx->input[12] += 1;
77 if (ctx->input[12] == 0) {
78 ctx->input[13] += 1;
79 if (ctx->input[13] == 0) { // and keep increasing into the nonce
80 ctx->input[14] += 1;
81 }
82 }
83}
84
85static uint32_t chacha_next32(mi_random_ctx_t* ctx) {
86 if (ctx->output_available <= 0) {

Callers 2

chacha_next32Function · 0.85
chacha_splitFunction · 0.85

Calls 1

qroundFunction · 0.85

Tested by

no test coverage detected