| 99 | } |
| 100 | |
| 101 | static 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 | |
| 120 | static 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)); |
no test coverage detected