diff options
author | lloyd <[email protected]> | 2008-11-06 19:06:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-06 19:06:21 +0000 |
commit | d50e41609c95945c714c445f6b400e02fe659b90 (patch) | |
tree | 54c210770876c5236f47bf4a60c1e119fb23af09 /src/cipher/salsa20/salsa20.cpp | |
parent | e9d21fd5c4aa9e5422f6c596665b1b563038d4d1 (diff) |
In Salsa20, move the state counter increment out of core salsa20() function
Diffstat (limited to 'src/cipher/salsa20/salsa20.cpp')
-rw-r--r-- | src/cipher/salsa20/salsa20.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/cipher/salsa20/salsa20.cpp b/src/cipher/salsa20/salsa20.cpp index 1ca45e48f..c2c8f289f 100644 --- a/src/cipher/salsa20/salsa20.cpp +++ b/src/cipher/salsa20/salsa20.cpp @@ -16,7 +16,7 @@ namespace { /************************************************* * Generate Salsa20 cipher stream * *************************************************/ -void salsa20(byte output[64], u32bit input[16]) +void salsa20(byte output[64], const u32bit input[16]) { u32bit x00 = input[0]; u32bit x01 = input[1]; @@ -88,10 +88,6 @@ void salsa20(byte output[64], u32bit input[16]) store_le(x13 + input[13], output + 4 * 13); store_le(x14 + input[14], output + 4 * 14); store_le(x15 + input[15], output + 4 * 15); - - ++input[8]; - if(!input[8]) - ++input[9]; } } @@ -108,6 +104,11 @@ void Salsa20::cipher(const byte in[], byte out[], u32bit length) in += (buffer.size() - position); out += (buffer.size() - position); salsa20(buffer.begin(), state); + + ++state[8]; + if(!state[8]) // if overflow in state[8] + ++state[9]; // carry to state[9] + position = 0; } @@ -178,6 +179,10 @@ void Salsa20::resync(const byte iv[], u32bit length) state[9] = 0; salsa20(buffer.begin(), state); + ++state[8]; + if(!state[8]) // if overflow in state[8] + ++state[9]; // carry to state[9] + position = 0; } |