learncrypto/source/cipher.d

28 lines
525 B
D
Raw Normal View History

2016-02-14 11:00:28 +01:00
module cipher;
private import std.range : isInputRange, ElementType;
private import salsa20;
private import chacha20;
import std.stdio;
2016-02-14 11:00:28 +01:00
public:
enum Cipher
{
2016-02-14 11:00:28 +01:00
salsa20,
chacha20
}
auto cipherFunction(R)(R range, ubyte[32] key, ubyte[8] nonce, Cipher cipher)
if(isInputRange!R && is(ElementType!R : ubyte))
{
final switch(cipher)
{
case Cipher.salsa20:
return range.salsa20Cipher(key, nonce);
2016-02-14 11:00:28 +01:00
case Cipher.chacha20:
return range.salsa20Cipher(key, nonce);
2016-02-14 11:00:28 +01:00
}
}