Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omtls/blob/main/tests/drv/bn.om # omtls omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0). Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtls / tests / drv / bn.om` 214 lines ยท 7572 bytes Raw Blame History 1 note omtls test driver bn: ot_bn_modexp (src/bn.om) against Wolfram, plus identities and refusals. 2 note Usage: bn (no arguments); one line per failed case, then PASS bn cases=N or FAIL bn pass=P fail=F. 3 note Case (l, el, s): n, x and e are generated bytes, byte i of seed t = (31 i^2 + 7 i t + 13 t + 5) mod 256; 4 note n = gen(l, s) with its top bit and bit 0 set, x = gen(l, s + 1) with its top bit cleared (so x < n), 5 note e = gen(el, s + 2); the expected value is SHA-256 of x^e mod n as l big-endian bytes. 6 note wolfram (WolframLanguageEvaluator, 2026-11-11): gen[l_, s_] := Table[Mod[i^2*31 + i*s*7 + s*13 + 5, 256], 7 note {i, 0, l - 1}], the same bit fixes, y = PowerMod[x, e, n], 8 note Hash[ByteArray[IntegerDigits[y, 256, l]], "SHA256", "HexString"]; x < n and OddQ[n] True for every case. 9 text ot_bnv_area "bn" 10 text ot_bnv_tfailed "FAILED bn-" 11 text ot_bnv_tnl "\n" 12 text ot_bnv_cases "1 1 1 `c4694f2e93d5c4e7d51f9c5deb75e6cc8be5e1114178c6a45b6fc2c566a0aa8c` 2 1 2 `1d9481e46f7811bca60f775dc441941edd0dd903609def214d525d7a70b6b965` 4 3 3 `7308abf80de2bf3eb90cca38652dfdcf5c2e0e520fcb5bef8ee92407b61c7947` 5 4 4 `953875d1c2e2b1cdb840b8674f36584b18bffb87d7cc4e59d50c32d62b59a133` 8 8 5 `beebfb481dc4922676f0b5df407acecedfbf93917b5d3872a6d81bdeb6015733` 9 3 6 `b4131a50f671b5ba941bcbbe03e0c99be3d12d4f2b27b06ff4ee1868c1e2f70a` 12 12 7 `930a69a144748e6c3288eba3169ed5bf30e4c8fd8aa05823035216419846a99b` 32 32 8 `0ef42e3ce1210d6443420fbdbedb9d3fe35994ec6d543a9e249beaa27d609d24` 33 3 9 `c7d33fc552bcb5e105241bd22158f4e73312d608282e1afd109bb01cb16a5a59` 64 64 10 `7ca06c5f7dace537f398817206ebb8c8d78a5eef036d72da690265fcbf873151` 128 3 11 `c01faf39fd36e28ab66464469ecb80f5ec652a78577bf759122dca535168dac7` 129 129 12 `9ca60986bf07efe592a1ee1f6329aaf34c7f72ea68bcfc549a63fd06740efb1c` 256 256 13 `836d7a76e83867b731f3b3c4d7639b00ef7aeb7edbbfa5dfc47629df2573442a` 256 3 14 `46ab0d194ebe276529381832165d3a47efc2d46ebf0005edab4186a774dc5257` 384 3 15 `bacd6ea113242a600bceb4c2c9f8425dcc3903d2e033b123dc695342849fb59c` 512 3 16 `764b1b31bad86c5ea2707a1c7c07e39a0f2b2d9f19d8b318973415d0d0a9a76f` 512 512 17 `e95106dcdcfeec879a53e7541a2a8206365b793efbd288cd47010531998cda75` 1024 3 18 `844564ae276737dc58bd5d03e04a24440c59ed280b05253c4fd843781306c8cd` 2048 3 19 `fe913bbd611a8967d5c9b0fd99af5461e3af66dd5f5aabc5cc96d92755cfc88f` 2048 1 20 `3f00b1619ef63bb094c2a116897419748f011078f44a18375cc339a73227dfb1`" 13 fn ot_bnv_gen o edit uchar * s ulong to void 14 for i ulong len o bound `9223372036854775807` 15 a = mul mul i i 31 16 a = add a mul mul i s 7 17 a = add a add mul s 13 5 18 put o i uchar and a 255 19 end 20 end 21 fn ot_bnv_ck r edit ulong 4 ok bool id ulong to void 22 if ok 23 put r 0 add get r 0 1 24 else 25 put r 1 add get r 1 1 26 ot_sy_put ot_bnv_tfailed 27 ot_sy_num id 28 ot_sy_put ot_bnv_tnl 29 end 30 end 31 note n, x, e of case (l, el, s) into nb, xb, eb. 32 fn ot_bnv_case nb edit uchar 4096 xb edit uchar 4096 eb edit uchar 4096 l ulong el ulong s ulong to void 33 for i ulong 4096 34 put nb i 0 35 put xb i 0 36 put eb i 0 37 end 38 ot_bnv_gen part nb 0 l s 39 ot_bnv_gen part xb 0 l add s 1 40 ot_bnv_gen part eb 0 el add s 2 41 put nb 0 or get nb 0 128 42 put nb sub l 1 or get nb sub l 1 1 43 put xb 0 and get xb 0 127 44 end 45 fn ot_bnv_run nb view uchar 4096 eb view uchar 4096 xb edit uchar 4096 c view ulong 4 to bool 46 ret ot_bn_modexp view part nb 0 get c 0 view part eb 0 get c 1 part xb 0 get c 0 47 end 48 note Case c (l, el, s) against the expected hash h. 49 fn ot_bnv_one r edit ulong 4 c view ulong 4 h view uchar 64 to void 50 nb = new uchar 4096 0 51 xb = new uchar 4096 0 52 eb = new uchar 4096 0 53 o = new uchar 64 0 54 ot_bnv_case nb xb eb get c 0 get c 1 get c 2 55 ok = ot_bnv_run nb eb xb c 56 hl = ot_hash 0 view part xb 0 get c 0 o 57 ot_bnv_ck r and ok ot_sy_eq o h 32 get c 2 58 end 59 fn ot_bnv_zero a view uchar * to bool 60 v = uchar 0 61 for i ulong len a bound `9223372036854775807` 62 v = or v get a i 63 end 64 ret eq v 0 65 end 66 note y equals the small number v (as l bytes). 67 fn ot_bnv_is a view uchar * v uchar to bool 68 if ne get a sub len a 1 v 69 ret false 70 end 71 ret ot_bnv_zero view part a 0 sub len a 1 72 end 73 note Identities on case (256, 3, 14): x = n - 1 with e = 2 and e = 65537, x = 0, x = 1, empty and zero e, 74 note and leading zero bytes on n and x. 75 fn ot_bnv_ids r edit ulong 4 to void 76 nb = new uchar 4096 0 77 xb = new uchar 4096 0 78 eb = new uchar 4096 0 79 h = new uchar 64 0 80 o = new uchar 64 0 81 ot_bnv_case nb xb eb 256 3 14 82 for i ulong 256 83 put xb i get nb i 84 end 85 put xb 255 sub get xb 255 1 86 put eb 0 2 87 ok = ot_bnv_x nb eb xb 256 1 256 88 ot_bnv_ck r and ok ot_bnv_is view part xb 0 256 1 101 89 for i ulong 256 90 put xb i get nb i 91 end 92 put xb 255 sub get xb 255 1 93 put eb 0 1 94 put eb 1 0 95 put eb 2 1 96 ok = ot_bnv_x nb eb xb 256 3 256 97 put xb 255 add get xb 255 1 98 ot_bnv_ck r and ok ot_sy_eq xb nb 256 102 99 for i ulong 256 100 put xb i 0 101 end 102 ok = ot_bnv_x nb eb xb 256 3 256 103 ot_bnv_ck r and ok ot_bnv_zero view part xb 0 256 103 104 put xb 255 1 105 ok = ot_bnv_x nb eb xb 256 3 256 106 ot_bnv_ck r and ok ot_bnv_is view part xb 0 256 1 104 107 put xb 7 9 108 ok = ot_bnv_x nb eb xb 256 0 256 109 ot_bnv_ck r and ok ot_bnv_is view part xb 0 256 1 105 110 put xb 7 9 111 put eb 0 0 112 put eb 1 0 113 ok = ot_bnv_x nb eb xb 256 2 256 114 ot_bnv_ck r and ok ot_bnv_is view part xb 0 256 1 106 115 ot_bnv_case nb xb eb 256 3 14 116 ot_bnv_lead nb xb 117 ok = ot_bnv_x nb eb xb 258 3 258 118 x = ot_hash 0 view part xb 2 256 o 119 x = ot_bnv_hex h 14 120 ot_bnv_ck r and and ok ot_sy_eq o h 32 ot_bnv_zero view part xb 0 2 107 121 end 122 note Shift n and x right by two bytes (two leading zeros). 123 fn ot_bnv_lead nb edit uchar 4096 xb edit uchar 4096 to void 124 for j ulong 256 125 i = sub 255 j 126 put nb add i 2 get nb i 127 put xb add i 2 get xb i 128 end 129 put nb 0 0 130 put nb 1 0 131 put xb 0 0 132 put xb 1 0 133 end 134 note The expected hash of case seed s from ot_bnv_cases into h; gives 0. 135 fn ot_bnv_hex h edit uchar 64 s ulong to ulong 136 st = new ulong 10 0 137 put st 4 len ot_bnv_cases 138 for c ulong 20 139 l = ot_sy_ndec ot_bnv_cases st 140 el = ot_sy_ndec ot_bnv_cases st 141 t = ot_sy_ndec ot_bnv_cases st 142 v = ot_sy_nhex ot_bnv_cases st h 143 if eq t s 144 ret 0 145 end 146 end 147 ret 1 148 end 149 fn ot_bnv_x nb view uchar 4096 eb view uchar 4096 xb edit uchar 4096 nl ulong el ulong xl ulong to bool 150 ret ot_bn_modexp view part nb 0 nl view part eb 0 el part xb 0 xl 151 end 152 note Refusal: modexp gives false and leaves xo all zero. 153 fn ot_bnv_no nb view uchar 4096 eb view uchar 4096 xb edit uchar 4096 nl ulong el ulong xl ulong to bool 154 ok = ot_bnv_x nb eb xb nl el xl 155 ret and not ok ot_bnv_zero view part xb 0 xl 156 end 157 fn ot_bnv_refuse r edit ulong 4 to void 158 nb = new uchar 4096 0 159 xb = new uchar 4096 0 160 eb = new uchar 4096 0 161 ot_bnv_case nb xb eb 256 3 14 162 put nb 255 and get nb 255 254 163 ot_bnv_ck r ot_bnv_no nb eb xb 256 3 256 110 164 ot_bnv_case nb xb eb 256 3 14 165 put nb 0 1 166 put xb 0 1 167 ot_bnv_ck r ot_bnv_no nb eb xb 1 3 1 111 168 put nb 0 0 169 put nb 1 0 170 put xb 0 0 171 ot_bnv_ck r ot_bnv_no nb eb xb 2 3 2 112 172 ot_bnv_ck r ot_bnv_no nb eb xb 0 3 0 113 173 ot_bnv_case nb xb eb 256 3 14 174 for i ulong 256 175 put xb i get nb i 176 end 177 ot_bnv_ck r ot_bnv_no nb eb xb 256 3 256 114 178 for i ulong 256 179 put xb i 255 180 end 181 ot_bnv_ck r ot_bnv_no nb eb xb 256 3 256 115 182 put xb 0 1 183 ot_bnv_ck r ot_bnv_no nb eb xb 256 3 255 116 184 for i ulong 2049 185 put nb i 255 186 put xb i 0 187 end 188 put xb 5 1 189 ot_bnv_ck r ot_bnv_no nb eb xb 2049 3 2049 117 190 ot_bnv_case nb xb eb 256 3 14 191 put xb 3 1 192 ot_bnv_ck r ot_bnv_no nb eb xb 256 2049 256 118 193 end 194 fn main to int 195 r = new ulong 4 0 196 st = new ulong 10 0 197 h = new uchar 64 0 198 c = new ulong 4 0 199 put st 4 len ot_bnv_cases 200 for j ulong 20 201 put c 0 ot_sy_ndec ot_bnv_cases st 202 put c 1 ot_sy_ndec ot_bnv_cases st 203 put c 2 ot_sy_ndec ot_bnv_cases st 204 v = ot_sy_nhex ot_bnv_cases st h 205 if eq v 32 206 ot_bnv_one r c h 207 else 208 ot_bnv_ck r false get c 2 209 end 210 end 211 ot_bnv_ids r 212 ot_bnv_refuse r 213 ret ot_sy_done ot_bnv_area get r 0 get r 1 214 end