Skip to content

Commit a1a618c

Browse files
author
Andras Fekete
committed
Use WolfCrypt's definitions
1 parent 178f4dc commit a1a618c

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

src/we_aes_block.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct we_AesBlock
3131
/** The wolfSSL AES data object. */
3232
Aes aes;
3333
/** Buffer for streaming. */
34-
unsigned char lastBlock[AES_BLOCK_SIZE];
34+
unsigned char lastBlock[WC_AES_BLOCK_SIZE];
3535
/** Number of buffered bytes. */
3636
unsigned int over;
3737
/** Flag to indicate whether we are doing encrypt (1) or decrpyt (0). */
@@ -216,7 +216,7 @@ static int we_aes_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
216216
ret = we_aes_cbc_decrypt(aes, out, in, len);
217217
}
218218

219-
XMEMCPY(EVP_CIPHER_CTX_iv_noconst(ctx), aes->aes.reg, AES_BLOCK_SIZE);
219+
XMEMCPY(EVP_CIPHER_CTX_iv_noconst(ctx), aes->aes.reg, WC_AES_BLOCK_SIZE);
220220
}
221221

222222
WOLFENGINE_LEAVE(WE_LOG_CIPHER, "we_aes_cbc_cipher", ret);
@@ -328,7 +328,7 @@ int we_init_aescbc_meths()
328328
WOLFENGINE_ENTER(WE_LOG_CIPHER, "we_init_aescbc_meths");
329329

330330
/* AES128-CBC */
331-
we_aes128_cbc_ciph = EVP_CIPHER_meth_new(NID_aes_128_cbc, AES_BLOCK_SIZE,
331+
we_aes128_cbc_ciph = EVP_CIPHER_meth_new(NID_aes_128_cbc, WC_AES_BLOCK_SIZE,
332332
AES_128_KEY_SIZE);
333333
if (we_aes128_cbc_ciph == NULL) {
334334
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
@@ -343,7 +343,7 @@ int we_init_aescbc_meths()
343343
/* AES192-CBC */
344344
if (ret == 1) {
345345
we_aes192_cbc_ciph = EVP_CIPHER_meth_new(NID_aes_192_cbc,
346-
AES_BLOCK_SIZE,
346+
WC_AES_BLOCK_SIZE,
347347
AES_192_KEY_SIZE);
348348
if (we_aes192_cbc_ciph == NULL) {
349349
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
@@ -359,7 +359,7 @@ int we_init_aescbc_meths()
359359
/* AES256-CBC */
360360
if (ret == 1) {
361361
we_aes256_cbc_ciph = EVP_CIPHER_meth_new(NID_aes_256_cbc,
362-
AES_BLOCK_SIZE,
362+
WC_AES_BLOCK_SIZE,
363363
AES_256_KEY_SIZE);
364364
if (we_aes256_cbc_ciph == NULL) {
365365
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
@@ -498,7 +498,7 @@ static int we_aes_ecb_encrypt(we_AesBlock* aes, unsigned char *out,
498498
"aes->over = %d", aes->over);
499499

500500
/* Partial block not yet encrypted. */
501-
l = AES_BLOCK_SIZE - aes->over;
501+
l = WC_AES_BLOCK_SIZE - aes->over;
502502
if (l > len) {
503503
l = (int)len;
504504
}
@@ -511,10 +511,10 @@ static int we_aes_ecb_encrypt(we_AesBlock* aes, unsigned char *out,
511511
len -= l;
512512
}
513513
/* Check if we have a complete block to encrypt. */
514-
if (aes->over == AES_BLOCK_SIZE) {
514+
if (aes->over == WC_AES_BLOCK_SIZE) {
515515
/* Encrypt and return block. */
516516
rc = wc_AesEcbEncrypt(&aes->aes, out, aes->lastBlock,
517-
AES_BLOCK_SIZE);
517+
WC_AES_BLOCK_SIZE);
518518
if (rc != 0) {
519519
WOLFENGINE_ERROR_FUNC(WE_LOG_CIPHER,
520520
"wc_AesEcbEncrypt", rc);
@@ -523,19 +523,19 @@ static int we_aes_ecb_encrypt(we_AesBlock* aes, unsigned char *out,
523523
else {
524524
WOLFENGINE_MSG_VERBOSE(WE_LOG_CIPHER,
525525
"Encrypted %d bytes (AES-ECB)",
526-
AES_BLOCK_SIZE);
527-
WOLFENGINE_BUFFER(WE_LOG_CIPHER, out, AES_BLOCK_SIZE);
526+
WC_AES_BLOCK_SIZE);
527+
WOLFENGINE_BUFFER(WE_LOG_CIPHER, out, WC_AES_BLOCK_SIZE);
528528
}
529529
/* Data put to output. */
530-
out += AES_BLOCK_SIZE;
530+
out += WC_AES_BLOCK_SIZE;
531531
/* No more cached data. */
532532
aes->over = 0;
533533
}
534534
}
535535
/* Encrypt full blocks from remaining input. */
536-
if ((ret == 1) && (len >= AES_BLOCK_SIZE)) {
536+
if ((ret == 1) && (len >= WC_AES_BLOCK_SIZE)) {
537537
/* Calculate full blocks. */
538-
l = (int)len & (~(AES_BLOCK_SIZE - 1));
538+
l = (int)len & (~(WC_AES_BLOCK_SIZE - 1));
539539

540540
rc = wc_AesEcbEncrypt(&aes->aes, out, in, l);
541541
if (rc != 0) {
@@ -599,7 +599,7 @@ static int we_aes_ecb_decrypt(we_AesBlock* aes, unsigned char *out,
599599
WOLFENGINE_MSG(WE_LOG_CIPHER, "Decrypting leftover cached data, "
600600
"aes->over = %d", aes->over);
601601
/* Calculate amount of input that can be used. */
602-
l = AES_BLOCK_SIZE - aes->over;
602+
l = WC_AES_BLOCK_SIZE - aes->over;
603603
if (l > len) {
604604
l = (int)len;
605605
}
@@ -612,10 +612,10 @@ static int we_aes_ecb_decrypt(we_AesBlock* aes, unsigned char *out,
612612
len -= l;
613613
}
614614
/* Padding and not last full block or not padding and full block. */
615-
if ((aes->over == AES_BLOCK_SIZE) || len > 0) {
615+
if ((aes->over == WC_AES_BLOCK_SIZE) || len > 0) {
616616
/* Decrypt block cached block. */
617617
rc = wc_AesEcbDecrypt(&aes->aes, out, aes->lastBlock,
618-
AES_BLOCK_SIZE);
618+
WC_AES_BLOCK_SIZE);
619619
if (rc != 0) {
620620
WOLFENGINE_ERROR_FUNC(WE_LOG_CIPHER,
621621
"wc_AesEcbDecrypt", rc);
@@ -624,19 +624,19 @@ static int we_aes_ecb_decrypt(we_AesBlock* aes, unsigned char *out,
624624
else {
625625
WOLFENGINE_MSG_VERBOSE(WE_LOG_CIPHER,
626626
"Decrypted %d bytes (AES-ECB)",
627-
AES_BLOCK_SIZE);
628-
WOLFENGINE_BUFFER(WE_LOG_CIPHER, out, AES_BLOCK_SIZE);
627+
WC_AES_BLOCK_SIZE);
628+
WOLFENGINE_BUFFER(WE_LOG_CIPHER, out, WC_AES_BLOCK_SIZE);
629629
}
630630
/* Data put to output. */
631-
out += AES_BLOCK_SIZE;
631+
out += WC_AES_BLOCK_SIZE;
632632
/* No more cached data. */
633633
aes->over = 0;
634634
}
635635
}
636636
/* Decrypt full blocks from remaining input. */
637-
if ((ret == 1) && (len >= AES_BLOCK_SIZE)) {
637+
if ((ret == 1) && (len >= WC_AES_BLOCK_SIZE)) {
638638
/* Calculate full blocks. */
639-
l = (int)len & (~(AES_BLOCK_SIZE - 1));
639+
l = (int)len & (~(WC_AES_BLOCK_SIZE - 1));
640640

641641
if (l > 0) {
642642
rc = wc_AesEcbDecrypt(&aes->aes, out, in, l);
@@ -812,7 +812,7 @@ int we_init_aesecb_meths()
812812
WOLFENGINE_ENTER(WE_LOG_CIPHER, "we_init_aesecb_meths");
813813

814814
/* AES128-ECB */
815-
we_aes128_ecb_ciph = EVP_CIPHER_meth_new(NID_aes_128_ecb, AES_BLOCK_SIZE,
815+
we_aes128_ecb_ciph = EVP_CIPHER_meth_new(NID_aes_128_ecb, WC_AES_BLOCK_SIZE,
816816
AES_128_KEY_SIZE);
817817
if (we_aes128_ecb_ciph == NULL) {
818818
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
@@ -827,7 +827,7 @@ int we_init_aesecb_meths()
827827
/* AES192-ECB */
828828
if (ret == 1) {
829829
we_aes192_ecb_ciph = EVP_CIPHER_meth_new(NID_aes_192_ecb,
830-
AES_BLOCK_SIZE, AES_192_KEY_SIZE);
830+
WC_AES_BLOCK_SIZE, AES_192_KEY_SIZE);
831831
if (we_aes192_ecb_ciph == NULL) {
832832
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
833833
"EVP_CIPHER_meth_new - AES-192-ECB",
@@ -842,7 +842,7 @@ int we_init_aesecb_meths()
842842
/* AES256-ECB */
843843
if (ret == 1) {
844844
we_aes256_ecb_ciph = EVP_CIPHER_meth_new(NID_aes_256_ecb,
845-
AES_BLOCK_SIZE, AES_256_KEY_SIZE);
845+
WC_AES_BLOCK_SIZE, AES_256_KEY_SIZE);
846846
if (we_aes256_ecb_ciph == NULL) {
847847
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
848848
"EVP_CIPHER_meth_new - AES-256-ECB",

src/we_aes_cbc_hmac.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int we_aes_cbc_hmac_enc(we_AesCbcHmac* aes, unsigned char *out,
171171
/* When TLS v1.1 and v1.2 the IV is at the front. */
172172
WOLFENGINE_MSG(WE_LOG_CIPHER, "Setting AES IV, aes->tls11 = %d",
173173
aes->tls11);
174-
off = AES_BLOCK_SIZE;
174+
off = WC_AES_BLOCK_SIZE;
175175
rc = wc_AesSetIV(&aes->aes, in);
176176
if (rc != 0) {
177177
WOLFENGINE_ERROR_FUNC(WE_LOG_CIPHER, "wc_AesSetIV", rc);
@@ -262,7 +262,7 @@ static int we_aes_cbc_hmac_dec(we_AesCbcHmac* aes, unsigned char *out,
262262
/* TLS v1.1 and v1.2 have IV before message. */
263263
WOLFENGINE_MSG(WE_LOG_CIPHER, "Setting AES IV, aes->tls11 = %d",
264264
aes->tls11);
265-
off = AES_BLOCK_SIZE;
265+
off = WC_AES_BLOCK_SIZE;
266266
rc = wc_AesSetIV(&aes->aes, in);
267267
if (rc != 0) {
268268
WOLFENGINE_ERROR_FUNC(WE_LOG_CIPHER, "wc_AesSetIV", rc);
@@ -289,7 +289,7 @@ static int we_aes_cbc_hmac_dec(we_AesCbcHmac* aes, unsigned char *out,
289289
/* TODO: not constant time. */
290290
/* Remove padding. */
291291
pb = out[off + ret - 1];
292-
if (pb >= AES_BLOCK_SIZE) {
292+
if (pb >= WC_AES_BLOCK_SIZE) {
293293
ret = -1;
294294
}
295295
for (i = 1; (ret != -1) && (i <= pb); i++) {
@@ -464,12 +464,12 @@ static int we_aes_cbc_hmac_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
464464
aes->pLen = len;
465465
if (aes->tls11) {
466466
/* Must be space for IV. */
467-
if (len < AES_BLOCK_SIZE) {
467+
if (len < WC_AES_BLOCK_SIZE) {
468468
ret = -1;
469469
}
470470
else {
471471
/* Remove IV and update record header. */
472-
len -= AES_BLOCK_SIZE;
472+
len -= WC_AES_BLOCK_SIZE;
473473
tls[arg - 2] = len >> 8;
474474
tls[arg - 1] = len;
475475
}
@@ -488,7 +488,7 @@ static int we_aes_cbc_hmac_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
488488
if (ret == 1) {
489489
/* Calculate length with padding. */
490490
ret = ((len + SHA256_DIGEST_LENGTH +
491-
AES_BLOCK_SIZE) & -AES_BLOCK_SIZE) - len;
491+
WC_AES_BLOCK_SIZE) & -WC_AES_BLOCK_SIZE) - len;
492492
}
493493
}
494494
else {
@@ -576,7 +576,7 @@ int we_init_aescbc_hmac_meths()
576576

577577
/* AES128-CBC HMAC-SHA256 */
578578
we_aes128_cbc_hmac_ciph = EVP_CIPHER_meth_new(NID_aes_128_cbc_hmac_sha256,
579-
AES_BLOCK_SIZE, AES_128_KEY_SIZE);
579+
WC_AES_BLOCK_SIZE, AES_128_KEY_SIZE);
580580
if (we_aes128_cbc_ciph == NULL) {
581581
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
582582
"EVP_CIPHER_meth_new - AES-128-CBC "
@@ -590,7 +590,7 @@ int we_init_aescbc_hmac_meths()
590590
/* AES256-CBC HMAC-SHA256 */
591591
if (ret == 1) {
592592
we_aes256_cbc_hmac_ciph = EVP_CIPHER_meth_new(
593-
NID_aes_256_cbc_hmac_sha256, AES_BLOCK_SIZE, AES_256_KEY_SIZE);
593+
NID_aes_256_cbc_hmac_sha256, WC_AES_BLOCK_SIZE, AES_256_KEY_SIZE);
594594
if (we_aes256_cbc_ciph == NULL) {
595595
WOLFENGINE_ERROR_FUNC_NULL(WE_LOG_CIPHER,
596596
"EVP_CIPHER_meth_new - AES-256-CBC "

src/we_aes_ccm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typedef struct we_AesCcm
7272
/** IV set. */
7373
int ivSet;
7474
/** Tag created when encrypting or tag set for decryption. */
75-
unsigned char tag[AES_BLOCK_SIZE];
75+
unsigned char tag[WC_AES_BLOCK_SIZE];
7676
/** Length of tag data stored. */
7777
int tagLen;
7878
/** Additional Authentication Data (AAD) - cumulative. */
@@ -530,7 +530,7 @@ static int we_aes_ccm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
530530
* arg [in] size of tag
531531
* ptr [in] tag data to copy
532532
*/
533-
if ((arg <= 0) || (arg > AES_BLOCK_SIZE)) {
533+
if ((arg <= 0) || (arg > WC_AES_BLOCK_SIZE)) {
534534
WOLFENGINE_ERROR_MSG(WE_LOG_CIPHER, "Invalid tag size");
535535
ret = 0;
536536
}

src/we_aes_ctr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int we_aes_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
154154
EVP_CIPHER_CTX_set_num(ctx, num);
155155

156156
XMEMCPY(EVP_CIPHER_CTX_iv_noconst(ctx), aes->aes.reg,
157-
AES_BLOCK_SIZE);
157+
WC_AES_BLOCK_SIZE);
158158

159159
ret = (int)len;
160160
}

src/we_aes_gcm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef struct we_AesGcm
4949
/** Length of IV data. */
5050
int ivLen;
5151
/** Tag created when encrypting or tag set for decryption. */
52-
unsigned char tag[AES_BLOCK_SIZE];
52+
unsigned char tag[WC_AES_BLOCK_SIZE];
5353
/** Length of tag data stored. */
5454
int tagLen;
5555
/** Additional Authentication Data (AAD) - cumulative. */
@@ -681,7 +681,7 @@ static int we_aes_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
681681
* arg [in] size of tag
682682
* ptr [in] tag data to copy
683683
*/
684-
if ((arg <= 0) || (arg > AES_BLOCK_SIZE)) {
684+
if ((arg <= 0) || (arg > WC_AES_BLOCK_SIZE)) {
685685
WOLFENGINE_ERROR_MSG(WE_LOG_CIPHER, "Invalid tag size");
686686
ret = 0;
687687
}

src/we_mac.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,11 +1597,11 @@ static int we_cmac_copy(we_Mac* mac, Cmac* dst, Cmac* src)
15971597
if (ret == 1) {
15981598
/* Copy over state of CMAC. */
15991599
/* Partially stored block. */
1600-
XMEMCPY(dst->buffer, src->buffer, AES_BLOCK_SIZE);
1600+
XMEMCPY(dst->buffer, src->buffer, WC_AES_BLOCK_SIZE);
16011601
/* Running digest. */
1602-
XMEMCPY(dst->digest, src->digest, AES_BLOCK_SIZE);
1603-
XMEMCPY(dst->k1, src->k1, AES_BLOCK_SIZE);
1604-
XMEMCPY(dst->k2, src->k2, AES_BLOCK_SIZE);
1602+
XMEMCPY(dst->digest, src->digest, WC_AES_BLOCK_SIZE);
1603+
XMEMCPY(dst->k1, src->k1, WC_AES_BLOCK_SIZE);
1604+
XMEMCPY(dst->k2, src->k2, WC_AES_BLOCK_SIZE);
16051605
dst->bufferSz = src->bufferSz;
16061606
dst->totalSz = src->totalSz;
16071607
}

0 commit comments

Comments
 (0)