MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / chacha_init

Function chacha_init

system/lib/mimalloc/src/random.c:92–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92static void chacha_init(mi_random_ctx_t* ctx, const uint8_t key[32], uint64_t nonce)
93{
94 // since we only use chacha for randomness (and not encryption) we
95 // do not _need_ to read 32-bit values as little endian but we do anyways
96 // just for being compatible :-)
97 _mi_memzero(ctx, sizeof(*ctx));
98 for (size_t i = 0; i < 4; i++) {
99 const uint8_t* sigma = (uint8_t*)"expand 32-byte k";
100 ctx->input[i] = read32(sigma,i);
101 }
102 for (size_t i = 0; i < 8; i++) {
103 ctx->input[i + 4] = read32(key,i);
104 }
105 ctx->input[12] = 0;
106 ctx->input[13] = 0;
107 ctx->input[14] = (uint32_t)nonce;
108 ctx->input[15] = (uint32_t)(nonce >> 32);
109}
110
111static void chacha_split(mi_random_ctx_t* ctx, uint64_t nonce, mi_random_ctx_t* ctx_new) {
112 _mi_memzero(ctx_new, sizeof(*ctx_new));

Callers 1

mi_random_init_exFunction · 0.85

Calls 2

_mi_memzeroFunction · 0.85
read32Function · 0.85

Tested by

no test coverage detected