From 48006196407251eaeb0a52297e4a412d76fce086 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 22 Oct 2024 03:06:21 -0400 Subject: Refactor random password generation to use mbedtls entropy source Signed-off-by: Malfurious --- Cryptor.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Cryptor.cpp b/Cryptor.cpp index 25a2ae9..9db2bdc 100644 --- a/Cryptor.cpp +++ b/Cryptor.cpp @@ -153,9 +153,7 @@ std::string Cryptor::loadAndDecrypt(std::string remoteHost, std::string port, st } std::string Cryptor::createRandomPassword(PasswordSpec spec) { - CryptoPP::AutoSeededRandomPool randl; std::string password; - std::vector validChars; // Always allow lower-case alphabetic characters @@ -208,14 +206,11 @@ std::string Cryptor::createRandomPassword(PasswordSpec spec) { validChars.push_back('0' + i); } - // Build string for (int i = 0; i < spec.ml; i++) { - unsigned char r[1]; - char c; - randl.GenerateBlock(r, sizeof(r)); - c = validChars[r[0] % validChars.size()]; - password += c; + unsigned char c; + generateRandom(&c, sizeof(c)); + password += validChars[c % validChars.size()]; } return password; -- cgit v1.2.3