code wiki / (root) / nx_mse_keys.nx

nx_mse_keys.nx

buildroot/runtime/nx_mse_keys.nx

5666 B83 linesdepth 5pulls 8 transitivereach 17 importersview sourcekind tooltopic mse
docsdependenciesstructsconstsfunctions

about

nx_mse_keys.nx -- MSE/PE key derivation: turn the DH shared secret S + info_hash SKEY into the two RC4 channel keys, per the MSE spec. keyA = SHA1("keyA" | S | SKEY) drives the INITIATOR->receiver stream; keyB = SHA1("keyB" | S | SKEY) drives receiver->initiator. Each RC4 stream discards its first 1024 bytes. Also derives the handshake sync hashes: HASH("req1",S), HASH("req2",SKEY), HASH("req3",S). Composes nx_mse_dh (DH) + nx_rc4 (cipher) + nx_sha1 (HASH). This is the crypto glue between DH and the wire handshake. nx_mse_keys -- no-arg = GATE: real DH secret -> keyA/keyB -> bidirectional RC4 channels round-trip; VC ok. license_tier: ORIGINAL module: nishi-core.torrent.mse_keys depends: mse_dh, rc4, sha1

dependencies 3 imports · 2 importers

nx_mse_dh.nx nx_rc4.nx nx_sha1.nx nx_mse_keys.nx nx_mse_handshake.nx nx_mse_wire.nx

imports: nx_mse_dh.nxnx_rc4.nxnx_sha1.nx

imported by: nx_mse_handshake.nxnx_mse_wire.nx

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

main md_p md_load_p md_hex2bytes md_hv bi_from_bytes_be bi_zero bi_zero ↻ mse_dh_public bi_zero ↻ bi_modexp bi_zero ↻ bi_copy bi_mod bi_zero ↻ bi_shl1 bi_cmp bi_sub bi_mul bi_zero ↻ mse_dh_shared bi_modexp ↻ md_eq bi_to_bytes_be mk_derive sha1 sys_mmap sha1_process_block if_ge mk_eq rc4_ksa rc4_skip rc4_prga_byte rc4_crypt rc4_prga_byte ↻ mk_hash_pref sha1 ↻ if_s

structs

none

consts

12const K_MAGIC_1024: i64 = 1024

functions

15func mk_derive(prefix: *u8, s_bytes: *u8, skey: *u8, out20: *u8) -> i64
24func mk_hash_pref(prefix: *u8, data: *u8, dlen: i64, out20: *u8) -> i64
32func mk_eq(a: *u8, b: *u8, n: i64) -> i64 { var i: i64=0; while i<n { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 1: main
34func main() -> i64