@@ -129,10 +129,11 @@ def calc_fpr_ecdsa(n):
129129
130130
131131def generate_key_ecdsa (ecdsa_curve ):
132- curve = find_curve_oid_hex ( ecdsa_curve )
132+ curve = ec . get_curve_for_oid ( get_curve_by_hex_oid ( ecdsa_curve ) )
133133 assert not (curve is None )
134- PrivateKey = ecdsa .SigningKey .generate (curve , hashfunc = sha256 )
135- PublicKey = PrivateKey .get_verifying_key ()
134+
135+ PrivateKey = ec .generate_private_key (curve (), default_backend ())
136+ PublicKey = PrivateKey .public_key ()
136137 return PublicKey , PrivateKey
137138
138139
@@ -156,7 +157,8 @@ def build_privkey_template_ecdsa(openpgp_keyno, ecdsa_curve):
156157 keyspec = 0xa4
157158
158159 PublicKey , PrivateKey = generate_key_ecdsa (ecdsa_curve )
159- return create_ecdsa_4D_key (keyspec , PrivateKey .to_string (), b"\x04 " + PublicKey .to_string ())
160+ return create_ecdsa_4D_key (keyspec , ecc_to_string (PrivateKey ),
161+ ecc_to_string (PublicKey ))
160162
161163
162164def int_to_binstr (vint , size = None ):
@@ -199,10 +201,10 @@ def ecc_to_string(key):
199201 serialization .PublicFormat .Raw )
200202
201203 if isinstance (key , ec .EllipticCurvePrivateKey ):
202- return key .private_bytes (
203- serialization . Encoding . Raw ,
204- serialization . PrivateFormat . Raw ,
205- serialization . NoEncryption () )
204+ numbers = key .private_numbers ()
205+ keysize = curve_keysize_bytes ( numbers . public_numbers . curve )
206+ print ( numbers . private_value , keysize , int_to_binstr ( numbers . private_value , keysize ). hex ())
207+ return int_to_binstr ( numbers . private_value , keysize )
206208
207209 if isinstance (key , ec .EllipticCurvePublicKey ):
208210 numbers = key .public_numbers ()
0 commit comments