]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/crypto/ed25519/ed25519_test.go
[dev.boringcrypto] all: merge commit 9d0819b27c (CL 314609) into dev.boringcrypto
[gostls13.git] / src / crypto / ed25519 / ed25519_test.go
index adb09e409a502c58a4f7910c4308a18708e5f9cc..84fdc3ca8b59fcf219fde18bf6b98c925872b2d8 100644 (file)
@@ -9,7 +9,6 @@ import (
        "bytes"
        "compress/gzip"
        "crypto"
-       "crypto/ed25519/internal/edwards25519"
        "crypto/rand"
        "encoding/hex"
        "os"
@@ -26,24 +25,6 @@ func (zeroReader) Read(buf []byte) (int, error) {
        return len(buf), nil
 }
 
-func TestUnmarshalMarshal(t *testing.T) {
-       pub, _, _ := GenerateKey(rand.Reader)
-
-       var A edwards25519.ExtendedGroupElement
-       var pubBytes [32]byte
-       copy(pubBytes[:], pub)
-       if !A.FromBytes(&pubBytes) {
-               t.Fatalf("ExtendedGroupElement.FromBytes failed")
-       }
-
-       var pub2 [32]byte
-       A.ToBytes(&pub2)
-
-       if pubBytes != pub2 {
-               t.Errorf("FromBytes(%v)->ToBytes does not round-trip, got %x\n", pubBytes, pub2)
-       }
-}
-
 func TestSignVerify(t *testing.T) {
        var zero zeroReader
        public, private, _ := GenerateKey(zero)
@@ -204,6 +185,25 @@ func TestMalleability(t *testing.T) {
        }
 }
 
+func TestAllocations(t *testing.T) {
+       t.Skip("skipping allocations test on Go+BoringCrypto, as cgo causes allocations")
+       if strings.HasSuffix(os.Getenv("GO_BUILDER_NAME"), "-noopt") {
+               t.Skip("skipping allocations test without relevant optimizations")
+       }
+       if allocs := testing.AllocsPerRun(100, func() {
+               seed := make([]byte, SeedSize)
+               message := []byte("Hello, world!")
+               priv := NewKeyFromSeed(seed)
+               pub := priv.Public().(PublicKey)
+               signature := Sign(priv, message)
+               if !Verify(pub, message, signature) {
+                       t.Fatal("signature didn't verify")
+               }
+       }); allocs > 0 {
+               t.Errorf("expected zero allocations, got %0.1v", allocs)
+       }
+}
+
 func BenchmarkKeyGeneration(b *testing.B) {
        var zero zeroReader
        for i := 0; i < b.N; i++ {
@@ -215,7 +215,6 @@ func BenchmarkKeyGeneration(b *testing.B) {
 
 func BenchmarkNewKeyFromSeed(b *testing.B) {
        seed := make([]byte, SeedSize)
-       b.ReportAllocs()
        for i := 0; i < b.N; i++ {
                _ = NewKeyFromSeed(seed)
        }
@@ -228,7 +227,6 @@ func BenchmarkSigning(b *testing.B) {
                b.Fatal(err)
        }
        message := []byte("Hello, world!")
-       b.ReportAllocs()
        b.ResetTimer()
        for i := 0; i < b.N; i++ {
                Sign(priv, message)