code wiki / (root) / nx_sha1.nx

nx_sha1.nx

buildroot/runtime/nx_sha1.nx

7683 B238 linesdepth 2pulls 2 transitivereach 102 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_sha1.nx hmac_sha1.nx nx_hash_bench.nx nx_hmac_sha1.nx nx_lsd.nx nx_metainfo.nx nx_metainfo_test.nx nx_mse_keys.nx nx_mse_seed_gate.nx nx_peer_download.nx nx_peer_meta_live.nx

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

main sys_mmap sha1 sys_mmap ↻ sha1_process_block if_ge

structs

none

consts

39const SHA1_H0: i64 = 0x67452301
40const SHA1_H1: i64 = 0xEFCDAB89
41const SHA1_H2: i64 = 0x98BADCFE
42const SHA1_H3: i64 = 0x10325476
43const SHA1_H4: i64 = 0xC3D2E1F0
45const SHA1_K0: i64 = 0x5A827999
46const SHA1_K1: i64 = 0x6ED9EBA1
47const SHA1_K2: i64 = 0x8F1BBCDC
48const SHA1_K3: i64 = 0xCA62C1D6
50const SHA1_MASK32: i64 = 0xFFFFFFFF

functions

61func sha1_rotl(x: i64, k: i64) -> i64
70func sha1_process_block(buf: *u8, off: i64, state: *i64, w: *i64) -> i64
called by 1: sha1
137func if_ge(a: i64, b: i64, v1: i64, v2: i64) -> i64;
called by 1: sha1
140func sha1(data: *u8, n: i64, out: *u8) -> i64
216func if_ge(a: i64, b: i64, v1: i64, v2: i64) -> i64
222func main() -> i64
calls 2: sys_mmapsha1