From a01e8dfb054fae877e4b94ece6b6f18dd5fd67f8 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 22 Oct 2024 02:54:02 -0400 Subject: Refactor SHA256 function to use mbedtls Signed-off-by: Malfurious --- Cryptor.cpp | 7 +++---- Cryptor.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cryptor.cpp b/Cryptor.cpp index fc27caf..25a2ae9 100644 --- a/Cryptor.cpp +++ b/Cryptor.cpp @@ -226,10 +226,9 @@ void Cryptor::rekey() { } void Cryptor::sha256(std::string str) { - CryptoPP::SHA256 hash; - std::string rtr; - CryptoPP::StringSource(str, true, new CryptoPP::HashFilter(hash, new CryptoPP::StringSink(rtr), false, CryptoPP::AES::DEFAULT_KEYLENGTH)); - memcpy(key, rtr.c_str(), rtr.size()); + unsigned char hashbuf[32]; + mbedtls_sha256((const unsigned char *)str.c_str(), str.size(), hashbuf, 0); + memcpy(key, hashbuf, sizeof(key)); haveKey = true; } diff --git a/Cryptor.h b/Cryptor.h index 1fcac36..f1448b0 100644 --- a/Cryptor.h +++ b/Cryptor.h @@ -16,6 +16,7 @@ #include "mbedtls/cipher.h" #include "mbedtls/ctr_drbg.h" #include "mbedtls/entropy.h" +#include "mbedtls/sha256.h" #include "Socket.h" -- cgit v1.2.3