mirror of https://github.com/wolfSSL/wolfTPM.git
examples/wrap: use modulus size for RSA NULL-pad test message
The RSA encrypt/decrypt test with TPM_ALG_NULL padding hardcoded message.size = 256, which is only valid for 2048-bit RSA keys. With TPM_ALG_NULL padding the TPM returns a full modulus-sized plaintext on decrypt, so with a 4096-bit key the 256-byte message never equals the 512-byte plaintext and the test reports TPM_RC_TESTING. Derive the message size from the key's own keyBits so the test passes for any modulus size. Reported against wolfTPM 4.0.0 on Nations NS350 hardware (NSING).pull/494/head
parent
72bd518daa
commit
6942a8eb31
|
|
@ -338,7 +338,9 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
|||
if (rc != 0) goto exit;
|
||||
|
||||
/* Perform RSA encrypt / decrypt (no pad) */
|
||||
message.size = 256; /* test message 0x11,0x11,etc */
|
||||
/* With TPM_ALG_NULL padding, the TPM returns a full modulus-sized
|
||||
* plaintext on decrypt, so the message must also be modulus-sized. */
|
||||
message.size = rsaKey.pub.publicArea.parameters.rsaDetail.keyBits / 8;
|
||||
XMEMSET(message.buffer, 0x11, message.size);
|
||||
cipher.size = sizeof(cipher.buffer); /* encrypted data */
|
||||
rc = wolfTPM2_RsaEncrypt(&dev, &rsaKey, TPM_ALG_NULL,
|
||||
|
|
|
|||
Loading…
Reference in New Issue