Merge pull request #11012 from davidhorstmann-arm/make-some-x509-fns-public-4.x

[4.1] Make some X.509 functions public
This commit is contained in:
Manuel Pégourié-Gonnard
2026-10-30 07:55:41 +00:00
committed by GitHub
6 changed files with 31 additions and 19 deletions
+5
View File
@@ -0,0 +1,5 @@
Features
* Re-add mbedtls_x509_oid_get_md_alg() to the public API. This function
gets the hash algorithm associated with the given algorithm OID.
* Re-add mbedtls_x509_get_sig_alg() to the public API. This function gets
the signature algorithm associated with a given OID and parameters.
+23
View File
@@ -500,4 +500,27 @@ size_t mbedtls_x509_crt_parse_cn_inet_pton(const char *cn, void *dst);
}
#endif
/**
* \brief Translate hash algorithm OID into md_type
*
* \param oid OID to use
* \param md_alg place to store message digest algorithm
*
* \return 0 if successful, or MBEDTLS_ERR_X509_UNKNOWN_OID
*/
int mbedtls_x509_oid_get_md_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg);
/**
* \brief Translate a signature algorithm OID and parameters into PK sigalg
*
* \param sig_oid OID of the signature algorithm from the AlgorithmIdentifier type
* \param sig_params Signature parameters from the AlgorithmIdentifier type
* \param[out] md_alg The hash algorithm component of the signature algorithm (if any)
* \param[out] pk_alg The PK algorithm that corresponds to the signature algorithm
*
* \return 0 if successful, or a negative error code on failure
*/
int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
mbedtls_md_type_t *md_alg, mbedtls_pk_sigalg_t *pk_alg);
#endif /* MBEDTLS_X509_H */
-2
View File
@@ -32,8 +32,6 @@ int mbedtls_x509_get_rsassa_pss_params(const mbedtls_x509_buf *params,
int *salt_len);
#endif
int mbedtls_x509_get_sig(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig);
int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
mbedtls_md_type_t *md_alg, mbedtls_pk_sigalg_t *pk_alg);
int mbedtls_x509_get_time(unsigned char **p, const unsigned char *end,
mbedtls_x509_time *t);
int mbedtls_x509_get_serial(unsigned char **p, const unsigned char *end,
+2 -2
View File
@@ -509,7 +509,7 @@ FN_OID_GET_OID_BY_ATTR2(mbedtls_x509_oid_get_oid_by_sig_alg,
#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CRT_WRITE_C || MBEDTLS_X509_CSR_WRITE_C */
#if defined(MBEDTLS_X509_OID_HAVE_GET_MD_ALG)
#if defined(MBEDTLS_X509_CRT_PARSE_C)
/*
* For digestAlgorithm
*/
@@ -598,6 +598,6 @@ static const oid_md_alg_t oid_md_alg[] =
FN_OID_TYPED_FROM_ASN1(oid_md_alg_t, md_alg, oid_md_alg)
FN_OID_GET_ATTR1(mbedtls_x509_oid_get_md_alg, oid_md_alg_t, md_alg, mbedtls_md_type_t, md_alg)
#endif /* MBEDTLS_X509_OID_HAVE_GET_MD_ALG */
#endif /* MBEDTLS_X509_CRT_PARSE_C */
#endif /* some X.509 is enabled */
-14
View File
@@ -107,20 +107,6 @@ int mbedtls_x509_oid_get_oid_by_sig_alg(mbedtls_pk_sigalg_t pk_alg, mbedtls_md_t
const char **oid, size_t *olen);
#endif /* MBEDTLS_X509_CRT_WRITE_C || MBEDTLS_X509_CSR_WRITE_C */
#if (defined(MBEDTLS_X509_USE_C) && defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)) || \
defined(MBEDTLS_PKCS7_C)
#define MBEDTLS_X509_OID_HAVE_GET_MD_ALG
/**
* \brief Translate hash algorithm OID into md_type
*
* \param oid OID to use
* \param md_alg place to store message digest algorithm
*
* \return 0 if successful, or MBEDTLS_ERR_X509_UNKNOWN_OID
*/
int mbedtls_x509_oid_get_md_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg);
#endif /* MBEDTLS_X509_OID_HAVE_GET_MD_ALG */
#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
/**
* \brief Translate Extended Key Usage OID into description
+1 -1
View File
@@ -68,7 +68,7 @@ void oid_get_x509_extension(data_t *oid, int exp_type)
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_OID_HAVE_GET_MD_ALG */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
void oid_get_md_alg_id(data_t *oid, int exp_md_id)
{
mbedtls_asn1_buf md_oid = { 0, 0, NULL };