question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Key Error when decoding DER signatures on P521 curve

See original GitHub issue

Hello,

There is a key error when decoding the encoded signature using the P521-curve.

'''
    Generating Keys
'''

from fastecdsa import keys, curve, ecdsa

priv_key,pub_key = keys.gen_keypair(curve.P521)

'''
    Signing and verifyng
'''
m = "Hello World"

r,s = ecdsa.sign(m,priv_key,curve=curve.P521)
valid = ecdsa.verify((r,s),m,pub_key,curve=curve.P521)

'''
    Encoding signatures
'''

from fastecdsa.encoding.der import DEREncoder

encoded = DEREncoder.encode_signature(r,s)
decoded_r, decoded_s = DEREncoder.decode_signature(encoded)

print(decoded_r)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pcececommented, Oct 29, 2020

I forgot to stress that I have tested the signature computation ECDSA NIST-P521 SHA2-512 with FIPS-186-4 test vectors and everything was OK. So thank you very much for this great library and this great work.

0reactions
AntonKueltzcommented, Jul 14, 2021

Fixed in 7fd41568eacc745811801396157b5672eb5789a4, will be in release v2.1.1.

   ...: '''
   ...:     Signing and verifyng
   ...: '''
   ...: m = "Hello World"
   ...:
   ...: r,s = ecdsa.sign(m,priv_key,curve=curve.P521)
   ...: valid = ecdsa.verify((r,s),m,pub_key,curve=curve.P521)
   ...:
   ...: '''
   ...:     Encoding signatures
   ...: '''
   ...:
   ...: from fastecdsa.encoding.der import DEREncoder
   ...:
   ...: encoded = DEREncoder.encode_signature(r,s)
   ...: decoded_r, decoded_s = DEREncoder.decode_signature(encoded)
   ...:
   ...: print(r == decoded_r, s == decoded_s)
True True
Read more comments on GitHub >

github_iconTop Results From Across the Web

elliptic curves - ECC key size and signature size
1-based encoding, which increases things a bit, up to 139 bytes for curve secp521r1. So people seems to bother with increasing signature size, ......
Read more >
any support for ASN.1 encoding signature? · Issue #55 - GitHub
The ecdsa.der module has a few functions which should help in properly encoding and decoding the DER-wrapped signatures.
Read more >
RFC 6979: Deterministic Usage of the Digital Signature ...
Deterministic signatures retain the cryptographic security features ... It is used in the specification of the encoding of an ECDSA private key (x)...
Read more >
Command Line Elliptic Curve Operations - OpenSSLWiki
OpenSSL provides two command line tools for working with keys suitable for Elliptic Curve (EC) algorithms: openssl ecparam openssl ec.
Read more >
ECDSA testing on staging - Let's Encrypt Community Support
Continuing the discussion from Elliptic Curve Cryptography (ECC) ... -outform der -out csr-p384.der osiris@server custom $ letsencrypt ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found