| 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)); |
| 113 | _mi_memcpy(ctx_new->input, ctx->input, sizeof(ctx_new->input)); |
| 114 | ctx_new->input[12] = 0; |
| 115 | ctx_new->input[13] = 0; |
| 116 | ctx_new->input[14] = (uint32_t)nonce; |
| 117 | ctx_new->input[15] = (uint32_t)(nonce >> 32); |
| 118 | mi_assert_internal(ctx->input[14] != ctx_new->input[14] || ctx->input[15] != ctx_new->input[15]); // do not reuse nonces! |
| 119 | chacha_block(ctx_new); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /* ---------------------------------------------------------------------------- |
no test coverage detected