]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/elliptic: add Name field to CurveParams struct
authorDavid Leon Gil <coruus@gmail.com>
Sat, 27 Dec 2014 02:24:39 +0000 (18:24 -0800)
committerAdam Langley <agl@golang.org>
Mon, 12 Jan 2015 22:08:49 +0000 (22:08 +0000)
And add names for the curve implemented in crypto/elliptic.

This permits a safer alternative to switching on BitSize
for code that implements curve-dependent cryptosystems.
(E.g., ECDSA on P-xxx curves with the matched SHA-2
instances.)

Change-Id: I653c8f47506648028a99a96ebdff8389b2a95fc1
Reviewed-on: https://go-review.googlesource.com/2133
Reviewed-by: Adam Langley <agl@golang.org>
src/crypto/elliptic/elliptic.go
src/crypto/elliptic/p224.go
src/crypto/elliptic/p256.go

index ba673f80ca6f9454180bb06c56ee41e6a7a6c555..fa987acf0bf359b80dd8193bda05a75afa194ec0 100644 (file)
@@ -45,6 +45,7 @@ type CurveParams struct {
        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 (curve *CurveParams) Params() *CurveParams {
@@ -334,7 +335,7 @@ func initAll() {
 
 func initP384() {
        // See FIPS 186-3, section D.2.4
-       p384 = new(CurveParams)
+       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)
@@ -345,7 +346,7 @@ func initP384() {
 
 func initP521() {
        // See FIPS 186-3, section D.2.5
-       p521 = new(CurveParams)
+       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)
index 1f7ff3f9da6933b640fbe59741855195bc1fcaf1..2d3fac74fbfa4bd019ae6a0997ad79354037aa17 100644 (file)
@@ -22,7 +22,7 @@ type p224Curve struct {
 
 func initP224() {
        // See FIPS 186-3, section D.2.2
-       p224.CurveParams = new(CurveParams)
+       p224.CurveParams = &CurveParams{Name: "P-224"}
        p224.P, _ = new(big.Int).SetString("26959946667150639794667015087019630673557916260026308143510066298881", 10)
        p224.N, _ = new(big.Int).SetString("26959946667150639794667015087019625940457807714424391721682722368061", 10)
        p224.B, _ = new(big.Int).SetString("b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4", 16)
index 82be51e62cd0afdbe4656d2dcc18cdcce86b2d57..82bc7b3019e62c6d7fd468bb2b59b88c43c3201e 100644 (file)
@@ -23,7 +23,7 @@ var (
 
 func initP256() {
        // See FIPS 186-3, section D.2.3
-       p256.CurveParams = new(CurveParams)
+       p256.CurveParams = &CurveParams{Name: "P-256"}
        p256.P, _ = new(big.Int).SetString("115792089210356248762697446949407573530086143415290314195533631308867097853951", 10)
        p256.N, _ = new(big.Int).SetString("115792089210356248762697446949407573529996955224135760342422259061068512044369", 10)
        p256.B, _ = new(big.Int).SetString("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", 16)