Module crypto/sha1
SHA-1 (FIPS 180-4) — streaming hasher + one-shot helpers
(plans/archive/STD_API_AUDIT.md §7 P0 item 7).
SHA-1 is cryptographically BROKEN for collision resistance (SHAttered, 2017) — do not use it for signatures or content addressing of untrusted input. It remains required by existing protocols (git object ids, HMAC-SHA1 in OAuth 1 / AWS SigV2-era APIs), which is why std ships it.
{ sha1_hex } :: import("std/crypto/sha1");
digest := sha1_hex(data); // 40-char lowercase hex
Stability
unstable — and the open question here is whether the module should
exist in this form at all, not how it computes. The vectors are right
and tested, but SHA-1 has no dedicated test file: its cases live in
tests/crypto/digest.test.yo beside the trait's. More importantly,
nothing in the API marks it as the legacy-compatibility algorithm the
module header says it is — a new caller reaching for sha1_hex gets no
signal — and whether std keeps shipping it plainly, gates it, or moves
it out has not been decided. The finish / finish_bytes double
surface and the single-use finish are the std/crypto/digest
questions.
Types
SHA-1 streaming state (the Sha256 skeleton).
Fields
| Name | Type | Description |
|---|---|---|
_h | Array(u32, 5) | |
_buf | Array(u8, 64) | |
_buflen | usize | |
_total | u64 |
Trait Implementations
impl(Sha1, ...)
new : (Sha1) fn() -> Sha1A hasher seeded with the SHA-1 initial state.
Returns: Sha1
update : (Sha1) fn(self : Sha1, data : ArrayList(u8)) -> Sha1finish : (Sha1) fn(self : Sha1) -> Array(u8, 20)Append the padding and the big-endian bit length, fold the last block in, and return the 20-byte digest.
Single use — the padding is written into the hasher's own buffer,
so a second finish digests the padded state rather than the
message.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Sha1 |
Returns: Array(u8, 20)
impl(Sha1, Digest(...))
new : (Sha1) fn() -> Sha1A hasher seeded with the SHA-1 initial state.
Returns: Sha1
update : (Sha1) fn(self : Sha1, data : ArrayList(u8)) -> Sha1digest_size : (Sha1) fn() -> usizeThe digest length in bytes (32/64/20/16).
Returns: usize
block_size : (Sha1) fn() -> usizeThe compression block size in bytes (64, or 128 for SHA-512) — what HMAC pads keys to.
Returns: usize
Functions
SHA-1 of data in one call — the 20-byte digest. Exactly
Sha1.new().update(data).finish().
Collision-broken (SHAttered, 2017): never use this to identify or sign
content an attacker can influence. sha256 is the replacement. This is
here for protocols that specify SHA-1 — git object ids, HMAC-SHA1 in
OAuth 1 and TOTP.
Parameters
| Name | Type | Notes |
|---|---|---|
data | ArrayList(u8) |
Returns: Array(u8, usize(20))