Skip to content

Commit

Permalink
Merge pull request #18 from insolar/p256k1
Browse files Browse the repository at this point in the history
Rename curve
  • Loading branch information
pavlushev authored May 21, 2019
2 parents bca1b23 + 88f64cb commit 8a44764
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions elliptic/elliptic.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func Unmarshal(curve Curve, data []byte) (x, y *big.Int) {
var initonce sync.Once
var p384 *CurveParams
var p521 *CurveParams
var secp256k1 *CurveParams
var p256k *CurveParams

func initAll() {
initP224()
Expand Down Expand Up @@ -396,14 +396,14 @@ func initP521() {
}

func initSecp256k1() {
secp256k1 = &CurveParams{Name: "secp256k1"}
secp256k1.P, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", 16)
secp256k1.N, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16)
secp256k1.A = new(big.Int)
secp256k1.B = new(big.Int).SetInt64(7)
secp256k1.Gx, _ = new(big.Int).SetString("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", 16)
secp256k1.Gy, _ = new(big.Int).SetString("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", 16)
secp256k1.BitSize = 256
p256k = &CurveParams{Name: "P-256K"}
p256k.P, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", 16)
p256k.N, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16)
p256k.A = new(big.Int)
p256k.B = new(big.Int).SetInt64(7)
p256k.Gx, _ = new(big.Int).SetString("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", 16)
p256k.Gy, _ = new(big.Int).SetString("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", 16)
p256k.BitSize = 256
}

// P256 returns a Curve which implements P-256 (see FIPS 186-3, section D.2.3)
Expand All @@ -430,10 +430,10 @@ func P521() Curve {
return p521
}

// Secp256k1 returns a Curve which implements secp256k1 (see SEC 2, section 2.4.1)
// P256K returns a Curve which implements p256k (see SEC 2, section 2.4.1)
//
// The cryptographic operations do not use constant-time algorithms.
func Secp256k1() Curve {
func P256K() Curve {
initonce.Do(initAll)
return secp256k1
return p256k
}
4 changes: 2 additions & 2 deletions elliptic/elliptic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestOnCurve(t *testing.T) {
for _, curve := range [...]Curve{
P224(), P256(), P384(), P521(), Secp256k1(),
P224(), P256(), P384(), P521(), P256K(),
} {
curveParams := curve.Params()
t.Logf("Testing G is on curve %v", curveParams.Name)
Expand Down Expand Up @@ -568,7 +568,7 @@ func TestBaseMult(t *testing.T) {
}
for _, tt := range []curveBaseMultTest{
{P224(), p224BaseMultTests},
{Secp256k1(), secp256k1BaseMultTests},
{P256K(), secp256k1BaseMultTests},
} {
name := tt.curve.Params().Name
for i, e := range tt.cases {
Expand Down
4 changes: 2 additions & 2 deletions x509/x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func namedCurveFromOID(oid asn1.ObjectIdentifier) elliptic.Curve {
case oid.Equal(oidNamedCurveP521):
return elliptic.P521()
case oid.Equal(oidNamedCurveSecp256k1):
return elliptic.Secp256k1()
return elliptic.P256K()
}
return nil
}
Expand All @@ -522,7 +522,7 @@ func oidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool) {
return oidNamedCurveP384, true
case elliptic.P521():
return oidNamedCurveP521, true
case elliptic.Secp256k1():
case elliptic.P256K():
return oidNamedCurveSecp256k1, true
}

Expand Down

0 comments on commit 8a44764

Please sign in to comment.