@@ -9,12 +9,12 @@ use base64::engine::Engine;
99use cryptography_crypto:: constant_time;
1010use pyo3:: types:: { PyAnyMethods , PyBytesMethods } ;
1111
12+ use crate :: asn1:: py_uint_to_be_bytes_with_length;
1213use crate :: backend:: hashes;
1314use crate :: backend:: hmac:: Hmac ;
1415use crate :: buf:: { CffiBuf , CffiMutBuf } ;
1516use crate :: error:: { CryptographyError , CryptographyResult } ;
1617use crate :: exceptions;
17- use crate :: types;
1818
1919// NO-COVERAGE-START
2020#[ pyo3:: pyclass(
@@ -1870,10 +1870,10 @@ impl KbkdfHmac {
18701870 for i in 1 ..=rounds {
18711871 let mut hmac = Hmac :: new_bytes ( py, key_material, algorithm_bound) ?;
18721872
1873- let py_counter = types:: INT_TO_BYTES . get ( py) ? . call1 ( ( i , self . params . rlen ) ) ? ;
1874- let counter = py_counter . extract :: < & [ u8 ] > ( ) ?;
1873+ let py_i = pyo3 :: types:: PyInt :: new ( py, i ) ;
1874+ let counter = py_uint_to_be_bytes_with_length ( py , py_i , self . params . rlen ) ?;
18751875 hmac. update_bytes ( data_before_ctr) ?;
1876- hmac. update_bytes ( counter) ?;
1876+ hmac. update_bytes ( counter. as_ref ( ) ) ?;
18771877 hmac. update_bytes ( data_after_ctr) ?;
18781878
18791879 let result = hmac. finalize_bytes ( ) ?;
@@ -1892,18 +1892,18 @@ impl KbkdfHmac {
18921892 }
18931893
18941894 // llen will exist if fixed data is not provided
1895- let py_l_val = types:: INT_TO_BYTES
1896- . get ( py ) ?
1897- . call1 ( ( self . length * 8 , self . params . llen . unwrap ( ) ) ) ?;
1898- let l_val = py_l_val . extract :: < & [ u8 ] > ( ) ?;
1895+ let py_bitlength = pyo3 :: types:: PyInt :: new ( py , self . length )
1896+ . mul ( 8 ) ?
1897+ . extract :: < pyo3 :: Bound < ' _ , pyo3 :: types :: PyInt > > ( ) ?;
1898+ let l_val = py_uint_to_be_bytes_with_length ( py , py_bitlength , self . params . llen . unwrap ( ) ) ?;
18991899
19001900 let mut result = Vec :: new ( ) ;
19011901 let label: & [ u8 ] = self . params . label . as_ref ( ) . map_or ( b"" , |l| l. as_bytes ( py) ) ;
19021902 result. extend_from_slice ( label) ;
19031903 result. push ( 0x00 ) ;
19041904 let context: & [ u8 ] = self . params . context . as_ref ( ) . map_or ( b"" , |l| l. as_bytes ( py) ) ;
19051905 result. extend_from_slice ( context) ;
1906- result. extend_from_slice ( l_val) ;
1906+ result. extend_from_slice ( l_val. as_ref ( ) ) ;
19071907
19081908 Ok ( result)
19091909 }
0 commit comments