-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
84 lines (65 loc) · 1.65 KB
/
main_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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Package ec
// Copyright 2023 Oleg Fomenko. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ec
import (
"crypto/elliptic"
"crypto/rand"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)
func TestECAdd(t *testing.T) {
curveEth := secp256k1.S256()
curveOleg := SECP256K1()
_, x1, y1, err := elliptic.GenerateKey(curveEth, rand.Reader)
if err != nil {
panic(err)
}
_, x2, y2, err := elliptic.GenerateKey(curveEth, rand.Reader)
if err != nil {
panic(err)
}
xres1, yres1 := curveEth.Add(x1, y1, x2, y2)
xres2, yres2 := curveOleg.Add(x1, y1, x2, y2)
if xres1.Cmp(xres2) != 0 {
panic("x result is not equal")
}
if yres1.Cmp(yres2) != 0 {
panic("y result is not equal")
}
}
func TestECDouble(t *testing.T) {
curveEth := secp256k1.S256()
curveOleg := SECP256K1()
_, x1, y1, err := elliptic.GenerateKey(curveEth, rand.Reader)
if err != nil {
panic(err)
}
xres1, yres1 := curveEth.Double(x1, y1)
xres2, yres2 := curveOleg.Double(x1, y1)
if xres1.Cmp(xres2) != 0 {
panic("x result is not equal")
}
if yres1.Cmp(yres2) != 0 {
panic("y result is not equal")
}
}
func TestECMul(t *testing.T) {
curveEth := secp256k1.S256()
curveOleg := SECP256K1()
_, x1, y1, err := elliptic.GenerateKey(curveEth, rand.Reader)
if err != nil {
panic(err)
}
k := new(big.Int).SetInt64(1234567)
xres1, yres1 := curveEth.ScalarMult(x1, y1, k.Bytes())
xres2, yres2 := curveOleg.ScalarMult(x1, y1, k.Bytes())
if xres1.Cmp(xres2) != 0 {
panic("x result is not equal")
}
if yres1.Cmp(yres2) != 0 {
panic("y result is not equal")
}
}