summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2024-10-22 02:54:02 -0400
committerMalfurious <m@lfurio.us>2024-10-24 06:41:41 -0400
commita01e8dfb054fae877e4b94ece6b6f18dd5fd67f8 (patch)
tree236f1b9b977949a6da4777b76152e336214f635c
parentd96e828be83f7adf0fe88001da865169cfd573c7 (diff)
downloadcompass-a01e8dfb054fae877e4b94ece6b6f18dd5fd67f8.tar.gz
compass-a01e8dfb054fae877e4b94ece6b6f18dd5fd67f8.zip
Refactor SHA256 function to use mbedtls
Signed-off-by: Malfurious <m@lfurio.us>
-rw-r--r--Cryptor.cpp7
-rw-r--r--Cryptor.h1
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"