sha1.nx
buildroot/runtime/sha1.nx
about
sha1.nx -- SHA-1 (FIPS 180-4 §6.1), 160-bit hash.
NOT cryptographically safe for new protocols -- SHAttered (2017)
produced chosen-prefix collisions; any signature scheme using
SHA-1 is considered broken. But SHA-1 remains on the wire:
- TLS 1.0/1.1 MAC (legacy handshake interop)
- WebSocket handshake (RFC 6455 uses it in Sec-WebSocket-Accept;
collision resistance is not relied on here -- just the
mixing property, so it's safe in this specific use)
- git object IDs (migrating to SHA-256 slowly)
- HMAC-SHA1 (still fine; HMAC is collision-agnostic)
- OAuth 1.0, PBKDF2, old certificates
So we ship it for protocol interop, never for new signatures.
Algorithm (FIPS 180-4 §6.1):
- Pad: append 1 bit, zero-pad, append 64-bit big-endian
length so total length is a multiple of 512 bits.
- Process in 512-bit blocks using 80 rounds.
- State is 5 words (H0..H4) initialised to the FIPS constants.
Invariants:
S1 Matches FIPS 180-4 test vectors.
S2 Empty input hashes to da39a3ee5e6b4b0d3255bfef95601890afd80709.
S3 State mmap'd per call -- no globals.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 29 | const SHA1_H0: i64 = 0x67452301 |
| 30 | const SHA1_H1: i64 = 0xEFCDAB89 |
| 31 | const SHA1_H2: i64 = 0x98BADCFE |
| 32 | const SHA1_H3: i64 = 0x10325476 |
| 33 | const SHA1_H4: i64 = 0xC3D2E1F0 |
| 35 | const SHA1_K0: i64 = 0x5A827999 |
| 36 | const SHA1_K1: i64 = 0x6ED9EBA1 |
| 37 | const SHA1_K2: i64 = 0x8F1BBCDC |
| 38 | const SHA1_K3: i64 = 0xCA62C1D6 |
| 40 | const SHA1_MASK32: i64 = 0xFFFFFFFF |
functions
| 43 | func sha1_rotl(x: i64, k: i64) -> i64 { |
| 51 | func sha1_process_block(buf: *u8, off: i64, state: *i64) -> i64 { |
| 121 | func if_ge(a: i64, b: i64, v1: i64, v2: i64) -> i64; |
| 124 | func sha1(data: *u8, n: i64, out: *u8) -> i64 { |
| 195 | func if_ge(a: i64, b: i64, v1: i64, v2: i64) -> i64 { |
| 201 | func main() -> i64 { |