mirror of
https://github.com/arnaucube/go-iden3-crypto.git
synced 2026-02-07 11:36:41 +01:00
Fix linters errors
This commit is contained in:
@@ -154,10 +154,7 @@ func (p *Point) InSubGroup() bool {
|
||||
// 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 {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package babyjub
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/big"
|
||||
@@ -10,25 +9,13 @@ import (
|
||||
"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 TestPublicKey(t *testing.T) {
|
||||
|
||||
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 TestSignVerifyMimc7(t *testing.T) {
|
||||
|
||||
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 TestSignVerifyPoseidon(t *testing.T) {
|
||||
|
||||
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 TestCompressDecompress(t *testing.T) {
|
||||
|
||||
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
|
||||
|
||||
@@ -8,6 +8,9 @@ import (
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user