github.com/cloudflare/circl@v1.5.0/sign/dilithium/mode3/internal/mat.go (about)

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