diff --git a/libi2pd/ChaCha20.cpp b/libi2pd/ChaCha20.cpp index 91a1fbd5..222111b7 100644 --- a/libi2pd/ChaCha20.cpp +++ b/libi2pd/ChaCha20.cpp @@ -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; } diff --git a/libi2pd/Crypto.cpp b/libi2pd/Crypto.cpp index 2145d773..cd6d5b8e 100644 --- a/libi2pd/Crypto.cpp +++ b/libi2pd/Crypto.cpp @@ -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);