49
49
#include "mbedtls/pem.h"
50
50
#endif
51
51
52
+ #if defined(MBEDTLS_USE_PSA_CRYPTO )
53
+ #include "psa/crypto.h"
54
+ #include "mbedtls/psa_util.h"
55
+ #endif
56
+
52
57
#if defined(MBEDTLS_PLATFORM_C )
53
58
#include "mbedtls/platform.h"
54
59
#else
@@ -1892,16 +1897,35 @@ static int x509_crt_check_signature( const mbedtls_x509_crt *child,
1892
1897
mbedtls_x509_crt * parent ,
1893
1898
mbedtls_x509_crt_restart_ctx * rs_ctx )
1894
1899
{
1895
- const mbedtls_md_info_t * md_info ;
1896
1900
unsigned char hash [MBEDTLS_MD_MAX_SIZE ];
1897
-
1901
+ size_t hash_len ;
1902
+ #if !defined(MBEDTLS_USE_PSA_CRYPTO )
1903
+ const mbedtls_md_info_t * md_info ;
1898
1904
md_info = mbedtls_md_info_from_type ( child -> sig_md );
1905
+ hash_len = mbedtls_md_get_size ( md_info );
1906
+
1907
+ /* Note: hash errors can happen only after an internal error */
1899
1908
if ( mbedtls_md ( md_info , child -> tbs .p , child -> tbs .len , hash ) != 0 )
1909
+ return ( -1 );
1910
+ #else
1911
+ psa_hash_operation_t hash_operation ;
1912
+ psa_algorithm_t hash_alg = mbedtls_psa_translate_md ( child -> sig_md );
1913
+
1914
+ if ( psa_hash_setup ( & hash_operation , hash_alg ) != PSA_SUCCESS )
1915
+ return ( -1 );
1916
+
1917
+ if ( psa_hash_update ( & hash_operation , child -> tbs .p , child -> tbs .len )
1918
+ != PSA_SUCCESS )
1900
1919
{
1901
- /* Note: this can't happen except after an internal error */
1902
1920
return ( -1 );
1903
1921
}
1904
1922
1923
+ if ( psa_hash_finish ( & hash_operation , hash , sizeof ( hash ), & hash_len )
1924
+ != PSA_SUCCESS )
1925
+ {
1926
+ return ( -1 );
1927
+ }
1928
+ #endif /* MBEDTLS_USE_PSA_CRYPTO */
1905
1929
/* Skip expensive computation on obvious mismatch */
1906
1930
if ( ! mbedtls_pk_can_do ( & parent -> pk , child -> sig_pk ) )
1907
1931
return ( -1 );
@@ -1910,15 +1934,15 @@ static int x509_crt_check_signature( const mbedtls_x509_crt *child,
1910
1934
if ( rs_ctx != NULL && child -> sig_pk == MBEDTLS_PK_ECDSA )
1911
1935
{
1912
1936
return ( mbedtls_pk_verify_restartable ( & parent -> pk ,
1913
- child -> sig_md , hash , mbedtls_md_get_size ( md_info ) ,
1937
+ child -> sig_md , hash , hash_len ,
1914
1938
child -> sig .p , child -> sig .len , & rs_ctx -> pk ) );
1915
1939
}
1916
1940
#else
1917
1941
(void ) rs_ctx ;
1918
1942
#endif
1919
1943
1920
1944
return ( mbedtls_pk_verify_ext ( child -> sig_pk , child -> sig_opts , & parent -> pk ,
1921
- child -> sig_md , hash , mbedtls_md_get_size ( md_info ) ,
1945
+ child -> sig_md , hash , hash_len ,
1922
1946
child -> sig .p , child -> sig .len ) );
1923
1947
}
1924
1948
0 commit comments