Skip to content

Commit d2a4b92

Browse files
committed
addressed review comments
run clang-format main
1 parent c73da15 commit d2a4b92

File tree

8 files changed

+133
-122
lines changed

8 files changed

+133
-122
lines changed

benchmark/bench_modules/wh_bench_mod_aes.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static int _benchAesCtr(whClientContext* client, whBenchOpContext* ctx, int id,
4949
Aes aes[1];
5050
char keyLabel[] = "key label";
5151
/* Input size is largest multiple of AES block size that fits in buffer */
52-
/* BUFFER-TODO */
5352
const size_t inLen =
5453
(WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE / WC_AES_BLOCK_SIZE) *
5554
WC_AES_BLOCK_SIZE;
@@ -183,7 +182,6 @@ static int _benchAesEcb(whClientContext* client, whBenchOpContext* ctx, int id,
183182
Aes aes[1];
184183
char keyLabel[] = "key label";
185184
/* Input size is largest multiple of AES block size that fits in buffer */
186-
/* BUFFER-TODO */
187185
const size_t inLen =
188186
(WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE / WC_AES_BLOCK_SIZE) *
189187
WC_AES_BLOCK_SIZE;
@@ -317,7 +315,6 @@ static int _benchAesCbc(whClientContext* client, whBenchOpContext* ctx, int id,
317315
Aes aes[1];
318316
char keyLabel[] = "key label";
319317
/* Input size is largest multiple of AES block size that fits in buffer */
320-
/* BUFFER-TODO */
321318
const size_t inLen =
322319
(WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE / WC_AES_BLOCK_SIZE) *
323320
WC_AES_BLOCK_SIZE;

src/wh_client_crypto.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,10 @@ int wh_Client_RngGenerate(whClientContext* ctx, uint8_t* out, uint32_t size)
242242
#ifndef NO_AES
243243

244244
#ifdef WOLFSSL_AES_COUNTER
245-
int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc,
246-
const uint8_t* in, uint32_t len, uint8_t* out)
245+
int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
246+
uint32_t len, uint8_t* out)
247247
{
248-
int ret = WH_ERROR_OK;
249-
/*uint16_t blocks = len / AES_BLOCK_SIZE;*/
248+
int ret = WH_ERROR_OK;
250249
whMessageCrypto_AesCtrRequest* req;
251250
whMessageCrypto_AesCtrResponse* res;
252251
uint8_t* dataPtr;
@@ -260,8 +259,8 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc,
260259
whKeyId key_id = WH_DEVCTX_TO_KEYID(aes->devCtx);
261260
uint8_t* iv = (uint8_t*)aes->reg;
262261
uint32_t iv_len = AES_IV_SIZE;
263-
uint32_t left = aes->left;
264-
uint8_t* tmp = (uint8_t*)aes->tmp;
262+
uint32_t left = aes->left;
263+
uint8_t* tmp = (uint8_t*)aes->tmp;
265264

266265
uint16_t group = WH_MESSAGE_GROUP_CRYPTO;
267266
uint16_t action = WC_ALGO_TYPE_CIPHER;
@@ -280,8 +279,8 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc,
280279
uint8_t* req_iv = req_key + key_len;
281280
uint8_t* req_tmp = req_iv + AES_BLOCK_SIZE;
282281
uint32_t req_len = sizeof(whMessageCrypto_GenericRequestHeader) +
283-
sizeof(*req) + len + key_len +
284-
iv_len + (AES_BLOCK_SIZE*2);
282+
sizeof(*req) + len + key_len + iv_len +
283+
(AES_BLOCK_SIZE * 2);
285284
#ifdef DEBUG_CRYPTOCB_VERBOSE
286285
printf("[client] %s: enc:%d keylen:%d ivsz:%d insz:%d reqsz:%u "
287286
"left:%d\n",
@@ -333,8 +332,8 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc,
333332
/* Response packet */
334333
uint16_t res_len = 0;
335334
do {
336-
ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len,
337-
dataPtr);
335+
ret =
336+
wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr);
338337
} while (ret == WH_ERROR_NOTREADY);
339338
if (ret == WH_ERROR_OK) {
340339
ret = _getCryptoResponse(dataPtr, type, (uint8_t**)&res);
@@ -349,7 +348,7 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc,
349348
printf("[client] out size:%d res_len:%d\n", res->sz, res_len);
350349
wh_Utils_Hexdump("[client] res_out: \n", res_out, res->sz);
351350
wh_Utils_Hexdump("[client] res_tmp: \n", res_tmp,
352-
AES_BLOCK_SIZE);
351+
AES_BLOCK_SIZE);
353352
#endif
354353
/* copy the response res_out */
355354
memcpy(out, res_out, res->sz);
@@ -388,11 +387,11 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
388387
return WH_ERROR_BADARGS;
389388
}
390389

391-
uint32_t key_len = aes->keylen;
392-
const uint8_t* key = (const uint8_t*)(aes->devKey);
393-
whKeyId key_id = WH_DEVCTX_TO_KEYID(aes->devCtx);
394-
uint8_t* iv = (uint8_t*)aes->reg;
395-
uint32_t iv_len = AES_IV_SIZE;
390+
uint32_t key_len = aes->keylen;
391+
const uint8_t* key = (const uint8_t*)(aes->devKey);
392+
whKeyId key_id = WH_DEVCTX_TO_KEYID(aes->devCtx);
393+
uint8_t* iv = (uint8_t*)aes->reg;
394+
uint32_t iv_len = AES_IV_SIZE;
396395

397396
uint16_t group = WH_MESSAGE_GROUP_CRYPTO;
398397
uint16_t action = WC_ALGO_TYPE_CIPHER;

src/wh_client_cryptocb.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,27 @@ int wh_Client_CryptoCb(int devId, wc_CryptoInfo* info, void* inCtx)
104104
#endif /* HAVE_AES_CBC */
105105

106106
#ifdef WOLFSSL_AES_COUNTER
107-
case WC_CIPHER_AES_CTR:
108-
{
107+
case WC_CIPHER_AES_CTR: {
109108
/* Extract info parameters */
110-
uint32_t enc = info->cipher.enc;
111-
Aes* aes = info->cipher.aesctr.aes;
112-
const uint8_t* in = info->cipher.aesctr.in;
113-
uint32_t len = info->cipher.aesctr.sz;
114-
uint8_t* out = info->cipher.aesctr.out;
109+
uint32_t enc = info->cipher.enc;
110+
Aes* aes = info->cipher.aesctr.aes;
111+
const uint8_t* in = info->cipher.aesctr.in;
112+
uint32_t len = info->cipher.aesctr.sz;
113+
uint8_t* out = info->cipher.aesctr.out;
115114

116115
ret = wh_Client_AesCtr(ctx, aes, enc, in, len, out);
117116

118117
} break;
119118
#endif /* WOLFSSL_AES_COUNTER */
120119

121120
#ifdef HAVE_AES_ECB
122-
case WC_CIPHER_AES_ECB:
123-
{
121+
case WC_CIPHER_AES_ECB: {
124122
/* Extract info parameters */
125-
uint32_t enc = info->cipher.enc;
126-
Aes* aes = info->cipher.aesecb.aes;
127-
const uint8_t* in = info->cipher.aesecb.in;
128-
uint32_t len = info->cipher.aesecb.sz;
129-
uint8_t* out = info->cipher.aesecb.out;
123+
uint32_t enc = info->cipher.enc;
124+
Aes* aes = info->cipher.aesecb.aes;
125+
const uint8_t* in = info->cipher.aesecb.in;
126+
uint32_t len = info->cipher.aesecb.sz;
127+
uint8_t* out = info->cipher.aesecb.out;
130128

131129
ret = wh_Client_AesEcb(ctx, aes, enc, in, len, out);
132130

src/wh_message_crypto.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ int wh_MessageCrypto_TranslateAesCtrResponse(
102102
}
103103
WH_T32(magic, dest, src, sz);
104104
WH_T32(magic, dest, src, left);
105-
/* Padding is already handled by the structure definition */
106105
return 0;
107106
}
108107
/* AES Ecb Request translation */

src/wh_server_crypto.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,16 +1289,16 @@ static int _HandleAesCtr(whServerContext* ctx, uint16_t magic,
12891289
if (ret != 0) {
12901290
return ret;
12911291
}
1292-
uint32_t enc = req.enc;
1293-
uint32_t key_len = req.keyLen;
1294-
uint32_t len = req.sz;
1295-
uint32_t left = req.left;
1292+
uint32_t enc = req.enc;
1293+
uint32_t key_len = req.keyLen;
1294+
uint32_t len = req.sz;
1295+
uint32_t left = req.left;
12961296
uint64_t needed_size = sizeof(whMessageCrypto_AesCtrResponse) + len +
1297-
key_len + AES_IV_SIZE + AES_BLOCK_SIZE;
1297+
key_len + AES_IV_SIZE + AES_BLOCK_SIZE;
12981298
if (needed_size > inSize) {
12991299
return WH_ERROR_BADARGS;
13001300
}
1301-
whKeyId key_id =
1301+
whKeyId key_id =
13021302
WH_MAKE_KEYID(WH_KEYTYPE_CRYPTO, ctx->comm->client_id, req.keyId);
13031303
/* in, key, iv, and out are after fixed size fields */
13041304
uint8_t* in =
@@ -1314,7 +1314,7 @@ static int _HandleAesCtr(whServerContext* ctx, uint16_t magic,
13141314
/* Debug printouts */
13151315
#ifdef DEBUG_CRYPTOCB_VERBOSE
13161316
wh_Utils_Hexdump("[AesCtr] Input data ", in, len);
1317-
wh_Utils_Hexdump("[AesCtr] IV " , iv, AES_BLOCK_SIZE);
1317+
wh_Utils_Hexdump("[AesCtr] IV ", iv, AES_BLOCK_SIZE);
13181318
wh_Utils_Hexdump("[AesCtr] tmp ", tmp, AES_BLOCK_SIZE);
13191319
#endif
13201320
/* Read the key if it is not erased */
@@ -1342,7 +1342,7 @@ static int _HandleAesCtr(whServerContext* ctx, uint16_t magic,
13421342
if (ret == 0) {
13431343
/* load the key */
13441344
ret = wc_AesSetKeyDirect(aes, (byte*)key, (word32)key_len, (byte*)iv,
1345-
enc != 0 ? AES_ENCRYPTION : AES_DECRYPTION);
1345+
enc != 0 ? AES_ENCRYPTION : AES_DECRYPTION);
13461346
if (ret == 0) {
13471347
/* do the crypto operation */
13481348
/* restore previous left */
@@ -1376,8 +1376,8 @@ static int _HandleAesCtr(whServerContext* ctx, uint16_t magic,
13761376
/* set sz */
13771377
res.sz = len;
13781378
res.left = left;
1379-
*outSize = sizeof(whMessageCrypto_AesCtrResponse) + len +
1380-
(AES_BLOCK_SIZE * 2);
1379+
*outSize =
1380+
sizeof(whMessageCrypto_AesCtrResponse) + len + (AES_BLOCK_SIZE * 2);
13811381
/* Translate response back */
13821382
ret = wh_MessageCrypto_TranslateAesCtrResponse(
13831383
magic, &res, (whMessageCrypto_AesCtrResponse*)cryptoDataOut);
@@ -1386,9 +1386,9 @@ static int _HandleAesCtr(whServerContext* ctx, uint16_t magic,
13861386
}
13871387
#endif /* WOLFSSL_AES_COUNTER */
13881388
#ifdef HAVE_AES_ECB
1389-
static int _HandleAesEcb(whServerContext* ctx, uint16_t magic, const void* cryptoDataIn,
1390-
uint16_t inSize, void* cryptoDataOut,
1391-
uint16_t* outSize)
1389+
static int _HandleAesEcb(whServerContext* ctx, uint16_t magic,
1390+
const void* cryptoDataIn, uint16_t inSize,
1391+
void* cryptoDataOut, uint16_t* outSize)
13921392
{
13931393
(void)inSize;
13941394

@@ -1409,13 +1409,13 @@ static int _HandleAesEcb(whServerContext* ctx, uint16_t magic, const void* crypt
14091409
uint32_t enc = req.enc;
14101410
uint32_t key_len = req.keyLen;
14111411
uint32_t len = req.sz;
1412-
uint64_t needed_size = sizeof(whMessageCrypto_AesEcbResponse) + len +
1413-
key_len + AES_BLOCK_SIZE;
1412+
uint64_t needed_size =
1413+
sizeof(whMessageCrypto_AesEcbResponse) + len + key_len + AES_BLOCK_SIZE;
14141414
if (needed_size > inSize) {
14151415
return WH_ERROR_BADARGS;
14161416
}
14171417

1418-
whKeyId key_id =
1418+
whKeyId key_id =
14191419
WH_MAKE_KEYID(WH_KEYTYPE_CRYPTO, ctx->comm->client_id, req.keyId);
14201420

14211421
/* in, key, iv, and out are after fixed size fields */

0 commit comments

Comments
 (0)