nx_bt_v2_merkle.nx
buildroot/runtime/nx_bt_v2_merkle.nx
about
nx_bt_v2_merkle.nx -- LIB: BitTorrent v2 (BEP 52) style SHA-256 MERKLE piece tree + INCLUSION PROOFS. Upgrades our
torrents from v1 (SHA-1 flat piece list) to v2: each leaf = SHA-256 of a block, internal node = SHA-256(left||right),
the root is the file's content hash (the basis for urn:btmh magnets). The killer feature is the inclusion PROOF:
a peer can verify ONE block belongs to the root using only log2(n) sibling hashes -- verifiable random access /
streaming, no need for the whole file. Composes nx_sha256 (our own). Leaf count assumed a power of two (BEP 52
zero-pads to that; padding is the trivial extension). No TLS. license_tier: ORIGINAL
dependencies 2 imports · 1 importers
imports: nx_sha256.nxnx_syscalls.nx
imported by: nx_bt_v2_merkle_gate.nx
structs
| none |
consts
| none |
functions
| 10 | func mk_memeq(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 } |
| 12 | func mk_leaf(block: *u8, len: i64, out32: *u8) -> i64 |
| 17 | func mk_node(l: *u8, r: *u8, out32: *u8) -> i64 |
| 23 | func mk_root(leaves: *u8, n: i64, out32: *u8) -> i64 |
| 38 | func mk_proof(leaves: *u8, n: i64, idx: i64, proof: *u8) -> i64 |
| 51 | func mk_verify(leaf32: *u8, idx: i64, proof: *u8, np: i64, root32: *u8) -> i64 |