@@ -201,34 +201,7 @@ define!(
201201//
202202// - Only used when creating/freeing - which is safe by design - eckey_alloc_wrap / eckey_free_wrap
203203//
204- // 3. ECDSA: mbedtls_ecdsa_info at ../../../mbedtls-sys/vendor/crypto/library/pk_wrap.c:729
205- // This does not use internal locks but avoids interior mutability.
206- //
207- // - Const access / copies context to stack based variables:
208- // ecdsa_verify_wrap: ../../../mbedtls-sys/vendor/crypto/library/pk_wrap.c:544
209- // This copies the public key on the stack - in buf[] and copies the group id and nbits.
210- // That is done via: mbedtls_pk_write_pubkey( &p, buf, &key ) where key.pk_ctx = ctx;
211- // And the key is a const parameter to mbedtls_pk_write_pubkey - ../../../mbedtls-sys/vendor/crypto/library/pkwrite.c:158
212- //
213- // - Const access with additional notes due to call stacks involved.
214- //
215- // ecdsa_sign_wrap: ../../../mbedtls-sys/vendor/crypto/library/pk_wrap.c:657
216- // mbedtls_ecdsa_write_signature ../../../mbedtls-sys/vendor/crypto/library/ecdsa.c:688
217- // mbedtls_ecdsa_write_signature_restartable ../../../mbedtls-sys/vendor/crypto/library/ecdsa.c:640
218- // MBEDTLS_ECDSA_DETERMINISTIC is not defined.
219- // MBEDTLS_ECDSA_SIGN_ALT is not defined.
220- // Passes grp to: ecdsa_sign_restartable: ../../../mbedtls-sys/vendor/crypto/library/ecdsa.c:253
221- // Const access to group - reads parameters, passed as const to mbedtls_ecp_gen_privkey,
222- // mbedtls_ecp_mul_restartable: ../../../mbedtls-sys/vendor/crypto/library/ecp.c:2351
223- // MBEDTLS_ECP_INTERNAL_ALT is not defined. (otherwise it might not be safe depending on ecp_init/ecp_free) ../../../mbedtls-sys/build/config.rs:131
224- // Passes as const to: mbedtls_ecp_check_privkey / mbedtls_ecp_check_pubkey / mbedtls_ecp_get_type( grp
225- //
226- // - Ignored due to not defined: ecdsa_verify_rs_wrap, ecdsa_sign_rs_wrap, ecdsa_rs_alloc, ecdsa_rs_free
227- // (Undefined - MBEDTLS_ECP_RESTARTABLE - ../../../mbedtls-sys/build/config.rs:173)
228- //
229- // - Only const access to context: eckey_check_pair
230- //
231- // - Only used when creating/freeing - which is safe by design: ecdsa_alloc_wrap, ecdsa_free_wrap
204+ // 3. ECDSA - code uses mbedtls_pk wrappers. In this case code goes through ECKEY logic above. (mbedtls_pk_parse_key intentionally never calls mbedtls_pk_info_from_type with MBEDTLS_PK_ECDSA)
232205//
233206unsafe impl Sync for Pk { }
234207
@@ -826,7 +799,7 @@ impl Pk {
826799 ///
827800 /// On success, returns the actual number of bytes written to `sig`.
828801 pub fn sign < F : Random > (
829- & mut self ,
802+ & self ,
830803 md : MdType ,
831804 hash : & [ u8 ] ,
832805 sig : & mut [ u8 ] ,
@@ -853,7 +826,7 @@ impl Pk {
853826 let mut ret = 0usize ;
854827 unsafe {
855828 pk_sign (
856- & mut self . inner ,
829+ & self . inner as * const _ as * mut _ ,
857830 md. into ( ) ,
858831 hash. as_ptr ( ) ,
859832 hash. len ( ) ,
@@ -922,15 +895,14 @@ impl Pk {
922895 }
923896 }
924897
925- pub fn verify ( & mut self , md : MdType , hash : & [ u8 ] , sig : & [ u8 ] ) -> Result < ( ) > {
926- // If hash or sig are allowed with size 0 (&[]) then mbedtls will attempt to auto-detect size and cause an invalid write.
898+ pub fn verify ( & self , md : MdType , hash : & [ u8 ] , sig : & [ u8 ] ) -> Result < ( ) > {
927899 if hash. len ( ) == 0 || sig. len ( ) == 0 {
928900 return Err ( Error :: PkBadInputData )
929901 }
930902
931903 unsafe {
932904 pk_verify (
933- & mut self . inner ,
905+ & self . inner as * const _ as * mut _ ,
934906 md. into ( ) ,
935907 hash. as_ptr ( ) ,
936908 hash. len ( ) ,
0 commit comments