File tree Expand file tree Collapse file tree 2 files changed +5
-25
lines changed
Expand file tree Collapse file tree 2 files changed +5
-25
lines changed Original file line number Diff line number Diff line change @@ -865,11 +865,7 @@ impl X963Kdf {
865865 . getattr ( pyo3:: intern!( py, "digest_size" ) ) ?
866866 . extract :: < usize > ( ) ?;
867867
868- let max_len = digest_size. checked_mul ( u32:: MAX as usize ) . ok_or_else ( || {
869- pyo3:: exceptions:: PyValueError :: new_err (
870- "Digest size too large, would cause overflow in max length calculation" ,
871- )
872- } ) ?;
868+ let max_len = digest_size. saturating_mul ( u32:: MAX as usize ) ;
873869
874870 if length > max_len {
875871 return Err ( CryptographyError :: from (
Original file line number Diff line number Diff line change 1414
1515
1616class TestX963KDF :
17+ @pytest .mark .skipif (
18+ sys .maxsize <= 2 ** 31 ,
19+ reason = "Skip on 32-bit systems" ,
20+ )
1721 def test_length_limit (self , backend ):
1822 big_length = hashes .SHA256 ().digest_size * (2 ** 32 - 1 ) + 1
1923
@@ -109,23 +113,3 @@ def test_unicode_typeerror(self, backend):
109113 )
110114
111115 xkdf .verify (b"foo" , "bar" ) # type: ignore[arg-type]
112-
113- def test_digest_size_overflow (self ):
114- # Create a mock algorithm with a digest_size that would overflow
115- # when multiplied by u32::MAX (2^32 - 1)
116- # Using sys.maxsize // 2 works on both 32-bit and 64-bit:
117- # - 32-bit: ~2^30 * 2^32 = 2^62 > 2^32-1 (overflow)
118- # - 64-bit: ~2^62 * 2^32 = 2^94 > 2^64-1 (overflow)
119- class MockHashAlgorithm (hashes .HashAlgorithm ):
120- digest_size = sys .maxsize // 2
121- name = "MockHashAlgorithm"
122- block_size = 2 ** 16
123-
124- with pytest .raises (
125- ValueError ,
126- match = (
127- "Digest size too large, would cause overflow in max "
128- "length calculation"
129- ),
130- ):
131- X963KDF (MockHashAlgorithm (), 16 , None )
You can’t perform that action at this time.
0 commit comments