@@ -602,7 +602,12 @@ def to_der(self, point_encoding="uncompressed"):
602
602
)
603
603
604
604
def verify (
605
- self , signature , data , hashfunc = None , sigdecode = sigdecode_string
605
+ self ,
606
+ signature ,
607
+ data ,
608
+ hashfunc = None ,
609
+ sigdecode = sigdecode_string ,
610
+ allow_truncate = True ,
606
611
):
607
612
"""
608
613
Verify a signature made over provided data.
@@ -629,6 +634,11 @@ def verify(
629
634
second one. See :func:`ecdsa.util.sigdecode_string` and
630
635
:func:`ecdsa.util.sigdecode_der` for examples.
631
636
:type sigdecode: callable
637
+ :param bool allow_truncate: if True, the provided digest can have
638
+ bigger bit-size than the order of the curve, the extra bits (at
639
+ the end of the digest) will be truncated. Use it when verifying
640
+ SHA-384 output using NIST256p or in similar situations. Defaults to
641
+ True.
632
642
633
643
:raises BadSignatureError: if the signature is invalid or malformed
634
644
@@ -641,7 +651,7 @@ def verify(
641
651
642
652
hashfunc = hashfunc or self .default_hashfunc
643
653
digest = hashfunc (data ).digest ()
644
- return self .verify_digest (signature , digest , sigdecode , True )
654
+ return self .verify_digest (signature , digest , sigdecode , allow_truncate )
645
655
646
656
def verify_digest (
647
657
self ,
@@ -1262,6 +1272,7 @@ def sign(
1262
1272
hashfunc = None ,
1263
1273
sigencode = sigencode_string ,
1264
1274
k = None ,
1275
+ allow_truncate = True ,
1265
1276
):
1266
1277
"""
1267
1278
Create signature over data using the probabilistic ECDSA algorithm.
@@ -1298,6 +1309,11 @@ def sign(
1298
1309
:param int k: a pre-selected nonce for calculating the signature.
1299
1310
In typical use cases, it should be set to None (the default) to
1300
1311
allow its generation from an entropy source.
1312
+ :param bool allow_truncate: if True, the provided digest can have
1313
+ bigger bit-size than the order of the curve, the extra bits (at
1314
+ the end of the digest) will be truncated. Use it when signing
1315
+ SHA-384 output using NIST256p or in similar situations. True by
1316
+ default.
1301
1317
1302
1318
:raises RSZeroError: in the unlikely event when "r" parameter or
1303
1319
"s" parameter is equal 0 as that would leak the key. Calee should
@@ -1309,7 +1325,7 @@ def sign(
1309
1325
hashfunc = hashfunc or self .default_hashfunc
1310
1326
data = normalise_bytes (data )
1311
1327
h = hashfunc (data ).digest ()
1312
- return self .sign_digest (h , entropy , sigencode , k , allow_truncate = True )
1328
+ return self .sign_digest (h , entropy , sigencode , k , allow_truncate )
1313
1329
1314
1330
def sign_digest (
1315
1331
self ,
0 commit comments