omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / om / tls / test / ec / wolfram.txt
| 1 | Curve parameter check for om/tls/ec.om (2026-10-26, Wolfram MCP tool WolframLanguageEvaluator). |
| 2 | p, n, b, Gx, Gy are taken verbatim from FIPS 186-4 Appendix D.1.2.3 (P-256) and D.1.2.4 (P-384), |
| 3 | equal to SEC 2 v2 sections 2.4.2 (secp256r1) and 2.5.1 (secp384r1), and to |
| 4 | `openssl ecparam -name prime256v1|secp384r1 -param_enc explicit -text`. Montgomery constants |
| 5 | (n0' = -m^-1 mod 2^32, R mod m, R^2 mod m) are not stored: ec_ctx computes them at run time. |
| 6 | |
| 7 | Query (exact code sent): |
| 8 | chk[p_,b_,gx_,gy_,n_]:=Module[{add,mul},add[P_,Q_]:=Which[P===0,Q,Q===0,P,Mod[P[[1]]-Q[[1]],p]==0&&Mod[P[[2]]+Q[[2]],p]==0,0,True,Module[{l=If[P===Q,Mod[(3P[[1]]^2-3)PowerMod[2P[[2]],-1,p],p],Mod[(Q[[2]]-P[[2]])PowerMod[Q[[1]]-P[[1]],-1,p],p]],x3},x3=Mod[l^2-P[[1]]-Q[[1]],p];{x3,Mod[l(P[[1]]-x3)-P[[2]],p]}]];mul[k_,P_]:=Module[{R=0,A=P,kk=k},While[kk>0,If[OddQ[kk],R=add[R,A]];A=add[A,A];kk=Quotient[kk,2]];R];{PrimeQ[p],PrimeQ[n],Mod[gy^2-(gx^3-3gx+b),p]==0,mul[n,{gx,gy}]===0,BitLength[p],BitLength[n],n<p<2n}];{chk[16^^ffffffff00000001000000000000000000000000ffffffffffffffffffffffff,16^^5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b,16^^6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296,16^^4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5,16^^ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551],chk[16^^fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff,16^^b3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef,16^^aa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7,16^^3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f,16^^ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973]} |
| 9 | |
| 10 | Result: |
| 11 | Out[1]= {{True, True, True, True, 256, 256, True}, {True, True, True, True, 384, 384, True}} |
| 12 | |
| 13 | Meaning, per curve: p prime, n prime, G on y^2 = x^3 - 3x + b mod p, n*G = point at infinity, |
| 14 | bit length of p and n (256 / 384, so bits2int truncation is byte aligned), n < p < 2n (so |
| 15 | x(R) mod n is one conditional subtraction, and e < 2^bitlen(n) < 2n likewise). |
| 16 | |
| 17 | P-256 specialised field (ec.om section p2_*), 2026-10-26, Wolfram MCP tool WolframLanguageEvaluator. |
| 18 | |
| 19 | Query 1 (exact code sent): the Solinas words r[0..7] exactly as p2_red forms them from the 16 |
| 20 | 32-bit product words t[0..15]; the difference sum t_k 2^(32k) - sum r_k 2^(32k) must have every |
| 21 | coefficient divisible by p; the fold of a carry out of word 8; and 2^256 < 2p (one masked |
| 22 | subtraction suffices after the folds). |
| 23 | p=2^256-2^224+2^192+2^96-1; t=Array[tt,16,0]; r={t[[1]]+t[[9]]+t[[10]]-t[[12]]-t[[13]]-t[[14]]-t[[15]], t[[2]]+t[[10]]+t[[11]]-t[[13]]-t[[14]]-t[[15]]-t[[16]], t[[3]]+t[[11]]+t[[12]]-t[[14]]-t[[15]]-t[[16]], t[[4]]+2(t[[12]]+t[[13]])+t[[14]]-t[[9]]-t[[10]]-t[[16]], t[[5]]+2(t[[13]]+t[[14]])+t[[15]]-t[[10]]-t[[11]], t[[6]]+2(t[[14]]+t[[15]])+t[[16]]-t[[11]]-t[[12]], t[[7]]+t[[14]]+3t[[15]]+2t[[16]]-t[[9]]-t[[10]], t[[8]]+t[[9]]+3t[[16]]-t[[11]]-t[[12]]-t[[13]]-t[[14]]}; diff=Expand[Sum[t[[k+1]] 2^(32k),{k,0,15}]-Sum[r[[k+1]] 2^(32k),{k,0,7}]]; {p==16^^ffffffff00000001000000000000000000000000ffffffffffffffffffffffff, AllTrue[Flatten[{Coefficient[diff,#]&/@t}], Mod[#,p]==0&], Mod[2^256-(2^224-2^192-2^96+1),p]==0, (2^256<2p)} |
| 24 | Result: |
| 25 | {True, True, True, True} |
| 26 | Negative control: the same query with -t[[15]] (the t14 term, the p2-red mutant) dropped from r[0], |
| 27 | returning only the AllTrue field, gave False. |
| 28 | |
| 29 | Query 2 (exact code sent): the exponent built by p2_inv, step by step as the code squares (sq e n = |
| 30 | e 2^n) and multiplies (adds exponents); the intermediates must be a^(2^k - 1) for k = 2, 3, 6, 15, |
| 31 | 30, 32 and the result a^(p-2). |
| 32 | p=2^256-2^224+2^192+2^96-1; sq[e_,n_]:=e*2^n; i0=sq[1,1]+1; i1=sq[i0,1]+1; i2=sq[i1,3]+i1; i3=sq[i2,6]+i2; i3=sq[i3,3]+i1; i4=sq[i3,15]+i3; i5=sq[i4,2]+i0; j=sq[i5,32]+1; j=sq[j,128]+i5; j=sq[j,32]+i5; j=sq[j,30]+i4; o=sq[j,2]+1; {{i0,i1,i2,i3,i4,i5}=={2^2-1,2^3-1,2^6-1,2^15-1,2^30-1,2^32-1}, o==p-2, 1+1+3+6+3+15+2+32+128+32+30+2, 12} |
| 33 | Result: |
| 34 | {True, True, 255, 12} |
| 35 | (255 squarings, 12 multiplications.) |