Cryptographic algorithms
How to recognise cryptographic algorithms by just looking at them? For each algorithm there is a list of bullet points, sometimes a high-level idea of how the function may look.
AES
Curve25519
void curve25519(out, scalar, point) {
uint8_t e[32];
...
for (pos = 254; pos >= 0; --pos) {
// EC sub, add, mul, sqr operations
}
}
>> 0x19
in the multiplication operation.
ChaCha20
Key: initial state includes 16-byte constant “expand 32-byte k”, 32-byte key, 4-byte counter, 12-byte nonce (in that order)
Quater Round:
a += b; d ^= a; d <<<= 16;
c += d; b ^= c; b <<<= 12;
a += b; d ^= a; d <<<= 8;
c += d; b ^= c; b <<<= 7;
Double Round:
// Odd round
QR(0, 4, 8, 12) // column 1
QR(1, 5, 9, 13) // column 2
QR(2, 6, 10, 14) // column 3
QR(3, 7, 11, 15) // column 4
// Even round
QR(0, 5, 10, 15) // diagonal 1 (main diagonal)
QR(1, 6, 11, 12) // diagonal 2
QR(2, 7, 8, 13) // diagonal 3
QR(3, 4, 9, 14) // diagonal 4
- As name suggests, 20 rounds (but there are reduced round variants)
- Commonly implemented as 10 iterations of double round
- “expand 32-byte k” constant
- First rotations are by 16, 12, 8, 7
ChaCha20-Poly1305
- As name suggests, 20 rounds (but there are reduced round variants)
- 256bit key, 96bit nonce
- ciphertext gets 16 byte tag