Skip to content

Commit 9bb9c33

Browse files
committed
Use XMEMSET / XMEMCPY in tests
1 parent 17615c9 commit 9bb9c33

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/crypto.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,10 +3298,9 @@ CK_RV C_Decrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedData,
32983298
if (!WP11_Session_IsOpInitialized(session, WP11_INIT_AES_KEYWRAP_DEC))
32993299
return CKR_OPERATION_NOT_INITIALIZED;
33003300

3301-
/* AES Key Wrap unwrapping reduces the size by 8 bytes (the
3302-
* integrity check value). If using padding then its even smaller
3303-
* but we can't know the final size without decrypting first. */
3304-
if (ulEncryptedDataLen < KEYWRAP_BLOCK_SIZE)
3301+
/* AES Key Wrap ciphertext is at least two semiblocks: one data
3302+
* semiblock plus the 8-byte integrity check value. */
3303+
if (ulEncryptedDataLen < 2 * KEYWRAP_BLOCK_SIZE)
33053304
return CKR_ENCRYPTED_DATA_LEN_RANGE;
33063305
decDataLen = (word32)(ulEncryptedDataLen - KEYWRAP_BLOCK_SIZE);
33073306
if (pData == NULL) {

tests/aes_cbc_pad_padding_test.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ static int test_valid_roundtrip(CK_SESSION_HANDLE session,
236236
CK_ULONG encSz, decSz;
237237
int result = 0;
238238

239-
memset(plain, 9, sizeof(plain));
240-
memset(iv, 9, sizeof(iv));
239+
XMEMSET(plain, 9, sizeof(plain));
240+
XMEMSET(iv, 9, sizeof(iv));
241241

242242
mech.mechanism = CKM_AES_CBC_PAD;
243243
mech.ulParameterLen = sizeof(iv);
@@ -270,7 +270,7 @@ static int test_valid_roundtrip(CK_SESSION_HANDLE session,
270270
ret = funcList->C_Decrypt(session, cipherOut, encSz, dec, &decSz);
271271
CHECK_CKR(ret, "Test1: C_Decrypt", CKR_OK);
272272

273-
if (decSz != sizeof(plain) || memcmp(dec, plain, sizeof(plain)) != 0) {
273+
if (decSz != sizeof(plain) || XMEMCMP(dec, plain, sizeof(plain)) != 0) {
274274
fprintf(stderr, "FAIL: Test1: decrypted plaintext mismatch\n");
275275
test_failed++;
276276
result = -1;
@@ -299,8 +299,8 @@ static int test_tampered_last_byte_oneshot(CK_SESSION_HANDLE session,
299299
CK_ULONG decSz;
300300
int result = 0;
301301

302-
memset(iv, 9, sizeof(iv));
303-
memcpy(tampered, cipher, cipherLen);
302+
XMEMSET(iv, 9, sizeof(iv));
303+
XMEMCPY(tampered, cipher, cipherLen);
304304
tampered[cipherLen - 1] ^= 0x01; /* flip one bit in last byte */
305305

306306
mech.mechanism = CKM_AES_CBC_PAD;
@@ -334,8 +334,8 @@ static int test_tampered_last_byte_multipart(CK_SESSION_HANDLE session,
334334
CK_ULONG decSz, lastPartLen;
335335
int result = 0;
336336

337-
memset(iv, 9, sizeof(iv));
338-
memcpy(tampered, cipher, cipherLen);
337+
XMEMSET(iv, 9, sizeof(iv));
338+
XMEMCPY(tampered, cipher, cipherLen);
339339
tampered[cipherLen - 1] ^= 0x01;
340340

341341
mech.mechanism = CKM_AES_CBC_PAD;
@@ -375,8 +375,8 @@ static int test_tampered_first_block_oneshot(CK_SESSION_HANDLE session,
375375
CK_ULONG decSz;
376376
int result = 0;
377377

378-
memset(iv, 9, sizeof(iv));
379-
memcpy(tampered, cipher, cipherLen);
378+
XMEMSET(iv, 9, sizeof(iv));
379+
XMEMCPY(tampered, cipher, cipherLen);
380380
tampered[15] ^= 0x01; /* flip one bit in last byte of first block */
381381

382382
mech.mechanism = CKM_AES_CBC_PAD;

0 commit comments

Comments
 (0)