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

     1  //go:build !amd64 || purego
     2  // +build !amd64 purego
     3  
     4  package dilithium
     5  
     6  // Execute an in-place forward NTT on as.
     7  //
     8  // Assumes the coefficients are in Montgomery representation and bounded
     9  // by 2*Q.  The resulting coefficients are again in Montgomery representation,
    10  // but are only bounded bt 18*Q.
    11  func (p *Poly) NTT() {
    12  	p.nttGeneric()
    13  }
    14  
    15  // Execute an in-place inverse NTT and multiply by Montgomery factor R
    16  //
    17  // Assumes the coefficients are in Montgomery representation and bounded
    18  // by 2*Q.  The resulting coefficients are again in Montgomery representation
    19  // and bounded by 2*Q.
    20  func (p *Poly) InvNTT() {
    21  	p.invNttGeneric()
    22  }
    23  
    24  // Sets p to the polynomial whose coefficients are the pointwise multiplication
    25  // of those of a and b.  The coefficients of p are bounded by 2q.
    26  //
    27  // Assumes a and b are in Montgomery form and that the pointwise product
    28  // of each coefficient is below 2³² q.
    29  func (p *Poly) MulHat(a, b *Poly) {
    30  	p.mulHatGeneric(a, b)
    31  }
    32  
    33  // Sets p to a + b.  Does not normalize polynomials.
    34  func (p *Poly) Add(a, b *Poly) {
    35  	p.addGeneric(a, b)
    36  }
    37  
    38  // Sets p to a - b.
    39  //
    40  // Warning: assumes coefficients of b are less than 2q.
    41  // Sets p to a + b.  Does not normalize polynomials.
    42  func (p *Poly) Sub(a, b *Poly) {
    43  	p.subGeneric(a, b)
    44  }
    45  
    46  // Writes p whose coefficients are in [0, 16) to buf, which must be of
    47  // length N/2.
    48  func (p *Poly) PackLe16(buf []byte) {
    49  	p.packLe16Generic(buf)
    50  }
    51  
    52  // Reduces each of the coefficients to <2q.
    53  func (p *Poly) ReduceLe2Q() {
    54  	p.reduceLe2QGeneric()
    55  }
    56  
    57  // Reduce each of the coefficients to <q.
    58  func (p *Poly) Normalize() {
    59  	p.normalizeGeneric()
    60  }
    61  
    62  // Normalize the coefficients in this polynomial assuming they are already
    63  // bounded by 2q.
    64  func (p *Poly) NormalizeAssumingLe2Q() {
    65  	p.normalizeAssumingLe2QGeneric()
    66  }
    67  
    68  // Checks whether the "supnorm" (see sec 2.1 of the spec) of p is equal
    69  // or greater than the given bound.
    70  //
    71  // Requires the coefficients of p to be normalized.
    72  func (p *Poly) Exceeds(bound uint32) bool {
    73  	return p.exceedsGeneric(bound)
    74  }
    75  
    76  // Sets p to 2ᵈ q without reducing.
    77  //
    78  // So it requires the coefficients of p  to be less than 2³²⁻ᴰ.
    79  func (p *Poly) MulBy2toD(q *Poly) {
    80  	p.mulBy2toDGeneric(q)
    81  }