Functional Weave
Code in Rust

crypto.sha1@1.0.0

README.md

1,541 bytes · view raw

# crypto.sha1

`sha1(utf8Encode("abc"))` is the 20 bytes
`a9993e364706816aba3e25717850c26c9cd0d89d` (print them with `hexEncode`). This
is SHA-1 exactly as FIPS 180-4 (and RFC 3174) defines it.

**SHA-1 is broken for collisions** (SHAttered, 2017; chosen-prefix collisions,
2020). Do not use it for new signatures, certificates, content addressing or
anything where two different inputs with the same digest would hurt. Use
`crypto.sha256`.

It is in the registry only because HOTP (RFC 4226) and TOTP (RFC 6238) are
defined over HMAC-SHA1, and nearly every authenticator app (Google
Authenticator, Microsoft Authenticator, 1Password, Authy) still defaults to
it. HMAC's security does not rest on collision resistance, so HMAC-SHA1 is
still sound for that job (RFC 6151 section 4 says the same of HMAC-MD5). Use
it through `crypto.hmac-sha1` or `auth.totp`.

Bytes in and out are lists of integers 0 to 255, as everywhere in the
registry. TypeScript and Rust are plain code with no `node:crypto` or
`crypto.subtle`; Python uses the standard library's `hashlib`.

The vectors are the published examples ("abc" and the 448-bit message from
FIPS 180-4's example values and RFC 3174 section 7.3), the empty string, and
messages of 55, 56, 64 and 119 bytes either side of the points where padding
needs another block, with Python's `hashlib` as the reference.

Source: FIPS 180-4, Secure Hash Standard, section 6.1
(https://csrc.nist.gov/pubs/fips/180-4/upd1/final); RFC 3174, US Secure Hash
Algorithm 1 (https://www.rfc-editor.org/rfc/rfc3174).