code wiki / (root) / nx_media_exclusion.nx

nx_media_exclusion.nx source

↩ module page · 66 lines · 2749 B

1// nx_media_exclusion.nx -- LIB: the media-recovery EXCLUSION gate (safety-by-construction). BEFORE any recovered or 2// indexed image is accepted, its perceptual fingerprint (dHash) is checked against a do-not-recover BLOCKLIST 3// (takedown / NCMEC-style hash-match feed). A match -- EXACT or within a per-entry Hamming threshold, so re-encoded / 4// resized RE-UPLOADS are caught too -- means REFUSE. Content removed for being illegal or non-consensual stays 5// removed, including its copies. Reuses nx_phash / nx_simhash (zero new hash math). The blocklist is DATA (a TSV), 6// never hardcoded, and starts empty. license_tier: ORIGINAL 7import "nx_phash.nx" 8 9// returns the index of the first blocklist entry within its Hamming threshold of qdhash, or 0-1 if ALLOWED. 10func excl_blocked(qdhash: i64, bl_dhash: *i64, bl_thresh: *i64, n: i64) -> i64 { 11 var i: i64 = 0 12 while i < n { 13 let h: i64 = nx_simhash_hamming(qdhash, bl_dhash[i]) 14 if h <= bl_thresh[i] { return i } 15 i = i + 1 16 } 17 return 0 - 1 18} 19 20// parse 16 lowercase-hex chars at p -> i64 (a stored dHash fingerprint). 21func excl_hex16(p: *u8) -> i64 { 22 var v: i64 = 0 23 var i: i64 = 0 24 while i < 16 { 25 let c: i64 = p[i] as i64 26 var nib: i64 = 0 27 if c>=48 { if c<=57 { nib=c-48 } } 28 if c>=97 { if c<=102 { nib=c-87 } } 29 v = (v<<4) | nib 30 i = i + 1 31 } 32 return v 33} 34 35// load a blocklist TSV (dhash_hex16<TAB>thresh<TAB>reason\n) -> bl_dhash[]/bl_thresh[]; returns count (0 if absent). 36func excl_load(path: *u8, bl_dhash: *i64, bl_thresh: *i64, cap: i64) -> i64 { 37 let box: *i64 = sys_mmap(16) as *i64 38 let buf: *u8 = sys_read_file(path, box) 39 if buf == (0 as *u8) { return 0 } 40 let n: i64 = box[0] 41 var c: i64 = 0 42 var ls: i64 = 0 43 var i: i64 = 0 44 while i <= n { 45 var eol: i64 = 0 46 if i==n { eol=1 } else { if (buf[i] as i64)==0x0a { eol=1 } } 47 if eol==1 { 48 if i >= ls + 16 { 49 if c < cap { 50 if (buf[ls] as i64) != 0x23 { 51 bl_dhash[c] = excl_hex16(((buf as i64)+ls) as *u8) 52 var t1: i64 = 0-1; var k: i64 = ls 53 while k < i { if (buf[k] as i64)==0x09 { if t1<0 { t1=k } } k=k+1 } 54 var th: i64 = 8 55 if t1 > 0 { var v: i64=0; var j: i64=t1+1; var go: i64=1; while go==1 { if j<i { let d: i64=buf[j] as i64; if d>=48 { if d<=57 { v=v*10+(d-48); j=j+1 } else { go=0 } } else { go=0 } } else { go=0 } } th=v } 56 bl_thresh[c] = th 57 c = c + 1 58 } 59 } 60 } 61 ls = i + 1 62 } 63 i = i + 1 64 } 65 return c 66}