Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct linter explaination #547

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion group/edwards25519/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Curve) NewKeyAndSeedWithInput(buffer []byte) (kyber.Scalar, []byte, []b
digest[31] &= 0x7f
digest[31] |= 0x40

secret := c.Scalar().(*scalar) //nolint:errcheck // V4 may bring better error handling
secret := c.Scalar().(*scalar) //nolint:errcheck // Design pattern to emulate generics
copy(secret.v[:], digest[:])
return secret, buffer, digest[32:]
}
Expand Down
8 changes: 4 additions & 4 deletions group/edwards25519/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func (P *point) Data() ([]byte, error) {
}

func (P *point) Add(P1, P2 kyber.Point) kyber.Point {
E1 := P1.(*point) //nolint:errcheck // V4 may bring better error handling
E2 := P2.(*point) //nolint:errcheck // V4 may bring better error handling
E1 := P1.(*point) //nolint:errcheck // Design pattern to emulate generics
E2 := P2.(*point) //nolint:errcheck // Design pattern to emulate generics

var t2 cachedGroupElement
var r completedGroupElement
Expand All @@ -199,8 +199,8 @@ func (P *point) Add(P1, P2 kyber.Point) kyber.Point {
}

func (P *point) Sub(P1, P2 kyber.Point) kyber.Point {
E1 := P1.(*point) //nolint:errcheck // V4 may bring better error handling
E2 := P2.(*point) //nolint:errcheck // V4 may bring better error handling
E1 := P1.(*point) //nolint:errcheck // Design pattern to emulate generics
E2 := P2.(*point) //nolint:errcheck // Design pattern to emulate generics

var t2 cachedGroupElement
var r completedGroupElement
Expand Down
2 changes: 1 addition & 1 deletion group/edwards25519/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *scalar) Div(a, b kyber.Scalar) kyber.Scalar {
func (s *scalar) Inv(a kyber.Scalar) kyber.Scalar {
var res scalar
res.One()
ac := a.(*scalar) //nolint:errcheck // V4 may bring better error handling
ac := a.(*scalar) //nolint:errcheck // Design pattern to emulate generics
// Modular inversion in a multiplicative group is a^(phi(m)-1) = a^-1 mod m
// Since m is prime, phi(m) = m - 1 => a^(m-2) = a^-1 mod m.
// The inverse is computed using the exponentation-and-square algorithm.
Expand Down
16 changes: 8 additions & 8 deletions group/edwards25519vartime/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type extPoint struct {
}

func (P *extPoint) initXY(x, y *big.Int, c kyber.Group) {
P.c = c.(*ExtendedCurve) //nolint:errcheck // V4 may bring better error handling
P.c = c.(*ExtendedCurve) //nolint:errcheck // Design pattern to emulate generics

P.X.Init(x, &P.c.P)
P.Y.Init(y, &P.c.P)
Expand Down Expand Up @@ -69,15 +69,15 @@ func (P *extPoint) UnmarshalFrom(r io.Reader) (int, error) {
// iff
// (X1*Z2,Y1*Z2) == (X2*Z1,Y2*Z1)
func (P *extPoint) Equal(CP2 kyber.Point) bool {
p2 := CP2.(*extPoint) //nolint:errcheck // V4 may bring better error handling
p2 := CP2.(*extPoint) //nolint:errcheck // Design pattern to emulate generics
var t1, t2 mod.Int
xeq := t1.Mul(&P.X, &p2.Z).Equal(t2.Mul(&p2.X, &P.Z))
yeq := t1.Mul(&P.Y, &p2.Z).Equal(t2.Mul(&p2.Y, &P.Z))
return xeq && yeq
}

func (P *extPoint) Set(CP2 kyber.Point) kyber.Point {
p2 := CP2.(*extPoint) //nolint:errcheck // V4 may bring better error handling
p2 := CP2.(*extPoint) //nolint:errcheck // Design pattern to emulate generics
P.c = p2.c
P.X.Set(&p2.X)
P.Y.Set(&p2.Y)
Expand Down Expand Up @@ -149,8 +149,8 @@ func (P *extPoint) Data() ([]byte, error) {
//
//nolint:dupl //Doesn't make sense to extract part of Add(), Sub(), double()
func (P *extPoint) Add(CP1, CP2 kyber.Point) kyber.Point {
p1 := CP1.(*extPoint) //nolint:errcheck // V4 may bring better error handling
p2 := CP2.(*extPoint) //nolint:errcheck // V4 may bring better error handling
p1 := CP1.(*extPoint) //nolint:errcheck // Design pattern to emulate generics
p2 := CP2.(*extPoint) //nolint:errcheck // Design pattern to emulate generics
X1, Y1, Z1, T1 := &p1.X, &p1.Y, &p1.Z, &p1.T
X2, Y2, Z2, T2 := &p2.X, &p2.Y, &p2.Z, &p2.T
X3, Y3, Z3, T3 := &P.X, &P.Y, &P.Z, &P.T
Expand All @@ -175,8 +175,8 @@ func (P *extPoint) Add(CP1, CP2 kyber.Point) kyber.Point {
//
//nolint:dupl //Doesn't make sense to extract part of Add(), Sub(), double()
func (P *extPoint) Sub(CP1, CP2 kyber.Point) kyber.Point {
p1 := CP1.(*extPoint) //nolint:errcheck // V4 may bring better error handling
p2 := CP2.(*extPoint) //nolint:errcheck // V4 may bring better error handling
p1 := CP1.(*extPoint) //nolint:errcheck // Design pattern to emulate generics
p2 := CP2.(*extPoint) //nolint:errcheck // Design pattern to emulate generics
X1, Y1, Z1, T1 := &p1.X, &p1.Y, &p1.Z, &p1.T
X2, Y2, Z2, T2 := &p2.X, &p2.Y, &p2.Z, &p2.T
X3, Y3, Z3, T3 := &P.X, &P.Y, &P.Z, &P.T
Expand All @@ -200,7 +200,7 @@ func (P *extPoint) Sub(CP1, CP2 kyber.Point) kyber.Point {
// Find the negative of point A.
// For Edwards curves, the negative of (x,y) is (-x,y).
func (P *extPoint) Neg(CA kyber.Point) kyber.Point {
A := CA.(*extPoint) //nolint:errcheck // V4 may bring better error handling
A := CA.(*extPoint) //nolint:errcheck // Design pattern to emulate generics
P.c = A.c
P.X.Neg(&A.X)
P.Y.Set(&A.Y)
Expand Down
16 changes: 8 additions & 8 deletions group/edwards25519vartime/proj.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type projPoint struct {
}

func (P *projPoint) initXY(x, y *big.Int, c kyber.Group) {
P.c = c.(*ProjectiveCurve) //nolint:errcheck // V4 may bring better error handling
P.c = c.(*ProjectiveCurve) //nolint:errcheck // Design pattern to emulate generics
P.X.Init(x, &P.c.P)
P.Y.Init(y, &P.c.P)
P.Z.Init64(1, &P.c.P)
Expand Down Expand Up @@ -61,15 +61,15 @@ func (P *projPoint) UnmarshalFrom(r io.Reader) (int, error) {
// iff
// (X1*Z2,Y1*Z2) == (X2*Z1,Y2*Z1)
func (P *projPoint) Equal(CP2 kyber.Point) bool {
P2 := CP2.(*projPoint) //nolint:errcheck // V4 may bring better error handling
P2 := CP2.(*projPoint) //nolint:errcheck // Design pattern to emulate generics
var t1, t2 mod.Int
xeq := t1.Mul(&P.X, &P2.Z).Equal(t2.Mul(&P2.X, &P.Z))
yeq := t1.Mul(&P.Y, &P2.Z).Equal(t2.Mul(&P2.Y, &P.Z))
return xeq && yeq
}

func (P *projPoint) Set(CP2 kyber.Point) kyber.Point {
P2 := CP2.(*projPoint) //nolint:errcheck // V4 may bring better error handling
P2 := CP2.(*projPoint) //nolint:errcheck // Design pattern to emulate generics
P.c = P2.c
P.X.Set(&P2.X)
P.Y.Set(&P2.Y)
Expand Down Expand Up @@ -131,8 +131,8 @@ func (P *projPoint) Data() ([]byte, error) {
//
//nolint:dupl //Doesn't make sense to extract part of Add(), Sub()
func (P *projPoint) Add(CP1, CP2 kyber.Point) kyber.Point {
P1 := CP1.(*projPoint) //nolint:errcheck // V4 may bring better error handling
P2 := CP2.(*projPoint) //nolint:errcheck // V4 may bring better error handling
P1 := CP1.(*projPoint) //nolint:errcheck // Design pattern to emulate generics
P2 := CP2.(*projPoint) //nolint:errcheck // Design pattern to emulate generics
X1, Y1, Z1 := &P1.X, &P1.Y, &P1.Z
X2, Y2, Z2 := &P2.X, &P2.Y, &P2.Z
var A, B, C, D, E, F, G, X3, Y3, Z3 mod.Int
Expand Down Expand Up @@ -160,8 +160,8 @@ func (P *projPoint) Add(CP1, CP2 kyber.Point) kyber.Point {
//
//nolint:dupl //Doesn't make sense to extract part of Add(), Sub(), double()
func (P *projPoint) Sub(CP1, CP2 kyber.Point) kyber.Point {
P1 := CP1.(*projPoint) //nolint:errcheck // V4 may bring better error handling
P2 := CP2.(*projPoint) //nolint:errcheck // V4 may bring better error handling
P1 := CP1.(*projPoint) //nolint:errcheck // Design pattern to emulate generics
P2 := CP2.(*projPoint) //nolint:errcheck // Design pattern to emulate generics
X1, Y1, Z1 := &P1.X, &P1.Y, &P1.Z
X2, Y2, Z2 := &P2.X, &P2.Y, &P2.Z
var A, B, C, D, E, F, G, X3, Y3, Z3 mod.Int
Expand All @@ -188,7 +188,7 @@ func (P *projPoint) Sub(CP1, CP2 kyber.Point) kyber.Point {
// Find the negative of point A.
// For Edwards curves, the negative of (x,y) is (-x,y).
func (P *projPoint) Neg(CA kyber.Point) kyber.Point {
A := CA.(*projPoint) //nolint:errcheck // V4 may bring better error handling
A := CA.(*projPoint) //nolint:errcheck // Design pattern to emulate generics
P.c = A.c
P.X.Neg(&A.X)
P.Y.Set(&A.Y)
Expand Down
28 changes: 14 additions & 14 deletions group/mod/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (i *Int) Nonzero() bool {
// Since this method copies the modulus as well,
// it may be used as an alternative to Init().
func (i *Int) Set(a kyber.Scalar) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.V.Set(&ai.V)
i.M = ai.M
return i
Expand Down Expand Up @@ -194,8 +194,8 @@ func (i *Int) Uint64() uint64 {

// Add sets the target to a + b mod M, where M is a's modulus..
func (i *Int) Add(a, b kyber.Scalar) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
bi := b.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
bi := b.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.M = ai.M
i.V.Add(&ai.V, &bi.V).Mod(&i.V, i.M)
return i
Expand All @@ -204,16 +204,16 @@ func (i *Int) Add(a, b kyber.Scalar) kyber.Scalar {
// Sub sets the target to a - b mod M.
// Target receives a's modulus.
func (i *Int) Sub(a, b kyber.Scalar) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
bi := b.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
bi := b.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.M = ai.M
i.V.Sub(&ai.V, &bi.V).Mod(&i.V, i.M)
return i
}

// Neg sets the target to -a mod M.
func (i *Int) Neg(a kyber.Scalar) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.M = ai.M
if ai.V.Sign() > 0 {
i.V.Sub(i.M, &ai.V)
Expand All @@ -226,17 +226,17 @@ func (i *Int) Neg(a kyber.Scalar) kyber.Scalar {
// Mul sets the target to a * b mod M.
// Target receives a's modulus.
func (i *Int) Mul(a, b kyber.Scalar) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
bi := b.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
bi := b.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.M = ai.M
i.V.Mul(&ai.V, &bi.V).Mod(&i.V, i.M)
return i
}

// Div sets the target to a * b^-1 mod M, where b^-1 is the modular inverse of b.
func (i *Int) Div(a, b kyber.Scalar) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
bi := b.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
bi := b.(*Int) //nolint:errcheck // Design pattern to emulate generics
var t big.Int
i.M = ai.M
i.V.Mul(&ai.V, t.ModInverse(&bi.V, i.M))
Expand All @@ -246,7 +246,7 @@ func (i *Int) Div(a, b kyber.Scalar) kyber.Scalar {

// Inv sets the target to the modular inverse of a with respect to modulus M.
func (i *Int) Inv(a kyber.Scalar) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.M = ai.M
i.V.ModInverse(&a.(*Int).V, i.M)
return i
Expand All @@ -255,7 +255,7 @@ func (i *Int) Inv(a kyber.Scalar) kyber.Scalar {
// Exp sets the target to a^e mod M,
// where e is an arbitrary big.Int exponent (not necessarily 0 <= e < M).
func (i *Int) Exp(a kyber.Scalar, e *big.Int) kyber.Scalar {
ai := a.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := a.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.M = ai.M
// to protect against golang/go#22830
var tmp big.Int
Expand All @@ -267,7 +267,7 @@ func (i *Int) Exp(a kyber.Scalar, e *big.Int) kyber.Scalar {
// Jacobi computes the Jacobi symbol of (a/M), which indicates whether a is
// zero (0), a positive square in M (1), or a non-square in M (-1).
func (i *Int) Jacobi(as kyber.Scalar) kyber.Scalar {
ai := as.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := as.(*Int) //nolint:errcheck // Design pattern to emulate generics
i.M = ai.M
i.V.SetInt64(int64(big.Jacobi(&ai.V, i.M)))
return i
Expand All @@ -277,7 +277,7 @@ func (i *Int) Jacobi(as kyber.Scalar) kyber.Scalar {
// Assumes the modulus M is an odd prime.
// Returns true on success, false if input a is not a square.
func (i *Int) Sqrt(as kyber.Scalar) bool {
ai := as.(*Int) //nolint:errcheck // V4 may bring better error handling
ai := as.(*Int) //nolint:errcheck // Design pattern to emulate generics
out := i.V.ModSqrt(&ai.V, ai.M)
i.M = ai.M
return out != nil
Expand Down
16 changes: 8 additions & 8 deletions group/p256/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (P *curvePoint) String() string {
}

func (P *curvePoint) Equal(P2 kyber.Point) bool {
cp2 := P2.(*curvePoint) //nolint:errcheck // V4 may bring better error handling
cp2 := P2.(*curvePoint) //nolint:errcheck // Design pattern to emulate generics

// Make sure both coordinates are normalized.
// Apparently Go's elliptic curve code doesn't always ensure this.
Expand Down Expand Up @@ -134,17 +134,17 @@ func (P *curvePoint) Data() ([]byte, error) {
}

func (P *curvePoint) Add(A, B kyber.Point) kyber.Point {
ca := A.(*curvePoint) //nolint:errcheck // V4 may bring better error handling
cb := B.(*curvePoint) //nolint:errcheck // V4 may bring better error handling
ca := A.(*curvePoint) //nolint:errcheck // Design pattern to emulate generics
cb := B.(*curvePoint) //nolint:errcheck // Design pattern to emulate generics
P.x, P.y = P.c.Add(ca.x, ca.y, cb.x, cb.y)
return P
}

func (P *curvePoint) Sub(A, B kyber.Point) kyber.Point {
ca := A.(*curvePoint) //nolint:errcheck // V4 may bring better error handling
cb := B.(*curvePoint) //nolint:errcheck // V4 may bring better error handling
ca := A.(*curvePoint) //nolint:errcheck // Design pattern to emulate generics
cb := B.(*curvePoint) //nolint:errcheck // Design pattern to emulate generics

cbn := P.c.Point().Neg(cb).(*curvePoint) //nolint:errcheck // V4 may bring better error handling
cbn := P.c.Point().Neg(cb).(*curvePoint) //nolint:errcheck // Design pattern to emulate generics
P.x, P.y = P.c.Add(ca.x, ca.y, cbn.x, cbn.y)
return P
}
Expand All @@ -156,9 +156,9 @@ func (P *curvePoint) Neg(A kyber.Point) kyber.Point {
}

func (P *curvePoint) Mul(s kyber.Scalar, B kyber.Point) kyber.Point {
cs := s.(*mod.Int) //nolint:errcheck // V4 may bring better error handling
cs := s.(*mod.Int) //nolint:errcheck // Design pattern to emulate generics
if B != nil {
cb := B.(*curvePoint) //nolint:errcheck // V4 may bring better error handling
cb := B.(*curvePoint) //nolint:errcheck // Design pattern to emulate generics
P.x, P.y = P.c.ScalarMult(cb.x, cb.y, cs.V.Bytes())
} else {
P.x, P.y = P.c.ScalarBaseMult(cs.V.Bytes())
Expand Down
Loading