From e9b2c0513e03436198f64f075daa2c7dc1fd69df Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 14 Aug 2025 18:12:33 -0400 Subject: [PATCH] Sync: Fix masking-out of unneeded bits in TpmMath_GetRandomBits Signed-off-by: Stefan Berger --- src/tpm2/TPMCmd/tpm/src/crypt/math/TpmMath_Util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tpm2/TPMCmd/tpm/src/crypt/math/TpmMath_Util.c b/src/tpm2/TPMCmd/tpm/src/crypt/math/TpmMath_Util.c index 8f7da092..5fc2f3e3 100644 --- a/src/tpm2/TPMCmd/tpm/src/crypt/math/TpmMath_Util.c +++ b/src/tpm2/TPMCmd/tpm/src/crypt/math/TpmMath_Util.c @@ -105,9 +105,9 @@ LIB_EXPORT BOOL TpmMath_GetRandomBits(BYTE* pBuffer, size_t bits, RAND_STATE* ra // 2 0x03 6 = (8 - 2) % 8 // ... etc ... // 7 0x7F 1 = (8 - 7) % 8 - int excessBits = bits % 8; - static const BYTE mask[8] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f}; // libtpms changed: fix - pBuffer[0] &= mask[excessBits]; // libtpms changed: fix + static const BYTE mask[8] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f}; + int excessBits = bits % 8; + pBuffer[0] = pBuffer[0] & mask[excessBits]; return TRUE; } return FALSE;