From ba5da0946c3abaa93d1161ca512c3c326cda3736 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Fri, 8 Feb 2019 01:48:12 +0100 Subject: Windows: Add implementation of ChaCha20 based random generator. Use it for driver need of random bytes (currently only wipe bytes but more to come later). --- src/Crypto/chacha256.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Crypto/chacha256.h (limited to 'src/Crypto/chacha256.h') diff --git a/src/Crypto/chacha256.h b/src/Crypto/chacha256.h new file mode 100644 index 00000000..e9533a39 --- /dev/null +++ b/src/Crypto/chacha256.h @@ -0,0 +1,31 @@ +#ifndef HEADER_Crypto_ChaCha256 +#define HEADER_Crypto_ChaCha256 + +#include "Common/Tcdefs.h" +#include "config.h" + +typedef struct +{ + CRYPTOPP_ALIGN_DATA(16) uint32 block_[16]; + CRYPTOPP_ALIGN_DATA(16) uint32 input_[16]; + size_t pos; + int internalRounds; +} ChaCha256Ctx; + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * key must be 32 bytes long and iv must be 8 bytes long + */ +void ChaCha256Init(ChaCha256Ctx* ctx, const unsigned char* key, const unsigned char* iv, int rounds); +void ChaCha256Encrypt(ChaCha256Ctx* ctx, const unsigned char* in, size_t len, unsigned char* out); +#define ChaCha256Decrypt ChaCha256Encrypt + +#ifdef __cplusplus +} +#endif + +#endif // HEADER_Crypto_ChaCha + -- cgit v1.2.3