@@ -602,7 +602,8 @@ 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 , signature , data , hashfunc = None , sigdecode = sigdecode_string ,
606
+ allow_truncate = True
606
607
):
607
608
"""
608
609
Verify a signature made over provided data.
@@ -629,6 +630,11 @@ def verify(
629
630
second one. See :func:`ecdsa.util.sigdecode_string` and
630
631
:func:`ecdsa.util.sigdecode_der` for examples.
631
632
:type sigdecode: callable
633
+ :param bool allow_truncate: if True, the provided digest can have
634
+ bigger bit-size than the order of the curve, the extra bits (at
635
+ the end of the digest) will be truncated. Use it when verifying
636
+ SHA-384 output using NIST256p or in similar situations. Defaults to
637
+ True.
632
638
633
639
:raises BadSignatureError: if the signature is invalid or malformed
634
640
@@ -641,7 +647,7 @@ def verify(
641
647
642
648
hashfunc = hashfunc or self .default_hashfunc
643
649
digest = hashfunc (data ).digest ()
644
- return self .verify_digest (signature , digest , sigdecode , True )
650
+ return self .verify_digest (signature , digest , sigdecode , allow_truncate )
645
651
646
652
def verify_digest (
647
653
self ,
@@ -1262,6 +1268,7 @@ def sign(
1262
1268
hashfunc = None ,
1263
1269
sigencode = sigencode_string ,
1264
1270
k = None ,
1271
+ allow_truncate = True ,
1265
1272
):
1266
1273
"""
1267
1274
Create signature over data using the probabilistic ECDSA algorithm.
@@ -1298,6 +1305,11 @@ def sign(
1298
1305
:param int k: a pre-selected nonce for calculating the signature.
1299
1306
In typical use cases, it should be set to None (the default) to
1300
1307
allow its generation from an entropy source.
1308
+ :param bool allow_truncate: if True, the provided digest can have
1309
+ bigger bit-size than the order of the curve, the extra bits (at
1310
+ the end of the digest) will be truncated. Use it when signing
1311
+ SHA-384 output using NIST256p or in similar situations. True by
1312
+ default.
1301
1313
1302
1314
:raises RSZeroError: in the unlikely event when "r" parameter or
1303
1315
"s" parameter is equal 0 as that would leak the key. Calee should
@@ -1309,7 +1321,7 @@ def sign(
1309
1321
hashfunc = hashfunc or self .default_hashfunc
1310
1322
data = normalise_bytes (data )
1311
1323
h = hashfunc (data ).digest ()
1312
- return self .sign_digest (h , entropy , sigencode , k , allow_truncate = True )
1324
+ return self .sign_digest (h , entropy , sigencode , k , allow_truncate )
1313
1325
1314
1326
def sign_digest (
1315
1327
self ,
0 commit comments