Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
affine.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_ARRAYS_AFFINE_H_
16#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_
17
18#include <stddef.h>
19
20namespace proofs {
21
22using corner_t = size_t;
23
24// return r * f0 + (1-r) * f1 = f0 + r * (f1 - f0)
25template <typename Field>
26typename Field::Elt affine_interpolation(const typename Field::Elt& r,
27 typename Field::Elt f0,
28 typename Field::Elt f1,
29 const Field& F) {
30 F.sub(f1, f0);
31 F.mul(f1, r);
32 F.add(f0, f1);
33 return f0;
34}
35
36// special case f0 = 0
37template <typename Field>
38typename Field::Elt affine_interpolation_z_nz(const typename Field::Elt& r,
39 typename Field::Elt f1,
40 const Field& F) {
41 F.mul(f1, r);
42 return f1;
43}
44
45// special case f1 = 0
46template <typename Field>
47typename Field::Elt affine_interpolation_nz_z(const typename Field::Elt& r,
48 typename Field::Elt f0,
49 const Field& F) {
50 F.sub(f0, F.mulf(f0, r));
51 return f0;
52}
53
54} // namespace proofs
55
56#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_
Definition gf2_128.h:63