-
Notifications
You must be signed in to change notification settings - Fork 163
/
multiexp_jacobian.go
171 lines (151 loc) · 4.72 KB
/
multiexp_jacobian.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2020 ConsenSys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by consensys/gnark-crypto DO NOT EDIT
package bls12381
func processChunkG1Jacobian[B ibg1JacExtended](chunk uint64,
chRes chan<- g1JacExtended,
c uint64,
points []G1Affine,
digits []uint16) {
var buckets B
for i := 0; i < len(buckets); i++ {
buckets[i].setInfinity()
}
// for each scalars, get the digit corresponding to the chunk we're processing.
for i, digit := range digits {
if digit == 0 {
continue
}
// if msbWindow bit is set, we need to substract
if digit&1 == 0 {
// add
buckets[(digit>>1)-1].addMixed(&points[i])
} else {
// sub
buckets[(digit >> 1)].subMixed(&points[i])
}
}
// reduce buckets into total
// total = bucket[0] + 2*bucket[1] + 3*bucket[2] ... + n*bucket[n-1]
var runningSum, total g1JacExtended
runningSum.setInfinity()
total.setInfinity()
for k := len(buckets) - 1; k >= 0; k-- {
if !buckets[k].ZZ.IsZero() {
runningSum.add(&buckets[k])
}
total.add(&runningSum)
}
chRes <- total
}
// we declare the buckets as fixed-size array types
// this allow us to allocate the buckets on the stack
type bucketg1JacExtendedC3 [4]g1JacExtended
type bucketg1JacExtendedC4 [8]g1JacExtended
type bucketg1JacExtendedC5 [16]g1JacExtended
type bucketg1JacExtendedC6 [32]g1JacExtended
type bucketg1JacExtendedC7 [64]g1JacExtended
type bucketg1JacExtendedC8 [128]g1JacExtended
type bucketg1JacExtendedC9 [256]g1JacExtended
type bucketg1JacExtendedC10 [512]g1JacExtended
type bucketg1JacExtendedC11 [1024]g1JacExtended
type bucketg1JacExtendedC12 [2048]g1JacExtended
type bucketg1JacExtendedC13 [4096]g1JacExtended
type bucketg1JacExtendedC14 [8192]g1JacExtended
type bucketg1JacExtendedC15 [16384]g1JacExtended
type bucketg1JacExtendedC16 [32768]g1JacExtended
type ibg1JacExtended interface {
bucketg1JacExtendedC3 |
bucketg1JacExtendedC4 |
bucketg1JacExtendedC5 |
bucketg1JacExtendedC6 |
bucketg1JacExtendedC7 |
bucketg1JacExtendedC8 |
bucketg1JacExtendedC9 |
bucketg1JacExtendedC10 |
bucketg1JacExtendedC11 |
bucketg1JacExtendedC12 |
bucketg1JacExtendedC13 |
bucketg1JacExtendedC14 |
bucketg1JacExtendedC15 |
bucketg1JacExtendedC16
}
func processChunkG2Jacobian[B ibg2JacExtended](chunk uint64,
chRes chan<- g2JacExtended,
c uint64,
points []G2Affine,
digits []uint16) {
var buckets B
for i := 0; i < len(buckets); i++ {
buckets[i].setInfinity()
}
// for each scalars, get the digit corresponding to the chunk we're processing.
for i, digit := range digits {
if digit == 0 {
continue
}
// if msbWindow bit is set, we need to substract
if digit&1 == 0 {
// add
buckets[(digit>>1)-1].addMixed(&points[i])
} else {
// sub
buckets[(digit >> 1)].subMixed(&points[i])
}
}
// reduce buckets into total
// total = bucket[0] + 2*bucket[1] + 3*bucket[2] ... + n*bucket[n-1]
var runningSum, total g2JacExtended
runningSum.setInfinity()
total.setInfinity()
for k := len(buckets) - 1; k >= 0; k-- {
if !buckets[k].ZZ.IsZero() {
runningSum.add(&buckets[k])
}
total.add(&runningSum)
}
chRes <- total
}
// we declare the buckets as fixed-size array types
// this allow us to allocate the buckets on the stack
type bucketg2JacExtendedC3 [4]g2JacExtended
type bucketg2JacExtendedC4 [8]g2JacExtended
type bucketg2JacExtendedC5 [16]g2JacExtended
type bucketg2JacExtendedC6 [32]g2JacExtended
type bucketg2JacExtendedC7 [64]g2JacExtended
type bucketg2JacExtendedC8 [128]g2JacExtended
type bucketg2JacExtendedC9 [256]g2JacExtended
type bucketg2JacExtendedC10 [512]g2JacExtended
type bucketg2JacExtendedC11 [1024]g2JacExtended
type bucketg2JacExtendedC12 [2048]g2JacExtended
type bucketg2JacExtendedC13 [4096]g2JacExtended
type bucketg2JacExtendedC14 [8192]g2JacExtended
type bucketg2JacExtendedC15 [16384]g2JacExtended
type bucketg2JacExtendedC16 [32768]g2JacExtended
type ibg2JacExtended interface {
bucketg2JacExtendedC3 |
bucketg2JacExtendedC4 |
bucketg2JacExtendedC5 |
bucketg2JacExtendedC6 |
bucketg2JacExtendedC7 |
bucketg2JacExtendedC8 |
bucketg2JacExtendedC9 |
bucketg2JacExtendedC10 |
bucketg2JacExtendedC11 |
bucketg2JacExtendedC12 |
bucketg2JacExtendedC13 |
bucketg2JacExtendedC14 |
bucketg2JacExtendedC15 |
bucketg2JacExtendedC16
}