mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

Move specialized constant-time functions to their respective modules

Open gilles-peskine-arm opened this issue 2 years ago • 0 comments

We had three purposes in creating constant_time.c: to reduce duplication and unify the “generic” functions (partly done), to have a home for public functions (currently and in the foreseeable future, only memcmp), and to make it easier to run analyses for constant-timeness. The last point doesn't really apply since more and more parts of the library are or will be constant-time, in particular with the bignum rewrite.

So let's move the specialized functions to their respective module (and rename them accordingly, with their module's prefix):

  • mbedtls_ct_base64_enc_char, mbedtls_ct_base64_dec_value to base64.c
  • mbedtls_ct_rsaes_pkcs1_v15_unpadding to rsa.c
  • mbedtls_ct_hmac to ssl_msg.c
  • Probably bignum functions that operate on limb arrays as well (but not functions that operate on scalar mbedtls_mpi_uint values).
  • But do create a test_suite_constant_time for mask_of_range and mbedtls_ct_memcpy_offset.
  • And move the tests of mbedtls_ct_hmac to their own test suite because they take a very long time. And fix the size of ref_out but use MBEDTLS_MAX_HASH_SIZE.

This is a replacement for https://github.com/Mbed-TLS/mbedtls/pull/6273 which went about creating test_suite_constant_time and moving all existing tests of constant_time.c functions there, but without moving library functions.

gilles-peskine-arm avatar Sep 13 '22 10:09 gilles-peskine-arm