-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
34 lines (31 loc) · 864 Bytes
/
utils_test.go
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
package gothemis
import (
"crypto/elliptic"
"crypto/rand"
"fmt"
"testing"
)
func TestCompressNISTPublicKey(t *testing.T) {
for i := 0; i < 1000; i++ {
_, x, y, err := elliptic.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
fmt.Println(err)
}
if !elliptic.P256().IsOnCurve(x, y) {
fmt.Println("generated points not on curve")
}
//fmt.Printf("\nx=%v\ny=%v\n", x.Bytes(), y.Bytes())
compressed := CompressNISTPublicKey(elliptic.P256(), x, y)
newX, newY, err := UncompressNISTPublicKey(elliptic.P256(), compressed)
//t.Logf("\nnewX=%v\nnewY=%v\n", newX.Bytes(), newY.Bytes())
if x.Cmp(newX) != 0 {
fmt.Println("decompressed X point not equal")
}
if y.Cmp(newY) != 0 {
fmt.Printf("decompressed Y point not equal, \nexpect: %v, \ntook: %v\n", y.Bytes(), newY.Bytes())
}
if err != nil {
t.Fatal(err)
}
}
}