blob: f6d371360c2c6fa574fd6c253a11991ba26db67b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "../include/odhtdb/PasswordHash.hpp"
#include <argon2.h>
namespace odhtdb
{
OwnedMemory hashPassword(const DataView &plainPassword, const DataView &salt)
{
OwnedMemory result;
const uint32_t tCost = 2;
const uint32_t mCost = 1 << 16;
const uint32_t parallelism = 1;
const uint32_t HASHLEN = 32;
result.data = new uint8_t[HASHLEN];
result.size = HASHLEN;
if(argon2i_hash_raw(tCost, mCost, parallelism, plainPassword.data, plainPassword.size, salt.data, salt.size, result.data, HASHLEN) != ARGON2_OK)
throw std::runtime_error("Failed to hash password");
return result;
}
}
|