From a58a1e84efde2d1435a327c42d3bd4e071003904 Mon Sep 17 00:00:00 2001 From: tnasu Date: Thu, 10 Mar 2022 12:57:36 +0900 Subject: [PATCH 1/5] Imporve using require --- crypto/vrf/internal/vrf/vrf_test.go | 157 +++++++--------------------- 1 file changed, 39 insertions(+), 118 deletions(-) diff --git a/crypto/vrf/internal/vrf/vrf_test.go b/crypto/vrf/internal/vrf/vrf_test.go index 478620468..22a081f63 100644 --- a/crypto/vrf/internal/vrf/vrf_test.go +++ b/crypto/vrf/internal/vrf/vrf_test.go @@ -4,8 +4,8 @@ package vrf import ( - "bytes" "encoding/hex" + "github.com/stretchr/testify/require" "math/rand" "testing" ) @@ -30,110 +30,59 @@ func enc(s []byte) string { } func TestConstants(t *testing.T) { - t.Logf("PUBLICKEYBYTES: %d\n", PUBLICKEYBYTES) - t.Logf("SECRETKEYBYTES: %d\n", SECRETKEYBYTES) - t.Logf("SEEDBYTES: %d\n", SEEDBYTES) - t.Logf("PROOFBYTES: %d\n", PROOFBYTES) - t.Logf("OUTPUTBYTES: %d\n", OUTPUTBYTES) - t.Logf("PRIMITIVE: %s\n", PRIMITIVE) - - if PUBLICKEYBYTES != 32 { - t.Errorf("public key size: %d != 32\n", PUBLICKEYBYTES) - } - if SECRETKEYBYTES != 64 { - t.Errorf("secret key size: %d != 64\n", SECRETKEYBYTES) - } - if SEEDBYTES != 32 { - t.Errorf("seed size: %d != 32\n", SEEDBYTES) - } - if OUTPUTBYTES != 64 { - t.Errorf("output size: %d != 64\n", OUTPUTBYTES) - } - if PRIMITIVE != "ietfdraft03" { - t.Errorf("primitive: %s != \"ietfdraft03\"\n", PRIMITIVE) - } + require.Equal(t, uint32(32), PUBLICKEYBYTES) + require.Equal(t, uint32(64), SECRETKEYBYTES) + require.Equal(t, uint32(32), SEEDBYTES) + require.Equal(t, uint32(64), OUTPUTBYTES) + require.Equal(t, "ietfdraft03", PRIMITIVE) } func TestKeyPair(t *testing.T) { var pk, sk = KeyPair() - t.Logf("random public key: %s (%d bytes)\n", enc(pk[:]), len(pk)) - t.Logf("random private key: %s (%d bytes)\n", enc(sk[:]), len(sk)) - if uint32(len(pk)) != PUBLICKEYBYTES { - t.Errorf("public key size: %d != %d", len(pk), PUBLICKEYBYTES) - } - if uint32(len(sk)) != SECRETKEYBYTES { - t.Errorf("secret key size: %d != %d", len(sk), SECRETKEYBYTES) - } + require.Equal(t, PUBLICKEYBYTES, uint32(len(pk))) + require.Equal(t, SECRETKEYBYTES, uint32(len(sk))) } func TestKeyPairFromSeed(t *testing.T) { + pkStr := "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29" + skStr := "0000000000000000000000000000000000000000000000000000000000000000" + pkStr var seed [SEEDBYTES]byte var pk, sk = KeyPairFromSeed(&seed) - t.Logf("static seed: %s (%d bytes)\n", enc(seed[:]), len(seed)) - t.Logf("static public key: %s (%d bytes)\n", enc(pk[:]), len(pk)) - t.Logf("static private key: %s (%d bytes)\n", enc(sk[:]), len(sk)) - if enc(pk[:]) != "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29" { - t.Errorf("unexpected public key: %s", enc(pk[:])) - } - if enc(sk[:]) != "0000000000000000000000000000000000000000000000000000000000000000"+ - "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29" { - t.Errorf("unexpected private key: %s", enc(sk[:])) - } - if uint32(len(pk)) != PUBLICKEYBYTES { - t.Errorf("public key size: %d != %d", len(pk), PUBLICKEYBYTES) - } - if uint32(len(sk)) != SECRETKEYBYTES { - t.Errorf("secret key size: %d != %d", len(sk), SECRETKEYBYTES) - } + require.Equal(t, PUBLICKEYBYTES, uint32(len(pk))) + require.Equal(t, pkStr, enc(pk[:])) + require.Equal(t, SECRETKEYBYTES, uint32(len(sk))) + require.Equal(t, skStr, enc(sk[:])) var message [0]byte var proof, err1 = Prove(sk, message[:]) - if err1 != nil { - t.Errorf("probe failed: %s", err1) - } - t.Logf("proof: %s (%d bytes)\n", enc(proof[:]), len(proof)) - if uint32(len(proof)) != PROOFBYTES { - t.Errorf("proof size: %d != %d", len(proof), PROOFBYTES) - } + require.NoError(t, err1) + require.Equal(t, PROOFBYTES, uint32(len(proof))) var output, err2 = ProofToHash(proof) - if err2 != nil { - t.Errorf("failed to hash proof: %s", err2) - } - t.Logf("output: %s (%d bytes)\n", enc(output[:]), len(output)) - if uint32(len(output)) != OUTPUTBYTES { - t.Errorf("output size: %d != %d", len(output), OUTPUTBYTES) - } + require.NoError(t, err2) + require.Equal(t, OUTPUTBYTES, uint32(len(output))) } func TestIsValidKey(t *testing.T) { // generated from KeyPair() var pk1, _ = KeyPair() - if !IsValidKey(pk1) { - t.Errorf("public key is not valid: %s", enc(pk1[:])) - } + require.True(t, IsValidKey(pk1)) // generated from KeyPairFromSeed() var seed [SEEDBYTES]byte var pk2, _ = KeyPairFromSeed(&seed) - if !IsValidKey(pk2) { - t.Errorf("public key is not valid: %s", enc(pk2[:])) - } + require.True(t, IsValidKey(pk2)) // zero var zero [PUBLICKEYBYTES]byte - if IsValidKey(&zero) { - t.Error("recognized as valid for zero pk") - } + require.False(t, IsValidKey(&zero)) // random bytes var random [PUBLICKEYBYTES]byte var rng = rand.New(rand.NewSource(0)) rng.Read(random[:]) - if IsValidKey(&random) { - t.Errorf("recognized as valid for random pk: %s", enc(random[:])) - } + require.False(t, IsValidKey(&zero)) } func TestInternalProveAndVerify(t *testing.T) { @@ -141,30 +90,20 @@ func TestInternalProveAndVerify(t *testing.T) { var zero [SEEDBYTES]byte var pk, sk = KeyPairFromSeed(&zero) - - t.Logf("private key: [%s]", enc(sk[:])) - t.Logf("public key: [%s]", enc(pk[:])) + require.Equal(t, PUBLICKEYBYTES, uint32(len(pk))) + require.Equal(t, SECRETKEYBYTES, uint32(len(sk))) var proof, err1 = Prove(sk, message) - if err1 != nil { - t.Errorf("probe failed: %s", err1) - } - - t.Logf("proof: %s", enc(proof[:])) + require.NoError(t, err1) + require.Equal(t, PROOFBYTES, uint32(len(proof))) var output, err2 = ProofToHash(proof) - if err2 != nil { - t.Errorf("failed to hash proof: %s", err2) - } + require.NoError(t, err2) + require.Equal(t, OUTPUTBYTES, uint32(len(output))) - t.Logf("output:[%s] from message:[%s]", enc(output[:]), enc(message)) - - var expected, err3 = Verify(pk, proof, message) - if err3 != nil { - t.Errorf("validation failed: %s", err3) - } else if bytes.Compare(expected[:], output[:]) != 0 { - t.Errorf("output not matches: %s", enc(output[:])) - } + var verified, err3 = Verify(pk, proof, message) + require.NoError(t, err3) + require.Equal(t, output[:], verified[:]) // essentially, the private key for ed25519 could be any value at a point on the finite field. var invalidPrivateKey [SECRETKEYBYTES]byte @@ -172,30 +111,22 @@ func TestInternalProveAndVerify(t *testing.T) { invalidPrivateKey[i] = 0xFF } var _, err4 = Prove(&invalidPrivateKey, message) - if err4 == nil { - t.Errorf("Prove() with invalid private key didn't fail") - } + require.Error(t, err4) // unexpected public key for Verify() var zero3 [PUBLICKEYBYTES]byte var _, err5 = Verify(&zero3, proof, message) - if err5 == nil { - t.Errorf("Verify() with zero public key didn't fail") - } + require.Error(t, err5) // unexpected proof for Verify() var zero4 [PROOFBYTES]byte var _, err6 = Verify(pk, &zero4, message) - if err6 == nil { - t.Errorf("Verify() with zero proof didn't fail") - } + require.Error(t, err6) // unexpected message for Verify() var message2 = []byte("good-by world") - var output2, err7 = Verify(pk, proof, message2) - if err7 == nil { - t.Errorf("Verify() success without error: %s", enc(output2[:])) - } + var _, err7 = Verify(pk, proof, message2) + require.Error(t, err7) // essentially, the proof for ed25519 could be any value at a point on the finite field. var invalidProof [PROOFBYTES]byte @@ -203,29 +134,19 @@ func TestInternalProveAndVerify(t *testing.T) { invalidProof[i] = 0xFF } var _, err8 = ProofToHash(&invalidProof) - if err8 == nil { - t.Errorf("ProofToHash() with invalid proof didn't fail") - } + require.Error(t, err8) } func TestSkToPk(t *testing.T) { var zero [SEEDBYTES]byte var expected, sk = KeyPairFromSeed(&zero) - var actual = SkToPk(sk) - - if bytes.Compare(expected[:], actual[:]) != 0 { - t.Errorf("public key didn't match: %s != %s", enc(expected[:]), enc(actual[:])) - } + require.Equal(t, expected[:], actual[:]) } func TestSkToSeed(t *testing.T) { var zero [SEEDBYTES]byte var _, sk = KeyPairFromSeed(&zero) - var actual = SkToSeed(sk) - - if bytes.Compare(zero[:], actual[:]) != 0 { - t.Errorf("seed didn't match: %s != %s", enc(zero[:]), enc(actual[:])) - } + require.Equal(t, zero[:], actual[:]) } From 5b922657bde14dece7ef7be21ef198e9540df9b9 Mon Sep 17 00:00:00 2001 From: tnasu Date: Thu, 10 Mar 2022 12:58:51 +0900 Subject: [PATCH 2/5] Improve using require and leave the comment for TestAvalancheEffect --- crypto/vrf/vrf_test.go | 52 +++++++++++------------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/crypto/vrf/vrf_test.go b/crypto/vrf/vrf_test.go index 432a95572..1afef9f91 100644 --- a/crypto/vrf/vrf_test.go +++ b/crypto/vrf/vrf_test.go @@ -2,8 +2,6 @@ package vrf import ( "crypto/ed25519" - "encoding/hex" - "fmt" "testing" "github.com/stretchr/testify/require" @@ -28,26 +26,15 @@ var ( } ) -func enc(s []byte) string { - return hex.EncodeToString(s) -} - func proveAndVerify(t *testing.T, privateKey, publicKey []byte) (bool, error) { - t.Logf("private key: %s (%d bytes)\n", enc(privateKey), len(privateKey)) - t.Logf("public key: %s (%d bytes)\n", enc(privateKey), len(privateKey)) - message := []byte("hello, world") proof, err1 := Prove(privateKey, message) - if err1 != nil { - t.Fatalf("failed to prove: %s", err1) - } - t.Logf("proof: %s (%d bytes)\n", enc(proof[:]), len(proof)) + require.NoError(t, err1) + require.NotNil(t, proof) output, err2 := ProofToHash(proof) - if err2 != nil { - t.Fatalf("failed to hash: %s", err2) - } - t.Logf("output: %s (%d bytes)\n", enc(output[:]), len(output)) + require.NoError(t, err2) + require.NotNil(t, output) return Verify(publicKey, proof, message) } @@ -60,12 +47,8 @@ func TestProveAndVerify(t *testing.T) { publicKey := privateKey.Public().(ed25519.PublicKey) verified, err := proveAndVerify(t, privateKey, publicKey) - - if err != nil { - t.Fatalf("failed to verify: %s", err) - } else if !verified { - t.Fatalf("incompatible output") - } + require.NoError(t, err) + require.True(t, verified) } func BenchmarkProveAndVerify(b *testing.B) { @@ -82,18 +65,17 @@ func BenchmarkProveAndVerify(b *testing.B) { proof, err = Prove(privateKey, message) } }) - if err != nil { - panic(err) - } + require.NoError(b, err) b.Run("VRF verify", func(b *testing.B) { b.ResetTimer() _, err = Verify(publicKey, proof, message) }) - if err != nil { - panic(err) - } + require.NoError(b, err) } +// Test avalanche effect for VRF prove hash +// https://en.wikipedia.org/wiki/Avalanche_effect +// Test the quality of the VRF prove hash generated by the external library(r2ishiguro, libsodium, and etc.) as a pseudo-random number func TestAvalancheEffect(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey := ed25519.NewKeyFromSeed(secret[:]) @@ -106,10 +88,7 @@ func TestAvalancheEffect(t *testing.T) { hash, err := ProofToHash(proof) require.NoError(t, err) - var avalanche []float32 n := len(message) * 8 - avalanche = make([]float32, n) - for i := 0; i < n; i++ { old := message[i/8] message[i/8] ^= byte(uint(1) << (uint(i) % uint(8))) // modify 1 bit @@ -119,17 +98,12 @@ func TestAvalancheEffect(t *testing.T) { hash2, err := ProofToHash(proof2) require.NoError(t, err) - avalanche[i] = getAvalanche(hash, hash2) + // test + require.InDelta(t, 0.5, getAvalanche(hash, hash2), 0.13) // restore old value message[i/8] = old } - - var result string - for j := 0; j < n; j++ { - result = fmt.Sprintf("%s, %.2f", result, avalanche[j]) - } - t.Logf(result) } } From 838e544cf496e847b378441861f5d38efa36db15 Mon Sep 17 00:00:00 2001 From: tnasu Date: Thu, 10 Mar 2022 13:06:33 +0900 Subject: [PATCH 3/5] Refactor separate into compatibility test --- crypto/vrf/compatibility_keys_test.go | 204 ++++++++++++++++++++++++++ crypto/vrf/compatibility_vrf_test.go | 44 ++++++ crypto/vrf/keygen_test.go | 86 ----------- crypto/vrf/vrf_coniks_test.go | 43 +----- crypto/vrf/vrf_libsodium.go | 5 +- crypto/vrf/vrf_libsodium_test.go | 84 ++--------- crypto/vrf/vrf_r2ishiguro.go | 1 - crypto/vrf/vrf_r2ishiguro_test.go | 24 +++ crypto/vrf/vrf_test.go | 4 +- 9 files changed, 295 insertions(+), 200 deletions(-) create mode 100644 crypto/vrf/compatibility_keys_test.go create mode 100644 crypto/vrf/compatibility_vrf_test.go delete mode 100644 crypto/vrf/keygen_test.go create mode 100644 crypto/vrf/vrf_r2ishiguro_test.go diff --git a/crypto/vrf/compatibility_keys_test.go b/crypto/vrf/compatibility_keys_test.go new file mode 100644 index 000000000..650dd71cd --- /dev/null +++ b/crypto/vrf/compatibility_keys_test.go @@ -0,0 +1,204 @@ +//go:build libsodium +// +build libsodium + +package vrf + +import ( + "bytes" + "crypto/ed25519" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + coniks "github.com/coniks-sys/coniks-go/crypto/vrf" + libsodium "github.com/line/ostracon/crypto/vrf/internal/vrf" + xed25519 "golang.org/x/crypto/ed25519" +) + +var secret [SEEDBYTES]byte +var message []byte = []byte("hello, world") + +func TestKeygen(t *testing.T) { + + privateKey, publicKey := keygen_ed25519(secret) + + t.Run("ed25519 and x/ed25519 have compatibility", + func(t *testing.T) { + testKeygen_compatibility(t, privateKey, publicKey, + keygen_xed25519, require.Equal, require.Equal) + }) + t.Run("ed25519 and coniks have NOT compatibility", + func(t *testing.T) { + testKeygen_compatibility(t, privateKey, publicKey, + keygen_coniks_ed25519, require.NotEqual, require.NotEqual) + }) + t.Run("ed25519 and libsodium have compatibility", + func(t *testing.T) { + testKeygen_compatibility(t, privateKey, publicKey, + keygen_libsodium_ed25519, require.Equal, require.Equal) + }) +} + +func testKeygen_compatibility( + t *testing.T, + sk1 ed25519.PrivateKey, pk1 ed25519.PublicKey, + keyGen2 func(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey), + skTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), + pkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), +) { + sk2, pk2 := keyGen2(secret) + skTest(t, sk1, sk2) + pkTest(t, pk1, pk2) +} + +func keygen_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { + privateKey := ed25519.NewKeyFromSeed(secret[:]) + publicKey := privateKey.Public().(ed25519.PublicKey) + return privateKey, publicKey +} + +func keygen_xed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { + publicKey, privateKey, _ := xed25519.GenerateKey(bytes.NewReader(secret[:])) + return privateKey, publicKey +} + +func keygen_coniks_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { + privKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) + pubKey, _ := privKey.Public() + privateKey := make([]byte, coniks.PrivateKeySize) + copy(privateKey, privKey[:]) + publicKey := make([]byte, coniks.PublicKeySize) + copy(publicKey, pubKey[:]) + return privateKey, publicKey +} + +func keygen_libsodium_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { + var seed [libsodium.SEEDBYTES]byte + copy(seed[:], secret[:]) + pubKey, privKey := libsodium.KeyPairFromSeed(&seed) + privateKey := make([]byte, libsodium.SECRETKEYBYTES) + copy(privateKey, privKey[:]) + publicKey := make([]byte, libsodium.PUBLICKEYBYTES) + copy(publicKey, pubKey[:]) + return privateKey, publicKey +} + +func TestKeypair(t *testing.T) { + privateKey, publicKey := keygen_ed25519(secret) + + t.Run("ed25519 and x/ed25519 have compatibility", + func(t *testing.T) { + testKeypair_compatibility_xed25519(t, privateKey, publicKey, + require.EqualValues, require.EqualValues) + }) + t.Run("ed25519 and coniks have NOT compatibility", + func(t *testing.T) { + testKeypair_compatibility_coniks_ed25519(t, privateKey, publicKey, + require.EqualValues, require.NotEqualValues) + }) + t.Run("ed25519 and libsodium have compatibility", + func(t *testing.T) { + testKeypair_compatibility_libsodium_ed25519(t, privateKey, publicKey, + require.EqualValues, require.EqualValues) + }) +} + +func testKeypair_compatibility_xed25519( + t *testing.T, + sk ed25519.PrivateKey, pk ed25519.PublicKey, + toPkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), + fromSkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), +) { + pk1, sk1, _ := xed25519.GenerateKey(bytes.NewReader(secret[:])) + + sk2 := ed25519.PrivateKey(make([]byte, ed25519.PrivateKeySize)) + copy(sk2[:], sk1[:]) + pk2 := sk2.Public().(ed25519.PublicKey) + + toPkTest(t, pk1[:], pk2[:]) + + copy(sk1[:], sk[:]) + pk1 = sk1.Public().(xed25519.PublicKey) + + fromSkTest(t, pk1[:], pk2[:]) +} + +func testKeypair_compatibility_coniks_ed25519( + t *testing.T, + sk ed25519.PrivateKey, pk ed25519.PublicKey, + toPkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), + fromSkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), +) { + sk1, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) + pk1, _ := sk1.Public() + + sk2 := ed25519.PrivateKey(make([]byte, ed25519.PrivateKeySize)) + copy(sk2[:], sk1[:]) + pk2 := sk2.Public().(ed25519.PublicKey) + + toPkTest(t, pk1[:], pk2[:]) + + copy(sk1[:], sk[:]) + pk1, _ = sk1.Public() + + fromSkTest(t, pk1[:], pk2[:]) +} + +func testKeypair_compatibility_libsodium_ed25519( + t *testing.T, + sk ed25519.PrivateKey, pk ed25519.PublicKey, + toPkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), + fromSkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), +) { + var seed [libsodium.SEEDBYTES]byte + copy(seed[:], secret[:]) + pk1, sk1 := libsodium.KeyPairFromSeed(&seed) + + sk2 := ed25519.PrivateKey(make([]byte, ed25519.PrivateKeySize)) + copy(sk2[:], sk1[:]) + pk2 := sk2.Public().(ed25519.PublicKey) + + toPkTest(t, pk1[:], pk2[:]) + + copy(sk1[:], sk[:]) + pk1 = libsodium.SkToPk(sk1) + + fromSkTest(t, pk1[:], pk2[:]) +} + +func TestSignVerify(t *testing.T) { + sk, pk := keygen_ed25519(secret) + t.Run("ed25519 and xed25119 have compatibility", func(t *testing.T) { + pk1, sk1, _ := xed25519.GenerateKey(bytes.NewReader(secret[:])) + + signature := ed25519.Sign(sk, message) + valid := xed25519.Verify(pk1, message, signature) + assert.True(t, valid) + + signature = xed25519.Sign(sk1, message) + valid = ed25519.Verify(pk, message, signature) + assert.True(t, valid) + }) +} + +func BenchmarkKeyGen_ed25519(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + keygen_ed25519(secret) + } +} + +func BenchmarkKeyGen_coniks_ed25519(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + keygen_coniks_ed25519(secret) + } +} + +func BenchmarkKeyGen_libsodium_ed25519(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + keygen_libsodium_ed25519(secret) + } +} diff --git a/crypto/vrf/compatibility_vrf_test.go b/crypto/vrf/compatibility_vrf_test.go new file mode 100644 index 000000000..96ad9d3ab --- /dev/null +++ b/crypto/vrf/compatibility_vrf_test.go @@ -0,0 +1,44 @@ +//go:build libsodium +// +build libsodium + +package vrf + +import ( + "crypto/ed25519" + "testing" + + "github.com/stretchr/testify/require" + + r2ishiguro "github.com/r2ishiguro/vrf/go/vrf_ed25519" +) + +func TestProveAndVerifyCompatibility(t *testing.T) { + privateKey := ed25519.NewKeyFromSeed(secret[:]) + publicKey := privateKey.Public().(ed25519.PublicKey) + + sk := make([]byte, ed25519.PrivateKeySize) + copy(sk, privateKey[:]) + pk := make([]byte, ed25519.PublicKeySize) + copy(pk, publicKey[:]) + + libsodiumImpl := newVrfEd25519libsodium() + + t.Run("libsodium.Prove and r2ishiguro.Verify have NOT compatibility", func(t *testing.T) { + proof, err := libsodiumImpl.Prove(sk, message) + require.NoError(t, err) + require.NotNil(t, proof) + + valid, err := r2ishiguro.ECVRF_verify(pk, proof, message) + require.Error(t, err) + require.False(t, valid) + }) + t.Run("r2ishiguro.Prove and libsodium.Verify have NOT compatibility", func(t *testing.T) { + proof, err := r2ishiguro.ECVRF_prove(pk, sk, message) + require.NoError(t, err) + require.NotNil(t, proof) + + valid, err := libsodiumImpl.Verify(pk, proof, message) + require.Error(t, err) + require.False(t, valid) + }) +} diff --git a/crypto/vrf/keygen_test.go b/crypto/vrf/keygen_test.go deleted file mode 100644 index dd713639f..000000000 --- a/crypto/vrf/keygen_test.go +++ /dev/null @@ -1,86 +0,0 @@ -//go:build libsodium -// +build libsodium - -package vrf - -import ( - "bytes" - "crypto/ed25519" - "github.com/stretchr/testify/require" - "testing" - - coniks "github.com/coniks-sys/coniks-go/crypto/vrf" - libsodium "github.com/line/ostracon/crypto/vrf/internal/vrf" -) - -var secret [SEEDBYTES]byte -var message []byte = []byte("hello, world") - -func keyGen_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { - privateKey := ed25519.NewKeyFromSeed(secret[:]) - publicKey := privateKey.Public().(ed25519.PublicKey) - return privateKey, publicKey -} - -func keyGen_coniks_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { - privKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) - pubKey, _ := privKey.Public() - privateKey := make([]byte, coniks.PrivateKeySize) - copy(privateKey, privKey[:]) - publicKey := make([]byte, coniks.PublicKeySize) - copy(publicKey, pubKey[:]) - return privateKey, publicKey -} - -func keyGen_libsodium_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { - var seed [libsodium.SEEDBYTES]byte - copy(seed[:], secret[:]) - pubKey, privKey := libsodium.KeyPairFromSeed(&seed) - privateKey := make([]byte, libsodium.SECRETKEYBYTES) - copy(privateKey, privKey[:]) - publicKey := make([]byte, libsodium.PUBLICKEYBYTES) - copy(publicKey, pubKey[:]) - return privateKey, publicKey -} - -func TestKeyGen(t *testing.T) { - t.Logf("secret: [%s]", enc(secret[:])) - - privateKey, publicKey := keyGen_ed25519(secret) - t.Logf("[ed25519 ]private key: [%s]", enc(privateKey[:])) - t.Logf("[ed25519 ]public key: [%s]", enc(publicKey[:])) - - coniksPrivateKey, coniksPublicKey := keyGen_coniks_ed25519(secret) - t.Logf("[coniks ]private key: [%s]", enc(coniksPrivateKey[:])) - t.Logf("[coniks ]public key: [%s]", enc(coniksPublicKey[:])) - - libsodiumPrivateKey, libsodiumPublicKey := keyGen_libsodium_ed25519(secret) - t.Logf("[libsodium]private key: [%s]", enc(libsodiumPrivateKey[:])) - t.Logf("[libsodium]public key: [%s]", enc(libsodiumPublicKey[:])) - - require.NotEqual(t, privateKey, coniksPrivateKey) - require.NotEqual(t, publicKey, coniksPublicKey) - require.Equal(t, privateKey, libsodiumPrivateKey) - require.Equal(t, publicKey, libsodiumPublicKey) -} - -func BenchmarkKeyGenED25519(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - keyGen_ed25519(secret) - } -} - -func BenchmarkKeyGenConiksED25519(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - keyGen_coniks_ed25519(secret) - } -} - -func BenchmarkKeyGenLibsodiumED25519(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - keyGen_libsodium_ed25519(secret) - } -} diff --git a/crypto/vrf/vrf_coniks_test.go b/crypto/vrf/vrf_coniks_test.go index 51bb9087f..f328f5f93 100644 --- a/crypto/vrf/vrf_coniks_test.go +++ b/crypto/vrf/vrf_coniks_test.go @@ -13,58 +13,29 @@ import ( "github.com/stretchr/testify/require" ) -func TestKeyPairCompatibilityConiks(t *testing.T) { - secret := [SEEDBYTES]byte{} - privateKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) - publicKey, _ := privateKey.Public() - - privateKey2 := ed25519.PrivateKey(make([]byte, ed25519.PrivateKeySize)) - copy(privateKey2[:], privateKey[:]) - publicKey2 := privateKey2.Public().(ed25519.PublicKey) - if !bytes.Equal(publicKey, publicKey2[:]) { - t.Error("public key is not matched: using same private key which is generated by coniks", - "coniks.Public", enc(publicKey), "ed25519.Public", enc(publicKey2[:])) - } - - privateKey2 = ed25519.NewKeyFromSeed(secret[:]) - publicKey2, _ = privateKey2.Public().(ed25519.PublicKey) - - copy(privateKey, privateKey2[:]) - publicKey, _ = privateKey.Public() - if !bytes.Equal(publicKey, publicKey2[:]) { - t.Error("public key is not matched: using same private key which is generated by ed25519", - "coniks.Public", enc(publicKey), "ed25519.Public", enc(publicKey2[:])) - } - -} - -func TestProveAndVerify_ConiksByCryptoED25519(t *testing.T) { +func TestProveAndVerify_coniks_by_crypto_ed25519(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey := ed25519.NewKeyFromSeed(secret[:]) publicKey := privateKey.Public().(ed25519.PublicKey) verified, err := proveAndVerify(t, privateKey, publicKey) - if err != nil { - t.Fatalf("failed to verify: %s", err) - } // - // "un-verified" when using crypto ED25519 - // If you want to use coniks, you should use coniks ED25519 + // "un-verified" when using crypto ed25519 + // If you want to use coniks, you should use coniks ed25519 // + require.NoError(t, err) require.False(t, verified) } -func TestProveAndVerify_ConiksByConiksED25519(t *testing.T) { +func TestProveAndVerify_coniks_by_coniks_ed25519(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) publicKey, _ := privateKey.Public() verified, err := proveAndVerify(t, privateKey, publicKey) - if err != nil { - t.Fatalf("failed to verify: %s", err) - } // - // verified when using coniks ED25519 + // verified when using coniks ed25519 // + require.NoError(t, err) require.True(t, verified) } diff --git a/crypto/vrf/vrf_libsodium.go b/crypto/vrf/vrf_libsodium.go index cdc61d68c..033ca496f 100644 --- a/crypto/vrf/vrf_libsodium.go +++ b/crypto/vrf/vrf_libsodium.go @@ -1,12 +1,13 @@ //go:build libsodium // +build libsodium -// This libsodiumwrap package makes the VRF API in Algorand's libsodium C library available to golang. +// This libsodium wrap package makes the VRF API in Algorand's libsodium C library available to golang. package vrf import ( "bytes" + libsodium "github.com/line/ostracon/crypto/vrf/internal/vrf" ) @@ -17,7 +18,7 @@ func init() { defaultVrf = newVrfEd25519libsodium() } -func newVrfEd25519libsodium() vrfEd25519 { +func newVrfEd25519libsodium() vrfEd25519libsodium { return vrfEd25519libsodium{} } diff --git a/crypto/vrf/vrf_libsodium_test.go b/crypto/vrf/vrf_libsodium_test.go index ed6c051c9..046a6cd90 100644 --- a/crypto/vrf/vrf_libsodium_test.go +++ b/crypto/vrf/vrf_libsodium_test.go @@ -4,99 +4,35 @@ package vrf import ( - "bytes" "crypto/ed25519" - r2ishiguro "github.com/r2ishiguro/vrf/go/vrf_ed25519" - "github.com/stretchr/testify/require" "testing" - coniks "github.com/coniks-sys/coniks-go/crypto/vrf" + "github.com/stretchr/testify/require" + libsodium "github.com/line/ostracon/crypto/vrf/internal/vrf" ) -func TestKeyPairCompatibilityLibsodium(t *testing.T) { - secret := [libsodium.SEEDBYTES]byte{} - publicKey, privateKey := libsodium.KeyPairFromSeed(&secret) - - privateKey2 := ed25519.PrivateKey(make([]byte, 64)) - copy(privateKey2, privateKey[:]) - publicKey2 := privateKey2.Public().(ed25519.PublicKey) - - if !bytes.Equal(publicKey[:], publicKey2[:]) { - t.Error("public key is not matched: using same private key which is generated by libsodium", - "libsodium.Public", enc(publicKey[:]), "ed25519.Public", enc(publicKey2[:])) - } -} - -func TestProveAndVerify_LibsodiumByCryptoED25519(t *testing.T) { - secret := [libsodium.SEEDBYTES]byte{} +func TestProveAndVerify_libsodium_by_crypto_ed25519(t *testing.T) { + secret := [SEEDBYTES]byte{} privateKey := ed25519.NewKeyFromSeed(secret[:]) publicKey := privateKey.Public().(ed25519.PublicKey) verified, err := proveAndVerify(t, privateKey, publicKey) // - // verified when using crypto ED25519 + // verified when using crypto ed25519 // - require.Nil(t, err) + require.NoError(t, err) require.True(t, verified) } -func TestProveAndVerify_LibsodiumByConiksED25519(t *testing.T) { - secret := [libsodium.SEEDBYTES]byte{} - privateKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) - publicKey, _ := privateKey.Public() - - verified, err := proveAndVerify(t, privateKey, publicKey) - // - // "un-verified" when using coniks ED25519 - // If you want to use libsodium, you should use crypto/libsodium ED25519 - // - require.NotNil(t, err) - require.False(t, verified) -} - -func TestProveAndVerify_LibsodiumByLibsodiumED25519(t *testing.T) { - secret := [libsodium.SEEDBYTES]byte{} +func TestProveAndVerify_libsodium_by_libsodium_ed25519(t *testing.T) { + secret := [SEEDBYTES]byte{} publicKey, privateKey := libsodium.KeyPairFromSeed(&secret) verified, err := proveAndVerify(t, privateKey[:], publicKey[:]) // - // verified when using libsodium ED25519 + // verified when using libsodium ed25519 // - require.Nil(t, err) + require.NoError(t, err) require.True(t, verified) } - -func TestProveAndVerifyCompatibilityLibsodium(t *testing.T) { - secret := [libsodium.SEEDBYTES]byte{} - message := []byte("hello, world") - privateKey := ed25519.NewKeyFromSeed(secret[:]) - publicKey := privateKey.Public().(ed25519.PublicKey) - - libsodiumImpl := newVrfEd25519libsodium() - - { - proof, err := libsodiumImpl.Prove(privateKey, message) - require.Nil(t, err) - require.NotNil(t, proof) - - output, err := r2ishiguro.ECVRF_verify(publicKey, proof, message) - // - // No compatibility between libsodium.Prove and r2ishiguro.Verify - // - require.NotNil(t, err) - require.NotNil(t, output) - } - { - proof, err := r2ishiguro.ECVRF_prove(publicKey, privateKey, message) - require.Nil(t, err) - require.NotNil(t, proof) - - output, err := libsodiumImpl.Verify(publicKey, proof, message) - // - // No compatibility between r2ishiguro.Prove and libsodium.Verify - // - require.NotNil(t, err) - require.NotNil(t, output) - } -} diff --git a/crypto/vrf/vrf_r2ishiguro.go b/crypto/vrf/vrf_r2ishiguro.go index 8ec0544e3..6ea49af15 100644 --- a/crypto/vrf/vrf_r2ishiguro.go +++ b/crypto/vrf/vrf_r2ishiguro.go @@ -14,7 +14,6 @@ type vrfEd25519r2ishiguro struct { func init() { // if you use build option for other implementation, defaultVrf is overridden by other implementation. - // It may vrfEd25519libsodium if defaultVrf == nil { defaultVrf = newVrfEd25519r2ishiguro() } diff --git a/crypto/vrf/vrf_r2ishiguro_test.go b/crypto/vrf/vrf_r2ishiguro_test.go new file mode 100644 index 000000000..e4c97e837 --- /dev/null +++ b/crypto/vrf/vrf_r2ishiguro_test.go @@ -0,0 +1,24 @@ +//go:build !libsodium && !coniks +// +build !libsodium,!coniks + +package vrf + +import ( + "crypto/ed25519" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestProveAndVerify_r2ishiguro_by_crypto_ed25519(t *testing.T) { + secret := [SEEDBYTES]byte{} + privateKey := ed25519.NewKeyFromSeed(secret[:]) + publicKey := privateKey.Public().(ed25519.PublicKey) + + verified, err := proveAndVerify(t, privateKey, publicKey) + // + // verified when using crypto ed25519 + // + require.NoError(t, err) + require.True(t, verified) +} diff --git a/crypto/vrf/vrf_test.go b/crypto/vrf/vrf_test.go index 1afef9f91..ed0ecaaf0 100644 --- a/crypto/vrf/vrf_test.go +++ b/crypto/vrf/vrf_test.go @@ -75,7 +75,9 @@ func BenchmarkProveAndVerify(b *testing.B) { // Test avalanche effect for VRF prove hash // https://en.wikipedia.org/wiki/Avalanche_effect -// Test the quality of the VRF prove hash generated by the external library(r2ishiguro, libsodium, and etc.) as a pseudo-random number +// +// Test the quality of the VRF prove hash generated +// by the external library(r2ishiguro, libsodium, and etc.) as a pseudo-random number func TestAvalancheEffect(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey := ed25519.NewKeyFromSeed(secret[:]) From 41fc42370c60045a8e037f3c93d3d6d1c4519569 Mon Sep 17 00:00:00 2001 From: tnasu Date: Tue, 5 Apr 2022 11:36:18 +0900 Subject: [PATCH 4/5] Add hdevalence/ed25519consensus --- crypto/vrf/compatibility_keys_test.go | 10 ++++++++-- go.mod | 1 + go.sum | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crypto/vrf/compatibility_keys_test.go b/crypto/vrf/compatibility_keys_test.go index 650dd71cd..73442bf7a 100644 --- a/crypto/vrf/compatibility_keys_test.go +++ b/crypto/vrf/compatibility_keys_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" coniks "github.com/coniks-sys/coniks-go/crypto/vrf" + ed25519consensus "github.com/hdevalence/ed25519consensus" libsodium "github.com/line/ostracon/crypto/vrf/internal/vrf" xed25519 "golang.org/x/crypto/ed25519" ) @@ -20,7 +21,9 @@ var secret [SEEDBYTES]byte var message []byte = []byte("hello, world") func TestKeygen(t *testing.T) { - + for i := 0; i < SEEDBYTES; i++ { + secret[i] = uint8(i) + } privateKey, publicKey := keygen_ed25519(secret) t.Run("ed25519 and x/ed25519 have compatibility", @@ -169,7 +172,7 @@ func testKeypair_compatibility_libsodium_ed25519( func TestSignVerify(t *testing.T) { sk, pk := keygen_ed25519(secret) - t.Run("ed25519 and xed25119 have compatibility", func(t *testing.T) { + t.Run("ed25519( and ed25519consensus.Verify) and xed25119 have compatibility", func(t *testing.T) { pk1, sk1, _ := xed25519.GenerateKey(bytes.NewReader(secret[:])) signature := ed25519.Sign(sk, message) @@ -179,6 +182,9 @@ func TestSignVerify(t *testing.T) { signature = xed25519.Sign(sk1, message) valid = ed25519.Verify(pk, message, signature) assert.True(t, valid) + + valid = ed25519consensus.Verify(pk, message, signature) + assert.True(t, valid) }) } diff --git a/go.mod b/go.mod index eaaef5738..b33610034 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/google/orderedcode v0.0.1 github.com/gorilla/websocket v1.5.0 github.com/gtank/merlin v0.1.1 + github.com/hdevalence/ed25519consensus v0.0.0-20200813231810-1694d75e712a github.com/herumi/bls-eth-go-binary v0.0.0-20200923072303-32b29e5d8cbf github.com/lib/pq v1.10.5 github.com/libp2p/go-buffer-pool v0.0.2 diff --git a/go.sum b/go.sum index f0a6bbbaf..eb2e92e20 100644 --- a/go.sum +++ b/go.sum @@ -411,6 +411,8 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= +github.com/hdevalence/ed25519consensus v0.0.0-20200813231810-1694d75e712a h1:H7I/CTwAupJEX4g8AesPYRKQY0wbGZxQBlg842dGK3k= +github.com/hdevalence/ed25519consensus v0.0.0-20200813231810-1694d75e712a/go.mod h1:V0zo781scjlo5OzNQb2GI8wMt6CD4vs7y1beXtxZEhM= github.com/herumi/bls-eth-go-binary v0.0.0-20200923072303-32b29e5d8cbf h1:Lw7EOMVxu3O+7Ro5bqn9M20a7GwuCqZQsmdXNzmcKE4= github.com/herumi/bls-eth-go-binary v0.0.0-20200923072303-32b29e5d8cbf/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= From 4aec07ec929d1fa46b68315acdccaa21b84e60e5 Mon Sep 17 00:00:00 2001 From: tnasu Date: Fri, 15 Apr 2022 16:23:25 +0900 Subject: [PATCH 5/5] (fxiup) Update the function name with the camel case --- crypto/vrf/compatibility_keys_test.go | 52 +++++++++++++-------------- crypto/vrf/vrf_coniks_test.go | 4 +-- crypto/vrf/vrf_libsodium_test.go | 4 +-- crypto/vrf/vrf_r2ishiguro_test.go | 2 +- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/crypto/vrf/compatibility_keys_test.go b/crypto/vrf/compatibility_keys_test.go index 73442bf7a..1790a3d8d 100644 --- a/crypto/vrf/compatibility_keys_test.go +++ b/crypto/vrf/compatibility_keys_test.go @@ -24,26 +24,26 @@ func TestKeygen(t *testing.T) { for i := 0; i < SEEDBYTES; i++ { secret[i] = uint8(i) } - privateKey, publicKey := keygen_ed25519(secret) + privateKey, publicKey := keygenByEd25519(secret) t.Run("ed25519 and x/ed25519 have compatibility", func(t *testing.T) { - testKeygen_compatibility(t, privateKey, publicKey, - keygen_xed25519, require.Equal, require.Equal) + testKeygenCompatibility(t, privateKey, publicKey, + keygenByXed25519, require.Equal, require.Equal) }) t.Run("ed25519 and coniks have NOT compatibility", func(t *testing.T) { - testKeygen_compatibility(t, privateKey, publicKey, - keygen_coniks_ed25519, require.NotEqual, require.NotEqual) + testKeygenCompatibility(t, privateKey, publicKey, + keygenByConiksEd25519, require.NotEqual, require.NotEqual) }) t.Run("ed25519 and libsodium have compatibility", func(t *testing.T) { - testKeygen_compatibility(t, privateKey, publicKey, - keygen_libsodium_ed25519, require.Equal, require.Equal) + testKeygenCompatibility(t, privateKey, publicKey, + keygenByLibsodiumEd25519, require.Equal, require.Equal) }) } -func testKeygen_compatibility( +func testKeygenCompatibility( t *testing.T, sk1 ed25519.PrivateKey, pk1 ed25519.PublicKey, keyGen2 func(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey), @@ -55,18 +55,18 @@ func testKeygen_compatibility( pkTest(t, pk1, pk2) } -func keygen_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { +func keygenByEd25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { privateKey := ed25519.NewKeyFromSeed(secret[:]) publicKey := privateKey.Public().(ed25519.PublicKey) return privateKey, publicKey } -func keygen_xed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { +func keygenByXed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { publicKey, privateKey, _ := xed25519.GenerateKey(bytes.NewReader(secret[:])) return privateKey, publicKey } -func keygen_coniks_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { +func keygenByConiksEd25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { privKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) pubKey, _ := privKey.Public() privateKey := make([]byte, coniks.PrivateKeySize) @@ -76,7 +76,7 @@ func keygen_coniks_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519. return privateKey, publicKey } -func keygen_libsodium_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { +func keygenByLibsodiumEd25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) { var seed [libsodium.SEEDBYTES]byte copy(seed[:], secret[:]) pubKey, privKey := libsodium.KeyPairFromSeed(&seed) @@ -88,26 +88,26 @@ func keygen_libsodium_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed255 } func TestKeypair(t *testing.T) { - privateKey, publicKey := keygen_ed25519(secret) + privateKey, publicKey := keygenByEd25519(secret) t.Run("ed25519 and x/ed25519 have compatibility", func(t *testing.T) { - testKeypair_compatibility_xed25519(t, privateKey, publicKey, + testKeypairCompatibilityWithXed25519(t, privateKey, publicKey, require.EqualValues, require.EqualValues) }) t.Run("ed25519 and coniks have NOT compatibility", func(t *testing.T) { - testKeypair_compatibility_coniks_ed25519(t, privateKey, publicKey, + testKeypairCompatibilityWithConiksEd25519(t, privateKey, publicKey, require.EqualValues, require.NotEqualValues) }) t.Run("ed25519 and libsodium have compatibility", func(t *testing.T) { - testKeypair_compatibility_libsodium_ed25519(t, privateKey, publicKey, + testKeypairCompatibilityWithLibsodiumEd25519(t, privateKey, publicKey, require.EqualValues, require.EqualValues) }) } -func testKeypair_compatibility_xed25519( +func testKeypairCompatibilityWithXed25519( t *testing.T, sk ed25519.PrivateKey, pk ed25519.PublicKey, toPkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), @@ -127,7 +127,7 @@ func testKeypair_compatibility_xed25519( fromSkTest(t, pk1[:], pk2[:]) } -func testKeypair_compatibility_coniks_ed25519( +func testKeypairCompatibilityWithConiksEd25519( t *testing.T, sk ed25519.PrivateKey, pk ed25519.PublicKey, toPkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), @@ -148,7 +148,7 @@ func testKeypair_compatibility_coniks_ed25519( fromSkTest(t, pk1[:], pk2[:]) } -func testKeypair_compatibility_libsodium_ed25519( +func testKeypairCompatibilityWithLibsodiumEd25519( t *testing.T, sk ed25519.PrivateKey, pk ed25519.PublicKey, toPkTest func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}), @@ -171,7 +171,7 @@ func testKeypair_compatibility_libsodium_ed25519( } func TestSignVerify(t *testing.T) { - sk, pk := keygen_ed25519(secret) + sk, pk := keygenByEd25519(secret) t.Run("ed25519( and ed25519consensus.Verify) and xed25119 have compatibility", func(t *testing.T) { pk1, sk1, _ := xed25519.GenerateKey(bytes.NewReader(secret[:])) @@ -188,23 +188,23 @@ func TestSignVerify(t *testing.T) { }) } -func BenchmarkKeyGen_ed25519(b *testing.B) { +func BenchmarkKeyGenByEd25519(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - keygen_ed25519(secret) + keygenByEd25519(secret) } } -func BenchmarkKeyGen_coniks_ed25519(b *testing.B) { +func BenchmarkKeyGenByConiksEd25519(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - keygen_coniks_ed25519(secret) + keygenByConiksEd25519(secret) } } -func BenchmarkKeyGen_libsodium_ed25519(b *testing.B) { +func BenchmarkKeyGenByLibsodiumEd25519(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - keygen_libsodium_ed25519(secret) + keygenByLibsodiumEd25519(secret) } } diff --git a/crypto/vrf/vrf_coniks_test.go b/crypto/vrf/vrf_coniks_test.go index f328f5f93..fd4dc5b23 100644 --- a/crypto/vrf/vrf_coniks_test.go +++ b/crypto/vrf/vrf_coniks_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestProveAndVerify_coniks_by_crypto_ed25519(t *testing.T) { +func TestProveAndVerifyConiksByCryptoEd25519(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey := ed25519.NewKeyFromSeed(secret[:]) publicKey := privateKey.Public().(ed25519.PublicKey) @@ -27,7 +27,7 @@ func TestProveAndVerify_coniks_by_crypto_ed25519(t *testing.T) { require.False(t, verified) } -func TestProveAndVerify_coniks_by_coniks_ed25519(t *testing.T) { +func TestProveAndVerifyConiksByConiksEd25519(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:])) publicKey, _ := privateKey.Public() diff --git a/crypto/vrf/vrf_libsodium_test.go b/crypto/vrf/vrf_libsodium_test.go index 046a6cd90..af62cf5ec 100644 --- a/crypto/vrf/vrf_libsodium_test.go +++ b/crypto/vrf/vrf_libsodium_test.go @@ -12,7 +12,7 @@ import ( libsodium "github.com/line/ostracon/crypto/vrf/internal/vrf" ) -func TestProveAndVerify_libsodium_by_crypto_ed25519(t *testing.T) { +func TestProveAndVerifyLibsodiumByCryptoEd25519(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey := ed25519.NewKeyFromSeed(secret[:]) publicKey := privateKey.Public().(ed25519.PublicKey) @@ -25,7 +25,7 @@ func TestProveAndVerify_libsodium_by_crypto_ed25519(t *testing.T) { require.True(t, verified) } -func TestProveAndVerify_libsodium_by_libsodium_ed25519(t *testing.T) { +func TestProveAndVerifyLibsodiumByLibsodiumEd25519(t *testing.T) { secret := [SEEDBYTES]byte{} publicKey, privateKey := libsodium.KeyPairFromSeed(&secret) diff --git a/crypto/vrf/vrf_r2ishiguro_test.go b/crypto/vrf/vrf_r2ishiguro_test.go index e4c97e837..1b5803193 100644 --- a/crypto/vrf/vrf_r2ishiguro_test.go +++ b/crypto/vrf/vrf_r2ishiguro_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestProveAndVerify_r2ishiguro_by_crypto_ed25519(t *testing.T) { +func TestProveAndVerifyR2ishiguroByCryptoEd25519(t *testing.T) { secret := [SEEDBYTES]byte{} privateKey := ed25519.NewKeyFromSeed(secret[:]) publicKey := privateKey.Public().(ed25519.PublicKey)