Documentation

CslibFrontier.Crypto.Primitives.Hash.SHA2

SHA-256 and SHA-512 #

This module implements the byte-aligned SHA-256 and SHA-512 hash functions from NIST FIPS 180-4. Words are BitVec 32 or BitVec 64, so addition and logical operations have exactly the modular semantics required by Sections 4 and 6. Input bytes are parsed big-endian, padding uses the 64-bit or 128-bit big-endian message-length field from Section 5.1, and the output types record the 32-byte or 64-byte digest length.

The public input predicates record the source domains ℓ < 2^64 for SHA-256 and ℓ < 2^128 for SHA-512, specialized to byte-aligned messages. The hash functions are total executable extensions; callers that specify standard-domain inputs can use those predicates separately. sha256Bytes and sha512Bytes are the same digests as byte lists. When executed they compute the hash state once, whereas enumerating the bytes of the function-valued sha256 or sha512 result computes it once for each byte. This module does not prove functional correctness against an independent FIPS model and is not a constant-time or machine-costed implementation, a security proof, or a claim of NIST validation.

Main definitions #

Main results #

References #

@[reducible, inline]

A SHA-256 word.

@[reducible, inline]

A SHA-512 word.

@[reducible, inline]

The eight-word SHA-256 chaining state.

@[reducible, inline]

The eight-word SHA-512 chaining state.

The FIPS 180-4 SHA-256 domain for a byte-aligned message: its bit length is below 2^64.

Instances For

    The FIPS 180-4 SHA-512 domain for a byte-aligned message: its bit length is below 2^128.

    Instances For

      The 64 SHA-256 round constants from FIPS 180-4, Section 4.2.2.

      The 80 SHA-512 round constants from FIPS 180-4, Section 4.2.3.

      The SHA-256 initial hash value from FIPS 180-4, Section 5.3.3.

      The SHA-512 initial hash value from FIPS 180-4, Section 5.3.5.

      One SHA-256 compression step on an exact 64-byte block (FIPS 180-4, Section 6.2.2).

      One SHA-512 compression step on an exact 128-byte block (FIPS 180-4, Section 6.4.2).

      Byte-aligned SHA-256 padding from FIPS 180-4, Section 5.1.1.

      Byte-aligned SHA-512 padding from FIPS 180-4, Section 5.1.2.

      @[simp]

      SHA-256 padding produces a whole number of 64-byte blocks.

      @[simp]

      SHA-512 padding produces a whole number of 128-byte blocks.

      SHA-256 digest computation on a byte-aligned message. ValidSHA256Input records the standard input domain separately.

      SHA-512 digest computation on a byte-aligned message. ValidSHA512Input records the standard input domain separately.

      The 32 bytes of the SHA-256 digest as a list. Execution computes the hash state once.

      The 64 bytes of the SHA-512 digest as a list. Execution computes the hash state once.