1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "github.com/tendermint/ed25519"
13 "golang.org/x/crypto/curve25519"
16 func TestCurve25519Conversion(t *testing.T) {
17 public, private, _ := ed25519.GenerateKey(rand.Reader)
19 var curve25519Public, curve25519Public2, curve25519Private [32]byte
20 PrivateKeyToCurve25519(&curve25519Private, private)
21 curve25519.ScalarBaseMult(&curve25519Public, &curve25519Private)
23 if !PublicKeyToCurve25519(&curve25519Public2, public) {
24 t.Fatalf("PublicKeyToCurve25519 failed")
27 if !bytes.Equal(curve25519Public[:], curve25519Public2[:]) {
28 t.Errorf("Values didn't match: curve25519 produced %x, conversion produced %x", curve25519Public[:], curve25519Public2[:])
32 func TestElligator(t *testing.T) {
33 var publicKey, publicKey2, publicKey3, representative, privateKey [32]byte
35 for i := 0; i < 1000; i++ {
36 rand.Reader.Read(privateKey[:])
38 if !ScalarBaseMult(&publicKey, &representative, &privateKey) {
41 RepresentativeToPublicKey(&publicKey2, &representative)
42 if !bytes.Equal(publicKey[:], publicKey2[:]) {
43 t.Fatal("The resulting public key doesn't match the initial one.")
46 curve25519.ScalarBaseMult(&publicKey3, &privateKey)
47 if !bytes.Equal(publicKey[:], publicKey3[:]) {
48 t.Fatal("The public key doesn't match the value that curve25519 produced.")
53 func BenchmarkKeyGeneration(b *testing.B) {
54 var publicKey, representative, privateKey [32]byte
56 // Find the private key that results in a point that's in the image of the map.
58 rand.Reader.Read(privateKey[:])
59 if ScalarBaseMult(&publicKey, &representative, &privateKey) {
65 for i := 0; i < b.N; i++ {
66 ScalarBaseMult(&publicKey, &representative, &privateKey)
70 func BenchmarkMap(b *testing.B) {
71 var publicKey, representative [32]byte
72 rand.Reader.Read(representative[:])
75 for i := 0; i < b.N; i++ {
76 RepresentativeToPublicKey(&publicKey, &representative)