From e732c6efd96a22296591f3becc1c63fc80299938 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Thu, 18 Jul 2024 15:15:11 +0200 Subject: Adding base64 for token preparation --- modules/crypto/c++/hash.hpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'modules/crypto') diff --git a/modules/crypto/c++/hash.hpp b/modules/crypto/c++/hash.hpp index 3d25b4e..5898adc 100644 --- a/modules/crypto/c++/hash.hpp +++ b/modules/crypto/c++/hash.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace saw { namespace crypto { struct Argon2i {}; @@ -11,9 +13,29 @@ class hash; template<> class hash { public: + error_or> apply(const data& input, const data& salt){ + SAW_ASSERT(input.size() > 0u){ + return make_error("Strings for hashing shouldn't be zero"); + } + uint32_t t_cost = 2; + uint32_t m_cost = 1<<16; + uint32_t parallel = 1; + char* salt_c_ptr = nullptr; + if(salt.size() > 0){ + salt_c_ptr = &salt.at(0); + } + data hash; + try { + hash = {128u}; + }catch(const std::exception&){ + return make_error("Couldn't allocate hash string"); + } + int rv = argon2i_hash_raw(t_cost, m_cost, parallel, &input.at(0), input.size(), &salt.at(0), salt.size(), &hash.at(0), hash.size()); + if(rc != ARGON2_OK){ + return make_error("Failed to hash"); + } - data apply(const data>& input){ - return {""}; + return hash; } }; } -- cgit v1.2.3