Arm Mbed and Pelion Device Management support forum

Comparing two mbedtls_asn1_buf variables for equality

I want to compare two variables of type mbedtls_asn1_buf for equality. In my case they contain the issuer_raw and subject_raw items of the mbedtls_x509_crt structure. Does mbedtls provide a default function for this? If not, would it be enough to compare lenghts first and then perform a memcmp if the length comparison resulted in “equal”?

Hi @TrinityTonic
I believe you are refering to something like the internal x509_name_cmp() function. Right?
Note this is an internal static function that is called during certificate verification and such.
Regards,
Mbed TLS Support
Ron

Hi Ron, I didn’t know your function at the time I asked, but I found it later and am now using it. Is there any reason this function is not public inside a asn_helper header or similar?

Hi @TrinityTonic
When the library was first written, it wasn’t intended to be a utility for ASN.1 or X509, but the X509 code was a utility for the library’s functionality(TLS stack). Due to that, this function was only internal, as there was no clear need for it outside the library.
However, if you see a need for it to make it public ( such as reducing memory footprint of the whole application) you are welcome to open a feature request \ create a PR in the repository.
Regards