Everything you need to know about PointyCastle's stream ciphers.
PointyCastle, as of now, supports three stream ciphers: ChaCha20 (original implementation), ChaCha20 (RFC-7539 implementation), and Salsa20. The parameters each needs are below in table form.
Cipher
IV? (Length)
Key Length
Salsa20
Yes, 8 bytes
32 bytes
ChaCha20
Yes, 8 bytes
32 bytes
ChaCha7539
Yes, 12 bytes
32 bytes
Because these are stream ciphers, no padding is necessary; each cipher can process any amount of data.
Constructing these algorithms is done either via the registry or via the class itself (see External API for more):
var salsa20 =StreamCipher('Salsa20');//With registryvar chacha20 =ChaCha20Engine();
If you are using one of the ChaCha ciphers, you may also select the number of rounds.
var chacha20 =ChaCha20Engine.fromRounds(8);//8-roundvar chacha7539 =StreamCipher('ChaCha7539/12') //12-round
Note: to use one of the ChaCha ciphers with the registry, you must append a /(rounds) to the end of the registry string. If you are unsure how many rounds to use, use 20.
Initializing looks pretty much the same with all these machines. Note the pattern of introducing parameters through the init method:
initialization.dart
var key =KeyParameter([]);//Replace [] with a 32 length Uint8Listvar iv = [];//Replace [] with a 8 length Uint8Listvar params =ParametersWithIV<KeyParameter>(key, iv);var chacha20 =ChaCha20Engine();// The bool below is inherited and represents whether this is for // encryption or decryption. Since stream ciphers have a symmetric // encryption process, it doesn't matter here.chacha20.init(true, params);// Now, we can either encrypt or decrypt using this instance of// ChaCha20Engine.
Finally, encryption (continuing from initialization.dart):
Decryption looks the same as encryption, but you pass the encrypted data and get back the original data. (This also continues from initialization.dart):
Isn't that simple? Most PointyCastle algorithms boil down like this: construct, initialize, and use.