#include #include #include #include #include "goldilocks.h" #include "ntt.h" // ----------------------------------------------------------------------------- void goldilocks_ntt_forward_noalloc(int m, int src_stride, const uint64_t *gpows, const uint64_t *src, uint64_t *buf, uint64_t *tgt) { if (m==0) { tgt[0] = src[0]; return; } if (m==1) { // N = 2 tgt[0] = goldilocks_add( src[0] , src[src_stride] ); // x + y tgt[1] = goldilocks_sub( src[0] , src[src_stride] ); // x - y return; } else { int N = (1<< m ); int halfN = (1<<(m-1)); goldilocks_ntt_forward_noalloc( m-1 , src_stride<<1 , gpows , src , buf + N , buf ); goldilocks_ntt_forward_noalloc( m-1 , src_stride<<1 , gpows , src + src_stride , buf + N , buf + halfN ); for(int j=0; j>1); // precalculate [1,g,g^2,g^3...] uint64_t *gpows = (uint64_t*) malloc( 8 * halfN ); assert( gpows != 0 ); uint64_t x = gen; gpows[0] = 1; gpows[1] = gen; for(int i=2; i= m_src ); int N_src = (1 << m_src); int N_tgt = (1 << m_tgt); int halfN_src = (N_src >> 1); int K = (1 << (m_tgt - m_src)); // precalculate [1,g,g^2,g^3...] uint64_t *gpows = malloc( 8 * halfN_src ); assert( gpows != 0 ); uint64_t x = gen_src; gpows[0] = 1; gpows[1] = gen_src; for(int i=2; i>1); // precalculate [1/2,g^{-1}/2,g^{-2}/2,g^{-3}/2...] uint64_t *gpows = malloc( 8 * halfN ); assert( gpows != 0 ); uint64_t x = goldilocks_oneHalf; // 1/2 uint64_t ginv = goldilocks_inv(gen); // gen^-1 for(int i=0; i