hmac-drbg

Pure Haskell HMAC-DRBG (docs.ppad.tech/hmac-drbg).
git clone git://git.ppad.tech/hmac-drbg.git
Log | Files | Refs | README | LICENSE

commit b7211a8cdfd4dec7eabda8e431135cc4cf461e62
parent 40670e17b116a96fabbd4e7e148db8827f972cde
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat,  5 Oct 2024 17:05:47 +0400

test: reuse exported HMAC type, comment/org

Diffstat:
Mtest/Main.hs | 64++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/test/Main.hs b/test/Main.hs @@ -31,8 +31,7 @@ cavs_14_3 cs = testGroup "CAVS 14.3" [ testGroup "SHA-256" (fmap (execute SHA256.hmac) cs) ] --- test cases - +-- test case spec data Case = Case { caseCount :: !Int -- instantiate @@ -55,6 +54,37 @@ data Case = Case { } deriving Show +-- execute test case +execute :: DRBG.HMAC -> Case -> TestTree +execute hmac Case {..} = testCase ("count " <> show caseCount) $ do + let bytes = fromIntegral (BS.length caseReturned) + + drbg <- DRBG.new hmac caseEntropy0 caseNonce casePs + v0 <- DRBG._read_v drbg + k0 <- DRBG._read_k drbg + + assertEqual "v0" v0 caseV0 + assertEqual "k0" k0 caseK0 + + DRBG.reseed caseEntropy1 caseAddl1 drbg + _ <- DRBG.gen mempty bytes drbg + v1 <- DRBG._read_v drbg + k1 <- DRBG._read_k drbg + + assertEqual "v1" v1 caseV1 + assertEqual "k1" k1 caseK1 + + DRBG.reseed caseEntropy2 caseAddl2 drbg + returned <- DRBG.gen mempty bytes drbg + v2 <- DRBG._read_v drbg + k2 <- DRBG._read_k drbg + + assertEqual "returned_bytes" returned caseReturned + assertEqual "v2" v2 caseV2 + assertEqual "k2" k2 caseK2 + +-- CAVS vector parsers + hex_digit :: A.Parser Char hex_digit = A.satisfy hd where hd c = @@ -118,33 +148,3 @@ parse_sha256_block = parse_sha256_blocks :: A.Parser [Case] parse_sha256_blocks = concat <$> A.many1 parse_sha256_block -type HMAC = BS.ByteString -> BS.ByteString -> BS.ByteString - -execute :: HMAC -> Case -> TestTree -execute hmac Case {..} = testCase ("count " <> show caseCount) $ do - let bytes = fromIntegral (BS.length caseReturned) - - drbg <- DRBG.new hmac caseEntropy0 caseNonce casePs - v0 <- DRBG._read_v drbg - k0 <- DRBG._read_k drbg - - assertEqual "v0" v0 caseV0 - assertEqual "k0" k0 caseK0 - - DRBG.reseed caseEntropy1 caseAddl1 drbg - _ <- DRBG.gen mempty bytes drbg - v1 <- DRBG._read_v drbg - k1 <- DRBG._read_k drbg - - assertEqual "v1" v1 caseV1 - assertEqual "k1" k1 caseK1 - - DRBG.reseed caseEntropy2 caseAddl2 drbg - returned <- DRBG.gen mempty bytes drbg - v2 <- DRBG._read_v drbg - k2 <- DRBG._read_k drbg - - assertEqual "returned_bytes" returned caseReturned - assertEqual "v2" v2 caseV2 - assertEqual "k2" k2 caseK2 -