ARGON2 -> PBKDF2

ARGON2 requires OpenSSL 3.2, not available in Ubuntu 24.04
This commit is contained in:
Guillaume Meunier
2024-11-26 23:59:35 +01:00
committed by Patrick Nicolas
parent 2778f7dd7e
commit 8a48f8ff7b
3 changed files with 4 additions and 16 deletions
+2 -14
View File
@@ -25,7 +25,6 @@
#include <openssl/kdf.h>
#include <openssl/params.h>
#include <openssl/pem.h>
// #include <openssl/thread.h>
#include <stdexcept>
#include <string>
@@ -506,27 +505,16 @@ void decrypt_context::decrypt_in_place(std::span<std::span<uint8_t>> text)
}
}
std::vector<uint8_t> argon2(std::string pass, std::string salt, std::span<uint8_t> secret, size_t size)
std::vector<uint8_t> pbkdf2(std::string pass, std::string salt, std::span<uint8_t> secret, size_t size)
{
/* argon2 params, please refer to RFC9106 for recommended defaults */
uint32_t lanes = 2;
uint32_t threads = 2;
uint32_t memcost = 65536;
// if (OSSL_set_max_threads(nullptr, threads) != 1)
// throw_openssl_error();
std::array params{
OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_THREADS, &threads),
OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_ARGON2_LANES, &lanes),
OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_ARGON2_MEMCOST, &memcost),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, salt.data(), salt.size()),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PASSWORD, pass.data(), pass.size()),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET, secret.data(), secret.size()),
OSSL_PARAM_construct_end(),
};
details::kdf_context kdf{"ARGON2I"};
details::kdf_context kdf{"PBKDF2"};
std::vector<uint8_t> result;
result.resize(size);
+1 -1
View File
@@ -182,6 +182,6 @@ public:
};
// Salt must be at least 8 characters
std::vector<uint8_t> argon2(std::string pass, std::string salt, std::span<uint8_t> secret, size_t size);
std::vector<uint8_t> pbkdf2(std::string pass, std::string salt, std::span<uint8_t> secret, size_t size);
} // namespace crypto
+1 -1
View File
@@ -24,7 +24,7 @@
secrets::secrets(crypto::key & my_key, crypto::key & peer_key, const std::string & pin)
{
std::vector<uint8_t> dh = crypto::key::diffie_hellman(my_key, peer_key);
std::vector<uint8_t> secret = crypto::argon2(pin, "saltsalt", dh, sizeof(*this));
std::vector<uint8_t> secret = crypto::pbkdf2(pin, "saltsalt", dh, sizeof(*this));
static_assert(std::is_standard_layout_v<secrets>);
static_assert(std::has_unique_object_representations_v<secrets>);