Skip to content

Commit

Permalink
Merge pull request #4006 from randombit/jack/argon2-h-cleanup
Browse files Browse the repository at this point in the history
Small cleanup to the freestanding argon2 function
  • Loading branch information
randombit authored Apr 12, 2024
2 parents 0699728 + 9b157ea commit c479ebb
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/lib/pbkdf/argon2/argon2.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,19 @@ inline void argon2(uint8_t output[],
size_t p,
size_t M,
size_t t) {
std::unique_ptr<PasswordHashFamily> pwdhash_fam;

if(y == 0) {
pwdhash_fam = PasswordHashFamily::create_or_throw("Argon2d");
} else if(y == 1) {
pwdhash_fam = PasswordHashFamily::create_or_throw("Argon2i");
} else if(y == 2) {
pwdhash_fam = PasswordHashFamily::create_or_throw("Argon2id");
} else {
throw Not_Implemented("Unknown Argon2 family type");
}

auto pwdhash_fam = PasswordHashFamily::create_or_throw([y] {
switch(y) {
case 0:
return "Argon2d";
case 1:
return "Argon2i";
case 2:
return "Argon2id";
default:
throw Not_Implemented("Unknown Argon2 family type");
}
}());
auto pwdhash = pwdhash_fam->from_params(M, t, p);

pwdhash->derive_key(output, output_len, password, password_len, salt, salt_len, ad, ad_len, key, key_len);
}

Expand Down

0 comments on commit c479ebb

Please sign in to comment.