2016-02-14 11:00:28 +01:00
|
|
|
module cipher;
|
|
|
|
|
2016-02-17 02:39:40 +01:00
|
|
|
private import std.range : isInputRange, ElementType, chooseAmong;
|
2016-02-14 11:00:28 +01:00
|
|
|
private import salsa20;
|
|
|
|
private import chacha20;
|
2016-02-14 12:01:00 +01:00
|
|
|
import std.stdio;
|
2016-02-14 11:00:28 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-02-14 12:01:00 +01:00
|
|
|
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))
|
|
|
|
{
|
2016-02-17 02:39:40 +01:00
|
|
|
return chooseAmong(cipher,
|
|
|
|
range.salsa20Cipher(key, nonce),
|
|
|
|
range.chacha20Cipher(key, nonce));
|
2016-02-14 11:00:28 +01:00
|
|
|
}
|