summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Langley <agl@imperialviolet.org>2015-08-30 11:26:16 -0700
committerAdam Langley <agl@imperialviolet.org>2015-08-30 11:28:03 -0700
commit278e1ec8e8a6e017cd07577924d6766039146ced (patch)
tree900da7c66846748572c5cce926f8af99e1770b83
parent446061e2131e917e692f241c66202d143338e0bb (diff)
downloaded25519-278e1ec8e8a6e017cd07577924d6766039146ced.tar.xz
Move FromBytes/ToBytes test into ed25519_test.go.
The two other tests weren't actually testing anything more than this one and, with them gone, we didn't need a separate file for single remaining test.
-rw-r--r--ed25519_test.go19
-rw-r--r--marshal_test.go58
2 files changed, 19 insertions, 58 deletions
diff --git a/ed25519_test.go b/ed25519_test.go
index 290e340..0b4651e 100644
--- a/ed25519_test.go
+++ b/ed25519_test.go
@@ -8,11 +8,14 @@ import (
"bufio"
"bytes"
"compress/gzip"
+ "crypto/rand"
"encoding/hex"
"io"
"os"
"strings"
"testing"
+
+ "github.com/agl/ed25519/edwards25519"
)
type zeroReader struct{}
@@ -24,6 +27,22 @@ func (zeroReader) Read(buf []byte) (int, error) {
return len(buf), nil
}
+func TestUnmarshalMarshal(t *testing.T) {
+ pub, _, _ := GenerateKey(rand.Reader)
+
+ var A edwards25519.ExtendedGroupElement
+ if !A.FromBytes(pub) {
+ t.Fatalf("ExtendedGroupElement.FromBytes failed")
+ }
+
+ var pub2 [32]byte
+ A.ToBytes(&pub2)
+
+ if *pub != pub2 {
+ t.Errorf("FromBytes(%v)->ToBytes does not round-trip, got %x\n", *pub, pub2)
+ }
+}
+
func TestSignVerify(t *testing.T) {
var zero zeroReader
public, private, _ := GenerateKey(zero)
diff --git a/marshal_test.go b/marshal_test.go
deleted file mode 100644
index 5f01d35..0000000
--- a/marshal_test.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package ed25519
-
-import (
- "crypto/rand"
- "testing"
-
- "github.com/agl/ed25519/edwards25519"
-)
-
-func TestUnmarshalMarshal(t *testing.T) {
- pk, _, _ := GenerateKey(rand.Reader)
-
- var A edwards25519.ExtendedGroupElement
- ret := A.FromBytes(pk)
-
- var pk2 [32]byte
- A.ToBytes(&pk2)
-
- if *pk != pk2 {
- _ = ret
- t.Errorf("FromBytes(%v)->ToBytes not idempotent:\n%x\nbytes:\n\t%x\n\t%x\ndelta: %x\n", ret, A, *pk, pk2, int(pk[31])-int(pk2[31]))
- }
-}
-
-func TestUnmarshalMarshalTwice(t *testing.T) {
- pk, _, _ := GenerateKey(rand.Reader)
-
- var A edwards25519.ExtendedGroupElement
- A.FromBytes(pk)
-
- var pk2 [32]byte
- A.ToBytes(&pk2)
-
- var B edwards25519.ExtendedGroupElement
- ret := B.FromBytes(&pk2)
-
- var pk3 [32]byte
- B.ToBytes(&pk3)
-
- if *pk != pk3 {
- t.Errorf("FromBytes(%v)->ToBytes not idempotent:\n%x\nbytes:\n\t%x\n\t%x\ndelta: %x\n", ret, A, *pk, pk3, int(pk[31])-int(pk2[31]))
- }
-}
-
-func TestUnmarshalMarshalNegative(t *testing.T) {
- pk, _, _ := GenerateKey(rand.Reader)
-
- var A edwards25519.ExtendedGroupElement
- ret := A.FromBytes(pk)
-
- var pk2 [32]byte
- A.ToBytes(&pk2)
- pk2[31] ^= 0x80
-
- if *pk == pk2 {
- t.Errorf("flipping sign did not change public key:\n%x\nbytes:\n\t%x\n\t%x\ndelta: %x\n", ret, A, *pk, pk2, int(pk[31])-int(pk2[31]))
- }
-}