learncrypto/source/cipher.d

22 lines
472 B
D

module cipher;
private import std.range : isInputRange, ElementType, chooseAmong;
private import salsa20;
private import chacha20;
import std.stdio;
public:
enum Cipher
{
salsa20,
chacha20
}
auto cipherFunction(R)(R range, ubyte[32] key, ubyte[8] nonce, Cipher cipher)
if(isInputRange!R && is(ElementType!R : ubyte))
{
return chooseAmong(cipher,
range.salsa20Cipher(key, nonce),
range.chacha20Cipher(key, nonce));
}