fixed some naming
This commit is contained in:
parent
9b9e023e61
commit
791e048012
1 changed files with 13 additions and 13 deletions
|
@ -21,7 +21,7 @@ auto chacha20Cipher(R)(R range, ubyte[32] key, ubyte[8] nonce)
|
|||
ubyte[8] nonce;
|
||||
ulong count;
|
||||
R range;
|
||||
ubyte[] salsaSection;
|
||||
ubyte[] chachaSection;
|
||||
public:
|
||||
this(R range, in ubyte[32] key, in ubyte[8] nonce)
|
||||
{
|
||||
|
@ -29,28 +29,28 @@ auto chacha20Cipher(R)(R range, ubyte[32] key, ubyte[8] nonce)
|
|||
this.key = key;
|
||||
this.nonce = nonce;
|
||||
this.count = 0;
|
||||
salsaSection = salsa20Exp(key, nonce ~ littleEndianInv(count));
|
||||
chachaSection = chacha20Exp(key, nonce ~ littleEndianInv(count));
|
||||
}
|
||||
|
||||
bool empty() @property
|
||||
{
|
||||
return range.empty || (count == ulong.max && salsaSection.empty);
|
||||
return range.empty || (count == ulong.max && chachaSection.empty);
|
||||
}
|
||||
|
||||
ubyte front() @property
|
||||
{
|
||||
assert(!empty);
|
||||
return range.front ^ salsaSection.front;
|
||||
return range.front ^ chachaSection.front;
|
||||
}
|
||||
|
||||
void popFront()
|
||||
{
|
||||
assert(!empty);
|
||||
salsaSection.popFront();
|
||||
if(salsaSection.empty)
|
||||
chachaSection.popFront();
|
||||
if(chachaSection.empty)
|
||||
{
|
||||
++count;
|
||||
salsaSection = salsa20Exp(key, nonce ~ littleEndianInv(count));
|
||||
chachaSection = chacha20Exp(key, nonce ~ littleEndianInv(count));
|
||||
}
|
||||
range.popFront();
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ auto chacha20Cipher(R)(R range, ubyte[32] key, ubyte[8] nonce)
|
|||
copy.key = key.dup;
|
||||
copy.nonce = nonce.dup;
|
||||
copy.count = count;
|
||||
copy.salsaSection = salsaSection.dup;
|
||||
copy.chachaSection = chachaSection.dup;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
@ -262,26 +262,26 @@ body
|
|||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
test0 = salsa20(test0);
|
||||
test0 = chacha20(test0);
|
||||
|
||||
ubyte[] test1 = [211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,191,187,234,136,
|
||||
49,237,179, 48, 1,106,178,219,175,199,166, 48, 86, 16,179,207,
|
||||
31,240, 32, 63, 15, 83, 93,161,116,147, 48,113,238, 55,204, 36,
|
||||
79,201,235, 79, 3, 81,156, 47,203, 26,244,243, 88,118,104, 54];
|
||||
test1 = salsa20(test1);
|
||||
test1 = chacha20(test1);
|
||||
|
||||
ubyte[] test2 = [ 88,118,104, 54, 79,201,235, 79, 3, 81,156, 47,203, 26,244,243,
|
||||
191,187,234,136,211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,
|
||||
86, 16,179,207, 49,237,179, 48, 1,106,178,219,175,199,166, 48,
|
||||
238, 55,204, 36, 31,240, 32, 63, 15, 83, 93,161,116,147, 48,113];
|
||||
test2 = salsa20(test2);
|
||||
test2 = chacha20(test2);
|
||||
|
||||
ubyte[] test3 = [ 6,124, 83,146, 38,191, 9, 50, 4,161, 47,222,122,182,223,185,
|
||||
75, 27, 0,216, 16,122, 7, 89,162,104,101,147,213, 21, 54, 95,
|
||||
225,253,139,176,105,132, 23,116, 76, 41,176,207,221, 34,157,108,
|
||||
94, 94, 99, 52, 90,117, 91,220,146,190,239,143,196,176,130,186];
|
||||
foreach(i; 0..1000000)
|
||||
test3 = salsa20(test3);
|
||||
test3 = chacha20(test3);
|
||||
|
||||
assert(test0 == [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -338,7 +338,7 @@ body
|
|||
foreach(i; 0..16)
|
||||
n[i] = cast(ubyte)(i + 1+ 100);
|
||||
|
||||
assert(salsa20Exp(key, n) == [ 69, 37, 68, 39, 41, 15,107,193,255,139,122, 6,170,233,217, 98,
|
||||
assert(chacha20Exp(key, n) == [ 69, 37, 68, 39, 41, 15,107,193,255,139,122, 6,170,233,217, 98,
|
||||
89,144,182,106, 21, 51,200, 65,239, 49,222, 34,215,114, 40,126,
|
||||
104,197, 7,225,197,153, 31, 2,102, 78, 76,176, 84,245,246,184,
|
||||
177,160,133,130, 6, 72,149,119,192,195,132,236,234,103,246, 74]);
|
||||
|
|
Loading…
Reference in a new issue