Skip to content

Commit 6942a8e

Browse files
committed
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).
1 parent 72bd518 commit 6942a8e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

examples/wrap/wrap_test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
338338
if (rc != 0) goto exit;
339339

340340
/* Perform RSA encrypt / decrypt (no pad) */
341-
message.size = 256; /* test message 0x11,0x11,etc */
341+
/* With TPM_ALG_NULL padding, the TPM returns a full modulus-sized
342+
* plaintext on decrypt, so the message must also be modulus-sized. */
343+
message.size = rsaKey.pub.publicArea.parameters.rsaDetail.keyBits / 8;
342344
XMEMSET(message.buffer, 0x11, message.size);
343345
cipher.size = sizeof(cipher.buffer); /* encrypted data */
344346
rc = wolfTPM2_RsaEncrypt(&dev, &rsaKey, TPM_ALG_NULL,

0 commit comments

Comments
 (0)