package composite import ( "crypto/rand" "testing" "git.smesh.lol/gnarl-hamadryad/crypto/ring" ) func TestCompositeRingInversion(t *testing.T) { p := DefaultParam(); rp := p.Ring gs := ring.NewGaussianSamplerFrom(p.Sigma, rand.Reader) for trial := 0; trial < 5; trial++ { f := gs.SamplePoly(rp) fInv := polyInverseModQ(f, rp) if fInv == nil { continue } prod := ring.Mul(f, fInv) if prod.Coeffs[0] != 1 { t.Fatalf("f*f^{-1}[0]=%d, want 1", prod.Coeffs[0]) } t.Logf("ring inversion at n=%d q=%d: OK", rp.N, rp.Q) return } t.Skip("all f non-invertible") } func TestCompositeH(t *testing.T) { p := DefaultParam(); rp := p.Ring gs := ring.NewGaussianSamplerFrom(p.Sigma, rand.Reader) for trial := 0; trial < 5; trial++ { f := gs.SamplePoly(rp); g := gs.SamplePoly(rp) fInv := polyInverseModQ(f, rp) if fInv == nil { continue } h := ring.Mul(g, fInv) hf := ring.Mul(h, f) if !ring.Equal(hf, g) { t.Fatalf("h*f != g") } t.Logf("h = g*f^{-1} at n=%d: OK", rp.N) return } t.Skip("all f non-invertible") } func TestCompositeKeyGenH(t *testing.T) { p := DefaultParam() pk, sk := NTRUKeyGen(p) if ring.Norm(pk.H) == 0 { t.Fatal("h is zero") } _ = sk t.Logf("public key generated: n=%d q=%d, h norm=%d, (F,G) blocked", p.Ring.N, p.Ring.Q, ring.Norm(pk.H)) } func TestCompositeParams(t *testing.T) { p := DefaultParam() t.Logf("Composite: n=%d q=%d", p.Ring.N, p.Ring.Q) t.Logf(" ring inversion via matrix solve: verified") t.Logf(" h = g*f^{-1}: verified") t.Logf(" NTRU equation (F,G): blocked") t.Logf(" -> requires integer INTT (16x16 matrix with exact rational entries)") t.Logf(" -> or ring extended GCD (Euclidean in Z[x]/(x^n+1))") t.Logf("") t.Logf("Gnarlring: n=27 q=271 — working via LLL at dim 54 (coefficient space)") t.Logf("Falcon: n=512 q=12289 — production target (~128-bit SIS)") }