Skip to content

Commit

Permalink
Rename Curve.Type to GenName
Browse files Browse the repository at this point in the history
  • Loading branch information
wussler committed Aug 12, 2022
1 parent 08fb591 commit 7fcef0d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
36 changes: 18 additions & 18 deletions openpgp/internal/ecc/curve_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,75 @@ import (
)

type CurveInfo struct {
Type string
GenName string
Oid *encoding.OID
Curve Curve
}

var Curves = []CurveInfo{
{
// NIST P-256
Type: "P256",
GenName: "P256",
Oid: encoding.NewOID([]byte{0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}),
Curve: NewGenericCurve(elliptic.P256()),
},
{
// NIST P-384
Type: "P384",
GenName: "P384",
Oid: encoding.NewOID([]byte{0x2B, 0x81, 0x04, 0x00, 0x22}),
Curve: NewGenericCurve(elliptic.P384()),
},
{
// NIST P-521
Type: "P521",
GenName: "P521",
Oid: encoding.NewOID([]byte{0x2B, 0x81, 0x04, 0x00, 0x23}),
Curve: NewGenericCurve(elliptic.P521()),
},
{
// SecP256k1
Type: "SecP256k1",
GenName: "SecP256k1",
Oid: encoding.NewOID([]byte{0x2B, 0x81, 0x04, 0x00, 0x0A}),
Curve: NewGenericCurve(bitcurves.S256()),
},
{
// Curve25519
Type: "Curve25519",
GenName: "Curve25519",
Oid: encoding.NewOID([]byte{0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01}),
Curve: NewCurve25519(),
},
{
// X448
Type: "Curve448",
GenName: "Curve448",
Oid: encoding.NewOID([]byte{0x2B, 0x65, 0x6F}),
Curve: NewX448(),
},
{
// Ed25519
Type: "Curve25519",
GenName: "Curve25519",
Oid: encoding.NewOID([]byte{0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01}),
Curve: NewEd25519(),
},
{
// Ed448
Type: "Curve448",
GenName: "Curve448",
Oid: encoding.NewOID([]byte{0x2B, 0x65, 0x71}),
Curve: NewEd448(),
},
{
// BrainpoolP256r1
Type: "BrainpoolP256",
GenName: "BrainpoolP256",
Oid: encoding.NewOID([]byte{0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07}),
Curve: NewGenericCurve(brainpool.P256r1()),
},
{
// BrainpoolP384r1
Type: "BrainpoolP384",
GenName: "BrainpoolP384",
Oid: encoding.NewOID([]byte{0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B}),
Curve: NewGenericCurve(brainpool.P384r1()),
},
{
// BrainpoolP512r1
Type: "BrainpoolP512",
GenName: "BrainpoolP512",
Oid: encoding.NewOID([]byte{0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D}),
Curve: NewGenericCurve(brainpool.P512r1()),
},
Expand All @@ -103,9 +103,9 @@ func FindByOid(oid encoding.Field) *CurveInfo {
return nil
}

func FindEdDSAByType(curveType string) EdDSACurve {
func FindEdDSAByGenName(curveGenName string) EdDSACurve {
for _, curveInfo := range Curves {
if curveInfo.Type == curveType {
if curveInfo.GenName == curveGenName {
curve, ok := curveInfo.Curve.(EdDSACurve)
if ok {
return curve
Expand All @@ -115,9 +115,9 @@ func FindEdDSAByType(curveType string) EdDSACurve {
return nil
}

func FindECDSAByType(curveType string) ECDSACurve {
func FindECDSAByGenName(curveGenName string) ECDSACurve {
for _, curveInfo := range Curves {
if curveInfo.Type == curveType {
if curveInfo.GenName == curveGenName {
curve, ok := curveInfo.Curve.(ECDSACurve)
if ok {
return curve
Expand All @@ -127,9 +127,9 @@ func FindECDSAByType(curveType string) ECDSACurve {
return nil
}

func FindECDHByType(curveType string) ECDHCurve {
func FindECDHByGenName(curveGenName string) ECDHCurve {
for _, curveInfo := range Curves {
if curveInfo.Type == curveType {
if curveInfo.GenName == curveGenName {
curve, ok := curveInfo.Curve.(ECDHCurve)
if ok {
return curve
Expand Down
12 changes: 5 additions & 7 deletions openpgp/key_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func newSigner(config *packet.Config) (signer interface{}, err error) {
}
return rsa.GenerateKey(config.Random(), bits)
case packet.PubKeyAlgoEdDSA:
curve := ecc.FindEdDSAByType(string(config.CurveType()))
curve := ecc.FindEdDSAByGenName(string(config.CurveName()))
if curve == nil {
return nil, errors.InvalidArgumentError("unsupported curve")
}
Expand All @@ -270,7 +270,7 @@ func newSigner(config *packet.Config) (signer interface{}, err error) {
}
return priv, nil
case packet.PubKeyAlgoECDSA:
curve := ecc.FindECDSAByType(string(config.CurveType()))
curve := ecc.FindECDSAByGenName(string(config.CurveName()))
if curve == nil {
return nil, errors.InvalidArgumentError("unsupported curve")
}
Expand Down Expand Up @@ -299,16 +299,14 @@ func newDecrypter(config *packet.Config) (decrypter interface{}, err error) {
return generateRSAKeyWithPrimes(config.Random(), 2, bits, primes)
}
return rsa.GenerateKey(config.Random(), bits)
case packet.PubKeyAlgoEdDSA:
fallthrough // When passing EdDSA, we generate an ECDH subkey
case packet.PubKeyAlgoECDSA:
fallthrough // When passing ECDSA, we generate an ECDH subkey
case packet.PubKeyAlgoEdDSA, packet.PubKeyAlgoECDSA:
fallthrough // When passing EdDSA or ECDSA, we generate an ECDH subkey
case packet.PubKeyAlgoECDH:
var kdf = ecdh.KDF{
Hash: algorithm.SHA512,
Cipher: algorithm.AES256,
}
curve := ecc.FindECDHByType(string(config.CurveType()))
curve := ecc.FindECDHByGenName(string(config.CurveName()))
if curve == nil {
return nil, errors.InvalidArgumentError("unsupported curve")
}
Expand Down
6 changes: 3 additions & 3 deletions openpgp/packet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type Config struct {
Algorithm PublicKeyAlgorithm
// Some known primes that are optionally prepopulated by the caller
RSAPrimes []*big.Int
// Curve configures the desired packet.Curve if the Algorithm is
// PubKeyAlgoECDSA or PubKeyAlgoEdDSA. If empty Curve25519 is used.
// Curve configures the desired packet.Curve if the Algorithm is PubKeyAlgoECDSA,
// PubKeyAlgoEdDSA, or PubKeyAlgoECDH. If empty Curve25519 is used.
Curve Curve
// AEADConfig configures the use of the new AEAD Encrypted Data Packet,
// defined in the draft of the next version of the OpenPGP specification.
Expand Down Expand Up @@ -159,7 +159,7 @@ func (c *Config) PublicKeyAlgorithm() PublicKeyAlgorithm {
return c.Algorithm
}

func (c *Config) CurveType() Curve {
func (c *Config) CurveName() Curve {
if c == nil || c.Curve == "" {
return Curve25519
}
Expand Down

0 comments on commit 7fcef0d

Please sign in to comment.