Skip to main content
LWChris
Associate III
May 17, 2022 12:51 PM UTC
Question

How to chose random seed for RSA encrypt in X-CUBE-CRYPTOLIB?

The call to "cmox_rsa_pkcs1v15_encrypt" requires a "Random buffer" and a "Random Length (in Bytes)" as input parameters. It will return error code CMOX_RSA_ERR_WRONG_RANDOM if "Random material too short or not valid for the functionality".

I keep getting this error code, but I cannot find any details on how I am SUPPOSED to choose or set the buffer size or contents etc.

The example uses a 36 byte message and a 20 byte random seed. I am trying to encrypt a 16 byte message with a 20 byte seed, but get the result "material too short or not valid". So, what shall I do? Any documentation on that parameter except for "it is a random seed that can be too short or not valid under certain untold circumstances"?

This topic has been closed for replies.

13 replies

LWChris
LWChrisAuthor
Associate III
Jun 13, 2022 12:49 PM UTC

Could my problem be explained with insufficient stack size within an RTOS task? Meaning the rsaContext variable may be not properly initialized or corrupted?

Jocelyn RICARD
ST Employee
Jan 5, 2024 9:02 AM UTC

Hello @LWChris,

I'm sorry to come back so late on this topic.

I have a new information to share that fully explains the issue you had.

This information is available in the wiki here

here is an extract:

"RSA PKCS#1 v1.5 Encryption
The array must contain at least (ModulusLength - InputLength - 3) not NULL bytes (that is, 0x00).
Only that number of bytes is used if no NULL bytes (that is, 0x00) are in the sequence, otherwise more bytes are necessary to replace the NULL bytes.

"

 

So, for a 36 bytes message, with a 2K RSA you need 256 - 36 - 3 = 217 non null bytes in the buffer

 

Best regards

Jocelyn

Visitor II
Mar 14, 2024 5:19 PM UTC