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

Method Keystream

src/crypto/chacha20.cpp:74–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void ChaCha20::Keystream(unsigned char* c, size_t bytes)
75{
76 uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
77 uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
78 unsigned char *ctarget = nullptr;
79 unsigned char tmp[64];
80 unsigned int i;
81
82 if (!bytes) return;
83
84 j0 = input[0];
85 j1 = input[1];
86 j2 = input[2];
87 j3 = input[3];
88 j4 = input[4];
89 j5 = input[5];
90 j6 = input[6];
91 j7 = input[7];
92 j8 = input[8];
93 j9 = input[9];
94 j10 = input[10];
95 j11 = input[11];
96 j12 = input[12];
97 j13 = input[13];
98 j14 = input[14];
99 j15 = input[15];
100
101 for (;;) {
102 if (bytes < 64) {
103 ctarget = c;
104 c = tmp;
105 }
106 x0 = j0;
107 x1 = j1;
108 x2 = j2;
109 x3 = j3;
110 x4 = j4;
111 x5 = j5;
112 x6 = j6;
113 x7 = j7;
114 x8 = j8;
115 x9 = j9;
116 x10 = j10;
117 x11 = j11;
118 x12 = j12;
119 x13 = j13;
120 x14 = j14;
121 x15 = j15;
122 for (i = 20;i > 0;i -= 2) {
123 QUARTERROUND( x0, x4, x8,x12)
124 QUARTERROUND( x1, x5, x9,x13)
125 QUARTERROUND( x2, x6,x10,x14)
126 QUARTERROUND( x3, x7,x11,x15)
127 QUARTERROUND( x0, x5,x10,x15)
128 QUARTERROUND( x1, x6,x11,x12)
129 QUARTERROUND( x2, x7, x8,x13)
130 QUARTERROUND( x3, x4, x9,x14)
131 }

Callers 9

randbytesMethod · 0.80
FillByteBufferMethod · 0.80
ToNum3072Method · 0.80
CryptMethod · 0.80
GetLengthMethod · 0.80
TestChaCha20Function · 0.80
TestChaCha20Poly1305AEADFunction · 0.80
FUZZ_TARGETFunction · 0.80
FUZZ_TARGETFunction · 0.80

Calls 1

WriteLE32Function · 0.70

Tested by 4

TestChaCha20Function · 0.64
TestChaCha20Poly1305AEADFunction · 0.64
FUZZ_TARGETFunction · 0.64
FUZZ_TARGETFunction · 0.64