2024-07-27 20:17:18 +03:00
2024-07-27 20:17:18 +03:00
2024-07-22 12:25:23 +03:00
2024-07-16 17:42:38 +03:00

### PicoLisp Chacha20 on coroutines.

There is already a lot of code available for testing coroutines in PicoLisp, but one can never have too many coroutines; more are needed.

This image shows the core of chacha20 and each function and variable in this image is represented as a single coroutine:

``````#define ROT_L32(x, n) x = (x << n) | (x >> (32 - n))
#define QUARTERROUND(a, b, c, d)       \
a += b;  d ^= a;  ROT_L32(d, 16);  \
c += d;  b ^= c;  ROT_L32(b, 12);  \
a += b;  d ^= a;  ROT_L32(d,  8);  \
c += d;  b ^= c;  ROT_L32(b,  7)

for (int i = 0; i < 10; i++) { // 20 rounds, 2 rounds per loop.
QUARTERROUND(block[0], block[4], block[ 8], block[12]); // column 0
QUARTERROUND(block[1], block[5], block[ 9], block[13]); // column 1
QUARTERROUND(block[2], block[6], block[10], block[14]); // column 2
QUARTERROUND(block[3], block[7], block[11], block[15]); // column 3
QUARTERROUND(block[0], block[5], block[10], block[15]); // diagonal 1
QUARTERROUND(block[1], block[6], block[11], block[12]); // diagonal 2
QUARTERROUND(block[2], block[7], block[ 8], block[13]); // diagonal 3
QUARTERROUND(block[3], block[4], block[ 9], block[14]); // diagonal 4
}
``````

This great article and Monocypher crypto library were used for creating and testing this code.

Happy coding!