nx_sha1.nx
buildroot/runtime/nx_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.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/nist/fips_180_4
dependencies 1 imports · 24 importers
diagram shows first 10 each side; +0 more imports, +14 more importers in the complete lists below.
imports: nx_syscalls.nx
imported by: hmac_sha1.nxnx_hash_bench.nxnx_hmac_sha1.nxnx_lsd.nxnx_metainfo.nxnx_metainfo_test.nxnx_mse_keys.nxnx_mse_seed_gate.nxnx_peer_download.nxnx_peer_meta_live.nxnx_peer_metadata.nxnx_peer_piece.nxnx_piece_manager.nxnx_piece_manager_test.nxnx_sha1_diff_probe.nxnx_tor_relay.nxnx_torrent_leech_probe.nxnx_torrent_peer_dl.nxnx_torrent_reseed.nxnx_torrent_seed_gate.nxnx_uuid5.nxnx_websocket_handshake.nxuuid5.nxwebsocket_handshake.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 39 | const SHA1_H0: i64 = 0x67452301 |
| 40 | const SHA1_H1: i64 = 0xEFCDAB89 |
| 41 | const SHA1_H2: i64 = 0x98BADCFE |
| 42 | const SHA1_H3: i64 = 0x10325476 |
| 43 | const SHA1_H4: i64 = 0xC3D2E1F0 |
| 45 | const SHA1_K0: i64 = 0x5A827999 |
| 46 | const SHA1_K1: i64 = 0x6ED9EBA1 |
| 47 | const SHA1_K2: i64 = 0x8F1BBCDC |
| 48 | const SHA1_K3: i64 = 0xCA62C1D6 |
| 50 | const SHA1_MASK32: i64 = 0xFFFFFFFF |
functions
| 61 | func sha1_rotl(x: i64, k: i64) -> i64 |
| 70 | func sha1_process_block(buf: *u8, off: i64, state: *i64, w: *i64) -> i64 called by 1: sha1 |
| 137 | func if_ge(a: i64, b: i64, v1: i64, v2: i64) -> i64; called by 1: sha1 |
| 140 | func sha1(data: *u8, n: i64, out: *u8) -> i64 called by 26: hmac_sha1nx_hb_sha1_mbpsnx_hb_sha1_okhmac_sha1nx_metainfo_parsemain+20 calls 3: sys_mmapsha1_process_blockif_ge |
| 216 | func if_ge(a: i64, b: i64, v1: i64, v2: i64) -> i64 |
| 222 | func main() -> i64 |