Hash Functions
A hash function maps a string of bytes of arbitrary length to a bit string of fixed length, called the digest of the input, in such a way that the digests of distinct inputs are spread uniformly over the range. Magma provides the SHA-1 function specified in FIPS PUB 180-1 (1995), whose digest has 160 bits. SHA-1 is no longer considered collision resistant, so it should not be relied on where an adversary may choose the input; its digests remain useful as fixed-length fingerprints of data, for instance to detect a change in a file or to index a table by the contents of a long string.
- SHA1(S): SeqEnum -> MonStgElt
- SHA1(s): MonStgElt -> MonStgElt
Given a sequence \(S\) of integers in the range \([0, 255]\), regarded as a sequence of bytes, or a string \(s\), regarded as the sequence of its bytes, return the SHA-1 digest of the input as a string of 40 lowercase hexadecimal digits.
- Example: Digest of a String and of Its Bytes (ex-d53a66)
The digest of a string agrees with that of the sequence of its byte values, and matches the test vector published for the message
"abc".> SHA1("abc"); a9993e364706816aba3e25717850c26c9cd0d89d > S := [StringToCode(c) : c in Eltseq("abc")]; S; [ 97, 98, 99 ] > SHA1(S); a9993e364706816aba3e25717850c26c9cd0d89d > SHA1("abd") eq SHA1("abc"); false