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

Function chacha_init

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

Source from the content-addressed store, hash-verified

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

Callers 1

mi_random_init_exFunction · 0.85

Calls 1

read32Function · 0.85

Tested by

no test coverage detected