{-# LANGUAGE OverloadedStrings, BangPatterns, ScopedTypeVariables #-}
module Crypto.PHKDF.Primitives
( HmacKey()
, hmacKey_init
, PhkdfCtx()
, phkdfCtx_init
, phkdfCtx_initFromHmacKey
, phkdfCtx_hmacKey
, phkdfCtx_resetCtx
, phkdfCtx_reset
, phkdfCtx_addArg
, phkdfCtx_addArgs
, phkdfCtx_addArgsBy
, phkdfCtx_finalize
, phkdfCtx_finalizeHmac
, phkdfCtx_finalizeHmacCtx
, phkdfCtx_finalizeStream
, phkdfCtx_finalizeGen
, PhkdfSlowCtx()
, phkdfSlowCtx_extract
, phkdfSlowCtx_addArg
, phkdfSlowCtx_addArgs
, phkdfSlowCtx_finalize
, phkdfSlowCtx_finalizeStream
, PhkdfGen()
, phkdfGen_initFromHmacKey
, phkdfGen_read
, phkdfGen_peek
, phkdfGen_finalizeStream
) where
import Data.Bits((.&.))
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.Function((&))
import Data.Foldable(Foldable, foldl')
import Data.Int
import Data.Word
import Data.Stream (Stream(..))
import qualified Data.Stream as Stream
import Network.ByteOrder (bytestring32)
import qualified Crypto.Hash.SHA256 as SHA256
import Crypto.PHKDF.HMAC
import Crypto.PHKDF.HMAC.Subtle
import Crypto.PHKDF.Primitives.Subtle
import Crypto.Encoding.PHKDF
import Crypto.Encoding.SHA3.TupleHash
import Control.Exception(assert)
phkdfCtx_init :: ByteString -> PhkdfCtx
phkdfCtx_init :: ByteString -> PhkdfCtx
phkdfCtx_init = HmacKey -> PhkdfCtx
phkdfCtx_initFromHmacKey (HmacKey -> PhkdfCtx)
-> (ByteString -> HmacKey) -> ByteString -> PhkdfCtx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> HmacKey
hmacKey_init
phkdfCtx_initFromHmacKey :: HmacKey -> PhkdfCtx
phkdfCtx_initFromHmacKey :: HmacKey -> PhkdfCtx
phkdfCtx_initFromHmacKey HmacKey
key =
PhkdfCtx {
phkdfCtx_byteLen :: Word64
phkdfCtx_byteLen = Word64
0,
phkdfCtx_state :: Ctx
phkdfCtx_state = HmacKey -> Ctx
hmacKey_ipad HmacKey
key,
phkdfCtx_hmacKey :: HmacKey
phkdfCtx_hmacKey = HmacKey
key
}
phkdfCtx_reset :: PhkdfCtx -> PhkdfCtx
phkdfCtx_reset :: PhkdfCtx -> PhkdfCtx
phkdfCtx_reset = HmacKey -> PhkdfCtx
phkdfCtx_initFromHmacKey (HmacKey -> PhkdfCtx)
-> (PhkdfCtx -> HmacKey) -> PhkdfCtx -> PhkdfCtx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PhkdfCtx -> HmacKey
phkdfCtx_hmacKey
phkdfCtx_resetCtx :: PhkdfCtx -> HmacCtx
phkdfCtx_resetCtx :: PhkdfCtx -> HmacCtx
phkdfCtx_resetCtx = HmacKey -> HmacCtx
hmacKey_run (HmacKey -> HmacCtx)
-> (PhkdfCtx -> HmacKey) -> PhkdfCtx -> HmacCtx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PhkdfCtx -> HmacKey
phkdfCtx_hmacKey
phkdfCtx_addArg :: ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArg :: ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArg ByteString
b PhkdfCtx
ctx = [ByteString] -> PhkdfCtx -> PhkdfCtx
forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_unsafeFeed [ Int -> ByteString
forall b. (Integral b, FiniteBits b) => b -> ByteString
leftEncodeFromBytes (ByteString -> Int
B.length ByteString
b), ByteString
b ] PhkdfCtx
ctx
phkdfCtx_addArgs :: Foldable f => f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArgs :: forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArgs f ByteString
params PhkdfCtx
ctx = (PhkdfCtx -> ByteString -> PhkdfCtx)
-> PhkdfCtx -> f ByteString -> PhkdfCtx
forall b a. (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((ByteString -> PhkdfCtx -> PhkdfCtx)
-> PhkdfCtx -> ByteString -> PhkdfCtx
forall a b c. (a -> b -> c) -> b -> a -> c
flip ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArg) PhkdfCtx
ctx f ByteString
params
phkdfCtx_addArgsBy :: Foldable f => (a -> ByteString) -> f a -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArgsBy :: forall (f :: * -> *) a.
Foldable f =>
(a -> ByteString) -> f a -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArgsBy a -> ByteString
f f a
params PhkdfCtx
ctx0 = (PhkdfCtx -> a -> PhkdfCtx) -> PhkdfCtx -> f a -> PhkdfCtx
forall b a. (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' PhkdfCtx -> a -> PhkdfCtx
delta PhkdfCtx
ctx0 f a
params
where delta :: PhkdfCtx -> a -> PhkdfCtx
delta PhkdfCtx
ctx a
a = ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArg (a -> ByteString
f a
a) PhkdfCtx
ctx
phkdfCtx_finalize :: (Int -> ByteString) -> Word32 -> ByteString -> PhkdfCtx -> ByteString
phkdfCtx_finalize :: (Int -> ByteString)
-> Word32 -> ByteString -> PhkdfCtx -> ByteString
phkdfCtx_finalize Int -> ByteString
genFillerPad Word32
counter ByteString
tag PhkdfCtx
ctx =
(Int -> ByteString) -> Word32 -> ByteString -> PhkdfCtx -> PhkdfGen
phkdfCtx_finalizeGen Int -> ByteString
genFillerPad Word32
counter ByteString
tag PhkdfCtx
ctx PhkdfGen
-> (PhkdfGen -> (ByteString, PhkdfGen)) -> (ByteString, PhkdfGen)
forall a b. a -> (a -> b) -> b
&
PhkdfGen -> (ByteString, PhkdfGen)
phkdfGen_read (ByteString, PhkdfGen)
-> ((ByteString, PhkdfGen) -> ByteString) -> ByteString
forall a b. a -> (a -> b) -> b
&
(ByteString, PhkdfGen) -> ByteString
forall a b. (a, b) -> a
fst
phkdfCtx_finalizeHmacCtx :: PhkdfCtx -> HmacCtx
phkdfCtx_finalizeHmacCtx :: PhkdfCtx -> HmacCtx
phkdfCtx_finalizeHmacCtx PhkdfCtx
ctx =
(PhkdfCtx -> HmacCtx
phkdfCtx_resetCtx PhkdfCtx
ctx) {
hmacCtx_ipad = phkdfCtx_state ctx
}
phkdfCtx_finalizeHmac :: PhkdfCtx -> ByteString
phkdfCtx_finalizeHmac :: PhkdfCtx -> ByteString
phkdfCtx_finalizeHmac = HmacCtx -> ByteString
hmacCtx_finalize (HmacCtx -> ByteString)
-> (PhkdfCtx -> HmacCtx) -> PhkdfCtx -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PhkdfCtx -> HmacCtx
phkdfCtx_finalizeHmacCtx
phkdfCtx_finalizeStream :: (Int -> ByteString) -> Word32 -> ByteString -> PhkdfCtx -> Stream ByteString
phkdfCtx_finalizeStream :: (Int -> ByteString)
-> Word32 -> ByteString -> PhkdfCtx -> Stream ByteString
phkdfCtx_finalizeStream Int -> ByteString
genFillerPad Word32
counter0 ByteString
tag PhkdfCtx
ctx =
(Int -> ByteString) -> Word32 -> ByteString -> PhkdfCtx -> PhkdfGen
phkdfCtx_finalizeGen Int -> ByteString
genFillerPad Word32
counter0 ByteString
tag PhkdfCtx
ctx PhkdfGen -> (PhkdfGen -> Stream ByteString) -> Stream ByteString
forall a b. a -> (a -> b) -> b
&
PhkdfGen -> Stream ByteString
phkdfGen_finalizeStream
phkdfCtx_finalizeGen :: (Int -> ByteString) -> Word32 -> ByteString -> PhkdfCtx -> PhkdfGen
phkdfCtx_finalizeGen :: (Int -> ByteString) -> Word32 -> ByteString -> PhkdfCtx -> PhkdfGen
phkdfCtx_finalizeGen Int -> ByteString
genFillerPad Word32
counter0 ByteString
tag PhkdfCtx
ctx =
PhkdfGen
{ phkdfGen_hmacKey :: HmacKey
phkdfGen_hmacKey = PhkdfCtx -> HmacKey
phkdfCtx_hmacKey PhkdfCtx
ctx
, phkdfGen_extTag :: ByteString
phkdfGen_extTag = ByteString -> ByteString
extendTag ByteString
tag
, phkdfGen_counter :: Word32
phkdfGen_counter = Word32
counter0
, phkdfGen_state :: ByteString
phkdfGen_state = ByteString
""
, phkdfGen_initCtx :: Maybe Ctx
phkdfGen_initCtx = Ctx -> Maybe Ctx
forall a. a -> Maybe a
Just Ctx
context0
}
where
n :: Word64
n = PhkdfCtx -> Word64
phkdfCtx_byteLen PhkdfCtx
ctx
endPadLen :: Int
endPadLen = Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word64
31 Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
n) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
63)
endPadding :: ByteString
endPadding = Int -> ByteString
genFillerPad Int
endPadLen
ctx' :: PhkdfCtx
ctx' = [ByteString] -> PhkdfCtx -> PhkdfCtx
forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_unsafeFeed [ByteString
"\x00",ByteString
endPadding] PhkdfCtx
ctx
endPaddingIsValid :: Bool
endPaddingIsValid = PhkdfCtx -> Word64
phkdfCtx_byteLen PhkdfCtx
ctx' Word64 -> Word64 -> Word64
forall a. Integral a => a -> a -> a
`mod` Word64
64 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
32
Bool -> Bool -> Bool
&& ByteString -> Int
B.length ByteString
endPadding Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
endPadLen
context0 :: Ctx
context0 = Bool -> Ctx -> Ctx
forall a. (?callStack::CallStack) => Bool -> a -> a
assert Bool
endPaddingIsValid (Ctx -> Ctx) -> Ctx -> Ctx
forall a b. (a -> b) -> a -> b
$ PhkdfCtx -> Ctx
phkdfCtx_state PhkdfCtx
ctx'
phkdfGen_initFromHmacKey :: ByteString -> Word32 -> ByteString -> HmacKey -> PhkdfGen
phkdfGen_initFromHmacKey :: ByteString -> Word32 -> ByteString -> HmacKey -> PhkdfGen
phkdfGen_initFromHmacKey ByteString
state0 Word32
counter0 ByteString
tag HmacKey
hmacKey = PhkdfGen
{ phkdfGen_hmacKey :: HmacKey
phkdfGen_hmacKey = HmacKey
hmacKey
, phkdfGen_extTag :: ByteString
phkdfGen_extTag = ByteString -> ByteString
extendTag ByteString
tag
, phkdfGen_counter :: Word32
phkdfGen_counter = Word32
counter0
, phkdfGen_state :: ByteString
phkdfGen_state = ByteString
state0
, phkdfGen_initCtx :: Maybe Ctx
phkdfGen_initCtx = Ctx -> Maybe Ctx
forall a. a -> Maybe a
Just (Ctx -> Maybe Ctx) -> Ctx -> Maybe Ctx
forall a b. (a -> b) -> a -> b
$ HmacKey -> Ctx
hmacKey_ipad HmacKey
hmacKey
}
phkdfGen_peek :: PhkdfGen -> Maybe ByteString
phkdfGen_peek :: PhkdfGen -> Maybe ByteString
phkdfGen_peek PhkdfGen
gen =
case PhkdfGen -> Maybe Ctx
phkdfGen_initCtx PhkdfGen
gen of
Maybe Ctx
Nothing -> ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ PhkdfGen -> ByteString
phkdfGen_state PhkdfGen
gen
Just Ctx
_ -> Maybe ByteString
forall a. Maybe a
Nothing
phkdfGen_finalizeHmacCtx :: PhkdfGen -> HmacCtx
phkdfGen_finalizeHmacCtx :: PhkdfGen -> HmacCtx
phkdfGen_finalizeHmacCtx PhkdfGen
gen =
(HmacKey -> HmacCtx
hmacKey_run (PhkdfGen -> HmacKey
phkdfGen_hmacKey PhkdfGen
gen)) {
hmacCtx_ipad = SHA256.update ipad (phkdfGen_state gen)
}
where
ipad :: Ctx
ipad =
case PhkdfGen -> Maybe Ctx
phkdfGen_initCtx PhkdfGen
gen of
Maybe Ctx
Nothing -> HmacCtx -> Ctx
hmacCtx_ipad (HmacCtx -> Ctx) -> (HmacKey -> HmacCtx) -> HmacKey -> Ctx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HmacKey -> HmacCtx
hmacKey_run (HmacKey -> Ctx) -> HmacKey -> Ctx
forall a b. (a -> b) -> a -> b
$ PhkdfGen -> HmacKey
phkdfGen_hmacKey PhkdfGen
gen
Just Ctx
x -> Ctx
x
phkdfGen_read :: PhkdfGen -> (ByteString, PhkdfGen)
phkdfGen_read :: PhkdfGen -> (ByteString, PhkdfGen)
phkdfGen_read PhkdfGen
gen = (ByteString
state', PhkdfGen
gen')
where
state' :: ByteString
state' =
PhkdfGen -> HmacCtx
phkdfGen_finalizeHmacCtx PhkdfGen
gen HmacCtx -> (HmacCtx -> HmacCtx) -> HmacCtx
forall a b. a -> (a -> b) -> b
&
[ByteString] -> HmacCtx -> HmacCtx
hmacCtx_updates [ Word32 -> ByteString
bytestring32 (PhkdfGen -> Word32
phkdfGen_counter PhkdfGen
gen)
, PhkdfGen -> ByteString
phkdfGen_extTag PhkdfGen
gen
] HmacCtx -> (HmacCtx -> ByteString) -> ByteString
forall a b. a -> (a -> b) -> b
&
HmacCtx -> ByteString
hmacCtx_finalize
hmacKey :: HmacKey
hmacKey = PhkdfGen -> HmacKey
phkdfGen_hmacKey PhkdfGen
gen
gen' :: PhkdfGen
gen' = PhkdfGen
{ phkdfGen_hmacKey :: HmacKey
phkdfGen_hmacKey = HmacKey
hmacKey
, phkdfGen_initCtx :: Maybe Ctx
phkdfGen_initCtx = Maybe Ctx
forall a. Maybe a
Nothing
, phkdfGen_state :: ByteString
phkdfGen_state = ByteString
state'
, phkdfGen_counter :: Word32
phkdfGen_counter = PhkdfGen -> Word32
phkdfGen_counter PhkdfGen
gen Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
1
, phkdfGen_extTag :: ByteString
phkdfGen_extTag = PhkdfGen -> ByteString
phkdfGen_extTag PhkdfGen
gen
}
phkdfGen_finalizeStream :: PhkdfGen -> Stream ByteString
phkdfGen_finalizeStream :: PhkdfGen -> Stream ByteString
phkdfGen_finalizeStream = (PhkdfGen -> (ByteString, PhkdfGen))
-> PhkdfGen -> Stream ByteString
forall c a. (c -> (a, c)) -> c -> Stream a
Stream.unfold PhkdfGen -> (ByteString, PhkdfGen)
phkdfGen_read
phkdfSlowCtx_extract :: (Int -> ByteString) -> Word32 -> ByteString -> ByteString -> Word32 -> PhkdfCtx -> PhkdfSlowCtx
Int -> ByteString
genFillerPad Word32
counter ByteString
tag ByteString
fnName Word32
rounds PhkdfCtx
ctx0 = PhkdfSlowCtx
out
where
(Cons ByteString
block0 Stream ByteString
innerStream) = (Int -> ByteString)
-> Word32 -> ByteString -> PhkdfCtx -> Stream ByteString
phkdfCtx_finalizeStream Int -> ByteString
genFillerPad Word32
counter ByteString
tag PhkdfCtx
ctx0
approxByteLen :: Int64
approxByteLen = ((Word32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
rounds :: Int64) Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
1) Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
* Int64
64 Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
32
encodedLengthByteLen :: Int
encodedLengthByteLen = Int64 -> Int
forall b. (Integral b, FiniteBits b) => b -> Int
lengthOfLeftEncodeFromBytes Int64
approxByteLen
exactByteLen :: Int64
exactByteLen = Int64
approxByteLen Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
encodedLengthByteLen
encodedLength :: ByteString
encodedLength = Int64 -> ByteString
forall b. (Integral b, FiniteBits b) => b -> ByteString
leftEncodeFromBytes Int64
exactByteLen
extFnNameByteLen :: Int
extFnNameByteLen = Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
encodedLengthByteLen
fnNameByteLen :: Int
fnNameByteLen = ByteString -> Int
B.length ByteString
fnName
extFnName :: ByteString
extFnName =
if Int
fnNameByteLen Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
extFnNameByteLen
then ByteString
encodedLength ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString -> ByteString
B.take Int
extFnNameByteLen ByteString
fnName
else let padLen :: Int
padLen = Int
31 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
encodedLengthByteLen Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fnNameByteLen
pad :: ByteString
pad = ByteString -> Int -> ByteString
cycleByteStringWithNull ByteString
tag Int
padLen
in [ByteString] -> ByteString
B.concat [ByteString
encodedLength, ByteString
fnName, ByteString
"\x00", ByteString
pad]
outerCtx :: PhkdfCtx
outerCtx =
PhkdfCtx -> PhkdfCtx
phkdfCtx_reset PhkdfCtx
ctx0 PhkdfCtx -> (PhkdfCtx -> PhkdfCtx) -> PhkdfCtx
forall a b. a -> (a -> b) -> b
&
[ByteString] -> PhkdfCtx -> PhkdfCtx
forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_unsafeFeed [ByteString
extFnName, ByteString
block0]
fillerTag :: ByteString
fillerTag = (ByteString -> Int -> ByteString)
-> Int -> ByteString -> ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip ByteString -> Int -> ByteString
cycleByteString Int
32 (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ByteString
B.concat
[ ByteString
tag, ByteString
"\x00", ByteString
fnName, ByteString
"\x00"]
go :: t -> PhkdfCtx -> Stream ByteString -> PhkdfSlowCtx
go t
n !PhkdfCtx
ctx ~(Cons ByteString
block Stream ByteString
stream)
| t
n t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
0 = PhkdfSlowCtx {
phkdfSlowCtx_phkdfCtx :: PhkdfCtx
phkdfSlowCtx_phkdfCtx = [ByteString] -> PhkdfCtx -> PhkdfCtx
forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_unsafeFeed [ByteString
fillerTag] PhkdfCtx
ctx,
phkdfSlowCtx_counter :: Word32
phkdfSlowCtx_counter = Word32
counter Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
rounds Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
1,
phkdfSlowCtx_tag :: ByteString
phkdfSlowCtx_tag = ByteString
tag
}
| Bool
otherwise = t -> PhkdfCtx -> Stream ByteString -> PhkdfSlowCtx
go (t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
1) ([ByteString] -> PhkdfCtx -> PhkdfCtx
forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_unsafeFeed [ByteString
fillerTag, ByteString
block] PhkdfCtx
ctx) Stream ByteString
stream
out :: PhkdfSlowCtx
out = Word32 -> PhkdfCtx -> Stream ByteString -> PhkdfSlowCtx
forall {t}.
(Ord t, Num t) =>
t -> PhkdfCtx -> Stream ByteString -> PhkdfSlowCtx
go Word32
rounds PhkdfCtx
outerCtx Stream ByteString
innerStream
phkdfSlowCtx_addArg :: ByteString -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_addArg :: ByteString -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_addArg = (PhkdfCtx -> PhkdfCtx) -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_lift ((PhkdfCtx -> PhkdfCtx) -> PhkdfSlowCtx -> PhkdfSlowCtx)
-> (ByteString -> PhkdfCtx -> PhkdfCtx)
-> ByteString
-> PhkdfSlowCtx
-> PhkdfSlowCtx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArg
phkdfSlowCtx_addArgs :: Foldable f => f ByteString -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_addArgs :: forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_addArgs = (PhkdfCtx -> PhkdfCtx) -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_lift ((PhkdfCtx -> PhkdfCtx) -> PhkdfSlowCtx -> PhkdfSlowCtx)
-> (f ByteString -> PhkdfCtx -> PhkdfCtx)
-> f ByteString
-> PhkdfSlowCtx
-> PhkdfSlowCtx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f ByteString -> PhkdfCtx -> PhkdfCtx
forall (f :: * -> *).
Foldable f =>
f ByteString -> PhkdfCtx -> PhkdfCtx
phkdfCtx_addArgs
phkdfSlowCtx_finalize :: (Int -> ByteString) -> PhkdfSlowCtx -> ByteString
phkdfSlowCtx_finalize :: (Int -> ByteString) -> PhkdfSlowCtx -> ByteString
phkdfSlowCtx_finalize Int -> ByteString
genFillerPad = Stream ByteString -> ByteString
forall a. Stream a -> a
Stream.head (Stream ByteString -> ByteString)
-> (PhkdfSlowCtx -> Stream ByteString)
-> PhkdfSlowCtx
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> ByteString) -> PhkdfSlowCtx -> Stream ByteString
phkdfSlowCtx_finalizeStream Int -> ByteString
genFillerPad
phkdfSlowCtx_finalizeStream :: (Int -> ByteString) -> PhkdfSlowCtx -> Stream ByteString
phkdfSlowCtx_finalizeStream :: (Int -> ByteString) -> PhkdfSlowCtx -> Stream ByteString
phkdfSlowCtx_finalizeStream Int -> ByteString
genFillerPad PhkdfSlowCtx
ctx =
(Int -> ByteString)
-> Word32 -> ByteString -> PhkdfCtx -> Stream ByteString
phkdfCtx_finalizeStream Int -> ByteString
genFillerPad
(PhkdfSlowCtx -> Word32
phkdfSlowCtx_counter PhkdfSlowCtx
ctx)
(PhkdfSlowCtx -> ByteString
phkdfSlowCtx_tag PhkdfSlowCtx
ctx)
(PhkdfSlowCtx -> PhkdfCtx
phkdfSlowCtx_phkdfCtx PhkdfSlowCtx
ctx)