arnaucube
arnaucube/go-iden3-cryptoPublic Self-hosted repository
Fix linters errors
Eduard S eduard@iden3.io
Tue, 14 Apr 2020 16:47:24 +0200
commit

0ac8b4649357603ffbbce5b0861a4be2a50fbd58

parent

14d09916cf2fa0fcab28921bbd929dc0dc20b975

M babyjub/babyjub.go → babyjub/babyjub.go

@@ -154,10 +154,7 @@

// PointCoordSign returns the sign of the curve point coordinate. It returns // false if the sign is positive and false if the sign is negative. func PointCoordSign(c *big.Int) bool { - if c.Cmp(new(big.Int).Rsh(constants.Q, 1)) == 1 { - return true - } - return false + return c.Cmp(new(big.Int).Rsh(constants.Q, 1)) == 1 } func PackPoint(ay *big.Int, sign bool) [32]byte {
M babyjub/eddsa_test.go → babyjub/eddsa_test.go

@@ -1,7 +1,6 @@

package babyjub import ( - "crypto/rand" "encoding/hex" "fmt" "math/big"

@@ -10,25 +9,13 @@

"github.com/iden3/go-iden3-crypto/constants" "github.com/iden3/go-iden3-crypto/utils" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func genInputs() (*PrivateKey, *big.Int) { - k := NewRandPrivKey() - fmt.Println("k", hex.EncodeToString(k[:])) - - msgBuf := [32]byte{} - rand.Read(msgBuf[:]) - msg := utils.SetBigIntFromLEBytes(new(big.Int), msgBuf[:]) - msg.Mod(msg, constants.Q) - fmt.Println("msg", msg) - - return &k, msg -} - func TestPublicKey(t *testing.T) { var k PrivateKey - for i := 0; i < 256; i++ { - hex.Decode(k[:], []byte{byte(i)}) + for i := 0; i < 32; i++ { + k[i] = byte(i) } pk := k.Public() assert.True(t, pk.X.Cmp(constants.Q) == -1)

@@ -37,7 +24,8 @@ }

func TestSignVerifyMimc7(t *testing.T) { var k PrivateKey - hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + _, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + require.Nil(t, err) msgBuf, err := hex.DecodeString("00010203040506070809") if err != nil { panic(err)

@@ -81,7 +69,8 @@ }

func TestSignVerifyPoseidon(t *testing.T) { var k PrivateKey - hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + _, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + require.Nil(t, err) msgBuf, err := hex.DecodeString("00010203040506070809") if err != nil { panic(err)

@@ -125,7 +114,8 @@ }

func TestCompressDecompress(t *testing.T) { var k PrivateKey - hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + _, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + require.Nil(t, err) pk := k.Public() for i := 0; i < 64; i++ { msgBuf, err := hex.DecodeString(fmt.Sprintf("000102030405060708%02d", i))

@@ -144,7 +134,8 @@ }

func BenchmarkBabyjubEddsa(b *testing.B) { var k PrivateKey - hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + _, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001")) + require.Nil(b, err) pk := k.Public() const n = 256
M babyjub/helpers.go → babyjub/helpers.go

@@ -8,6 +8,9 @@ // Blake512 performs the blake-512 hash over the buffer m. Note that this is

// the original blake from the SHA3 competition and not the new blake2 version. func Blake512(m []byte) []byte { h := blake512.New() - h.Write(m[:]) + _, err := h.Write(m[:]) + if err != nil { + panic(err) + } return h.Sum(nil) }
M mimc7/mimc7_test.go → mimc7/mimc7_test.go

@@ -87,6 +87,6 @@ b41 := big.NewInt(int64(41))

bigArray4 := []*big.Int{b12, b45, b78, b41} for i := 0; i < b.N; i++ { - Hash(bigArray4, nil) + Hash(bigArray4, nil) //nolint:errcheck } }
M poseidon/poseidon_test.go → poseidon/poseidon_test.go

@@ -104,7 +104,7 @@ b41 := big.NewInt(int64(41))

bigArray4 := []*big.Int{b12, b45, b78, b41} for i := 0; i < b.N; i++ { - Hash(bigArray4) + Hash(bigArray4) //nolint:errcheck } }

@@ -117,6 +117,6 @@

bigArray4 := []*big.Int{b12, b45, b78, b41} for i := 0; i < b.N; i++ { - Hash(bigArray4) + Hash(bigArray4) //nolint:errcheck } }
M utils/utils.go → utils/utils.go

@@ -66,9 +66,7 @@ }

// HexDecode decodes a hex string into an array of bytes. func HexDecode(h string) ([]byte, error) { - if strings.HasPrefix(h, "0x") { - h = h[2:] - } + h = strings.TrimPrefix(h, "0x") return hex.DecodeString(h) }

@@ -92,10 +90,7 @@ }

// CheckBigIntInField checks if given *big.Int fits in a Field Q element func CheckBigIntInField(a *big.Int) bool { - if a.Cmp(constants.Q) != -1 { - return false - } - return true + return a.Cmp(constants.Q) == -1 } // CheckBigIntArrayInField checks if given *big.Int fits in a Field Q element