Browse Source

counter is always in Little Endian

pull/1334/head
orignal 6 years ago
parent
commit
5b56f4007b
  1. 5
      libi2pd/ChaCha20.cpp
  2. 2
      libi2pd/Crypto.cpp

5
libi2pd/ChaCha20.cpp

@ -9,6 +9,7 @@ @@ -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 * @@ -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;
}

2
libi2pd/Crypto.cpp

@ -1236,7 +1236,7 @@ namespace crypto @@ -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…
Cancel
Save