aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/passhash/passhash9/passhash9.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/passhash/passhash9/passhash9.cpp')
-rw-r--r--src/lib/passhash/passhash9/passhash9.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/lib/passhash/passhash9/passhash9.cpp b/src/lib/passhash/passhash9/passhash9.cpp
index f30684ec6..b457fc5c7 100644
--- a/src/lib/passhash/passhash9/passhash9.cpp
+++ b/src/lib/passhash/passhash9/passhash9.cpp
@@ -7,7 +7,6 @@
#include <botan/passhash9.h>
#include <botan/loadstor.h>
-#include <botan/lookup.h>
#include <botan/pbkdf2.h>
#include <botan/base64.h>
@@ -24,18 +23,18 @@ const size_t PASSHASH9_PBKDF_OUTPUT_LEN = 24; // 192 bits output
const size_t WORK_FACTOR_SCALE = 10000;
-MessageAuthenticationCode* get_pbkdf_prf(byte alg_id)
+std::unique_ptr<MessageAuthenticationCode> get_pbkdf_prf(byte alg_id)
{
if(alg_id == 0)
- return get_mac("HMAC(SHA-1)");
+ return MessageAuthenticationCode::create("HMAC(SHA-1)");
else if(alg_id == 1)
- return get_mac("HMAC(SHA-256)");
+ return MessageAuthenticationCode::create("HMAC(SHA-256)");
else if(alg_id == 2)
- return get_mac("CMAC(Blowfish)");
+ return MessageAuthenticationCode::create("CMAC(Blowfish)");
else if(alg_id == 3)
- return get_mac("HMAC(SHA-384)");
+ return MessageAuthenticationCode::create("HMAC(SHA-384)");
else if(alg_id == 4)
- return get_mac("HMAC(SHA-512)");
+ return MessageAuthenticationCode::create("HMAC(SHA-512)");
return nullptr;
}
@@ -46,14 +45,14 @@ std::string generate_passhash9(const std::string& pass,
u16bit work_factor,
byte alg_id)
{
- MessageAuthenticationCode* prf = get_pbkdf_prf(alg_id);
+ std::unique_ptr<MessageAuthenticationCode> prf = get_pbkdf_prf(alg_id);
if(!prf)
throw Invalid_Argument("Passhash9: Algorithm id " +
std::to_string(alg_id) +
" is not defined");
- PKCS5_PBKDF2 kdf(prf); // takes ownership of pointer
+ PKCS5_PBKDF2 kdf(prf.release()); // takes ownership of pointer
secure_vector<byte> salt(SALT_BYTES);
rng.randomize(salt.data(), salt.size());
@@ -110,12 +109,12 @@ bool check_passhash9(const std::string& pass, const std::string& hash)
const size_t kdf_iterations = WORK_FACTOR_SCALE * work_factor;
- MessageAuthenticationCode* pbkdf_prf = get_pbkdf_prf(alg_id);
+ std::unique_ptr<MessageAuthenticationCode> pbkdf_prf = get_pbkdf_prf(alg_id);
if(!pbkdf_prf)
return false; // unknown algorithm, reject
- PKCS5_PBKDF2 kdf(pbkdf_prf); // takes ownership of pointer
+ PKCS5_PBKDF2 kdf(pbkdf_prf.release()); // takes ownership of pointer
secure_vector<byte> cmp = kdf.derive_key(
PASSHASH9_PBKDF_OUTPUT_LEN,