mirror of
https://github.com/stefanberger/libtpms
synced 2026-08-08 10:06:32 +00:00
tpm2: Add asserts to silence compiler warning due to -Wstringop-overflow=
The following error occurrs on Fedora build servers. To silence the
compiler warning add runtime asserts:
tpm2/crypto/openssl/CryptCmac.c: In function 'CryptCmacEnd':
tpm2/crypto/openssl/CryptCmac.c:194:48: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
194 | subkey.t.buffer[subkey.t.size - 1] ^= xorVal;
| ^
tpm2/TpmTypes.h:1477:33: note: at offset -1 into destination object 'buffer' of size 16
1477 | BYTE buffer[MAX_SYM_BLOCK_SIZE];
| ^
lto1: all warnings being treated as errors
In CryptCmacStart the following initialization is done:
cState->iv.t.size = CryptGetSymmetricBlockSize(def->algorithm, def->keyBits.sym);
Also ensure that CryptGetSymmetricBlockSize in this case also always returns
a valid size to the TPM2B_IV that it is initializing, which would be the root
cause of any error.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
5e08ef1f53
commit
e0dceb11e5
@ -92,6 +92,7 @@ CryptCmacStart(
|
||||
cState->symAlg = def->algorithm;
|
||||
cState->keySizeBits = def->keyBits.sym;
|
||||
cState->iv.t.size = CryptGetSymmetricBlockSize(def->algorithm, def->keyBits.sym);
|
||||
pAssert(cState->iv.t.size > 0 && cState->iv.t.size <= sizeof(cState->iv.t.buffer)); // libtpms added
|
||||
MemoryCopy2B(&cState->symKey.b, key, sizeof(cState->symKey.t.buffer));
|
||||
|
||||
// Set up the dispatch methods for the CMAC
|
||||
@ -191,6 +192,9 @@ CryptCmacEnd(SMAC_STATES* state, UINT32 outSize, BYTE* outBuffer)
|
||||
// Now compute K2
|
||||
xorVal = ((subkey.t.buffer[0] & 0x80) == 0) ? 0 : 0x87;
|
||||
ShiftLeft(&subkey.b);
|
||||
MUST_BE(MAX_SYM_BLOCK_SIZE == 16); // libtpms added begin: gcc -Wstringop-overflow=
|
||||
pAssert(subkey.t.size > 0 &&
|
||||
subkey.t.size <= sizeof(subkey.t.buffer)); // libtpms added end
|
||||
subkey.t.buffer[subkey.t.size - 1] ^= xorVal;
|
||||
}
|
||||
// XOR the subkey into the IV
|
||||
|
||||
Loading…
Reference in New Issue
Block a user