Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Legrandin committed Sep 29, 2024
1 parent 19494e0 commit 229f93f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-latest, macos-12]
os: [ubuntu-20.04, macos-12]

if: github.actor == 'Legrandin'

Expand Down
13 changes: 13 additions & 0 deletions lib/Crypto/PublicKey/ECC.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,18 +826,25 @@ def _import_rfc5915_der(encoded, passphrase, curve_oid=None):
# publicKey [1] BIT STRING OPTIONAL
# }

print("************************************************")
print("Processing %d bytes" % len(encoded))

ec_private_key = DerSequence().decode(encoded, nr_elements=(2, 3, 4))
if ec_private_key[0] != 1:
print("Incorrect version")
raise ValueError("Incorrect ECC private key version")

scalar_bytes = DerOctetString().decode(ec_private_key[1]).payload
print("Payload is %d bytes" % len(scalar_bytes))

next_element = 2

# Try to decode 'parameters'
if next_element < len(ec_private_key):
print("Decoding parameters")
try:
parameters = DerObjectId(explicit=0).decode(ec_private_key[next_element]).value
print("Parameters is", parameters)
if curve_oid is not None and parameters != curve_oid:
raise ValueError("Curve mismatch")
curve_oid = parameters
Expand All @@ -846,30 +853,36 @@ def _import_rfc5915_der(encoded, passphrase, curve_oid=None):
pass

if curve_oid is None:
print("No curve_oid")
raise ValueError("No curve found")

for curve_name, curve in _curves.items():
if curve.oid == curve_oid:
break
else:
print("Unknown curve_oid", curve_oid)
raise UnsupportedEccFeature("Unsupported ECC curve (OID: %s)" % curve_oid)

modulus_bytes = curve.p.size_in_bytes()
if len(scalar_bytes) != modulus_bytes:
print("Small modulus %d bytes", len(modulus_bytes))
raise ValueError("Private key is too small")

# Try to decode 'publicKey'
point_x = point_y = None
if next_element < len(ec_private_key):
try:
print("Decode public key I")
public_key_enc = DerBitString(explicit=1).decode(ec_private_key[next_element]).value
print("Decode public key II")
public_key = _import_public_der(public_key_enc, curve_oid=curve_oid)
point_x = public_key.pointQ.x
point_y = public_key.pointQ.y
next_element += 1
except ValueError:
pass

print("Build private key")
d = Integer.from_bytes(scalar_bytes)
return construct(curve=curve_name, d=d, point_x=point_x, point_y=point_y)

Expand Down

0 comments on commit 229f93f

Please sign in to comment.