add argon2

This commit is contained in:
nek0 2022-04-17 13:47:46 +02:00
parent f829d14384
commit c99bca0511
3 changed files with 15 additions and 9 deletions

View file

@ -36,7 +36,7 @@ library
API API
Classes Classes
Util Util
Util.Random Util.Crypto
Model.Product Model.Product
Model.Auth Model.Auth
Model.User Model.User

14
src/Util/Crypto.hs Normal file
View file

@ -0,0 +1,14 @@
module Util.Crypto where
import Crypto.KDF.Argon2
import Crypto.Error (CryptoFailable)
import qualified Data.ByteString as BS
import System.Random.Stateful (uniformByteStringM, newIOGenM, mkStdGen)
randomString :: IO BS.ByteString
randomString = uniformByteStringM 32 =<< newIOGenM (mkStdGen 23)
argon2 :: BS.ByteString -> BS.ByteString -> CryptoFailable BS.ByteString
argon2 salt payload = hash defaultOptions payload salt 64

View file

@ -1,8 +0,0 @@
module Util.Random where
import qualified Data.ByteString as BS
import System.Random.Stateful (uniformByteStringM, newIOGenM, mkStdGen)
randomString :: IO BS.ByteString
randomString = uniformByteStringM 32 =<< newIOGenM (mkStdGen 23)