-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
740 additions
and
612 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package bign | ||
|
||
import ( | ||
"sync" | ||
"math/big" | ||
"crypto/elliptic" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
p256v1, p384v1, p512v1 *elliptic.CurveParams | ||
) | ||
|
||
func initAll() { | ||
initP256v1() | ||
initP384v1() | ||
initP512v1() | ||
} | ||
|
||
func initP256v1() { | ||
p256v1 = new(elliptic.CurveParams) | ||
p256v1.P = bigFromHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff43") | ||
p256v1.N = bigFromHex("ffffffffffffffffffffffffffffffffd95c8ed60dfb4dfc7e5abf99263d6607") | ||
p256v1.B = bigFromHex("77ce6c1515f3a8edd2c13aabe4d8fbbe4cf55069978b9253b22e7d6bd69c03f1") | ||
p256v1.Gx = bigFromHex("0000000000000000000000000000000000000000000000000000000000000000") | ||
p256v1.Gy = bigFromHex("6bf7fc3cfb16d69f5ce4c9a351d6835d78913966c408f6521e29cf1804516a93") | ||
p256v1.BitSize = 256 | ||
p256v1.Name = "BIGN256V1" | ||
} | ||
|
||
func initP384v1() { | ||
p384v1 = new(elliptic.CurveParams) | ||
p384v1.P = bigFromHex("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec3") | ||
p384v1.N = bigFromHex("fffffffffffffffffffffffffffffffffffffffffffffffe6cccc40373af7bbb8046dae7a6a4ff0a3db7dc3ff30ca7b7") | ||
p384v1.B = bigFromHex("3c75dfe1959cef2033075aab655d34d2712748bb0ffbb196a6216af9e9712e3a14bde2f0f3cebd7cbca7fc236873bf64") | ||
p384v1.Gx = bigFromHex("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") | ||
p384v1.Gy = bigFromHex("5d438224a82e9e9e6330117e432dbf893a729a11dc86ffa00549e79e66b1d35584403e276b2a42f9ea5ecb31f733c451") | ||
p384v1.BitSize = 384 | ||
p384v1.Name = "BIGN384V1" | ||
} | ||
|
||
func initP512v1() { | ||
p512v1 = new(elliptic.CurveParams) | ||
p512v1.P = bigFromHex("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7") | ||
p512v1.N = bigFromHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb2c0092c0198004ef26bebb02e2113f4361bcae59556df32dcffad490d068ef1") | ||
p512v1.B = bigFromHex("6cb45944933b8c43d88c5d6a60fd58895bc6a9eedd5d255117ce13e3daadb0882711dcb5c4245e952933008c87aca243ea8622273a49a27a09346998d6139c90") | ||
p512v1.Gx = bigFromHex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") | ||
p512v1.Gy = bigFromHex("a826ff7ae4037681b182e6f7a0d18fabb0ab41b3b361bce2d2edf81b00cccada6973dde20efa6fd2ff777395eee8226167aa83b9c94c0d04b792ae6fceefedbd") | ||
p512v1.BitSize = 512 | ||
p512v1.Name = "BIGN512V1" | ||
} | ||
|
||
func bigFromHex(s string) *big.Int { | ||
b, ok := new(big.Int).SetString(s, 16) | ||
if !ok { | ||
panic("go-cryptobin/bign: invalid encoding") | ||
} | ||
|
||
return b | ||
} |
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,70 @@ | ||
// Package bitelliptic implements several Koblitz elliptic curves over prime fields. | ||
package bitcurves | ||
|
||
import ( | ||
"sync" | ||
"math/big" | ||
) | ||
|
||
// curve parameters taken from: | ||
// http://www.secg.org/collateral/sec2_final.pdf | ||
|
||
var ( | ||
initonce sync.Once | ||
secp160k1, secp192k1, secp224k1, secp256k1 *BitCurve | ||
) | ||
|
||
func initAll() { | ||
initS160() | ||
initS192() | ||
initS224() | ||
initS256() | ||
} | ||
|
||
func initS160() { | ||
// See SEC 2 section 2.4.1 | ||
secp160k1 = new(BitCurve) | ||
secp160k1.Name = "secp160k1" | ||
secp160k1.P, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", 16) | ||
secp160k1.N, _ = new(big.Int).SetString("0100000000000000000001B8FA16DFAB9ACA16B6B3", 16) | ||
secp160k1.B, _ = new(big.Int).SetString("0000000000000000000000000000000000000007", 16) | ||
secp160k1.Gx, _ = new(big.Int).SetString("3B4C382CE37AA192A4019E763036F4F5DD4D7EBB", 16) | ||
secp160k1.Gy, _ = new(big.Int).SetString("938CF935318FDCED6BC28286531733C3F03C4FEE", 16) | ||
secp160k1.BitSize = 160 | ||
} | ||
|
||
func initS192() { | ||
// See SEC 2 section 2.5.1 | ||
secp192k1 = new(BitCurve) | ||
secp192k1.Name = "secp192k1" | ||
secp192k1.P, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", 16) | ||
secp192k1.N, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", 16) | ||
secp192k1.B, _ = new(big.Int).SetString("000000000000000000000000000000000000000000000003", 16) | ||
secp192k1.Gx, _ = new(big.Int).SetString("DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D", 16) | ||
secp192k1.Gy, _ = new(big.Int).SetString("9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D", 16) | ||
secp192k1.BitSize = 192 | ||
} | ||
|
||
func initS224() { | ||
// See SEC 2 section 2.6.1 | ||
secp224k1 = new(BitCurve) | ||
secp224k1.Name = "secp224k1" | ||
secp224k1.P, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D", 16) | ||
secp224k1.N, _ = new(big.Int).SetString("010000000000000000000000000001DCE8D2EC6184CAF0A971769FB1F7", 16) | ||
secp224k1.B, _ = new(big.Int).SetString("00000000000000000000000000000000000000000000000000000005", 16) | ||
secp224k1.Gx, _ = new(big.Int).SetString("A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C", 16) | ||
secp224k1.Gy, _ = new(big.Int).SetString("7E089FED7FBA344282CAFBD6F7E319F7C0B0BD59E2CA4BDB556D61A5", 16) | ||
secp224k1.BitSize = 224 | ||
} | ||
|
||
func initS256() { | ||
// See SEC 2 section 2.7.1 | ||
secp256k1 = new(BitCurve) | ||
secp256k1.Name = "secp256k1" | ||
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 | ||
} |
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
Oops, something went wrong.