Skip to content

Commit d93977d

Browse files
suiyuan1314gzliudan
authored andcommitted
crypto/secp256k1: change receiver variable name to lowercase (ethereum#29889)
1 parent f1a0bcd commit d93977d

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

crypto/secp256k1/curve.go

+44-44
Original file line numberDiff line numberDiff line change
@@ -79,52 +79,52 @@ type BitCurve struct {
7979
BitSize int // the size of the underlying field
8080
}
8181

82-
func (BitCurve *BitCurve) Params() *elliptic.CurveParams {
82+
func (bitCurve *BitCurve) Params() *elliptic.CurveParams {
8383
return &elliptic.CurveParams{
84-
P: BitCurve.P,
85-
N: BitCurve.N,
86-
B: BitCurve.B,
87-
Gx: BitCurve.Gx,
88-
Gy: BitCurve.Gy,
89-
BitSize: BitCurve.BitSize,
84+
P: bitCurve.P,
85+
N: bitCurve.N,
86+
B: bitCurve.B,
87+
Gx: bitCurve.Gx,
88+
Gy: bitCurve.Gy,
89+
BitSize: bitCurve.BitSize,
9090
}
9191
}
9292

9393
// IsOnCurve returns true if the given (x,y) lies on the BitCurve.
94-
func (BitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool {
94+
func (bitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool {
9595
// y² = x³ + b
9696
y2 := new(big.Int).Mul(y, y) //y²
97-
y2.Mod(y2, BitCurve.P) //y²%P
97+
y2.Mod(y2, bitCurve.P) //y²%P
9898

9999
x3 := new(big.Int).Mul(x, x) //x²
100100
x3.Mul(x3, x) //x³
101101

102-
x3.Add(x3, BitCurve.B) //x³+B
103-
x3.Mod(x3, BitCurve.P) //(x³+B)%P
102+
x3.Add(x3, bitCurve.B) //x³+B
103+
x3.Mod(x3, bitCurve.P) //(x³+B)%P
104104

105105
return x3.Cmp(y2) == 0
106106
}
107107

108108
// affineFromJacobian reverses the Jacobian transform. See the comment at the
109109
// top of the file.
110-
func (BitCurve *BitCurve) affineFromJacobian(x, y, z *big.Int) (xOut, yOut *big.Int) {
110+
func (bitCurve *BitCurve) affineFromJacobian(x, y, z *big.Int) (xOut, yOut *big.Int) {
111111
if z.Sign() == 0 {
112112
return new(big.Int), new(big.Int)
113113
}
114114

115-
zinv := new(big.Int).ModInverse(z, BitCurve.P)
115+
zinv := new(big.Int).ModInverse(z, bitCurve.P)
116116
zinvsq := new(big.Int).Mul(zinv, zinv)
117117

118118
xOut = new(big.Int).Mul(x, zinvsq)
119-
xOut.Mod(xOut, BitCurve.P)
119+
xOut.Mod(xOut, bitCurve.P)
120120
zinvsq.Mul(zinvsq, zinv)
121121
yOut = new(big.Int).Mul(y, zinvsq)
122-
yOut.Mod(yOut, BitCurve.P)
122+
yOut.Mod(yOut, bitCurve.P)
123123
return
124124
}
125125

126126
// Add returns the sum of (x1,y1) and (x2,y2)
127-
func (BitCurve *BitCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) {
127+
func (bitCurve *BitCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) {
128128
// If one point is at infinity, return the other point.
129129
// Adding the point at infinity to any point will preserve the other point.
130130
if x1.Sign() == 0 && y1.Sign() == 0 {
@@ -135,41 +135,41 @@ func (BitCurve *BitCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) {
135135
}
136136
z := new(big.Int).SetInt64(1)
137137
if x1.Cmp(x2) == 0 && y1.Cmp(y2) == 0 {
138-
return BitCurve.affineFromJacobian(BitCurve.doubleJacobian(x1, y1, z))
138+
return bitCurve.affineFromJacobian(bitCurve.doubleJacobian(x1, y1, z))
139139
}
140-
return BitCurve.affineFromJacobian(BitCurve.addJacobian(x1, y1, z, x2, y2, z))
140+
return bitCurve.affineFromJacobian(bitCurve.addJacobian(x1, y1, z, x2, y2, z))
141141
}
142142

143143
// addJacobian takes two points in Jacobian coordinates, (x1, y1, z1) and
144144
// (x2, y2, z2) and returns their sum, also in Jacobian form.
145-
func (BitCurve *BitCurve) addJacobian(x1, y1, z1, x2, y2, z2 *big.Int) (*big.Int, *big.Int, *big.Int) {
145+
func (bitCurve *BitCurve) addJacobian(x1, y1, z1, x2, y2, z2 *big.Int) (*big.Int, *big.Int, *big.Int) {
146146
// See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-add-2007-bl
147147
z1z1 := new(big.Int).Mul(z1, z1)
148-
z1z1.Mod(z1z1, BitCurve.P)
148+
z1z1.Mod(z1z1, bitCurve.P)
149149
z2z2 := new(big.Int).Mul(z2, z2)
150-
z2z2.Mod(z2z2, BitCurve.P)
150+
z2z2.Mod(z2z2, bitCurve.P)
151151

152152
u1 := new(big.Int).Mul(x1, z2z2)
153-
u1.Mod(u1, BitCurve.P)
153+
u1.Mod(u1, bitCurve.P)
154154
u2 := new(big.Int).Mul(x2, z1z1)
155-
u2.Mod(u2, BitCurve.P)
155+
u2.Mod(u2, bitCurve.P)
156156
h := new(big.Int).Sub(u2, u1)
157157
if h.Sign() == -1 {
158-
h.Add(h, BitCurve.P)
158+
h.Add(h, bitCurve.P)
159159
}
160160
i := new(big.Int).Lsh(h, 1)
161161
i.Mul(i, i)
162162
j := new(big.Int).Mul(h, i)
163163

164164
s1 := new(big.Int).Mul(y1, z2)
165165
s1.Mul(s1, z2z2)
166-
s1.Mod(s1, BitCurve.P)
166+
s1.Mod(s1, bitCurve.P)
167167
s2 := new(big.Int).Mul(y2, z1)
168168
s2.Mul(s2, z1z1)
169-
s2.Mod(s2, BitCurve.P)
169+
s2.Mod(s2, bitCurve.P)
170170
r := new(big.Int).Sub(s2, s1)
171171
if r.Sign() == -1 {
172-
r.Add(r, BitCurve.P)
172+
r.Add(r, bitCurve.P)
173173
}
174174
r.Lsh(r, 1)
175175
v := new(big.Int).Mul(u1, i)
@@ -179,41 +179,41 @@ func (BitCurve *BitCurve) addJacobian(x1, y1, z1, x2, y2, z2 *big.Int) (*big.Int
179179
x3.Sub(x3, j)
180180
x3.Sub(x3, v)
181181
x3.Sub(x3, v)
182-
x3.Mod(x3, BitCurve.P)
182+
x3.Mod(x3, bitCurve.P)
183183

184184
y3 := new(big.Int).Set(r)
185185
v.Sub(v, x3)
186186
y3.Mul(y3, v)
187187
s1.Mul(s1, j)
188188
s1.Lsh(s1, 1)
189189
y3.Sub(y3, s1)
190-
y3.Mod(y3, BitCurve.P)
190+
y3.Mod(y3, bitCurve.P)
191191

192192
z3 := new(big.Int).Add(z1, z2)
193193
z3.Mul(z3, z3)
194194
z3.Sub(z3, z1z1)
195195
if z3.Sign() == -1 {
196-
z3.Add(z3, BitCurve.P)
196+
z3.Add(z3, bitCurve.P)
197197
}
198198
z3.Sub(z3, z2z2)
199199
if z3.Sign() == -1 {
200-
z3.Add(z3, BitCurve.P)
200+
z3.Add(z3, bitCurve.P)
201201
}
202202
z3.Mul(z3, h)
203-
z3.Mod(z3, BitCurve.P)
203+
z3.Mod(z3, bitCurve.P)
204204

205205
return x3, y3, z3
206206
}
207207

208208
// Double returns 2*(x,y)
209-
func (BitCurve *BitCurve) Double(x1, y1 *big.Int) (*big.Int, *big.Int) {
209+
func (bitCurve *BitCurve) Double(x1, y1 *big.Int) (*big.Int, *big.Int) {
210210
z1 := new(big.Int).SetInt64(1)
211-
return BitCurve.affineFromJacobian(BitCurve.doubleJacobian(x1, y1, z1))
211+
return bitCurve.affineFromJacobian(bitCurve.doubleJacobian(x1, y1, z1))
212212
}
213213

214214
// doubleJacobian takes a point in Jacobian coordinates, (x, y, z), and
215215
// returns its double, also in Jacobian form.
216-
func (BitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, *big.Int) {
216+
func (bitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, *big.Int) {
217217
// See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l
218218

219219
a := new(big.Int).Mul(x, x) //X1²
@@ -231,30 +231,30 @@ func (BitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int,
231231

232232
x3 := new(big.Int).Mul(big.NewInt(2), d) //2*D
233233
x3.Sub(f, x3) //F-2*D
234-
x3.Mod(x3, BitCurve.P)
234+
x3.Mod(x3, bitCurve.P)
235235

236236
y3 := new(big.Int).Sub(d, x3) //D-X3
237237
y3.Mul(e, y3) //E*(D-X3)
238238
y3.Sub(y3, new(big.Int).Mul(big.NewInt(8), c)) //E*(D-X3)-8*C
239-
y3.Mod(y3, BitCurve.P)
239+
y3.Mod(y3, bitCurve.P)
240240

241241
z3 := new(big.Int).Mul(y, z) //Y1*Z1
242242
z3.Mul(big.NewInt(2), z3) //3*Y1*Z1
243-
z3.Mod(z3, BitCurve.P)
243+
z3.Mod(z3, bitCurve.P)
244244

245245
return x3, y3, z3
246246
}
247247

248248
// ScalarBaseMult returns k*G, where G is the base point of the group and k is
249249
// an integer in big-endian form.
250-
func (BitCurve *BitCurve) ScalarBaseMult(k []byte) (*big.Int, *big.Int) {
251-
return BitCurve.ScalarMult(BitCurve.Gx, BitCurve.Gy, k)
250+
func (bitCurve *BitCurve) ScalarBaseMult(k []byte) (*big.Int, *big.Int) {
251+
return bitCurve.ScalarMult(bitCurve.Gx, bitCurve.Gy, k)
252252
}
253253

254254
// Marshal converts a point into the form specified in section 4.3.6 of ANSI
255255
// X9.62.
256-
func (BitCurve *BitCurve) Marshal(x, y *big.Int) []byte {
257-
byteLen := (BitCurve.BitSize + 7) >> 3
256+
func (bitCurve *BitCurve) Marshal(x, y *big.Int) []byte {
257+
byteLen := (bitCurve.BitSize + 7) >> 3
258258
ret := make([]byte, 1+2*byteLen)
259259
ret[0] = 4 // uncompressed point flag
260260
readBits(x, ret[1:1+byteLen])
@@ -264,8 +264,8 @@ func (BitCurve *BitCurve) Marshal(x, y *big.Int) []byte {
264264

265265
// Unmarshal converts a point, serialised by Marshal, into an x, y pair. On
266266
// error, x = nil.
267-
func (BitCurve *BitCurve) Unmarshal(data []byte) (x, y *big.Int) {
268-
byteLen := (BitCurve.BitSize + 7) >> 3
267+
func (bitCurve *BitCurve) Unmarshal(data []byte) (x, y *big.Int) {
268+
byteLen := (bitCurve.BitSize + 7) >> 3
269269
if len(data) != 1+2*byteLen {
270270
return
271271
}

crypto/secp256k1/scalar_mult_cgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, const unsigned
2121
*/
2222
import "C"
2323

24-
func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) {
24+
func (bitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) {
2525
// Ensure scalar is exactly 32 bytes. We pad always, even if
2626
// scalar is 32 bytes long, to avoid a timing side channel.
2727
if len(scalar) > 32 {

crypto/secp256k1/scalar_mult_nocgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ package secp256k1
99

1010
import "math/big"
1111

12-
func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) {
12+
func (bitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) {
1313
panic("ScalarMult is not available when secp256k1 is built without cgo")
1414
}

0 commit comments

Comments
 (0)