Mbed-TLS / mbedtls

An open source, portable, easy to use, readable and flexible TLS library, and reference implementation of the PSA Cryptography API. Releases are on a varying cadence, typically around 3 - 6 months between releases.
https://www.trustedfirmware.org/projects/mbed-tls/
Other
5.53k stars 2.6k forks source link

Redesign OID API for smaller code size #9380

Open gilles-peskine-arm opened 4 months ago

gilles-peskine-arm commented 4 months ago

The OID API (oid.h) and implementation (oid.c) are not good for code size for several reasons:

The goal of this issue is to redesign the OID API and implementation with code size in mind, both to enable more compact code and to automatically include only what is needed. The general idea is:

This is a design issue. The goal is a design specification. Once we have a design, there will be further tasks for implementation.

davidhorstmann-arm commented 2 months ago

This may be off-topic but it does relate to the design of the OID module. The way we currently define OIDs is something like:

#define MBEDTLS_OID_FOO "\x05\x05\x07"

Creating a null-terminated C string containing the bytes of the OID. Later, when we use it and need to set the OID's length field, we do:

oid.len = strlen(attr_descr->oid);

This is not ideal because OIDs are not guaranteed not to contain null bytes. In fact, we use one that has null bytes as test data for our conversion functions.

It would be better if we could find a way to define OIDs properly as arrays of arbitrary data with lengths.

gilles-peskine-arm commented 2 months ago

Later, when we use it and need to set the OID's length field, we do: (…)

That looks like a bug in X.509 code, please file it as a separate issue. It has nothing to do with the oid.h interface! It exposes OIDs through either MBEDTLS_OID_xxx string literals (for which you can use sizeof to get the length) or mbedtls_asn1_buf structures which contain a binary string and its length.