Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class AlgorithmSetup (algorithm :: Symbol) a where
- type WordSize algorithm :: Natural
- type ChunkSize algorithm :: Natural
- type ResultSize algorithm :: Natural
- initialHashes :: Vector (ByteString (WordSize algorithm) a)
- roundConstants :: Vector (ByteString (WordSize algorithm) a)
- truncateResult :: ByteString (8 * WordSize algorithm) a -> ByteString (ResultSize algorithm) a
- sigmaShifts :: (Natural, Natural, Natural, Natural, Natural, Natural)
- sumShifts :: (Natural, Natural, Natural, Natural, Natural, Natural)
- type SHA2 algorithm element k = (AlgorithmSetup algorithm element, KnownNat k, Finite element, NFData element, FromConstant Natural element, KnownNat (ChunkSize algorithm), KnownNat (WordSize algorithm), KnownNat (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)), Iso (UInt (WordSize algorithm) element) (ByteString (WordSize algorithm) element), Iso (ByteString (WordSize algorithm) element) (UInt (WordSize algorithm) element), AdditiveSemigroup (UInt (WordSize algorithm) element), BoolType (ByteString (WordSize algorithm) element), ShiftBits (ByteString (WordSize algorithm) element), ShiftBits (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element), BoolType (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element), Extend (ByteString k element) (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element), ToWords (ByteString (ChunkSize algorithm) element) (ByteString (WordSize algorithm) element), Concat (ByteString (WordSize algorithm) element) (ByteString (8 * WordSize algorithm) element), ToWords (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element) (ByteString (ChunkSize algorithm) element))
- sha2 :: forall (algorithm :: Symbol) element k. SHA2 algorithm element k => ByteString k element -> ByteString (ResultSize algorithm) element
- type SHA2N algorithm element = (AlgorithmSetup algorithm element, Finite element, NFData element, FromConstant Natural element, KnownNat (ChunkSize algorithm), KnownNat (WordSize algorithm), Iso (UInt (WordSize algorithm) element) (ByteString (WordSize algorithm) element), Iso (ByteString (WordSize algorithm) element) (UInt (WordSize algorithm) element), AdditiveSemigroup (UInt (WordSize algorithm) element), BoolType (ByteString (WordSize algorithm) element), ShiftBits (ByteString (WordSize algorithm) element), ToWords (ByteString (ChunkSize algorithm) element) (ByteString (WordSize algorithm) element), Concat (ByteString (WordSize algorithm) element) (ByteString (8 * WordSize algorithm) element))
- sha2Natural :: forall (algorithm :: Symbol) element. SHA2N algorithm element => Natural -> Natural -> ByteString (ResultSize algorithm) element
Documentation
class AlgorithmSetup (algorithm :: Symbol) a where Source #
SHA2 is a family of hashing functions with almost identical implementations but different constants and parameters. This class links these varying parts with the appropriate algorithm.
type WordSize algorithm :: Natural Source #
The length of words the algorithm operates internally, in bits.
type ChunkSize algorithm :: Natural Source #
Hashing algorithms from SHA2 family require splitting the input message into blocks. This type describes the size of these blocks, in bits.
type ResultSize algorithm :: Natural Source #
The length of the resulting hash, in bits.
initialHashes :: Vector (ByteString (WordSize algorithm) a) Source #
Initial hash values which will be mixed with the message bits.
roundConstants :: Vector (ByteString (WordSize algorithm) a) Source #
Constants used in the internal loop, one per each round.
truncateResult :: ByteString (8 * WordSize algorithm) a -> ByteString (ResultSize algorithm) a Source #
A function to postprocess the hash. For example, SHA224 requires dropping the last 32 bits of a SHA256 hash.
sigmaShifts :: (Natural, Natural, Natural, Natural, Natural, Natural) Source #
Round rotation values for Sigma in the internal loop.
sumShifts :: (Natural, Natural, Natural, Natural, Natural, Natural) Source #
Round rotation values for Sum in the internal loop.
Instances
type SHA2 algorithm element k = (AlgorithmSetup algorithm element, KnownNat k, Finite element, NFData element, FromConstant Natural element, KnownNat (ChunkSize algorithm), KnownNat (WordSize algorithm), KnownNat (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)), Iso (UInt (WordSize algorithm) element) (ByteString (WordSize algorithm) element), Iso (ByteString (WordSize algorithm) element) (UInt (WordSize algorithm) element), AdditiveSemigroup (UInt (WordSize algorithm) element), BoolType (ByteString (WordSize algorithm) element), ShiftBits (ByteString (WordSize algorithm) element), ShiftBits (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element), BoolType (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element), Extend (ByteString k element) (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element), ToWords (ByteString (ChunkSize algorithm) element) (ByteString (WordSize algorithm) element), Concat (ByteString (WordSize algorithm) element) (ByteString (8 * WordSize algorithm) element), ToWords (ByteString (PaddedLength k (ChunkSize algorithm) (2 * WordSize algorithm)) element) (ByteString (ChunkSize algorithm) element)) Source #
Constraints required for a type-safe SHA2
sha2 :: forall (algorithm :: Symbol) element k. SHA2 algorithm element k => ByteString k element -> ByteString (ResultSize algorithm) element Source #
A generalised version of SHA2. It is agnostic of the ByteString base field. Sample usage:
>>>
bs = fromConstant (42 :: Natural) :: ByteString 8 (Zp BLS12_381_Scalar)
>>>
hash = sha2 @"SHA256" bs
type SHA2N algorithm element = (AlgorithmSetup algorithm element, Finite element, NFData element, FromConstant Natural element, KnownNat (ChunkSize algorithm), KnownNat (WordSize algorithm), Iso (UInt (WordSize algorithm) element) (ByteString (WordSize algorithm) element), Iso (ByteString (WordSize algorithm) element) (UInt (WordSize algorithm) element), AdditiveSemigroup (UInt (WordSize algorithm) element), BoolType (ByteString (WordSize algorithm) element), ShiftBits (ByteString (WordSize algorithm) element), ToWords (ByteString (ChunkSize algorithm) element) (ByteString (WordSize algorithm) element), Concat (ByteString (WordSize algorithm) element) (ByteString (8 * WordSize algorithm) element)) Source #
Constraints required for a SHA2 of a Natural number.
sha2Natural :: forall (algorithm :: Symbol) element. SHA2N algorithm element => Natural -> Natural -> ByteString (ResultSize algorithm) element Source #
Same as sha2
but accepts a Natural number and length of message in bits instead of a ByteString.
Only used for testing.
Orphan instances
(KnownNat n, FromConstant Natural a) => ToWords Natural (ByteString n a) Source # | This allows us to calculate hash of a bytestring represented by a Natural number. This is only useful for testing when the length of the test string is unknown at compile time. This should not be exposed to users (and they probably won't find it useful anyway). |
toWords :: Natural -> [ByteString n a] Source # |