mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
counter is always in Little Endian
This commit is contained in:
parent
e2071542bf
commit
5b56f4007b
|
@ -9,6 +9,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "I2PEndian.h"
|
||||
#include "ChaCha20.h"
|
||||
|
||||
#if !OPENSSL_AEAD_CHACHA20_POLY1305
|
||||
|
@ -89,14 +90,14 @@ void Chacha20Init (Chacha20State& state, const uint8_t * nonce, const uint8_t *
|
|||
for (size_t i = 0; i < 8; i++)
|
||||
state.data[4 + i] = chacha::u8t32le(key + i * 4);
|
||||
|
||||
state.data[12] = counter;
|
||||
state.data[12] = htole32 (counter);
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
state.data[13 + i] = chacha::u8t32le(nonce + i * 4);
|
||||
}
|
||||
|
||||
void Chacha20SetCounter (Chacha20State& state, uint32_t counter)
|
||||
{
|
||||
state.data[12] = counter;
|
||||
state.data[12] = htole32 (counter);
|
||||
state.offset = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1236,7 +1236,7 @@ namespace crypto
|
|||
#if OPENSSL_AEAD_CHACHA20_POLY1305
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new ();
|
||||
uint32_t iv[4];
|
||||
iv[0] = 1; memcpy (iv + 1, nonce, 12); // counter | nonce
|
||||
iv[0] = htole32 (1); memcpy (iv + 1, nonce, 12); // counter | nonce
|
||||
EVP_EncryptInit_ex(ctx, EVP_chacha20 (), NULL, key, (const uint8_t *)iv);
|
||||
int outlen = 0;
|
||||
EVP_EncryptUpdate(ctx, out, &outlen, msg, msgLen);
|
||||
|
|
Loading…
Reference in a new issue