Skip to content

Commit 8aa63e3

Browse files
committed
One more time to quiet clang tidy
1 parent 5e1db68 commit 8aa63e3

1 file changed

Lines changed: 37 additions & 35 deletions

File tree

wolfcrypt/src/cmac.c

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -299,53 +299,55 @@ int wc_CmacFinalNoFree(Cmac* cmac, byte* out, word32* outSz)
299299
NULL);
300300
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
301301
return ret;
302+
302303
/* Clear CRYPTOCB_UNAVAILABLE return code */
303304
ret = 0;
304305

305306
/* fall-through when unavailable */
306307
}
307308
#endif
308-
switch (cmac->type) {
309-
#if !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
310-
case WC_CMAC_AES:
311-
{
312-
const byte* subKey;
313-
word32 remainder;
314-
315-
if (cmac->bufferSz == AES_BLOCK_SIZE) {
316-
subKey = cmac->k1;
317-
}
318-
else {
319-
/* ensure we will have a valid remainder value */
320-
if (cmac->bufferSz > AES_BLOCK_SIZE) {
321-
ret = BAD_STATE_E;
322-
break;
309+
if (ret == 0) {
310+
switch (cmac->type) {
311+
#if !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
312+
case WC_CMAC_AES:
313+
{
314+
const byte* subKey;
315+
word32 remainder;
316+
317+
if (cmac->bufferSz == AES_BLOCK_SIZE) {
318+
subKey = cmac->k1;
323319
}
324-
remainder = AES_BLOCK_SIZE - cmac->bufferSz;
320+
else {
321+
/* ensure we will have a valid remainder value */
322+
if (cmac->bufferSz > AES_BLOCK_SIZE) {
323+
ret = BAD_STATE_E;
324+
break;
325+
}
326+
remainder = AES_BLOCK_SIZE - cmac->bufferSz;
325327

326-
if (remainder == 0) {
327-
remainder = AES_BLOCK_SIZE;
328+
if (remainder == 0) {
329+
remainder = AES_BLOCK_SIZE;
330+
}
331+
if (remainder > 1) {
332+
XMEMSET(cmac->buffer + AES_BLOCK_SIZE - remainder, 0,
333+
remainder);
334+
}
335+
336+
cmac->buffer[AES_BLOCK_SIZE - remainder] = 0x80;
337+
subKey = cmac->k2;
328338
}
329-
if (remainder > 1) {
330-
XMEMSET(cmac->buffer + AES_BLOCK_SIZE - remainder, 0,
331-
remainder);
339+
xorbuf(cmac->buffer, cmac->digest, AES_BLOCK_SIZE);
340+
xorbuf(cmac->buffer, subKey, AES_BLOCK_SIZE);
341+
ret = wc_AesEncryptDirect(&cmac->aes, cmac->digest, cmac->buffer);
342+
if (ret == 0) {
343+
XMEMCPY(out, cmac->digest, *outSz);
332344
}
333-
334-
cmac->buffer[AES_BLOCK_SIZE - remainder] = 0x80;
335-
subKey = cmac->k2;
336-
}
337-
xorbuf(cmac->buffer, cmac->digest, AES_BLOCK_SIZE);
338-
xorbuf(cmac->buffer, subKey, AES_BLOCK_SIZE);
339-
ret = wc_AesEncryptDirect(&cmac->aes, cmac->digest, cmac->buffer);
340-
if (ret == 0) {
341-
XMEMCPY(out, cmac->digest, *outSz);
345+
}; break;
346+
#endif /* !NO_AES && WOLFSSL_AES_DIRECT */
347+
default :
348+
ret = BAD_FUNC_ARG;
342349
}
343-
}; break;
344-
#endif /* !NO_AES && WOLFSSL_AES_DIRECT */
345-
default :
346-
ret = BAD_FUNC_ARG;
347350
}
348-
349351
return ret;
350352
}
351353

0 commit comments

Comments
 (0)