code wiki / (root) / nx_rc4.nx

nx_rc4.nx

buildroot/runtime/nx_rc4.nx

4911 B74 linesdepth 2pulls 2 transitivereach 18 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_rc4.nx -- RC4 stream cipher (the MSE/PE data cipher). KSA + PRGA, byte-at-a-time keystream. MSE/PE encrypts the peer stream with RC4 keyed from the DH shared secret + info_hash, DISCARDING the first 1024 keystream bytes (drops RC4's biased prefix). This is the cipher half of the anti-throttle handshake. RC4 is cryptographically weak in general -- here it is used ONLY as the wire-obfuscation MSE mandates for interop with real BitTorrent peers (last-mile), NOT as a security primitive for our own data at rest. nx_rc4 -- no-arg = GATE (RFC/Wikipedia known-answer vectors) license_tier: ORIGINAL module: nishi-core.crypto.rc4 depends: nishi-core.syscalls

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_rc4.nx nx_mse_keys.nx

imports: nx_syscalls.nx

imported by: nx_mse_keys.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap r4_p sys_write r4_case sys_mmap ↻ rc4_ksa rc4_crypt rc4_prga_byte r4_hexval r4_p ↻ rc4_ksa ↻ rc4_skip rc4_prga_byte ↻ rc4_crypt ↻ sys_write ↻ sys_exit

structs

none

consts

11const K_MAGIC_1024: i64 = 1024

functions

13func r4_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: r4_casemain calls 1: sys_write
16func rc4_ksa(S: *u8, key: *u8, keylen: i64) -> i64
27func rc4_prga_byte(S: *u8, ij: *i64) -> i64
called by 2: rc4_cryptrc4_skip
36func rc4_crypt(S: *u8, ij: *i64, data: *u8, n: i64) -> i64
40func rc4_skip(S: *u8, ij: *i64, n: i64) -> i64 { var k: i64 = 0; while k < n { rc4_prga_byte(S, ij); k = k + 1 } return 0 }
42func r4_hexval(c: i64) -> i64 { if c>=48 { if c<=57 { return c-48 } } if c>=97 { if c<=102 { return c-87 } } if c>=65 { if c<=70 { return c-55 } } return 0 }
called by 1: r4_case
44func r4_case(label: *u8, key: *u8, keylen: i64, pt: *u8, ptlen: i64, cthex: *u8, pass: *i64, tot: *i64) -> i64
55func main() -> i64