13 constexpr
static inline uint32_t rotl32(uint32_t v,
int c) {
return (v << c) | (v >> (32 - c)); }
15 #define QUARTERROUND(a,b,c,d) \
16 a += b; d = rotl32(d ^ a, 16); \
17 c += d; b = rotl32(b ^ c, 12); \
18 a += b; d = rotl32(d ^ a, 8); \
19 c += d; b = rotl32(b ^ c, 7);
21 static const unsigned char sigma[] =
"expand 32-byte k";
22 static const unsigned char tau[] =
"expand 16-byte k";
26 const unsigned char *constants;
28 input[4] = ReadLE32(k + 0);
29 input[5] = ReadLE32(k + 4);
30 input[6] = ReadLE32(k + 8);
31 input[7] = ReadLE32(k + 12);
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);
71 input[13] = pos >> 32;
78 unsigned char *ctarget =
nullptr;
79 unsigned char tmp[64];
84 for (uint32_t i=0; i<16; i++) {
93 for (uint32_t i=0; i<16; i++) {
96 for (i = 20;i > 0;i -= 2) {
106 for (uint32_t i=0; i<16; i++) {
113 for (uint32_t i=0; i<16; i++) {
114 WriteLE32(c + 4*i, x[i]);
119 for (i = 0;i < bytes;++i) ctarget[i] = c[i];
132 uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
133 uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
134 unsigned char *ctarget =
nullptr;
135 unsigned char tmp[64];
161 for (i = 0;i < bytes;++i) tmp[i] = m[i];
182 for (i = 20;i > 0;i -= 2) {
209 x0 ^= ReadLE32(m + 0);
210 x1 ^= ReadLE32(m + 4);
211 x2 ^= ReadLE32(m + 8);
212 x3 ^= ReadLE32(m + 12);
213 x4 ^= ReadLE32(m + 16);
214 x5 ^= ReadLE32(m + 20);
215 x6 ^= ReadLE32(m + 24);
216 x7 ^= ReadLE32(m + 28);
217 x8 ^= ReadLE32(m + 32);
218 x9 ^= ReadLE32(m + 36);
219 x10 ^= ReadLE32(m + 40);
220 x11 ^= ReadLE32(m + 44);
221 x12 ^= ReadLE32(m + 48);
222 x13 ^= ReadLE32(m + 52);
223 x14 ^= ReadLE32(m + 56);
224 x15 ^= ReadLE32(m + 60);
229 WriteLE32(c + 0, x0);
230 WriteLE32(c + 4, x1);
231 WriteLE32(c + 8, x2);
232 WriteLE32(c + 12, x3);
233 WriteLE32(c + 16, x4);
234 WriteLE32(c + 20, x5);
235 WriteLE32(c + 24, x6);
236 WriteLE32(c + 28, x7);
237 WriteLE32(c + 32, x8);
238 WriteLE32(c + 36, x9);
239 WriteLE32(c + 40, x10);
240 WriteLE32(c + 44, x11);
241 WriteLE32(c + 48, x12);
242 WriteLE32(c + 52, x13);
243 WriteLE32(c + 56, x14);
244 WriteLE32(c + 60, x15);
248 for (i = 0;i < bytes;++i) ctarget[i] = c[i];
void Keystream(unsigned char *c, size_t bytes)
outputs the keystream of size <bytes> into
void Crypt(const unsigned char *input, unsigned char *output, size_t bytes)
enciphers the message <input> of length <bytes> and write the enciphered representation into <output>...
void SetKey(const unsigned char *key, size_t keylen)
set key with flexible keylength; 256bit recommended */
#define QUARTERROUND(a, b, c, d)