MCPcopy Create free account
hub / github.com/ElementsProject/elements / SetKey

Method SetKey

src/crypto/chacha20.cpp:24–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22static const unsigned char tau[] = "expand 16-byte k";
23
24void ChaCha20::SetKey(const unsigned char* k, size_t keylen)
25{
26 const unsigned char *constants;
27
28 input[4] = ReadLE32(k + 0);
29 input[5] = ReadLE32(k + 4);
30 input[6] = ReadLE32(k + 8);
31 input[7] = ReadLE32(k + 12);
32 if (keylen == 32) { /* recommended */
33 k += 16;
34 constants = sigma;
35 } else { /* keylen == 16 */
36 constants = tau;
37 }
38 input[8] = ReadLE32(k + 0);
39 input[9] = ReadLE32(k + 4);
40 input[10] = ReadLE32(k + 8);
41 input[11] = ReadLE32(k + 12);
42 input[0] = ReadLE32(constants + 0);
43 input[1] = ReadLE32(constants + 4);
44 input[2] = ReadLE32(constants + 8);
45 input[3] = ReadLE32(constants + 12);
46 input[12] = 0;
47 input[13] = 0;
48 input[14] = 0;
49 input[15] = 0;
50}
51
52ChaCha20::ChaCha20()
53{

Callers 1

ChaCha20Poly1305AEADMethod · 0.45

Calls 1

ReadLE32Function · 0.85

Tested by

no test coverage detected