Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
twiddle.h
1// Copyright 2025 Google LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_
16#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_
17
18#include <stddef.h>
19#include <stdint.h>
20
21#include <vector>
22
23// Twiddle factors for FFT
24namespace proofs {
25
26template <class Field>
27class Twiddle {
28 using Elt = typename Field::Elt;
29
30 public:
31 size_t order_;
32 // powers of omega_n
33 std::vector<Elt> w_;
34
35 explicit Twiddle(size_t n, const Elt& omega_n, const Field& F)
36 : order_(n), w_(n / 2) {
37 auto w = F.one();
38 for (size_t i = 0; 2 * i < n; ++i) {
39 w_[i] = w;
40 F.mul(w, omega_n);
41 }
42 }
43
44 // given a n-th root of unity omega_n, return a r-th root of unity
45 // for r <= n
46 static Elt reroot(const Elt& omega_n, uint64_t n, uint64_t r,
47 const Field& F) {
48 Elt omega_r = omega_n;
49 while (r < n) {
50 F.mul(omega_r, omega_r);
51 r += r;
52 }
53 return omega_r;
54 }
55};
56
57} // namespace proofs
58
59#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_
Definition gf2_128.h:63