aboutsummaryrefslogtreecommitdiff
path: root/src/PasswordHash.cpp
blob: 329733bb3099e2b115a60c94f0e2ee3175f5de8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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;
        
        result.data = new uint8_t[HASH_PASSWORD_LENGTH];
        result.size = HASH_PASSWORD_LENGTH;
        
        if(argon2i_hash_raw(tCost, mCost, parallelism, plainPassword.data, plainPassword.size, salt.data, salt.size, result.data, HASH_PASSWORD_LENGTH) != ARGON2_OK)
            throw std::runtime_error("Failed to hash password");
        
        return result;
    }
}