Skip to content

Commit

Permalink
Remove the 'name' property from the curve info
Browse files Browse the repository at this point in the history
  • Loading branch information
Legrandin committed Aug 17, 2024
1 parent aca0117 commit 36080c9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/Crypto/PublicKey/ECC.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def _export_openssh(self, compress):
desc = self._curve.openssh

if desc is None:
raise ValueError("Cannot export %s keys as OpenSSH" % self._curve.name)
raise ValueError("Cannot export %s keys as OpenSSH" % self.curve)
elif desc == "ssh-ed25519":
public_key = self._export_eddsa_public()
comps = (tobytes(desc), tobytes(public_key))
Expand Down
6 changes: 2 additions & 4 deletions lib/Crypto/PublicKey/_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# human-friendly name, such as "P-256". The element has the following fields:
#
# - p the prime number that defines the finite field for all modulo operations
# - b the constant in the Short Weierstrass curve equation
# - b the constant in the Short Weierstrass curve equation (can be None)
# - order the number of elements in the group with the generator below
# - Gx the affine coordinate X of the generator point
# - Gy the affine coordinate Y of the generator point
Expand All @@ -15,13 +15,12 @@
# - context a raw pointer to memory holding a context for all curve operations (can be None)
# - canonical the canonical name of the curve
# - openssh the ASCII string used in OpenSSH id files for public keys on this curve
# - name the ASCII string which is also a valid key in _curves
# - rawlib the reference to the dynamic libary with the low-level functions

class _Curve(object):

def __init__(self, p, b, order, Gx, Gy, G, modulus_bits, oid, context,
canonical, openssh, name, rawlib):
canonical, openssh, rawlib):
self.p = p
self.b = b
self.order = order
Expand All @@ -33,5 +32,4 @@ def __init__(self, p, b, order, Gx, Gy, G, modulus_bits, oid, context,
self.context = context
self.canonical = canonical
self.openssh = openssh
self.name = name
self.rawlib = rawlib
6 changes: 2 additions & 4 deletions lib/Crypto/PublicKey/_edwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ class EcLib(object):
255,
"1.3.101.112", # RFC8410
None,
"Ed25519", # Used throughout; do not change
"Ed25519",
"ssh-ed25519",
"ed25519",
EcLib)
return ed25519

Expand Down Expand Up @@ -111,8 +110,7 @@ class EcLib(object):
448,
"1.3.101.113", # RFC8410
context,
"Ed448", # Used throughout; do not change
"Ed448",
None,
"ed448",
EcLib)
return ed448
3 changes: 1 addition & 2 deletions lib/Crypto/PublicKey/_montgomery.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class EcLib(object):
255,
"1.3.101.110", # RFC8410
None,
"Curve25519", # desc: used throughout; do not change
"Curve25519",
None,
"curve25519",
EcLib)
return curve25519
5 changes: 0 additions & 5 deletions lib/Crypto/PublicKey/_nist_ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def p192_curve():
context,
"NIST P-192",
"ecdsa-sha2-nistp192",
"p192",
EcLib)
return p192

Expand Down Expand Up @@ -129,7 +128,6 @@ def p224_curve():
context,
"NIST P-224",
"ecdsa-sha2-nistp224",
"p224",
EcLib)
return p224

Expand Down Expand Up @@ -168,7 +166,6 @@ def p256_curve():
context,
"NIST P-256",
"ecdsa-sha2-nistp256",
"p256",
EcLib)
return p256

Expand Down Expand Up @@ -207,7 +204,6 @@ def p384_curve():
context,
"NIST P-384",
"ecdsa-sha2-nistp384",
"p384",
EcLib)
return p384

Expand Down Expand Up @@ -246,6 +242,5 @@ def p521_curve():
context,
"NIST P-521",
"ecdsa-sha2-nistp521",
"p521",
EcLib)
return p521
2 changes: 1 addition & 1 deletion lib/Crypto/Signature/DSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def new(key, mode, encoding='binary', randfunc=None):
if isinstance(key, EccKey):
order = key._curve.order
private_key_attr = 'd'
if key._curve.name == "ed25519":
if not key.curve.startswith("NIST"):
raise ValueError("ECC key is not on a NIST P curve")
elif isinstance(key, DsaKey):
order = Integer(key.q)
Expand Down
8 changes: 4 additions & 4 deletions lib/Crypto/Signature/eddsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ def sign(self, msg_or_hash):
if not self._key.has_private():
raise TypeError("Private key is needed to sign")

if self._key._curve.name == "ed25519":
if self._key.curve == "Ed25519":
ph = isinstance(msg_or_hash, SHA512.SHA512Hash)
if not (ph or is_bytes(msg_or_hash)):
raise TypeError("'msg_or_hash' must be bytes of a SHA-512 hash")
eddsa_sign_method = self._sign_ed25519

elif self._key._curve.name == "ed448":
elif self._key.curve == "Ed448":
ph = isinstance(msg_or_hash, SHAKE256.SHAKE256_XOF)
if not (ph or is_bytes(msg_or_hash)):
raise TypeError("'msg_or_hash' must be bytes of a SHAKE256 hash")
Expand Down Expand Up @@ -224,13 +224,13 @@ def verify(self, msg_or_hash, signature):
:raise ValueError: if the signature is not authentic
"""

if self._key._curve.name == "ed25519":
if self._key.curve == "Ed25519":
ph = isinstance(msg_or_hash, SHA512.SHA512Hash)
if not (ph or is_bytes(msg_or_hash)):
raise TypeError("'msg_or_hash' must be bytes of a SHA-512 hash")
eddsa_verify_method = self._verify_ed25519

elif self._key._curve.name == "ed448":
elif self._key.curve == "Ed448":
ph = isinstance(msg_or_hash, SHAKE256.SHAKE256_XOF)
if not (ph or is_bytes(msg_or_hash)):
raise TypeError("'msg_or_hash' must be bytes of a SHAKE256 hash")
Expand Down

0 comments on commit 36080c9

Please sign in to comment.