File: ed448_test.go

package info (click to toggle)
golang-github-protonmail-go-crypto 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: makefile: 10
file content (63 lines) | stat: -rw-r--r-- 1,162 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ed448

import (
	"crypto/rand"
	"io"
	"testing"
)

func TestGenerate(t *testing.T) {
	priv, err := GenerateKey(rand.Reader)
	if err != nil {
		t.Fatal(err)
	}
	if len(priv.Key) != SeedSize+PublicKeySize && len(priv.Point) != PublicKeySize {
		t.Error("gnerated wrong key sizes")
	}
}

func TestSignVerify(t *testing.T) {
	digest := make([]byte, 32)
	_, err := io.ReadFull(rand.Reader, digest[:])
	if err != nil {
		t.Fatal(err)
	}

	priv, err := GenerateKey(rand.Reader)
	if err != nil {
		t.Fatal(err)
	}

	signature, err := Sign(priv, digest)
	if err != nil {
		t.Errorf("error signing: %s", err)
	}

	result := Verify(&priv.PublicKey, digest, signature)

	if !result {
		t.Error("unable to verify message")
	}

	digest[0] += 1
	result = Verify(&priv.PublicKey, digest, signature)

	if result {
		t.Error("signature should be invalid")
	}
}

func TestValidation(t *testing.T) {
	priv, err := GenerateKey(rand.Reader)
	if err != nil {
		t.Fatal(err)
	}
	if err := Validate(priv); err != nil {
		t.Fatalf("valid key marked as invalid: %s", err)
	}

	priv.Key[0] += 1
	if err := Validate(priv); err == nil {
		t.Fatal("failed to detect invalid key")
	}
}