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 #
Cslib.Crypto.SHA2.ValidSHA256Input,ValidSHA512Input: FIPS 180-4 message-length domains.Cslib.Crypto.SHA2.sha256Pad,sha512Pad: byte-aligned Section 5.1 padding.Cslib.Crypto.SHA2.sha256Compress,sha512Compress: one-block compression functions.Cslib.Crypto.SHA2.sha256,sha512: typed 32-byte and 64-byte digests.Cslib.Crypto.SHA2.sha256Bytes,sha512Bytes: the same digests as byte lists.
Main results #
Cslib.Crypto.SHA2.sha256Pad_length_mod,sha512Pad_length_mod: padding produces a whole number of compression blocks.
References #
- National Institute of Standards and Technology, Secure Hash Standard, FIPS PUB 180-4, August 2015, Sections 4.1.2--4.2.3, 5.1--5.3, 6.2 and 6.4.
The eight-word SHA-256 chaining state.
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).
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.
sha256Bytes lists the bytes of sha256.
sha512Bytes lists the bytes of sha512.