sha-validation-0.1.0.1: Validation SHA Implementations
CopyrightCopyright © 2022-2024 Lars Kuhtz <lakuhtz@gmail.com>
LicenseMIT
MaintainerLars Kuhtz <lakuhtz@gmail.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Hash.SHA

Description

Synopsis

Selected Long Messages Test for Byte-Oriented Implementations

data MsgFile Source #

Constructors

MsgFile 

Instances

Instances details
Show MsgFile Source # 
Instance details

Defined in Test.Hash.Internal

Eq MsgFile Source # 
Instance details

Defined in Test.Hash.Internal

Methods

(==) :: MsgFile -> MsgFile -> Bool #

(/=) :: MsgFile -> MsgFile -> Bool #

Ord MsgFile Source # 
Instance details

Defined in Test.Hash.Internal

Lift MsgFile Source # 
Instance details

Defined in Test.Hash.Internal

Methods

lift :: Quote m => MsgFile -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => MsgFile -> Code m MsgFile #

data MsgVector Source #

Constructors

MsgVector 

Instances

Instances details
Show MsgVector Source # 
Instance details

Defined in Test.Hash.Internal

Eq MsgVector Source # 
Instance details

Defined in Test.Hash.Internal

Ord MsgVector Source # 
Instance details

Defined in Test.Hash.Internal

Lift MsgVector Source # 
Instance details

Defined in Test.Hash.Internal

Methods

lift :: Quote m => MsgVector -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => MsgVector -> Code m MsgVector #

sha1LongMsg :: MsgFile Source #

SHA1LongMsg.rsp

sha224LongMsg :: MsgFile Source #

SHA224LongMsg.rsp

sha256LongMsg :: MsgFile Source #

SHA256LongMsg.rsp

sha384LongMsg :: MsgFile Source #

SHA384LongMsg.rsp

sha512LongMsg :: MsgFile Source #

SHA512LongMsg.rsp

sha512_224LongMsg :: MsgFile Source #

SHA512_224LongMsg.rsp

sha512_256LongMsg :: MsgFile Source #

SHA512_256LongMsg.rsp

Selected Short Messages Test for Byte-Oriented Implementations

sha1ShortMsg :: MsgFile Source #

SHA1ShortMsg.rsp

sha224ShortMsg :: MsgFile Source #

SHA224ShortMsg.rsp

sha256ShortMsg :: MsgFile Source #

SHA256ShortMsg.rsp

sha384ShortMsg :: MsgFile Source #

SHA384ShortMsg.rsp

sha512ShortMsg :: MsgFile Source #

SHA512ShortMsg.rsp

sha512_224ShortMsg :: MsgFile Source #

SHA512_224ShortMsg.rsp

sha512_256ShortMsg :: MsgFile Source #

SHA512_256ShortMsg.rsp

The Pseudorandomly Generated Messages (Monte Carlo) Tests

data MonteFile Source #

Instances

Instances details
Show MonteFile Source # 
Instance details

Defined in Test.Hash.Internal

Eq MonteFile Source # 
Instance details

Defined in Test.Hash.Internal

Ord MonteFile Source # 
Instance details

Defined in Test.Hash.Internal

Lift MonteFile Source # 
Instance details

Defined in Test.Hash.Internal

Methods

lift :: Quote m => MonteFile -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => MonteFile -> Code m MonteFile #

sha1Monte :: MonteFile Source #

SHA1Monte.rsp

sha224Monte :: MonteFile Source #

SHA224Monte.rsp

sha256Monte :: MonteFile Source #

SHA256Monte.rsp

sha384Monte :: MonteFile Source #

SHA384Monte.rsp

sha512Monte :: MonteFile Source #

SHA512Monte.rsp

sha512_224Monte :: MonteFile Source #

SHA512_224Monte.rsp

sha512_256Monte :: MonteFile Source #

SHA512_256Monte.rsp

Test Utils

msgTest :: (ByteString -> ByteString) -> MsgFile -> Bool Source #

Check that all test vectors in a File are satisfied by a given hash implementation.

msgAssert Source #

Arguments

:: Monad m 
=> (String -> ByteString -> ByteString -> m ())

Function to assertion Equality. The first argument is a test label, the second argument is the actual value, and the thrid value is the expected value.

-> (ByteString -> ByteString)

Hash function

-> MsgFile 
-> m () 

For a given hash implementation, assert the correct result for each test vector in a MsgFile.

The function to assert equality is usually provided by some testing framework.

monteTest :: (ByteString -> ByteString) -> MonteFile -> Bool Source #

Test a given SHA1 or SHA2 implementation for the test vectors in a monte file. See monteAssert for details.

monteAssert Source #

Arguments

:: Monad m 
=> (String -> ByteString -> ByteString -> m ())

Function to assertion Equality. The first argument is a test label, the second argument is the actual value, and the thrid value is the expected value.

-> (ByteString -> ByteString)

Hash function

-> MonteFile 
-> m () 

For a given SHA1 or SHA2 implementation, assert the correct result for each test vector in a MonteFile.

The function to assert equality is usually provided by some testing framework.

NOTE that the test algorithms for SHA (SHA1 and SHA2) and SHA3 are different.

The test algorithm is describe in cf. https://csrc.nist.gov/csrc/media/projects/cryptographic-algorithm-validation-program/documents/shs/shavs.pdf. The pseudo code is as follows:

INPUT: Seed - A random seed n bits long
{
    for (j=0; j<100; j++) {
        MD0 = MD1 = MD2 = Seed;
        for (i=3; i<1003; i++) {
            Mi = MDi-3 || MDi-2 || MDi-1;
            MDi = SHA(Mi);
        }
        MDj = Seed = MD1002;
        OUTPUT: MDj
    }
}