crypto: use golangci-lint (#20295)

This commit is contained in:
Daniel Liu 2024-11-29 16:08:31 +08:00
parent e1eb00ef99
commit 6033722b72
2 changed files with 6 additions and 22 deletions

View file

@ -19,17 +19,18 @@
// Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
package bn256 package bn256
import "github.com/XinFinOrg/XDPoSChain/crypto/bn256/cloudflare" import (
bn256cf "github.com/XinFinOrg/XDPoSChain/crypto/bn256/cloudflare"
)
// G1 is an abstract cyclic group. The zero value is suitable for use as the // G1 is an abstract cyclic group. The zero value is suitable for use as the
// output of an operation, but cannot be used as an input. // output of an operation, but cannot be used as an input.
type G1 = bn256.G1 type G1 = bn256cf.G1
// G2 is an abstract cyclic group. The zero value is suitable for use as the // G2 is an abstract cyclic group. The zero value is suitable for use as the
// output of an operation, but cannot be used as an input. // output of an operation, but cannot be used as an input.
type G2 = bn256.G2 type G2 = bn256cf.G2
// PairingCheck calculates the Optimal Ate pairing for a set of points. // PairingCheck calculates the Optimal Ate pairing for a set of points.
func PairingCheck(a []*G1, b []*G2) bool { func PairingCheck(a []*G1, b []*G2) bool {
return bn256.PairingCheck(a, b) return bn256cf.PairingCheck(a, b)
} }

View file

@ -36,7 +36,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt"
"math/big" "math/big"
"testing" "testing"
@ -67,22 +66,6 @@ func cmpParams(p1, p2 *ECIESParams) bool {
p1.BlockSize == p2.BlockSize p1.BlockSize == p2.BlockSize
} }
// cmpPublic returns true if the two public keys represent the same pojnt.
func cmpPublic(pub1, pub2 PublicKey) bool {
if pub1.X == nil || pub1.Y == nil {
fmt.Println(ErrInvalidPublicKey.Error())
return false
}
if pub2.X == nil || pub2.Y == nil {
fmt.Println(ErrInvalidPublicKey.Error())
return false
}
pub1Out := elliptic.Marshal(pub1.Curve, pub1.X, pub1.Y)
pub2Out := elliptic.Marshal(pub2.Curve, pub2.X, pub2.Y)
return bytes.Equal(pub1Out, pub2Out)
}
// Validate the ECDH component. // Validate the ECDH component.
func TestSharedKey(t *testing.T) { func TestSharedKey(t *testing.T) {
prv1, err := GenerateKey(rand.Reader, DefaultCurve, nil) prv1, err := GenerateKey(rand.Reader, DefaultCurve, nil)