"bytes"
"compress/gzip"
"crypto"
- "crypto/ed25519/internal/edwards25519"
"crypto/rand"
"encoding/hex"
"os"
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)
}
}
+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++ {
func BenchmarkNewKeyFromSeed(b *testing.B) {
seed := make([]byte, SeedSize)
- b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = NewKeyFromSeed(seed)
}
b.Fatal(err)
}
message := []byte("Hello, world!")
- b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Sign(priv, message)