2
$\begingroup$

As defined in Kyber's specification 1, the NTT consists of two formulas:

$$\hat{f}_{2i} = \sum_{j=0}^{127} f_{2j} \zeta^{(2 \cdot \text{br}_7(i)+1)\cdot j}$$

$$\hat{f}_{2i+1} = \sum_{j=0}^{127} f_{2j+1} \zeta^{(2 \cdot \text{br}_7(i)+1)\cdot j}$$

Judging by the formulas, I would assume that the NTT is now implemented in such a way that you have two vectors each of length 128 and then calculate two 128-point NTTs. But I have now noticed in the reference implementation 2 that the NTT uses a vector of length 256 as input.

/*************************************************
* Name:        ntt
*
* Description: Inplace number-theoretic transform (NTT) in Rq.
*              input is in standard order, output is in bitreversed order
*
* Arguments:   - int16_t r[256]: pointer to input/output vector of elements of Zq
**************************************************/
void ntt(int16_t r[256]) {
  unsigned int len, start, j, k;
  int16_t t, zeta;

  k = 1;
  for(len = 128; len >= 2; len >>= 1) {
    for(start = 0; start < 256; start = j + len) {
      zeta = zetas[k++];
      for(j = start; j < start + len; j++) {
        t = fqmul(zeta, r[j + len]);
        r[j + len] = r[j] - t;
        r[j] = r[j] + t;
      }
    }
  }
}

Apparently, this code looks to me as if the NTT is not split in the reference implementation but instead a full 256-point NTT is executed directly. But how can this work, when zeta is a 256th primitive root and we therefore also have to work with these two formulas. That's exactly why we have the two different formulas. However, in the implementation, it looks to me as if the following formula was used instead:

$$\hat{f}_{i} = \sum_{j=0}^{256} f_{j} \zeta^{(2 \cdot \text{br}_7(i)+1)\cdot j}$$

In short: For me, the implementation looks different than I would have expected it from the two formulas from above.

$\endgroup$

1 Answer 1

3
$\begingroup$

The first formula you describe is the formula to compute an NTT using what is known as the "Gentleman-Sande Butterfly" (also known as "Decimation in Frequency"). The code you quote instead uses what is often called a "Cooley-Tukey Butterfly" (also known as "Decimation in Time"). They both can compute FFTs, but are mildly different techniques for doing so, so it is reasonable to be confused how they yield the same result.

To learn more about this, see Section 4 of Denisa Greconici's Masters Thesis. In particular, Figure 4.2 contains (sort of) formula for the GS butterfly, e.g. your first equations. Listing 4.2.3 contains code that is essentially the Kyber code you quote, where it is described as computing an FFT using CT butterflies.

$\endgroup$
5
  • 1
    $\begingroup$ doesn't this all exist in Richard Blahut's book? $\endgroup$
    – kelalaka
    Commented Feb 9 at 22:33
  • 1
    $\begingroup$ @kelalaka probably, but the thesis is about Kyber specifically, freely available, and I don't know if Blahut covers the number-theoretic transform (I imagine there is a version over $\mathbb{C}$ in any signals processing book though). $\endgroup$
    – Mark Schultz-Wu
    Commented Feb 10 at 0:14
  • $\begingroup$ Blahut's book went through a number of versions. I do believe the first edition linked above by @kelalaka is the one with most details. $\endgroup$
    – kodlu
    Commented Feb 10 at 6:10
  • $\begingroup$ @kodlu Unfortunately, my copy went away with a friend, I bought it years ago for like 125$ for a used copy :) $\endgroup$
    – kelalaka
    Commented Feb 10 at 10:31
  • $\begingroup$ @Mark those are tricks to make the calculations faster, I believe it is a matter of time before someone can get better results from some AI. $\endgroup$
    – kelalaka
    Commented Feb 10 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.