Reputation: 4951
I'm really having a hard time getting to get to grips with this 3rd party Python module. I'm trying to sign a 28-byte SHA-224 digest using a 28-byte SHA-224 digest private key under secp224k1.
My attempt:
import ecdsa
private_key = int("b89ea7fcd22cc059c2673dc24ff40b978307464686560d0ad7561b83", 16).to_bytes(28, byteorder='big')
digest_msg = int("d8af940293347bc348df1896b0d93bf3952399702cef4fbf199d1cf4", 16).to_bytes(28, byteorder='big')
sk = SigningKey.generate(private_key, curve=ecdsa.secp224k1)
sig = sk.sign_digest(digest_msg)
>> AttributeError: module 'ecdsa' has no attribute 'secp224k1'
Hopelessly, I can't even google my way out of this error.
Upvotes: 1
Views: 2363
Reputation: 651
I suggest using the fastecdsa
for doing this type of task.
As far as I know, ecdsa
does not support secp224k1
curve.
fastecdsa
does not support importing the key from a string, but you can export it to a pem
format and import it using keys.import_key()
.
Check it here.
from fastecdsa import keys, curve, ecdsa
#generating the private key over secp224k1 curve
private_key = keys.gen_private_key(curve=curve.secp224k1)
#get the public key from the corresponding private key
public_key = keys.get_public_key(private_key, curve=curve.secp224k1)
msg = "Sign this message with secp224k1"
r, s = ecdsa.sign(msg, private_key, curve.secp224k1)
print(ecdsa.verify((r, s), msg, public_key, curve.secp224k1))
Output:
True
Upvotes: 1