github.com/cloudflare/circl@v1.5.0/sign/dilithium/mode2/internal/mat.go (about) 1 // Code generated from mode3/internal/mat.go by gen.go 2 3 package internal 4 5 import ( 6 common "github.com/cloudflare/circl/sign/internal/dilithium" 7 ) 8 9 // A k by l matrix of polynomials. 10 type Mat [K]VecL 11 12 // Expands the given seed to a complete matrix. 13 // 14 // This function is called ExpandA in the specification. 15 func (m *Mat) Derive(seed *[32]byte) { 16 if !DeriveX4Available { 17 for i := uint16(0); i < K; i++ { 18 for j := uint16(0); j < L; j++ { 19 PolyDeriveUniform(&m[i][j], seed, (i<<8)+j) 20 } 21 } 22 return 23 } 24 25 idx := 0 26 var nonces [4]uint16 27 var ps [4]*common.Poly 28 for i := uint16(0); i < K; i++ { 29 for j := uint16(0); j < L; j++ { 30 nonces[idx] = (i << 8) + j 31 ps[idx] = &m[i][j] 32 idx++ 33 if idx == 4 { 34 idx = 0 35 PolyDeriveUniformX4(ps, seed, nonces) 36 } 37 } 38 } 39 if idx != 0 { 40 for i := idx; i < 4; i++ { 41 ps[i] = nil 42 } 43 PolyDeriveUniformX4(ps, seed, nonces) 44 } 45 } 46 47 // Set p to the inner product of a and b using pointwise multiplication. 48 // 49 // Assumes a and b are in Montgomery form and their coefficients are 50 // pairwise sufficiently small to multiply, see Poly.MulHat(). Resulting 51 // coefficients are bounded by 2Lq. 52 func PolyDotHat(p *common.Poly, a, b *VecL) { 53 var t common.Poly 54 *p = common.Poly{} // zero p 55 for i := 0; i < L; i++ { 56 t.MulHat(&a[i], &b[i]) 57 p.Add(&t, p) 58 } 59 }