-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: implement key recover interops
Part of #1003
- Loading branch information
1 parent
0f6d01f
commit 53bb283
Showing
5 changed files
with
212 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package keys | ||
|
||
import ( | ||
"crypto/elliptic" | ||
"math/big" | ||
"sync" | ||
) | ||
|
||
// Secp256k1Curve represents the name of Secp256k1 elliptic curve, which is set to be "Secp256k1". | ||
const Secp256k1Curve string = "Secp256k1" | ||
|
||
type secp256k1Curve struct { | ||
*elliptic.CurveParams | ||
} | ||
|
||
var ( | ||
initonce sync.Once | ||
secp256k1 secp256k1Curve | ||
) | ||
|
||
// parameters' values are taken from section 2.4.1 of http://www.secg.org/sec2-v2.pdf | ||
func initSecp256k1() { | ||
secp256k1.CurveParams = &elliptic.CurveParams{Name: Secp256k1Curve} | ||
secp256k1.P, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", 16) | ||
secp256k1.N, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16) | ||
secp256k1.B, _ = new(big.Int).SetString("0000000000000000000000000000000000000000000000000000000000000007", 16) | ||
secp256k1.Gx, _ = new(big.Int).SetString("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", 16) | ||
secp256k1.Gy, _ = new(big.Int).SetString("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", 16) | ||
secp256k1.BitSize = 256 | ||
} | ||
|
||
// Secp256k1 returns a Curve which implements secp256k1 elliptic curve. | ||
// The CurveParams.Name of this Curve is "Secp256k1". | ||
func Secp256k1() elliptic.Curve { | ||
initonce.Do(initSecp256k1) | ||
return secp256k1 | ||
} |