| 90 | } |
| 91 | |
| 92 | static 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 | |
| 111 | static 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)); |
no test coverage detected