forked from btcsuite/btcec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal_test.go
76 lines (65 loc) · 2.36 KB
/
internal_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
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package btcec
import (
"math/big"
)
const (
TstPubkeyUncompressed = pubkeyUncompressed
TstPubkeyCompressed = pubkeyCompressed
TstPubkeyHybrid = pubkeyHybrid
)
// TstRawInts allows the test package to get the integers from the internal
// field representation for ensuring correctness. It is only available during
// the tests.
func (f *fieldVal) TstRawInts() [10]uint32 {
return f.n
}
// TstSetRawInts allows the test package to directly set the integers used by
// the internal field representation. It is only available during the tests.
func (f *fieldVal) TstSetRawInts(raw [10]uint32) *fieldVal {
for i := 0; i < len(raw); i++ {
f.n[i] = raw[i]
}
return f
}
// TstPad makes the internal pad function available to the test package.
func TstPad(size int, b []byte) []byte {
return pad(size, b)
}
// TstFieldJacobianToBigAffine makes the internal fieldJacobianToBigAffine
// function available to the test package.
func (curve *KoblitzCurve) TstFieldJacobianToBigAffine(x, y, z *fieldVal) (*big.Int, *big.Int) {
return curve.fieldJacobianToBigAffine(x, y, z)
}
// TstIsJacobianOnCurve returns boolean if the point (x,y,z) is on the curve.
func (curve *KoblitzCurve) TstIsJacobianOnCurve(x, y, z *fieldVal) bool {
// Elliptic curve equation for secp256k1 is: y^2 = x^3 + 7
// In Jacobian coordinates, Y = y/z^3 and X = x/z^2
// Thus:
// (y/z^3)^2 = (x/z^2)^3 + 7
// y^2/z^6 = x^3/z^6 + 7
// y^2 = x^3 + 7*z^6
var y2, z2, x3, result fieldVal
y2.SquareVal(y).Normalize()
z2.SquareVal(z)
x3.SquareVal(x).Mul(x)
result.SquareVal(&z2).Mul(&z2).MulInt(7).Add(&x3).Normalize()
return y2.Equals(&result)
}
// TstAddJacobian makes the internal addJacobian function available to the test
// package.
func (curve *KoblitzCurve) TstAddJacobian(x1, y1, z1, x2, y2, z2, x3, y3, z3 *fieldVal) {
curve.addJacobian(x1, y1, z1, x2, y2, z2, x3, y3, z3)
}
// TstDoubleJacobian makes the internal doubleJacobian function available to the test
// package.
func (curve *KoblitzCurve) TstDoubleJacobian(x1, y1, z1, x3, y3, z3 *fieldVal) {
curve.doubleJacobian(x1, y1, z1, x3, y3, z3)
}
// NewFieldVal returns a new field value set to 0. This is only available to
// the test package.
func NewFieldVal() *fieldVal {
return new(fieldVal)
}