MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / generateChaCha20

Function generateChaCha20

src/utils/random/chacha20.ts:29–49  ·  view source on GitHub ↗
(dst: Uint32Array, state: Uint32Array)

Source from the content-addressed store, hash-verified

27 x[d] = vd;
28}
29function generateChaCha20(dst: Uint32Array, state: Uint32Array) : void {
30 if (dst.length < 16 || state.length < 16) return;
31 dst.set(state);
32 for (let i = 0; i < CHACHA_ROUNDS; i += 2) {
33 quarterRound(dst, 0, 4, 8, 12);
34 quarterRound(dst, 1, 5, 9, 13);
35 quarterRound(dst, 2, 6, 10, 14);
36 quarterRound(dst, 3, 7, 11, 15);
37 quarterRound(dst, 0, 5, 10, 15);
38 quarterRound(dst, 1, 6, 11, 12);
39 quarterRound(dst, 2, 7, 8, 13);
40 quarterRound(dst, 3, 4, 9, 14);
41 }
42 for (let i = 0; i < 16; i++) {
43 let d = dst[i];
44 const s = state[i];
45 if (d === undefined || s === undefined) throw new Error('generateChaCha20: Something went wrong!');
46 d = (d + s) | 0;
47 dst[i] = d;
48 }
49}
50export class ChaCha20 extends RandomBase {
51 private keynonce: Uint32Array;
52 private state: Uint32Array;

Callers 1

fillBufferDirectMethod · 0.85

Calls 2

quarterRoundFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected