Mbed-TLS size_t

I am trying to compile the MbedTls for a 16 bit processor., actually, some parts like ASN1 and ECDSE. The compilation goes through but, I noticed that the code makes use of size_t profusely and it looks like it operates under the assumption that it is always a 32 bit unsigned integer. But on my platform, size_t is 16 bits. I can change all instances of size_t to uint32_t and get it working. But I am concerned that it may affect portability or code updates.
This is not a bug; but essentially, something that needs attention. Is there a workaround?


AS mentioned in this post Mbed TLS, does not support 16 bit architecture.
The code supports size_t as a 32 bit or 64 bit, depending on the architecture.
If you change size_t touint32_t` I suspect there might be some portability issues.

Mbed TLS member

Thanks Ron for the quick confirmation. I actually, compiled and got it working on a 16 bit CPU (just the signature validation and it works!!!) But I see that there is lot of memory leakage after calling mbedtls_ecdsa_read_signature(…). My observation could be wrong. But when I look at heap there are lots of allocated memory that is not freed. (FYI)



I had a look at whether Mbed TLS could work on a 16-bit architecture a while back. Indeed the code assumes that size_t is 32 bits or 64 bits. You can get it to compile with a few small patches, and many parts will work, functionally speaking.

However, do beware that the code was written, reviewed and tested under the assumption that size_t and int are 32-bit types or bigger. There are parts of the code where a 16-bit size_t would cause security holes. For example, TLS option parsing assumes that adding two 16-bit values doesn’t overflow size_t. I’m not aware of any such problem in the cryptography part of the library, but we cannot guarantee that the library is secure if compiled with 16-bit int or 16-bit size_t.

Regarding memory that is not freed, we do test for memory leaks. If you can reproduce the memory leak with the original source code on a 32-bit or 64-bit platform, please submit your code in a bug report. But if the issue is only on a 16-bit platform, I can’t guarantee that we’ll look into it, since we don’t support such platforms.

Best regards,
Gilles Peskine (Mbed TLS team member)