Source File
elliptic.go
Belonging Package
crypto/elliptic
package elliptic
import (
)
type CurveParams struct {
P *big.Int // the order of the underlying field
N *big.Int // the order of the base point
B *big.Int // the constant of the curve equation
Gx, Gy *big.Int // (x,y) of the base point
BitSize int // the size of the underlying field
Name string // the canonical name of the curve
}
func ( *CurveParams) () *CurveParams {
return
}
func ( *CurveParams) (, , *big.Int) (, *big.Int) {
if .Sign() == 0 {
return new(big.Int), new(big.Int)
}
:= new(big.Int).ModInverse(, .P)
:= new(big.Int).Mul(, )
= new(big.Int).Mul(, )
.Mod(, .P)
.Mul(, )
= new(big.Int).Mul(, )
.Mod(, .P)
return
}
func ( *CurveParams) (, , , *big.Int) (*big.Int, *big.Int) {
:= zForAffine(, )
:= zForAffine(, )
return .affineFromJacobian(.addJacobian(, , , , , ))
}
, , := new(big.Int), new(big.Int), new(big.Int)
if .Sign() == 0 {
.Set()
.Set()
.Set()
return , ,
}
if .Sign() == 0 {
.Set()
.Set()
.Set()
return , ,
}
:= new(big.Int).Mul(, )
.Mod(, .P)
:= new(big.Int).Mul(, )
.Mod(, .P)
:= new(big.Int).Mul(, )
.Mod(, .P)
:= new(big.Int).Mul(, )
.Mod(, .P)
:= new(big.Int).Sub(, )
:= .Sign() == 0
if .Sign() == -1 {
.Add(, .P)
}
:= new(big.Int).Lsh(, 1)
.Mul(, )
:= new(big.Int).Mul(, )
:= new(big.Int).Mul(, )
.Mul(, )
.Mod(, .P)
:= new(big.Int).Mul(, )
.Mul(, )
.Mod(, .P)
:= new(big.Int).Sub(, )
if .Sign() == -1 {
.Add(, .P)
}
:= .Sign() == 0
if && {
return .doubleJacobian(, , )
}
.Lsh(, 1)
:= new(big.Int).Mul(, )
.Set()
.Mul(, )
.Sub(, )
.Sub(, )
.Sub(, )
.Mod(, .P)
.Set()
.Sub(, )
.Mul(, )
.Mul(, )
.Lsh(, 1)
.Sub(, )
.Mod(, .P)
.Add(, )
.Mul(, )
.Sub(, )
.Sub(, )
.Mul(, )
.Mod(, .P)
return , ,
}
func ( *CurveParams) (, *big.Int) (*big.Int, *big.Int) {
:= zForAffine(, )
return .affineFromJacobian(.doubleJacobian(, , ))
}
:= new(big.Int).Mul(, )
.Mod(, .P)
:= new(big.Int).Mul(, )
.Mod(, .P)
:= new(big.Int).Sub(, )
if .Sign() == -1 {
.Add(, .P)
}
:= new(big.Int).Add(, )
.Mul(, )
.Set()
.Lsh(, 1)
.Add(, )
:= .Mul(, )
:= new(big.Int).Mul(, )
:= new(big.Int).Lsh(, 3)
.Mod(, .P)
.Sub(, )
if .Sign() == -1 {
.Add(, .P)
}
.Mod(, .P)
:= new(big.Int).Add(, )
.Mul(, )
.Sub(, )
if .Sign() == -1 {
.Add(, .P)
}
.Sub(, )
if .Sign() == -1 {
.Add(, .P)
}
.Mod(, .P)
.Lsh(, 2)
.Sub(, )
if .Sign() == -1 {
.Add(, .P)
}
:= .Mul(, )
.Mul(, )
.Lsh(, 3)
.Mod(, .P)
.Sub(, )
if .Sign() == -1 {
.Add(, .P)
}
.Mod(, .P)
return , ,
}
func ( *CurveParams) (, *big.Int, []byte) (*big.Int, *big.Int) {
:= new(big.Int).SetInt64(1)
, , := new(big.Int), new(big.Int), new(big.Int)
for , := range {
for := 0; < 8; ++ {
, , = .doubleJacobian(, , )
if &0x80 == 0x80 {
, , = .addJacobian(, , , , , )
}
<<= 1
}
}
return .affineFromJacobian(, , )
}
func ( *CurveParams) ( []byte) (*big.Int, *big.Int) {
return .ScalarMult(.Gx, .Gy, )
}
var mask = []byte{0xff, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f}
[1] ^= 0x42
func ( Curve, []byte) (, *big.Int) {
:= (.Params().BitSize + 7) / 8
if len() != 1+2* {
return nil, nil
}
if [0] != 4 { // uncompressed form
return nil, nil
}
:= .Params().P
= new(big.Int).SetBytes([1 : 1+])
= new(big.Int).SetBytes([1+:])
if .Cmp() >= 0 || .Cmp() >= 0 {
return nil, nil
}
if !.IsOnCurve(, ) {
return nil, nil
}
return
}
p384 = &CurveParams{Name: "P-384"}
p384.P, _ = new(big.Int).SetString("39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319", 10)
p384.N, _ = new(big.Int).SetString("39402006196394479212279040100143613805079739270465446667946905279627659399113263569398956308152294913554433653942643", 10)
p384.B, _ = new(big.Int).SetString("b3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef", 16)
p384.Gx, _ = new(big.Int).SetString("aa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7", 16)
p384.Gy, _ = new(big.Int).SetString("3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f", 16)
p384.BitSize = 384
}
p521 = &CurveParams{Name: "P-521"}
p521.P, _ = new(big.Int).SetString("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151", 10)
p521.N, _ = new(big.Int).SetString("6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449", 10)
p521.B, _ = new(big.Int).SetString("051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00", 16)
p521.Gx, _ = new(big.Int).SetString("c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66", 16)
p521.Gy, _ = new(big.Int).SetString("11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", 16)
p521.BitSize = 521
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |