Skip to content

Commit

Permalink
In wolfcrypt/src/port/ and IDE/, replace remaining uses of AES_BLOCK_…
Browse files Browse the repository at this point in the history
…SIZE with WC_AES_BLOCKSIZE for compatibility with OPENSSL_COEXIST.

Automated replacement with
```
git ls-files -z wolfcrypt/src/port/ IDE/ | xargs -0 pcre2grep -l '[^_]AES_BLOCK_SIZE' | xargs sed --regexp-extended --in-place 's/([^_])AES_BLOCK_SIZE/\1WC_AES_BLOCK_SIZE/g'
```

Checked for mis-transformations with
```
git ls-files -z | xargs -0 pcre2grep '[^-[()+*/[:space:]]WC_AES_BLOCK_SIZE' | less
```

Checked for residual hits with
```
git ls-files -z | xargs -0 pcre2grep '[^_]AES_BLOCK_SIZE' | less
```

Deliberately excluded:
* ChangeLog.md -- do not alter history.
* doc/ -- do not confuse documentation with newly prefixed macro, because AES_BLOCK_SIZE is available unless -DOPENSSL_COEXIST.
* tests/api.c -- the unit tests deliberately use compatibility names, and are not compatible with -DOPENSSL_COEXIST.
* wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs -- false positive hits on C# names.
* wrapper/CSharp/wolfCrypt-Test/wolfCrypt-Test.cs -- false positive hits on C# names.
* reference in wolfssl/wolfcrypt/aes.h that defines AES_BLOCK_SIZE when -UOPENSSL_COEXIST.
* reference in wolfssl/wolfcrypt/settings.h that defines WC_AES_BLOCK_SIZE for old FIPS when -UWC_AES_BLOCK_SIZE.
  • Loading branch information
douzzer committed Dec 21, 2024
1 parent 4ff73b9 commit ed18bf3
Show file tree
Hide file tree
Showing 25 changed files with 572 additions and 572 deletions.
4 changes: 2 additions & 2 deletions IDE/QNX/example-cmac/cmac-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ static int createTag(const byte* key, int keySz, byte* msg, int msgSz,
byte* msg2, int msg2Sz)
{
Cmac cmac;
byte tag[AES_BLOCK_SIZE];
byte tag[WC_AES_BLOCK_SIZE];
word32 i, tagSz;
byte out[48];
word32 outSz;

XMEMSET(tag, 0, sizeof(tag));
tagSz = AES_BLOCK_SIZE;
tagSz = WC_AES_BLOCK_SIZE;

outSz = 48;
wc_caamCoverKey((byte*)key, keySz, out, &outSz, 0);
Expand Down
46 changes: 23 additions & 23 deletions IDE/Renesas/e2studio/RA6M4/test/src/wolfssl_sce_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ static int sce_aes_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)

Aes aes[1];

byte cipher[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[WC_AES_BLOCK_SIZE];
byte plain[WC_AES_BLOCK_SIZE];
int ret = 0;

WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
Expand All @@ -119,8 +119,8 @@ static int sce_aes_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
};
byte iv[] = "1234567890abcdef "; /* align */

XMEMSET(cipher, 0, AES_BLOCK_SIZE);
XMEMSET(plain, 0, AES_BLOCK_SIZE);
XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);

if (prnt) {
printf(" sce_aes_cbc_test() ");
Expand All @@ -129,9 +129,9 @@ static int sce_aes_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
ret = wc_AesInit(aes, NULL, devId);
if (ret == 0) {
ret = wc_AesSetKey(aes, (byte*)aes_key,
AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
if (ret == 0) {
ret = wc_AesCbcEncrypt(aes, cipher, msg, AES_BLOCK_SIZE);
ret = wc_AesCbcEncrypt(aes, cipher, msg, WC_AES_BLOCK_SIZE);
}

wc_AesFree(aes);
Expand All @@ -144,15 +144,15 @@ static int sce_aes_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
ret = wc_AesInit(aes, NULL, devId);
if (ret == 0) {
ret = wc_AesSetKey(aes, (byte*)aes_key,
AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
if (ret == 0)
ret = wc_AesCbcDecrypt(aes, plain, cipher, AES_BLOCK_SIZE);
ret = wc_AesCbcDecrypt(aes, plain, cipher, WC_AES_BLOCK_SIZE);

wc_AesFree(aes);
}
if (ret != 0)
ret = -2;
if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE) != 0)
ret = -3;
#endif /* HAVE_AES_DECRYPT */

Expand Down Expand Up @@ -189,8 +189,8 @@ static void tskAes128_Cbc_Test(void *pvParam)
static int sce_aes256_test(int prnt, FSPSM_AES_PWKEY aes_key)
{
Aes enc[1];
byte cipher[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[WC_AES_BLOCK_SIZE];
byte plain[WC_AES_BLOCK_SIZE];
Aes dec[1];
int ret = 0;

Expand Down Expand Up @@ -219,28 +219,28 @@ static int sce_aes256_test(int prnt, FSPSM_AES_PWKEY aes_key)
}

ret = wc_AesSetKey(enc, (byte*)aes_key,
AES_BLOCK_SIZE*2, iv, AES_ENCRYPTION);
WC_AES_BLOCK_SIZE*2, iv, AES_ENCRYPTION);
if (ret != 0){
ret = -3;
goto out;
}

ret = wc_AesSetKey(dec, (byte*)aes_key,
AES_BLOCK_SIZE*2, iv, AES_DECRYPTION);
WC_AES_BLOCK_SIZE*2, iv, AES_DECRYPTION);
if (ret != 0) {
ret = -4;
goto out;
}

XMEMSET(cipher, 0, AES_BLOCK_SIZE);
XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));

if (ret != 0) {
ret = -5;
goto out;
}

XMEMSET(plain, 0, AES_BLOCK_SIZE);
XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));

if (ret != 0){
Expand Down Expand Up @@ -340,8 +340,8 @@ static int sce_aesgcm256_test(int prnt, FSPSM_AES_PWKEY aes256_key)
};

byte resultT[sizeof(t1)];
byte resultP[sizeof(p) + AES_BLOCK_SIZE];
byte resultC[sizeof(p) + AES_BLOCK_SIZE];
byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE];
byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE];
int result = 0;
int ret;

Expand All @@ -366,7 +366,7 @@ static int sce_aesgcm256_test(int prnt, FSPSM_AES_PWKEY aes256_key)
}

result = wc_AesGcmSetKey(enc,
(byte*)aes256_key, AES_BLOCK_SIZE*2);
(byte*)aes256_key, WC_AES_BLOCK_SIZE*2);
if (result != 0) {
ret = -3;
goto out;
Expand All @@ -383,7 +383,7 @@ static int sce_aesgcm256_test(int prnt, FSPSM_AES_PWKEY aes256_key)
}

result = wc_AesGcmSetKey(dec,
(byte*)aes256_key, AES_BLOCK_SIZE*2);
(byte*)aes256_key, WC_AES_BLOCK_SIZE*2);
if (result != 0) {
ret = -7;
goto out;
Expand All @@ -408,7 +408,7 @@ static int sce_aesgcm256_test(int prnt, FSPSM_AES_PWKEY aes256_key)
XMEMSET(resultP, 0, sizeof(resultP));

wc_AesGcmSetKey(enc,
(byte*)aes256_key, AES_BLOCK_SIZE*2);
(byte*)aes256_key, WC_AES_BLOCK_SIZE*2);
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
result = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p),
(byte*)iv1, sizeof(iv1),
Expand Down Expand Up @@ -527,8 +527,8 @@ static int sce_aesgcm128_test(int prnt, FSPSM_AES_PWKEY aes128_key)
};

byte resultT[sizeof(t1)];
byte resultP[sizeof(p) + AES_BLOCK_SIZE];
byte resultC[sizeof(p) + AES_BLOCK_SIZE];
byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE];
byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE];
int result = 0;
int ret;

Expand All @@ -553,7 +553,7 @@ static int sce_aesgcm128_test(int prnt, FSPSM_AES_PWKEY aes128_key)
goto out;
}

wc_AesGcmSetKey(enc, (byte*)aes128_key, AES_BLOCK_SIZE);
wc_AesGcmSetKey(enc, (byte*)aes128_key, WC_AES_BLOCK_SIZE);
if (result != 0) {
ret = -3;
goto out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)

Aes aes[1];

byte cipher[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[WC_AES_BLOCK_SIZE];
byte plain[WC_AES_BLOCK_SIZE];
int ret = 0;

WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
Expand All @@ -139,22 +139,22 @@ static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)
byte key[] = "0123456789abcdef "; /* align */
byte iv[] = "1234567890abcdef "; /* align */

ForceZero(cipher, AES_BLOCK_SIZE);
ForceZero(plain, AES_BLOCK_SIZE);
ForceZero(cipher, WC_AES_BLOCK_SIZE);
ForceZero(plain, WC_AES_BLOCK_SIZE);

if (prnt) {
printf(" tsip_aes_cbc_test() ");
}

ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) {
ret = wc_AesSetKey(aes, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
ret = wc_AesSetKey(aes, key, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
XMEMCPY(&aes->ctx.tsip_keyIdx, aes_key,
sizeof(tsip_aes_key_index_t));

aes->ctx.keySize = aes->keylen;
if (ret == 0) {
ret = wc_tsip_AesCbcEncrypt(aes, cipher, msg, AES_BLOCK_SIZE);
ret = wc_tsip_AesCbcEncrypt(aes, cipher, msg, WC_AES_BLOCK_SIZE);
}

wc_AesFree(aes);
Expand All @@ -167,18 +167,18 @@ static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)
if (ret == 0)
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) {
ret = wc_AesSetKey(aes, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
ret = wc_AesSetKey(aes, key, WC_AES_BLOCK_SIZE, iv, AES_DECRYPTION);
XMEMCPY(&aes->ctx.tsip_keyIdx, aes_key,
sizeof(tsip_aes_key_index_t));
aes->ctx.keySize = aes->keylen;
if (ret == 0)
ret = wc_tsip_AesCbcDecrypt(aes, plain, cipher, AES_BLOCK_SIZE);
ret = wc_tsip_AesCbcDecrypt(aes, plain, cipher, WC_AES_BLOCK_SIZE);

wc_AesFree(aes);
}
if (ret != 0)
ret = -2;
if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE) != 0)
ret = -3;
#endif /* HAVE_AES_DECRYPT */

Expand Down Expand Up @@ -216,8 +216,8 @@ static void tskAes128_Cbc_Test(void *pvParam)
static int tsip_aes256_test(int prnt, tsip_aes_key_index_t* aes_key)
{
Aes enc[1];
byte cipher[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[WC_AES_BLOCK_SIZE];
byte plain[WC_AES_BLOCK_SIZE];
Aes dec[1];
int ret = 0;

Expand Down Expand Up @@ -279,15 +279,15 @@ static int tsip_aes256_test(int prnt, tsip_aes_key_index_t* aes_key)
dec->ctx.keySize = dec->keylen;
}

ForceZero(cipher, AES_BLOCK_SIZE);
ForceZero(cipher, WC_AES_BLOCK_SIZE);
ret = wc_tsip_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));

if (ret != 0) {
ret = -5;
goto out;
}

ForceZero(plain, AES_BLOCK_SIZE);
ForceZero(plain, WC_AES_BLOCK_SIZE);
ret = wc_tsip_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));

if (ret != 0){
Expand Down Expand Up @@ -395,8 +395,8 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
};

byte resultT[sizeof(t1)];
byte resultP[sizeof(p) + AES_BLOCK_SIZE];
byte resultC[sizeof(p) + AES_BLOCK_SIZE];
byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE];
byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE];
int result = 0;
int ret;

Expand Down Expand Up @@ -575,8 +575,8 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
};

byte resultT[sizeof(t3)];
byte resultP[sizeof(p3) + AES_BLOCK_SIZE];
byte resultC[sizeof(p3) + AES_BLOCK_SIZE];
byte resultP[sizeof(p3) + WC_AES_BLOCK_SIZE];
byte resultC[sizeof(p3) + WC_AES_BLOCK_SIZE];
int result = 0;
int ret;

Expand Down
30 changes: 15 additions & 15 deletions IDE/Renesas/e2studio/RZN2L/test/src/test/wolfssl_rsip_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ static int rsip_aes128_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)

Aes aes[1];

byte cipher[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[WC_AES_BLOCK_SIZE];
byte plain[WC_AES_BLOCK_SIZE];
word32 keySz = (word32)(128/8);
int ret = 0;

Expand All @@ -147,8 +147,8 @@ static int rsip_aes128_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
};
byte iv[] = "1234567890abcdef "; /* align */

XMEMSET(cipher, 0, AES_BLOCK_SIZE);
XMEMSET(plain, 0, AES_BLOCK_SIZE);
XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);

if (prnt) {
printf(" rsip_aes_cbc_test() ");
Expand All @@ -159,7 +159,7 @@ static int rsip_aes128_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
ret = wc_AesSetKey(aes, (byte*)aes_key, keySz,
iv, AES_ENCRYPTION);
if (ret == 0) {
ret = wc_AesCbcEncrypt(aes, cipher, msg, AES_BLOCK_SIZE);
ret = wc_AesCbcEncrypt(aes, cipher, msg, WC_AES_BLOCK_SIZE);
}

wc_AesFree(aes);
Expand All @@ -174,13 +174,13 @@ static int rsip_aes128_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
ret = wc_AesSetKey(aes, (byte*)aes_key, keySz,
iv, AES_DECRYPTION);
if (ret == 0)
ret = wc_AesCbcDecrypt(aes, plain, cipher, AES_BLOCK_SIZE);
ret = wc_AesCbcDecrypt(aes, plain, cipher, WC_AES_BLOCK_SIZE);

wc_AesFree(aes);
}
if (ret != 0)
ret = -2;
if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE) != 0)
ret = -3;
#endif /* HAVE_AES_DECRYPT */

Expand Down Expand Up @@ -217,8 +217,8 @@ static void tskAes128_Cbc_Test(void *pvParam)
static int rsip_aes256_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
{
Aes enc[1];
byte cipher[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[WC_AES_BLOCK_SIZE];
byte plain[WC_AES_BLOCK_SIZE];
Aes dec[1];
const word32 keySz = (word32)(256/8);
int ret = 0;
Expand Down Expand Up @@ -261,15 +261,15 @@ static int rsip_aes256_cbc_test(int prnt, FSPSM_AES_PWKEY aes_key)
goto out;
}

XMEMSET(cipher, 0, AES_BLOCK_SIZE);
XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));

if (ret != 0) {
ret = -5;
goto out;
}

XMEMSET(plain, 0, AES_BLOCK_SIZE);
XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));

if (ret != 0){
Expand Down Expand Up @@ -368,8 +368,8 @@ static int rsip_aesgcm256_test(int prnt, FSPSM_AES_PWKEY aes256_key)
};

byte resultT[sizeof(t1)];
byte resultP[sizeof(p) + AES_BLOCK_SIZE];
byte resultC[sizeof(p) + AES_BLOCK_SIZE];
byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE];
byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE];
int result = 0;
int ret;

Expand Down Expand Up @@ -554,8 +554,8 @@ static int rsip_aesgcm128_test(int prnt, FSPSM_AES_PWKEY aes128_key)
};

byte resultT[sizeof(t1)];
byte resultP[sizeof(p) + AES_BLOCK_SIZE];
byte resultC[sizeof(p) + AES_BLOCK_SIZE];
byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE];
byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE];
int result = 0;
int ret;

Expand Down
Loading

0 comments on commit ed18bf3

Please sign in to comment.