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.23k stars 2.56k forks source link

`rsa_sign` example is not working #5419

Open Oldes opened 2 years ago

Oldes commented 2 years ago

Summary

When trying rsa_sign.exe, I get this output:

  . Reading private key from rsa_priv.txt
  . Checking the private key
  . Generating the RSA/SHA-256 signature failed
  ! mbedtls_rsa_pkcs1_sign returned -0x4080

  + Press Enter to exit this program.

It is failing at this line: https://github.com/ARMmbed/mbedtls/blob/d1d0b41fc0b9e3d4012ccf9796ef9e641079cea2/library/rsa.c#L1887 because of this check: https://github.com/ARMmbed/mbedtls/blob/d1d0b41fc0b9e3d4012ccf9796ef9e641079cea2/library/rsa.c#L918-L919

I suppose, that there cannot be NULL for the random function here: https://github.com/ARMmbed/mbedtls/blob/d1d0b41fc0b9e3d4012ccf9796ef9e641079cea2/programs/pkey/rsa_sign.c#L145-L146

NOTE: It was tested with the version 3.1.0.

ronald-cron-arm commented 2 years ago

Thanks for reporting this issue. The documentation of mbedtls_rsa_pkcs1_sign says that the RNG function parameter is mandatory thus you are right, the call to it in rsa_sign.c is not correct.