mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
x509: use the PSA API to perform hashing operations
So far limited only to certificate verification withour CRL and CSR generation.
This commit is contained in:
@ -37,6 +37,11 @@
|
||||
#include "mbedtls/asn1write.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -136,7 +141,11 @@ int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, s
|
||||
size_t pub_len = 0, sig_and_oid_len = 0, sig_len;
|
||||
size_t len = 0;
|
||||
mbedtls_pk_type_t pk_alg;
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_hash_operation_t hash_operation;
|
||||
size_t hash_len;
|
||||
psa_algorithm_t hash_alg = mbedtls_psa_translate_md( ctx->md_alg );
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
/*
|
||||
* Prepare data to be signed in tmp_buf
|
||||
*/
|
||||
@ -187,9 +196,26 @@ int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, s
|
||||
|
||||
/*
|
||||
* Prepare signature
|
||||
* Note: hash errors can happen only after an internal error
|
||||
*/
|
||||
mbedtls_md( mbedtls_md_info_from_type( ctx->md_alg ), c, len, hash );
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if( psa_hash_setup( &hash_operation, hash_alg ) != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_X509_FATAL_ERROR );
|
||||
|
||||
if( psa_hash_update( &hash_operation, c, len) != PSA_SUCCESS )
|
||||
{
|
||||
psa_hash_abort( &hash_operation );
|
||||
return( MBEDTLS_ERR_X509_FATAL_ERROR );
|
||||
}
|
||||
if( psa_hash_finish( &hash_operation, hash, sizeof( hash ), &hash_len )
|
||||
!= PSA_SUCCESS )
|
||||
{
|
||||
psa_hash_abort( &hash_operation );
|
||||
return( MBEDTLS_ERR_X509_FATAL_ERROR );
|
||||
}
|
||||
#else /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_md( mbedtls_md_info_from_type( ctx->md_alg ), c, len, hash );
|
||||
#endif
|
||||
if( ( ret = mbedtls_pk_sign( ctx->key, ctx->md_alg, hash, 0, sig, &sig_len,
|
||||
f_rng, p_rng ) ) != 0 )
|
||||
{
|
||||
|
Reference in New Issue
Block a user