module Crypto.Spake2.Util
( expandData
, expandArbitraryElementSeed
, bytesToNumber
, numberToBytes
, unsafeNumberToBytes
) where
import Protolude
import Crypto.Hash.Algorithms (SHA256)
import Crypto.Number.Serialize (os2ip, i2ospOf, i2ospOf_)
import qualified Crypto.KDF.HKDF as HKDF
import Data.ByteArray (ByteArray, ByteArrayAccess(..))
expandData :: (ByteArrayAccess input, ByteArray output) => ByteString -> input -> Int -> output
expandData :: ByteString -> input -> Int -> output
expandData ByteString
info input
input Int
size =
PRK SHA256 -> ByteString -> Int -> output
forall a info out.
(HashAlgorithm a, ByteArrayAccess info, ByteArray out) =>
PRK a -> info -> Int -> out
HKDF.expand PRK SHA256
prk ByteString
info Int
size
where
prk :: HKDF.PRK SHA256
prk :: PRK SHA256
prk = ByteString -> input -> PRK SHA256
forall a salt ikm.
(HashAlgorithm a, ByteArrayAccess salt, ByteArrayAccess ikm) =>
salt -> ikm -> PRK a
HKDF.extract ByteString
salt input
input
salt :: ByteString
salt :: ByteString
salt = ByteString
""
expandArbitraryElementSeed :: (ByteArrayAccess ikm, ByteArray out) => ikm -> Int -> out
expandArbitraryElementSeed :: ikm -> Int -> out
expandArbitraryElementSeed =
ByteString -> ikm -> Int -> out
forall input output.
(ByteArrayAccess input, ByteArray output) =>
ByteString -> input -> Int -> output
expandData ByteString
"SPAKE2 arbitrary element"
numberToBytes :: ByteArray bytes => Int -> Integer -> Maybe bytes
numberToBytes :: Int -> Integer -> Maybe bytes
numberToBytes = Int -> Integer -> Maybe bytes
forall ba. ByteArray ba => Int -> Integer -> Maybe ba
i2ospOf
unsafeNumberToBytes :: ByteArray bytes => Int -> Integer -> bytes
unsafeNumberToBytes :: Int -> Integer -> bytes
unsafeNumberToBytes = Int -> Integer -> bytes
forall ba. ByteArray ba => Int -> Integer -> ba
i2ospOf_
bytesToNumber :: ByteArrayAccess bytes => bytes -> Integer
bytesToNumber :: bytes -> Integer
bytesToNumber = bytes -> Integer
forall ba. ByteArrayAccess ba => ba -> Integer
os2ip