1
2
3
4
5 package fiat_test
6
7 import (
8 "crypto/elliptic/internal/fiat"
9 "crypto/rand"
10 "testing"
11 )
12
13 func p521Random(t *testing.T) *fiat.P521Element {
14 buf := make([]byte, 66)
15 if _, err := rand.Read(buf); err != nil {
16 t.Fatal(err)
17 }
18 buf[65] &= 1
19 e, err := new(fiat.P521Element).SetBytes(buf)
20 if err != nil {
21 t.Fatal(err)
22 }
23 return e
24 }
25
26 func TestP521Invert(t *testing.T) {
27 a := p521Random(t)
28 inv := new(fiat.P521Element).Invert(a)
29 one := new(fiat.P521Element).Mul(a, inv)
30 if new(fiat.P521Element).One().Equal(one) != 1 {
31 t.Errorf("a * 1/a != 1; got %x for %x", one.Bytes(), a.Bytes())
32 }
33 inv.Invert(new(fiat.P521Element))
34 if new(fiat.P521Element).Equal(inv) != 1 {
35 t.Errorf("1/0 != 0; got %x", inv.Bytes())
36 }
37 }
38
View as plain text