Mbed forum

Mbedtls_mpi issue


(t a) #1

im trying to do the following :slight_smile:

  • define a big number by mbedtls_mpi
  • do some calculation on this bug number like encrypt it or xor it with some random data
  • i expect to get the exact number of bytes by the mbedtls_mpi_size
    but if the first bytes appear to be 0 ( because my encryption ) im getting less bytes than expected .
    ( because the mbedtls_mpi_size dont count the leading zero )

any suggestion ?


(Ron Eldor) #2

Hi @tavitzur
Thank you for your question.
It is reasonable that you are not receiving same size, as the returned value is the size in bytes of the actual number.
The leading zeros are not part of the number.
Regards,
Mbed TLS Team member
Ron


(t a) #3

Thanks .
Is there a way to keep the same length and not ignoring the zero that are part of the actual size?

תומר


(Ron Eldor) #4

Hi Tomer,
The size returned is the size of the bignum, in bytes.
If you want to have a buffer holding the value of the bignum, just have a maximal value of the original bignum, and the bignum after the operation you did.
Regards,
Mbed TLS Team member
Ron