From bfeb0ad48e11bd288f0a1c34400a953a477c762a Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Fri, 22 Nov 2024 19:27:56 -0600 Subject: [PATCH] expand opensslcoexist to all low level crypto APIs. --- linuxkm/lkcapi_glue.c | 158 ++-- src/internal.c | 24 +- src/keys.c | 150 +-- src/pk.c | 2 +- src/ssl.c | 10 +- src/ssl_crypto.c | 102 +- src/tls.c | 4 +- src/x509.c | 22 +- wolfcrypt/benchmark/benchmark.c | 22 +- wolfcrypt/src/aes.c | 1546 +++++++++++++++---------------- wolfcrypt/src/asn.c | 10 +- wolfcrypt/src/camellia.c | 44 +- wolfcrypt/src/cmac.c | 34 +- wolfcrypt/src/ecc.c | 12 +- wolfcrypt/src/evp.c | 110 +-- wolfcrypt/src/hash.c | 8 +- wolfcrypt/src/hpke.c | 4 +- wolfcrypt/src/kdf.c | 20 +- wolfcrypt/src/md2.c | 40 +- wolfcrypt/src/md4.c | 38 +- wolfcrypt/src/pkcs7.c | 12 +- wolfcrypt/src/wc_pkcs11.c | 4 +- wolfcrypt/test/test.c | 750 +++++++-------- wolfssl/internal.h | 7 +- wolfssl/openssl/aes.h | 33 +- wolfssl/openssl/cmac.h | 8 +- wolfssl/openssl/des.h | 13 +- wolfssl/openssl/evp.h | 4 +- wolfssl/openssl/md4.h | 3 + wolfssl/openssl/md5.h | 4 + wolfssl/openssl/rc4.h | 7 +- wolfssl/openssl/srp.h | 4 + wolfssl/openssl/x509v3.h | 157 ++-- wolfssl/ssl.h | 58 ++ wolfssl/test.h | 4 +- wolfssl/wolfcrypt/aes.h | 31 +- wolfssl/wolfcrypt/camellia.h | 45 +- wolfssl/wolfcrypt/cmac.h | 12 +- wolfssl/wolfcrypt/md2.h | 40 +- wolfssl/wolfcrypt/md4.h | 34 +- wolfssl/wolfcrypt/pkcs7.h | 2 +- wolfssl/wolfcrypt/settings.h | 5 + 42 files changed, 1881 insertions(+), 1716 deletions(-) diff --git a/linuxkm/lkcapi_glue.c b/linuxkm/lkcapi_glue.c index 082531959a..94a41bf015 100644 --- a/linuxkm/lkcapi_glue.c +++ b/linuxkm/lkcapi_glue.c @@ -367,14 +367,14 @@ static struct skcipher_alg cbcAesAlg = { .base.cra_name = WOLFKM_AESCBC_NAME, .base.cra_driver_name = WOLFKM_AESCBC_DRIVER, .base.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY, - .base.cra_blocksize = AES_BLOCK_SIZE, + .base.cra_blocksize = WC_AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct km_AesCtx), .base.cra_module = THIS_MODULE, .init = km_AesCbcInit, .exit = km_AesExit, .min_keysize = AES_128_KEY_SIZE, .max_keysize = AES_256_KEY_SIZE, - .ivsize = AES_BLOCK_SIZE, + .ivsize = WC_AES_BLOCK_SIZE, .setkey = km_AesCbcSetKey, .encrypt = km_AesCbcEncrypt, .decrypt = km_AesCbcDecrypt, @@ -506,14 +506,14 @@ static struct skcipher_alg cfbAesAlg = { .base.cra_name = WOLFKM_AESCFB_NAME, .base.cra_driver_name = WOLFKM_AESCFB_DRIVER, .base.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY, - .base.cra_blocksize = AES_BLOCK_SIZE, + .base.cra_blocksize = WC_AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct km_AesCtx), .base.cra_module = THIS_MODULE, .init = km_AesCfbInit, .exit = km_AesExit, .min_keysize = AES_128_KEY_SIZE, .max_keysize = AES_256_KEY_SIZE, - .ivsize = AES_BLOCK_SIZE, + .ivsize = WC_AES_BLOCK_SIZE, .setkey = km_AesCfbSetKey, .encrypt = km_AesCfbEncrypt, .decrypt = km_AesCfbDecrypt, @@ -565,7 +565,7 @@ static int km_AesGcmSetKey(struct crypto_aead *tfm, const u8 *in_key, static int km_AesGcmSetAuthsize(struct crypto_aead *tfm, unsigned int authsize) { (void)tfm; - if (authsize > AES_BLOCK_SIZE || + if (authsize > WC_AES_BLOCK_SIZE || authsize < WOLFSSL_MIN_AUTH_TAG_SZ) { pr_err("%s: invalid authsize: %d\n", crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)), authsize); @@ -591,7 +591,7 @@ static int km_AesGcmEncrypt(struct aead_request *req) struct skcipher_walk walk; struct scatter_walk assocSgWalk; unsigned int nbytes = 0; - u8 authTag[AES_BLOCK_SIZE]; + u8 authTag[WC_AES_BLOCK_SIZE]; int err = 0; unsigned int assocLeft = 0; unsigned int cryptLeft = 0; @@ -612,7 +612,7 @@ static int km_AesGcmEncrypt(struct aead_request *req) } err = wc_AesGcmInit(ctx->aes_encrypt, NULL /*key*/, 0 /*keylen*/, walk.iv, - AES_BLOCK_SIZE); + WC_AES_BLOCK_SIZE); if (unlikely(err)) { pr_err("%s: wc_AesGcmInit failed: %d\n", crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)), err); @@ -692,7 +692,7 @@ static int km_AesGcmDecrypt(struct aead_request *req) struct skcipher_walk walk; struct scatter_walk assocSgWalk; unsigned int nbytes = 0; - u8 origAuthTag[AES_BLOCK_SIZE]; + u8 origAuthTag[WC_AES_BLOCK_SIZE]; int err = 0; unsigned int assocLeft = 0; unsigned int cryptLeft = 0; @@ -718,7 +718,7 @@ static int km_AesGcmDecrypt(struct aead_request *req) } err = wc_AesGcmInit(ctx->aes_encrypt, NULL /*key*/, 0 /*keylen*/, walk.iv, - AES_BLOCK_SIZE); + WC_AES_BLOCK_SIZE); if (unlikely(err)) { pr_err("%s: wc_AesGcmInit failed: %d\n", crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)), err); @@ -805,9 +805,9 @@ static struct aead_alg gcmAesAead = { .setauthsize = km_AesGcmSetAuthsize, .encrypt = km_AesGcmEncrypt, .decrypt = km_AesGcmDecrypt, - .ivsize = AES_BLOCK_SIZE, - .maxauthsize = AES_BLOCK_SIZE, - .chunksize = AES_BLOCK_SIZE, + .ivsize = WC_AES_BLOCK_SIZE, + .maxauthsize = WC_AES_BLOCK_SIZE, + .chunksize = WC_AES_BLOCK_SIZE, }; static int gcmAesAead_loaded = 0; @@ -894,7 +894,7 @@ static int km_AesXtsEncrypt(struct skcipher_request *req) tfm = crypto_skcipher_reqtfm(req); ctx = crypto_skcipher_ctx(tfm); - if (req->cryptlen < AES_BLOCK_SIZE) + if (req->cryptlen < WC_AES_BLOCK_SIZE) return -EINVAL; err = skcipher_walk_virt(&walk, req, false); @@ -918,12 +918,12 @@ static int km_AesXtsEncrypt(struct skcipher_request *req) err = skcipher_walk_done(&walk, 0); } else { - int tail = req->cryptlen % AES_BLOCK_SIZE; + int tail = req->cryptlen % WC_AES_BLOCK_SIZE; struct skcipher_request subreq; struct XtsAesStreamData stream; if (tail > 0) { - int blocks = DIV_ROUND_UP(req->cryptlen, AES_BLOCK_SIZE) - 2; + int blocks = DIV_ROUND_UP(req->cryptlen, WC_AES_BLOCK_SIZE) - 2; skcipher_walk_abort(&walk); @@ -932,7 +932,7 @@ static int km_AesXtsEncrypt(struct skcipher_request *req) skcipher_request_flags(req), NULL, NULL); skcipher_request_set_crypt(&subreq, req->src, req->dst, - blocks * AES_BLOCK_SIZE, req->iv); + blocks * WC_AES_BLOCK_SIZE, req->iv); req = &subreq; err = skcipher_walk_virt(&walk, req, false); @@ -955,9 +955,9 @@ static int km_AesXtsEncrypt(struct skcipher_request *req) * end-of-message ciphertext stealing. */ if (nbytes < walk.total) - nbytes &= ~(AES_BLOCK_SIZE - 1); + nbytes &= ~(WC_AES_BLOCK_SIZE - 1); - if (nbytes & ((unsigned int)AES_BLOCK_SIZE - 1U)) + if (nbytes & ((unsigned int)WC_AES_BLOCK_SIZE - 1U)) err = wc_AesXtsEncryptFinal(ctx->aesXts, walk.dst.virt.addr, walk.src.virt.addr, nbytes, &stream); @@ -989,7 +989,7 @@ static int km_AesXtsEncrypt(struct skcipher_request *req) if (req->dst != req->src) dst = scatterwalk_ffwd(sg_dst, req->dst, req->cryptlen); - skcipher_request_set_crypt(req, src, dst, AES_BLOCK_SIZE + tail, + skcipher_request_set_crypt(req, src, dst, WC_AES_BLOCK_SIZE + tail, req->iv); err = skcipher_walk_virt(&walk, &subreq, false); @@ -1007,7 +1007,7 @@ static int km_AesXtsEncrypt(struct skcipher_request *req) } err = skcipher_walk_done(&walk, 0); - } else if (! (stream.bytes_crypted_with_this_tweak & ((word32)AES_BLOCK_SIZE - 1U))) { + } else if (! (stream.bytes_crypted_with_this_tweak & ((word32)WC_AES_BLOCK_SIZE - 1U))) { err = wc_AesXtsEncryptFinal(ctx->aesXts, NULL, NULL, 0, &stream); } } @@ -1026,7 +1026,7 @@ static int km_AesXtsDecrypt(struct skcipher_request *req) tfm = crypto_skcipher_reqtfm(req); ctx = crypto_skcipher_ctx(tfm); - if (req->cryptlen < AES_BLOCK_SIZE) + if (req->cryptlen < WC_AES_BLOCK_SIZE) return -EINVAL; err = skcipher_walk_virt(&walk, req, false); @@ -1050,12 +1050,12 @@ static int km_AesXtsDecrypt(struct skcipher_request *req) err = skcipher_walk_done(&walk, 0); } else { - int tail = req->cryptlen % AES_BLOCK_SIZE; + int tail = req->cryptlen % WC_AES_BLOCK_SIZE; struct skcipher_request subreq; struct XtsAesStreamData stream; if (unlikely(tail > 0)) { - int blocks = DIV_ROUND_UP(req->cryptlen, AES_BLOCK_SIZE) - 2; + int blocks = DIV_ROUND_UP(req->cryptlen, WC_AES_BLOCK_SIZE) - 2; skcipher_walk_abort(&walk); @@ -1064,7 +1064,7 @@ static int km_AesXtsDecrypt(struct skcipher_request *req) skcipher_request_flags(req), NULL, NULL); skcipher_request_set_crypt(&subreq, req->src, req->dst, - blocks * AES_BLOCK_SIZE, req->iv); + blocks * WC_AES_BLOCK_SIZE, req->iv); req = &subreq; err = skcipher_walk_virt(&walk, req, false); @@ -1087,9 +1087,9 @@ static int km_AesXtsDecrypt(struct skcipher_request *req) * end-of-message ciphertext stealing. */ if (nbytes < walk.total) - nbytes &= ~(AES_BLOCK_SIZE - 1); + nbytes &= ~(WC_AES_BLOCK_SIZE - 1); - if (nbytes & ((unsigned int)AES_BLOCK_SIZE - 1U)) + if (nbytes & ((unsigned int)WC_AES_BLOCK_SIZE - 1U)) err = wc_AesXtsDecryptFinal(ctx->aesXts, walk.dst.virt.addr, walk.src.virt.addr, nbytes, &stream); @@ -1121,7 +1121,7 @@ static int km_AesXtsDecrypt(struct skcipher_request *req) if (req->dst != req->src) dst = scatterwalk_ffwd(sg_dst, req->dst, req->cryptlen); - skcipher_request_set_crypt(req, src, dst, AES_BLOCK_SIZE + tail, + skcipher_request_set_crypt(req, src, dst, WC_AES_BLOCK_SIZE + tail, req->iv); err = skcipher_walk_virt(&walk, &subreq, false); @@ -1139,7 +1139,7 @@ static int km_AesXtsDecrypt(struct skcipher_request *req) } err = skcipher_walk_done(&walk, 0); - } else if (! (stream.bytes_crypted_with_this_tweak & ((word32)AES_BLOCK_SIZE - 1U))) { + } else if (! (stream.bytes_crypted_with_this_tweak & ((word32)WC_AES_BLOCK_SIZE - 1U))) { err = wc_AesXtsDecryptFinal(ctx->aesXts, NULL, NULL, 0, &stream); } } @@ -1150,14 +1150,14 @@ static struct skcipher_alg xtsAesAlg = { .base.cra_name = WOLFKM_AESXTS_NAME, .base.cra_driver_name = WOLFKM_AESXTS_DRIVER, .base.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY, - .base.cra_blocksize = AES_BLOCK_SIZE, + .base.cra_blocksize = WC_AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct km_AesXtsCtx), .base.cra_module = THIS_MODULE, .min_keysize = 2 * AES_128_KEY_SIZE, .max_keysize = 2 * AES_256_KEY_SIZE, - .ivsize = AES_BLOCK_SIZE, - .walksize = 2 * AES_BLOCK_SIZE, + .ivsize = WC_AES_BLOCK_SIZE, + .walksize = 2 * WC_AES_BLOCK_SIZE, .init = km_AesXtsInit, .exit = km_AesXtsExit, .setkey = km_AesXtsSetKey, @@ -1229,7 +1229,7 @@ static int linuxkm_test_aescbc(void) } aes_inited = 1; - ret = wc_AesSetKey(aes, key32, AES_BLOCK_SIZE * 2, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(aes, key32, WC_AES_BLOCK_SIZE * 2, iv, AES_ENCRYPTION); if (ret) { pr_err("wolfcrypt wc_AesSetKey failed with return code %d\n", ret); goto test_cbc_end; @@ -1257,7 +1257,7 @@ static int linuxkm_test_aescbc(void) } aes_inited = 1; - ret = wc_AesSetKey(aes, key32, AES_BLOCK_SIZE * 2, iv, AES_DECRYPTION); + ret = wc_AesSetKey(aes, key32, WC_AES_BLOCK_SIZE * 2, iv, AES_DECRYPTION); if (ret) { pr_err("wolfcrypt wc_AesSetKey failed with return code %d.\n", ret); goto test_cbc_end; @@ -1310,7 +1310,7 @@ static int linuxkm_test_aescbc(void) } #endif - ret = crypto_skcipher_setkey(tfm, key32, AES_BLOCK_SIZE * 2); + ret = crypto_skcipher_setkey(tfm, key32, WC_AES_BLOCK_SIZE * 2); if (ret) { pr_err("error: crypto_skcipher_setkey returned: %d\n", ret); goto test_cbc_end; @@ -1435,7 +1435,7 @@ static int linuxkm_test_aescfb(void) } aes_inited = 1; - ret = wc_AesSetKey(aes, key32, AES_BLOCK_SIZE * 2, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(aes, key32, WC_AES_BLOCK_SIZE * 2, iv, AES_ENCRYPTION); if (ret) { pr_err("wolfcrypt wc_AesSetKey failed with return code %d\n", ret); goto test_cfb_end; @@ -1463,7 +1463,7 @@ static int linuxkm_test_aescfb(void) } aes_inited = 1; - ret = wc_AesSetKey(aes, key32, AES_BLOCK_SIZE * 2, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(aes, key32, WC_AES_BLOCK_SIZE * 2, iv, AES_ENCRYPTION); if (ret) { pr_err("wolfcrypt wc_AesSetKey failed with return code %d.\n", ret); goto test_cfb_end; @@ -1516,7 +1516,7 @@ static int linuxkm_test_aescfb(void) } #endif - ret = crypto_skcipher_setkey(tfm, key32, AES_BLOCK_SIZE * 2); + ret = crypto_skcipher_setkey(tfm, key32, WC_AES_BLOCK_SIZE * 2); if (ret) { pr_err("error: crypto_skcipher_setkey returned: %d\n", ret); goto test_cfb_end; @@ -1632,7 +1632,7 @@ static int linuxkm_test_aesgcm(void) 0xe4,0x28,0x90,0xaa,0x09,0xab,0xf9,0x7c }; byte enc[sizeof(p_vector)]; - byte authTag[AES_BLOCK_SIZE]; + byte authTag[WC_AES_BLOCK_SIZE]; byte dec[sizeof(p_vector)]; u8 * assoc2 = NULL; u8 * enc2 = NULL; @@ -1644,7 +1644,7 @@ static int linuxkm_test_aesgcm(void) /* Init stack variables. */ XMEMSET(enc, 0, sizeof(p_vector)); XMEMSET(dec, 0, sizeof(p_vector)); - XMEMSET(authTag, 0, AES_BLOCK_SIZE); + XMEMSET(authTag, 0, WC_AES_BLOCK_SIZE); aes = (Aes *)malloc(sizeof(*aes)); if (aes == NULL) @@ -1658,7 +1658,7 @@ static int linuxkm_test_aesgcm(void) aes_inited = 1; ret = wc_AesGcmInit(aes, key32, sizeof(key32)/sizeof(byte), ivstr, - AES_BLOCK_SIZE); + WC_AES_BLOCK_SIZE); if (ret) { pr_err("error: wc_AesGcmInit failed with return code %d.\n", ret); goto test_gcm_end; @@ -1684,7 +1684,7 @@ static int linuxkm_test_aesgcm(void) goto test_gcm_end; } - ret = wc_AesGcmEncryptFinal(aes, authTag, AES_BLOCK_SIZE); + ret = wc_AesGcmEncryptFinal(aes, authTag, WC_AES_BLOCK_SIZE); if (ret) { pr_err("error: wc_AesGcmEncryptFinal failed with return code %d\n", ret); @@ -1698,7 +1698,7 @@ static int linuxkm_test_aesgcm(void) } ret = wc_AesGcmInit(aes, key32, sizeof(key32)/sizeof(byte), ivstr, - AES_BLOCK_SIZE); + WC_AES_BLOCK_SIZE); if (ret) { pr_err("error: wc_AesGcmInit failed with return code %d.\n", ret); goto test_gcm_end; @@ -1712,7 +1712,7 @@ static int linuxkm_test_aesgcm(void) goto test_gcm_end; } - ret = wc_AesGcmDecryptFinal(aes, authTag, AES_BLOCK_SIZE); + ret = wc_AesGcmDecryptFinal(aes, authTag, WC_AES_BLOCK_SIZE); if (ret) { pr_err("error: wc_AesGcmEncryptFinal failed with return code %d\n", ret); @@ -1734,13 +1734,13 @@ static int linuxkm_test_aesgcm(void) memset(assoc2, 0, sizeof(assoc)); memcpy(assoc2, assoc, sizeof(assoc)); - iv = malloc(AES_BLOCK_SIZE); + iv = malloc(WC_AES_BLOCK_SIZE); if (IS_ERR(iv)) { pr_err("error: malloc failed\n"); goto test_gcm_end; } - memset(iv, 0, AES_BLOCK_SIZE); - memcpy(iv, ivstr, AES_BLOCK_SIZE); + memset(iv, 0, WC_AES_BLOCK_SIZE); + memcpy(iv, ivstr, WC_AES_BLOCK_SIZE); enc2 = malloc(decryptLen); if (IS_ERR(enc2)) { @@ -1777,7 +1777,7 @@ static int linuxkm_test_aesgcm(void) } #endif - ret = crypto_aead_setkey(tfm, key32, AES_BLOCK_SIZE * 2); + ret = crypto_aead_setkey(tfm, key32, WC_AES_BLOCK_SIZE * 2); if (ret) { pr_err("error: crypto_aead_setkey returned: %d\n", ret); goto test_gcm_end; @@ -1891,7 +1891,7 @@ static int aes_xts_128_test(void) XtsAes *aes = NULL; int aes_inited = 0; int ret = 0; -#define AES_XTS_128_TEST_BUF_SIZ (AES_BLOCK_SIZE * 2 + 8) +#define AES_XTS_128_TEST_BUF_SIZ (WC_AES_BLOCK_SIZE * 2 + 8) unsigned char *buf = NULL; unsigned char *cipher = NULL; u8 * enc2 = NULL; @@ -2049,12 +2049,12 @@ static int aes_xts_128_test(void) ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream); if (ret != 0) goto out; - ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; - ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, - p2 + AES_BLOCK_SIZE, - sizeof(p2) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, + p2 + WC_AES_BLOCK_SIZE, + sizeof(p2) - WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; if (XMEMCMP(c2, buf, sizeof(c2))) { @@ -2070,7 +2070,7 @@ static int aes_xts_128_test(void) ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1)); if (ret != 0) goto out; - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) { + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) { ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E; goto out; } @@ -2081,7 +2081,7 @@ static int aes_xts_128_test(void) WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); if (ret != 0) goto out; - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) { + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) { ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E; goto out; } @@ -2141,7 +2141,7 @@ static int aes_xts_128_test(void) ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1)); if (ret != 0) goto out; - if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) { + if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE)) { ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E; goto out; } @@ -2153,7 +2153,7 @@ static int aes_xts_128_test(void) WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); if (ret != 0) goto out; - if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) { + if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE)) { ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E; goto out; } @@ -2235,14 +2235,14 @@ static int aes_xts_128_test(void) ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream); if (ret != 0) goto out; - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION); @@ -2275,14 +2275,14 @@ static int aes_xts_128_test(void) ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream); if (ret != 0) goto out; - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } for (i = 0; i < j; i++) { @@ -2491,7 +2491,7 @@ static int aes_xts_256_test(void) XtsAes *aes = NULL; int aes_inited = 0; int ret = 0; -#define AES_XTS_256_TEST_BUF_SIZ (AES_BLOCK_SIZE * 3) +#define AES_XTS_256_TEST_BUF_SIZ (WC_AES_BLOCK_SIZE * 3) unsigned char *buf = NULL; unsigned char *cipher = NULL; u8 * enc2 = NULL; @@ -2625,12 +2625,12 @@ static int aes_xts_256_test(void) ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream); if (ret != 0) goto out; - ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; - ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, - p2 + AES_BLOCK_SIZE, - sizeof(p2) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, + p2 + WC_AES_BLOCK_SIZE, + sizeof(p2) - WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; if (XMEMCMP(c2, buf, sizeof(c2))) { @@ -2645,7 +2645,7 @@ static int aes_xts_256_test(void) ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1)); if (ret != 0) goto out; - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) { + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) { ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E; goto out; } @@ -2674,7 +2674,7 @@ static int aes_xts_256_test(void) ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1)); if (ret != 0) goto out; - if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) { + if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE)) { ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E; goto out; } @@ -2715,14 +2715,14 @@ static int aes_xts_256_test(void) ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream); if (ret != 0) goto out; - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION); @@ -2755,14 +2755,14 @@ static int aes_xts_256_test(void) ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream); if (ret != 0) goto out; - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); if (ret != 0) goto out; - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } for (i = 0; i < j; i++) { diff --git a/src/internal.c b/src/internal.c index 462e3c7244..756f2812fc 100644 --- a/src/internal.c +++ b/src/internal.c @@ -796,16 +796,16 @@ static int ExportCipherSpecState(WOLFSSL* ssl, byte* exp, word32 len, byte ver, ssl->specs.bulk_cipher_algorithm == wolfssl_aes) { byte *pt = (byte*)ssl->encrypt.aes->reg; - if ((idx + 2*AES_BLOCK_SIZE) > len) { + if ((idx + 2*WC_AES_BLOCK_SIZE) > len) { WOLFSSL_MSG("Can not fit AES state into buffer"); return BUFFER_E; } - XMEMCPY(exp + idx, pt, AES_BLOCK_SIZE); - idx += AES_BLOCK_SIZE; + XMEMCPY(exp + idx, pt, WC_AES_BLOCK_SIZE); + idx += WC_AES_BLOCK_SIZE; pt = (byte*)ssl->decrypt.aes->reg; - XMEMCPY(exp + idx, pt, AES_BLOCK_SIZE); - idx += AES_BLOCK_SIZE; + XMEMCPY(exp + idx, pt, WC_AES_BLOCK_SIZE); + idx += WC_AES_BLOCK_SIZE; } WOLFSSL_LEAVE("ExportCipherSpecState", idx); @@ -1048,12 +1048,12 @@ static int ImportCipherSpecState(WOLFSSL* ssl, const byte* exp, word32 len, if (type == WOLFSSL_EXPORT_TLS && ssl->specs.bulk_cipher_algorithm == wolfssl_aes) { byte *pt = (byte*)ssl->encrypt.aes->reg; - XMEMCPY(pt, exp + idx, AES_BLOCK_SIZE); - idx += AES_BLOCK_SIZE; + XMEMCPY(pt, exp + idx, WC_AES_BLOCK_SIZE); + idx += WC_AES_BLOCK_SIZE; pt = (byte*)ssl->decrypt.aes->reg; - XMEMCPY(pt, exp + idx, AES_BLOCK_SIZE); - idx += AES_BLOCK_SIZE; + XMEMCPY(pt, exp + idx, WC_AES_BLOCK_SIZE); + idx += WC_AES_BLOCK_SIZE; } WOLFSSL_LEAVE("ImportCipherSpecState", idx); @@ -2108,7 +2108,7 @@ int wolfSSL_session_export_internal(WOLFSSL* ssl, byte* buf, word32* sz, /* possible AES state needed */ if (type == WOLFSSL_EXPORT_TLS) { - *sz += AES_BLOCK_SIZE*2; + *sz += WC_AES_BLOCK_SIZE*2; } ret = WC_NO_ERR_TRACE(LENGTH_ONLY_E); } @@ -39554,7 +39554,7 @@ static int TicketEncDec(byte* key, int keyLen, byte* iv, byte* aad, int aadSz, } if (ret == 0) { ret = wc_AesGcmEncrypt(aes, in, out, inLen, iv, GCM_NONCE_MID_SZ, - tag, AES_BLOCK_SIZE, aad, aadSz); + tag, WC_AES_BLOCK_SIZE, aad, aadSz); } wc_AesFree(aes); } @@ -39565,7 +39565,7 @@ static int TicketEncDec(byte* key, int keyLen, byte* iv, byte* aad, int aadSz, } if (ret == 0) { ret = wc_AesGcmDecrypt(aes, in, out, inLen, iv, GCM_NONCE_MID_SZ, - tag, AES_BLOCK_SIZE, aad, aadSz); + tag, WC_AES_BLOCK_SIZE, aad, aadSz); } wc_AesFree(aes); } diff --git a/src/keys.c b/src/keys.c index b5b982c1b3..693e6b1333 100644 --- a/src/keys.c +++ b/src/keys.c @@ -341,7 +341,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -358,7 +358,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -374,7 +374,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -431,7 +431,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -448,7 +448,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -466,7 +466,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -503,7 +503,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -530,7 +530,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -547,7 +547,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -601,7 +601,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -618,7 +618,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -635,7 +635,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -653,7 +653,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -671,7 +671,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_16_AUTH_SZ; @@ -689,7 +689,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_8_AUTH_SZ; @@ -707,7 +707,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_8_AUTH_SZ; @@ -747,7 +747,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 1; specs->key_size = AES_128_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -764,7 +764,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 1; specs->key_size = AES_128_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -781,7 +781,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 1; specs->key_size = AES_256_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -798,7 +798,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->static_ecdh = 1; specs->key_size = AES_256_KEY_SIZE; specs->iv_size = AES_IV_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; break; #endif @@ -814,7 +814,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -907,7 +907,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -924,7 +924,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -941,7 +941,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -958,7 +958,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -976,7 +976,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -994,7 +994,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1012,7 +1012,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 1; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1068,7 +1068,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_8_AUTH_SZ; @@ -1086,7 +1086,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_8_AUTH_SZ; @@ -1104,7 +1104,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_8_AUTH_SZ; @@ -1124,7 +1124,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_8_AUTH_SZ; @@ -1144,7 +1144,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_16_AUTH_SZ; @@ -1164,7 +1164,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_16_AUTH_SZ; @@ -1184,7 +1184,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_16_AUTH_SZ; @@ -1204,7 +1204,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_IMP_IV_SZ; specs->aead_mac_size = AES_CCM_16_AUTH_SZ; @@ -1273,7 +1273,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_NONCE_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1291,7 +1291,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_NONCE_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1329,7 +1329,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_NONCE_SZ; specs->aead_mac_size = AES_CCM_16_AUTH_SZ; @@ -1347,7 +1347,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESCCM_NONCE_SZ; specs->aead_mac_size = AES_CCM_8_AUTH_SZ; @@ -1375,7 +1375,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1564,7 +1564,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -1581,7 +1581,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -1649,7 +1649,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -1666,7 +1666,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -1683,7 +1683,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1703,7 +1703,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1723,7 +1723,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1743,7 +1743,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1763,7 +1763,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -1783,7 +1783,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -1802,7 +1802,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -1821,7 +1821,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -1840,7 +1840,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -1859,7 +1859,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -1878,7 +1878,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -1992,7 +1992,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -2026,7 +2026,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -2043,7 +2043,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -2060,7 +2060,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; break; @@ -2077,7 +2077,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -2095,7 +2095,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -2113,7 +2113,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -2131,7 +2131,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_256_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AESGCM_IMP_IV_SZ; specs->aead_mac_size = AES_GCM_AUTH_SZ; @@ -2149,7 +2149,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_128_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2166,7 +2166,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_256_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2183,7 +2183,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_128_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2200,7 +2200,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_256_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2217,7 +2217,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_128_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2234,7 +2234,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_256_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2251,7 +2251,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_128_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2268,7 +2268,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = CAMELLIA_256_KEY_SIZE; - specs->block_size = CAMELLIA_BLOCK_SIZE; + specs->block_size = WC_CAMELLIA_BLOCK_SIZE; specs->iv_size = CAMELLIA_IV_SIZE; break; @@ -2285,7 +2285,7 @@ int GetCipherSpec(word16 side, byte cipherSuite0, byte cipherSuite, specs->pad_size = PAD_SHA; specs->static_ecdh = 0; specs->key_size = AES_128_KEY_SIZE; - specs->block_size = AES_BLOCK_SIZE; + specs->block_size = WC_AES_BLOCK_SIZE; specs->iv_size = AES_IV_SIZE; if (opts != NULL) @@ -2976,13 +2976,13 @@ int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs, if (enc && enc->cam == NULL) enc->cam = - (Camellia*)XMALLOC(sizeof(Camellia), heap, DYNAMIC_TYPE_CIPHER); + (wc_Camellia*)XMALLOC(sizeof(wc_Camellia), heap, DYNAMIC_TYPE_CIPHER); if (enc && enc->cam == NULL) return MEMORY_E; if (dec && dec->cam == NULL) dec->cam = - (Camellia*)XMALLOC(sizeof(Camellia), heap, DYNAMIC_TYPE_CIPHER); + (wc_Camellia*)XMALLOC(sizeof(wc_Camellia), heap, DYNAMIC_TYPE_CIPHER); if (dec && dec->cam == NULL) return MEMORY_E; diff --git a/src/pk.c b/src/pk.c index 2510c32a02..7790d98b79 100644 --- a/src/pk.c +++ b/src/pk.c @@ -12980,7 +12980,7 @@ int wolfSSL_PEM_write_mem_ECPrivateKey(WOLFSSL_EC_KEY* ec, /* Calculate maximum size of DER encoding. * 4 > size of pub, priv + ASN.1 additional information */ der_max_len = 4 * (word32)wc_ecc_size((ecc_key*)ec->internal) + - AES_BLOCK_SIZE; + WC_AES_BLOCK_SIZE; /* Allocate buffer big enough to hold encoding. */ derBuf = (byte*)XMALLOC((size_t)der_max_len, NULL, diff --git a/src/ssl.c b/src/ssl.c index fd10e5e5b7..b11ed59a7e 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -24982,7 +24982,7 @@ int wolfSSL_RAND_load_file(const char* fname, long len) case WC_AES_192_CTR_TYPE : case WC_AES_256_CTR_TYPE : WOLFSSL_MSG("AES CTR"); - XMEMCPY(ctx->iv, &ctx->cipher.aes.reg, AES_BLOCK_SIZE); + XMEMCPY(ctx->iv, &ctx->cipher.aes.reg, WC_AES_BLOCK_SIZE); break; #endif /* WOLFSSL_AES_COUNTER */ #ifdef WOLFSSL_AES_CFB @@ -25121,7 +25121,7 @@ int wolfSSL_RAND_load_file(const char* fname, long len) case WC_AES_192_CBC_TYPE : case WC_AES_256_CBC_TYPE : WOLFSSL_MSG("AES CBC"); - XMEMCPY(&ctx->cipher.aes.reg, ctx->iv, AES_BLOCK_SIZE); + XMEMCPY(&ctx->cipher.aes.reg, ctx->iv, WC_AES_BLOCK_SIZE); break; #endif #ifdef HAVE_AESGCM @@ -25129,7 +25129,7 @@ int wolfSSL_RAND_load_file(const char* fname, long len) case WC_AES_192_GCM_TYPE : case WC_AES_256_GCM_TYPE : WOLFSSL_MSG("AES GCM"); - XMEMCPY(&ctx->cipher.aes.reg, ctx->iv, AES_BLOCK_SIZE); + XMEMCPY(&ctx->cipher.aes.reg, ctx->iv, WC_AES_BLOCK_SIZE); break; #endif #ifdef HAVE_AES_ECB @@ -25144,7 +25144,7 @@ int wolfSSL_RAND_load_file(const char* fname, long len) case WC_AES_192_CTR_TYPE : case WC_AES_256_CTR_TYPE : WOLFSSL_MSG("AES CTR"); - XMEMCPY(&ctx->cipher.aes.reg, ctx->iv, AES_BLOCK_SIZE); + XMEMCPY(&ctx->cipher.aes.reg, ctx->iv, WC_AES_BLOCK_SIZE); break; #endif @@ -25274,7 +25274,7 @@ void wolfSSL_aes_ctr_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, int doset, if (doset) (void)wc_AesSetIV(&ctx->cipher.aes, iv); /* OpenSSL compat, no ret */ else - XMEMCPY(iv, &ctx->cipher.aes.reg, AES_BLOCK_SIZE); + XMEMCPY(iv, &ctx->cipher.aes.reg, WC_AES_BLOCK_SIZE); } #endif /* NO_AES */ diff --git a/src/ssl_crypto.c b/src/ssl_crypto.c index e5153f258d..6907822a64 100644 --- a/src/ssl_crypto.c +++ b/src/ssl_crypto.c @@ -45,12 +45,12 @@ void wolfSSL_MD4_Init(WOLFSSL_MD4_CTX* md4) { /* Ensure WOLFSSL_MD4_CTX is big enough for wolfCrypt Md4. */ - WOLFSSL_ASSERT_SIZEOF_GE(md4->buffer, Md4); + WOLFSSL_ASSERT_SIZEOF_GE(md4->buffer, wc_Md4); WOLFSSL_ENTER("MD4_Init"); /* Initialize wolfCrypt MD4 object. */ - wc_InitMd4((Md4*)md4); + wc_InitMd4((wc_Md4*)md4); } /* Update MD4 hash with data. @@ -65,7 +65,7 @@ void wolfSSL_MD4_Update(WOLFSSL_MD4_CTX* md4, const void* data, WOLFSSL_ENTER("MD4_Update"); /* Update wolfCrypt MD4 object with data. */ - wc_Md4Update((Md4*)md4, (const byte*)data, (word32)len); + wc_Md4Update((wc_Md4*)md4, (const byte*)data, (word32)len); } /* Finalize MD4 hash and return output. @@ -79,7 +79,7 @@ void wolfSSL_MD4_Final(unsigned char* digest, WOLFSSL_MD4_CTX* md4) WOLFSSL_ENTER("MD4_Final"); /* Finalize wolfCrypt MD4 hash into digest. */ - wc_Md4Final((Md4*)md4, digest); + wc_Md4Final((wc_Md4*)md4, digest); } #endif /* NO_MD4 */ @@ -2228,7 +2228,7 @@ int wolfSSL_CMAC_Update(WOLFSSL_CMAC_CTX* ctx, const void* data, size_t len) * * @param [in, out] ctx CMAC context object. * @param [out] out Buffer to place CMAC result into. - * Must be able to hold AES_BLOCK_SIZE bytes. + * Must be able to hold WC_AES_BLOCK_SIZE bytes. * @param [out] len Length of CMAC result. May be NULL. * @return 1 on success. * @return 0 when ctx is NULL. @@ -2567,7 +2567,7 @@ WOLFSSL_DES_LONG wolfSSL_DES_cbc_cksum(const unsigned char* in, if (!err) { /* Encrypt data into temporary. */ wolfSSL_DES_cbc_encrypt(data, tmp, dataSz, sc, (WOLFSSL_DES_cblock*)iv, - DES_ENCRYPT); + WC_DES_ENCRYPT); /* Copy out last block. */ XMEMCPY((unsigned char*)out, tmp + (dataSz - DES_BLOCK_SIZE), DES_BLOCK_SIZE); @@ -2631,7 +2631,7 @@ void wolfSSL_DES_cbc_encrypt(const unsigned char* input, unsigned char* output, /* Length of data that is a multiple of a block. */ word32 len = (word32)(length - lb_sz); - if (enc == DES_ENCRYPT) { + if (enc == WC_DES_ENCRYPT) { /* Encrypt full blocks into output. */ wc_Des_CbcEncrypt(des, output, input, len); if (lb_sz != 0) { @@ -2687,7 +2687,7 @@ void wolfSSL_DES_ncbc_encrypt(const unsigned char* input, unsigned char* output, offset = (offset + DES_BLOCK_SIZE - 1) / DES_BLOCK_SIZE; offset *= DES_BLOCK_SIZE; offset -= DES_BLOCK_SIZE; - if (enc == DES_ENCRYPT) { + if (enc == WC_DES_ENCRYPT) { /* Encrypt data. */ wolfSSL_DES_cbc_encrypt(input, output, length, schedule, ivec, enc); /* Use last encrypted block as new IV. */ @@ -2761,7 +2761,7 @@ void wolfSSL_DES_ede3_cbc_encrypt(const unsigned char* input, ret = wc_Des3Init(des3, NULL, INVALID_DEVID); (void)ret; - if (enc == DES_ENCRYPT) { + if (enc == WC_DES_ENCRYPT) { /* Initialize wolfCrypt DES3 object. */ if (wc_Des3_SetKey(des3, key, (const byte*)ivec, DES_ENCRYPTION) == 0) { @@ -2858,7 +2858,7 @@ void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* in, WOLFSSL_DES_cblock* out, /* Validate parameters. */ if ((in == NULL) || (out == NULL) || (key == NULL) || - ((enc != DES_ENCRYPT) && (enc != DES_DECRYPT))) { + ((enc != WC_DES_ENCRYPT) && (enc != WC_DES_DECRYPT))) { WOLFSSL_MSG("Bad argument passed to wolfSSL_DES_ecb_encrypt"); } #ifdef WOLFSSL_SMALL_STACK @@ -2869,13 +2869,13 @@ void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* in, WOLFSSL_DES_cblock* out, } #endif /* Set key in wolfCrypt DES object for encryption or decryption. - * DES_ENCRYPT = 1, wolfSSL DES_ENCRYPTION = 0. - * DES_DECRYPT = 0, wolfSSL DES_DECRYPTION = 1. + * WC_DES_ENCRYPT = 1, wolfSSL DES_ENCRYPTION = 0. + * WC_DES_DECRYPT = 0, wolfSSL DES_DECRYPTION = 1. */ else if (wc_Des_SetKey(des, (const byte*)key, NULL, !enc) != 0) { WOLFSSL_MSG("wc_Des_SetKey return error."); } - else if (enc == DES_ENCRYPT) { + else if (enc == WC_DES_ENCRYPT) { /* Encrypt a block with wolfCrypt DES object. */ if (wc_Des_EcbEncrypt(des, (byte*)out, (const byte*)in, DES_KEY_SIZE) != 0) { @@ -2917,15 +2917,15 @@ void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* in, WOLFSSL_DES_cblock* out, * @param [in] key Key data. * @param [in] bits Number of bits in key. * @param [out] aes AES key object. - * @param [in] enc Whether to encrypt. AES_ENCRYPT or AES_DECRYPT. + * @param [in] enc Whether to encrypt. AES_ENCRYPTION or AES_DECRYPTION. * @return 0 on success. * @return -1 when key or aes is NULL. * @return -1 when setting key with wolfCrypt fails. */ static int wolfssl_aes_set_key(const unsigned char *key, const int bits, - AES_KEY *aes, int enc) + WOLFSSL_AES_KEY *aes, int enc) { - wc_static_assert(sizeof(AES_KEY) >= sizeof(Aes)); + wc_static_assert(sizeof(WOLFSSL_AES_KEY) >= sizeof(Aes)); /* Validate parameters. */ if ((key == NULL) || (aes == NULL)) { @@ -2933,7 +2933,7 @@ static int wolfssl_aes_set_key(const unsigned char *key, const int bits, return WOLFSSL_FATAL_ERROR; } - XMEMSET(aes, 0, sizeof(AES_KEY)); + XMEMSET(aes, 0, sizeof(WOLFSSL_AES_KEY)); if (wc_AesInit((Aes*)aes, NULL, INVALID_DEVID) != 0) { WOLFSSL_MSG("Error in initting AES key"); @@ -2957,11 +2957,11 @@ static int wolfssl_aes_set_key(const unsigned char *key, const int bits, * @return -1 when setting key with wolfCrypt fails. */ int wolfSSL_AES_set_encrypt_key(const unsigned char *key, const int bits, - AES_KEY *aes) + WOLFSSL_AES_KEY *aes) { WOLFSSL_ENTER("wolfSSL_AES_set_encrypt_key"); - return wolfssl_aes_set_key(key, bits, aes, AES_ENCRYPT); + return wolfssl_aes_set_key(key, bits, aes, AES_ENCRYPTION); } /* Sets the key into the AES key object for decryption. @@ -2974,11 +2974,11 @@ int wolfSSL_AES_set_encrypt_key(const unsigned char *key, const int bits, * @return -1 when setting key with wolfCrypt fails. */ int wolfSSL_AES_set_decrypt_key(const unsigned char *key, const int bits, - AES_KEY *aes) + WOLFSSL_AES_KEY *aes) { WOLFSSL_ENTER("wolfSSL_AES_set_decrypt_key"); - return wolfssl_aes_set_key(key, bits, aes, AES_DECRYPT); + return wolfssl_aes_set_key(key, bits, aes, AES_DECRYPTION); } #ifdef WOLFSSL_AES_DIRECT @@ -2986,15 +2986,15 @@ int wolfSSL_AES_set_decrypt_key(const unsigned char *key, const int bits, * * wolfSSL_AES_set_encrypt_key() must have been called. * - * #input must contain AES_BLOCK_SIZE bytes of data. - * #output must be a buffer at least AES_BLOCK_SIZE bytes in length. + * #input must contain WC_AES_BLOCK_SIZE bytes of data. + * #output must be a buffer at least WC_AES_BLOCK_SIZE bytes in length. * * @param [in] input Data to encrypt. * @param [out] output Encrypted data. * @param [in] key AES key to use for encryption. */ void wolfSSL_AES_encrypt(const unsigned char* input, unsigned char* output, - AES_KEY *key) + WOLFSSL_AES_KEY *key) { WOLFSSL_ENTER("wolfSSL_AES_encrypt"); @@ -3023,15 +3023,15 @@ void wolfSSL_AES_encrypt(const unsigned char* input, unsigned char* output, * * wolfSSL_AES_set_decrypt_key() must have been called. * - * #input must contain AES_BLOCK_SIZE bytes of data. - * #output must be a buffer at least AES_BLOCK_SIZE bytes in length. + * #input must contain WC_AES_BLOCK_SIZE bytes of data. + * #output must be a buffer at least WC_AES_BLOCK_SIZE bytes in length. * * @param [in] input Data to decrypt. * @param [out] output Decrypted data. * @param [in] key AES key to use for encryption. */ void wolfSSL_AES_decrypt(const unsigned char* input, unsigned char* output, - AES_KEY *key) + WOLFSSL_AES_KEY *key) { WOLFSSL_ENTER("wolfSSL_AES_decrypt"); @@ -3063,17 +3063,17 @@ void wolfSSL_AES_decrypt(const unsigned char* input, unsigned char* output, * wolfSSL_AES_set_encrypt_key() or wolfSSL_AES_set_decrypt_key ()must have been * called. * - * #input must contain AES_BLOCK_SIZE bytes of data. - * #output must be a buffer at least AES_BLOCK_SIZE bytes in length. + * #input must contain WC_AES_BLOCK_SIZE bytes of data. + * #output must be a buffer at least WC_AES_BLOCK_SIZE bytes in length. * * @param [in] in Data to encipher. * @param [out] out Enciphered data. * @param [in] key AES key to use for encryption/decryption. * @param [in] enc Whether to encrypt. - * AES_ENCRPT for encryption, AES_DECRYPT for decryption. + * AES_ENCRPT for encryption, AES_DECRYPTION for decryption. */ void wolfSSL_AES_ecb_encrypt(const unsigned char *in, unsigned char* out, - AES_KEY *key, const int enc) + WOLFSSL_AES_KEY *key, const int enc) { WOLFSSL_ENTER("wolfSSL_AES_ecb_encrypt"); @@ -3081,16 +3081,16 @@ void wolfSSL_AES_ecb_encrypt(const unsigned char *in, unsigned char* out, if ((key == NULL) || (in == NULL) || (out == NULL)) { WOLFSSL_MSG("Error, Null argument passed in"); } - else if (enc == AES_ENCRYPT) { + else if (enc == AES_ENCRYPTION) { /* Encrypt block. */ - if (wc_AesEcbEncrypt((Aes*)key, out, in, AES_BLOCK_SIZE) != 0) { + if (wc_AesEcbEncrypt((Aes*)key, out, in, WC_AES_BLOCK_SIZE) != 0) { WOLFSSL_MSG("Error with AES CBC encrypt"); } } else { #ifdef HAVE_AES_DECRYPT /* Decrypt block. */ - if (wc_AesEcbDecrypt((Aes*)key, out, in, AES_BLOCK_SIZE) != 0) { + if (wc_AesEcbDecrypt((Aes*)key, out, in, WC_AES_BLOCK_SIZE) != 0) { WOLFSSL_MSG("Error with AES CBC decrypt"); } #else @@ -3114,10 +3114,10 @@ void wolfSSL_AES_ecb_encrypt(const unsigned char *in, unsigned char* out, * On in, used with first block. * On out, IV for further operations. * @param [in] enc Whether to encrypt. - * AES_ENCRPT for encryption, AES_DECRYPT for decryption. + * AES_ENCRPT for encryption, AES_DECRYPTION for decryption. */ void wolfSSL_AES_cbc_encrypt(const unsigned char *in, unsigned char* out, - size_t len, AES_KEY *key, unsigned char* iv, const int enc) + size_t len, WOLFSSL_AES_KEY *key, unsigned char* iv, const int enc) { WOLFSSL_ENTER("wolfSSL_AES_cbc_encrypt"); @@ -3134,7 +3134,7 @@ void wolfSSL_AES_cbc_encrypt(const unsigned char *in, unsigned char* out, if ((ret = wc_AesSetIV(aes, (const byte*)iv)) != 0) { WOLFSSL_MSG("Error with setting iv"); } - else if (enc == AES_ENCRYPT) { + else if (enc == AES_ENCRYPTION) { /* Encrypt with wolfCrypt AES object. */ if ((ret = wc_AesCbcEncrypt(aes, out, in, (word32)len)) != 0) { WOLFSSL_MSG("Error with AES CBC encrypt"); @@ -3149,7 +3149,7 @@ void wolfSSL_AES_cbc_encrypt(const unsigned char *in, unsigned char* out, if (ret == 0) { /* Get IV for next operation. */ - XMEMCPY(iv, (byte*)(aes->reg), AES_BLOCK_SIZE); + XMEMCPY(iv, (byte*)(aes->reg), WC_AES_BLOCK_SIZE); } } } @@ -3169,10 +3169,10 @@ void wolfSSL_AES_cbc_encrypt(const unsigned char *in, unsigned char* out, * On out, IV for further operations. * @param [out] num Number of bytes used from last incomplete block. * @param [in] enc Whether to encrypt. - * AES_ENCRPT for encryption, AES_DECRYPT for decryption. + * AES_ENCRPT for encryption, AES_DECRYPTION for decryption. */ void wolfSSL_AES_cfb128_encrypt(const unsigned char *in, unsigned char* out, - size_t len, AES_KEY *key, unsigned char* iv, int* num, const int enc) + size_t len, WOLFSSL_AES_KEY *key, unsigned char* iv, int* num, const int enc) { #ifndef WOLFSSL_AES_CFB WOLFSSL_MSG("CFB mode not enabled please use macro WOLFSSL_AES_CFB"); @@ -3199,9 +3199,9 @@ void wolfSSL_AES_cfb128_encrypt(const unsigned char *in, unsigned char* out, * leftover bytes field "left", and this function relies on the leftover * bytes being preserved between calls. */ - XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, iv, WC_AES_BLOCK_SIZE); - if (enc == AES_ENCRYPT) { + if (enc == AES_ENCRYPTION) { /* Encrypt data with AES-CFB. */ if ((ret = wc_AesCfbEncrypt(aes, out, in, (word32)len)) != 0) { WOLFSSL_MSG("Error with AES CBC encrypt"); @@ -3216,11 +3216,11 @@ void wolfSSL_AES_cfb128_encrypt(const unsigned char *in, unsigned char* out, if (ret == 0) { /* Copy IV out after operation. */ - XMEMCPY(iv, (byte*)(aes->reg), AES_BLOCK_SIZE); + XMEMCPY(iv, (byte*)(aes->reg), WC_AES_BLOCK_SIZE); /* Store number of left over bytes to num. */ if (num != NULL) { - *num = (AES_BLOCK_SIZE - aes->left) % AES_BLOCK_SIZE; + *num = (WC_AES_BLOCK_SIZE - aes->left) % WC_AES_BLOCK_SIZE; } } } @@ -3240,7 +3240,7 @@ void wolfSSL_AES_cfb128_encrypt(const unsigned char *in, unsigned char* out, * @return 0 when key, iv, out or in is NULL. * @return 0 when key length is not valid. */ -int wolfSSL_AES_wrap_key(AES_KEY *key, const unsigned char *iv, +int wolfSSL_AES_wrap_key(WOLFSSL_AES_KEY *key, const unsigned char *iv, unsigned char *out, const unsigned char *in, unsigned int inSz) { int ret = 0; @@ -3275,7 +3275,7 @@ int wolfSSL_AES_wrap_key(AES_KEY *key, const unsigned char *iv, * @return 0 when key, iv, out or in is NULL. * @return 0 when wrapped key data length is not valid. */ -int wolfSSL_AES_unwrap_key(AES_KEY *key, const unsigned char *iv, +int wolfSSL_AES_unwrap_key(WOLFSSL_AES_KEY *key, const unsigned char *iv, unsigned char *out, const unsigned char *in, unsigned int inSz) { int ret = 0; @@ -3336,7 +3336,7 @@ size_t wolfSSL_CRYPTO_cts128_encrypt(const unsigned char *in, } /* Encrypt data up to last block */ - (*cbc)(in, out, len - lastBlkLen, key, iv, AES_ENCRYPT); + (*cbc)(in, out, len - lastBlkLen, key, iv, AES_ENCRYPTION); /* Move to last block */ in += len - lastBlkLen; @@ -3349,7 +3349,7 @@ size_t wolfSSL_CRYPTO_cts128_encrypt(const unsigned char *in, XMEMCPY(out, out - WOLFSSL_CTS128_BLOCK_SZ, lastBlkLen); /* Encrypt last block. */ (*cbc)(lastBlk, out - WOLFSSL_CTS128_BLOCK_SZ, WOLFSSL_CTS128_BLOCK_SZ, - key, iv, AES_ENCRYPT); + key, iv, AES_ENCRYPTION); } return len; @@ -3404,13 +3404,13 @@ size_t wolfSSL_CRYPTO_cts128_decrypt(const unsigned char *in, * Use 0 buffer as IV to do straight decryption. * This places the Cn-1 block at lastBlk */ XMEMSET(lastBlk, 0, WOLFSSL_CTS128_BLOCK_SZ); - (*cbc)(in, prevBlk, WOLFSSL_CTS128_BLOCK_SZ, key, lastBlk, AES_DECRYPT); + (*cbc)(in, prevBlk, WOLFSSL_CTS128_BLOCK_SZ, key, lastBlk, AES_DECRYPTION); /* RFC2040: Append the tail (BB minus Ln) bytes of Xn to Cn * to create En. */ XMEMCPY(prevBlk, in + WOLFSSL_CTS128_BLOCK_SZ, lastBlkLen); /* Cn and Cn-1 can now be decrypted */ - (*cbc)(prevBlk, out, WOLFSSL_CTS128_BLOCK_SZ, key, iv, AES_DECRYPT); - (*cbc)(lastBlk, lastBlk, WOLFSSL_CTS128_BLOCK_SZ, key, iv, AES_DECRYPT); + (*cbc)(prevBlk, out, WOLFSSL_CTS128_BLOCK_SZ, key, iv, AES_DECRYPTION); + (*cbc)(lastBlk, lastBlk, WOLFSSL_CTS128_BLOCK_SZ, key, iv, AES_DECRYPTION); XMEMCPY(out + WOLFSSL_CTS128_BLOCK_SZ, lastBlk, lastBlkLen); } diff --git a/src/tls.c b/src/tls.c index 3c55c6632a..7618c696b6 100644 --- a/src/tls.c +++ b/src/tls.c @@ -12474,7 +12474,7 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size, readBuf_p += ech->encLen; ato16(readBuf_p, &ech->innerClientHelloLen); - ech->innerClientHelloLen -= AES_BLOCK_SIZE; + ech->innerClientHelloLen -= WC_AES_BLOCK_SIZE; readBuf_p += 2; ech->outerClientPayload = readBuf_p; @@ -12490,7 +12490,7 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size, /* set the ech payload of the copy to zeros */ XMEMSET(aadCopy + (readBuf_p - ech->aad), 0, - ech->innerClientHelloLen + AES_BLOCK_SIZE); + ech->innerClientHelloLen + WC_AES_BLOCK_SIZE); /* allocate the inner payload buffer */ ech->innerClientHello = diff --git a/src/x509.c b/src/x509.c index 2f000131e6..1f5dfca0c9 100644 --- a/src/x509.c +++ b/src/x509.c @@ -49,10 +49,10 @@ unsigned int wolfSSL_X509_get_extension_flags(WOLFSSL_X509* x509) if (x509 != NULL) { if (x509->keyUsageSet) { - flags |= EXFLAG_KUSAGE; + flags |= WOLFSSL_EXFLAG_KUSAGE; } if (x509->extKeyUsageSrc != NULL) { - flags |= EXFLAG_XKUSAGE; + flags |= WOLFSSL_EXFLAG_XKUSAGE; } } @@ -92,19 +92,19 @@ unsigned int wolfSSL_X509_get_extended_key_usage(WOLFSSL_X509* x509) if (x509 != NULL) { if (x509->extKeyUsage & EXTKEYUSE_OCSP_SIGN) - ret |= XKU_OCSP_SIGN; + ret |= WOLFSSL_XKU_OCSP_SIGN; if (x509->extKeyUsage & EXTKEYUSE_TIMESTAMP) - ret |= XKU_TIMESTAMP; + ret |= WOLFSSL_XKU_TIMESTAMP; if (x509->extKeyUsage & EXTKEYUSE_EMAILPROT) - ret |= XKU_SMIME; + ret |= WOLFSSL_XKU_SMIME; if (x509->extKeyUsage & EXTKEYUSE_CODESIGN) - ret |= XKU_CODE_SIGN; + ret |= WOLFSSL_XKU_CODE_SIGN; if (x509->extKeyUsage & EXTKEYUSE_CLIENT_AUTH) - ret |= XKU_SSL_CLIENT; + ret |= WOLFSSL_XKU_SSL_CLIENT; if (x509->extKeyUsage & EXTKEYUSE_SERVER_AUTH) - ret |= XKU_SSL_SERVER; + ret |= WOLFSSL_XKU_SSL_SERVER; if (x509->extKeyUsage & EXTKEYUSE_ANY) - ret |= XKU_ANYEKU; + ret |= WOLFSSL_XKU_ANYEKU; } WOLFSSL_LEAVE("wolfSSL_X509_get_extended_key_usage", ret); @@ -1688,7 +1688,7 @@ WOLFSSL_v3_ext_method* wolfSSL_X509V3_EXT_get(WOLFSSL_X509_EXTENSION* ex) case WC_NID_basic_constraints: break; case WC_NID_subject_key_identifier: - method.i2s = (X509V3_EXT_I2S)wolfSSL_i2s_ASN1_STRING; + method.i2s = (WOLFSSL_X509V3_EXT_I2S)wolfSSL_i2s_ASN1_STRING; break; case WC_NID_subject_alt_name: WOLFSSL_MSG("i2v function not yet implemented for Subject " @@ -2965,7 +2965,7 @@ static void wolfSSL_X509V3_EXT_METHOD_populate(WOLFSSL_v3_ext_method *method, WOLFSSL_ENTER("wolfSSL_X509V3_EXT_METHOD_populate"); switch (nid) { case WC_NID_subject_key_identifier: - method->i2s = (X509V3_EXT_I2S)wolfSSL_i2s_ASN1_STRING; + method->i2s = (WOLFSSL_X509V3_EXT_I2S)wolfSSL_i2s_ASN1_STRING; FALL_THROUGH; case WC_NID_authority_key_identifier: case WC_NID_key_usage: diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index daf9a228b8..cc131eb67a 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -2485,7 +2485,7 @@ static void bench_multi_value_stats(double max, double min, double sum, #endif /* countSz is number of bytes that 1 count represents. Normally bench_size, - * except for AES direct that operates on AES_BLOCK_SIZE blocks */ + * except for AES direct that operates on WC_AES_BLOCK_SIZE blocks */ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, word32 countSz, double start, int ret) @@ -4846,7 +4846,7 @@ static void bench_aesecb_internal(int useDeviceID, double start; DECLARE_MULTI_VALUE_STATS_VARS() #ifdef HAVE_FIPS - const word32 benchSz = AES_BLOCK_SIZE; + const word32 benchSz = WC_AES_BLOCK_SIZE; #else const word32 benchSz = bench_size; #endif @@ -5373,9 +5373,9 @@ static void bench_aessiv_internal(const byte* key, word32 keySz, const char* { int i; int ret = 0; - byte assoc[AES_BLOCK_SIZE]; - byte nonce[AES_BLOCK_SIZE]; - byte siv[AES_BLOCK_SIZE]; + byte assoc[WC_AES_BLOCK_SIZE]; + byte nonce[WC_AES_BLOCK_SIZE]; + byte siv[WC_AES_BLOCK_SIZE]; int count = 0; double start; DECLARE_MULTI_VALUE_STATS_VARS() @@ -5383,8 +5383,8 @@ static void bench_aessiv_internal(const byte* key, word32 keySz, const char* bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { - ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce, - AES_BLOCK_SIZE, bench_plain, bench_size, + ret = wc_AesSivEncrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce, + WC_AES_BLOCK_SIZE, bench_plain, bench_size, siv, bench_cipher); if (ret != 0) { printf("wc_AesSivEncrypt failed (%d)\n", ret); @@ -5409,8 +5409,8 @@ static void bench_aessiv_internal(const byte* key, word32 keySz, const char* bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { - ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce, - AES_BLOCK_SIZE, bench_cipher, bench_size, + ret = wc_AesSivDecrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce, + WC_AES_BLOCK_SIZE, bench_cipher, bench_size, siv, bench_plain); if (ret != 0) { printf("wc_AesSivDecrypt failed (%d)\n", ret); @@ -5510,7 +5510,7 @@ void bench_poly1305(void) #ifdef HAVE_CAMELLIA void bench_camellia(void) { - Camellia cam; + wc_Camellia cam; double start; int ret, i, count; DECLARE_MULTI_VALUE_STATS_VARS() @@ -7926,7 +7926,7 @@ void bench_blake2s(void) static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID) { Cmac cmac; - byte digest[AES_BLOCK_SIZE]; + byte digest[WC_AES_BLOCK_SIZE]; word32 digestSz = sizeof(digest); double start; int ret, i, count; diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 8887ef502f..8d45298c59 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -174,13 +174,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits HAL_CRYP_Init(&hcryp); #if defined(STM32_HAL_V2) - ret = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)inBlock, AES_BLOCK_SIZE, + ret = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)inBlock, WC_AES_BLOCK_SIZE, (uint32_t*)outBlock, STM32_HAL_TIMEOUT); #elif defined(STM32_CRYPTO_AES_ONLY) - ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)inBlock, AES_BLOCK_SIZE, + ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)inBlock, WC_AES_BLOCK_SIZE, outBlock, STM32_HAL_TIMEOUT); #else - ret = HAL_CRYP_AESECB_Encrypt(&hcryp, (uint8_t*)inBlock, AES_BLOCK_SIZE, + ret = HAL_CRYP_AESECB_Encrypt(&hcryp, (uint8_t*)inBlock, WC_AES_BLOCK_SIZE, outBlock, STM32_HAL_TIMEOUT); #endif if (ret != HAL_OK) { @@ -275,13 +275,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits HAL_CRYP_Init(&hcryp); #if defined(STM32_HAL_V2) - ret = HAL_CRYP_Decrypt(&hcryp, (uint32_t*)inBlock, AES_BLOCK_SIZE, + ret = HAL_CRYP_Decrypt(&hcryp, (uint32_t*)inBlock, WC_AES_BLOCK_SIZE, (uint32_t*)outBlock, STM32_HAL_TIMEOUT); #elif defined(STM32_CRYPTO_AES_ONLY) - ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)inBlock, AES_BLOCK_SIZE, + ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)inBlock, WC_AES_BLOCK_SIZE, outBlock, STM32_HAL_TIMEOUT); #else - ret = HAL_CRYP_AESECB_Decrypt(&hcryp, (uint8_t*)inBlock, AES_BLOCK_SIZE, + ret = HAL_CRYP_AESECB_Decrypt(&hcryp, (uint8_t*)inBlock, WC_AES_BLOCK_SIZE, outBlock, STM32_HAL_TIMEOUT); #endif if (ret != HAL_OK) { @@ -379,7 +379,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits #endif if (wolfSSL_CryptHwMutexLock() == 0) { - LTC_AES_EncryptEcb(LTC_BASE, inBlock, outBlock, AES_BLOCK_SIZE, + LTC_AES_EncryptEcb(LTC_BASE, inBlock, outBlock, WC_AES_BLOCK_SIZE, key, keySize); wolfSSL_CryptHwMutexUnLock(); } @@ -402,7 +402,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits #endif if (wolfSSL_CryptHwMutexLock() == 0) { - LTC_AES_DecryptEcb(LTC_BASE, inBlock, outBlock, AES_BLOCK_SIZE, + LTC_AES_DecryptEcb(LTC_BASE, inBlock, outBlock, WC_AES_BLOCK_SIZE, key, keySize, kLTC_EncryptKey); wolfSSL_CryptHwMutexUnLock(); } @@ -493,7 +493,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits #endif /* Thread mutex protection handled in Pic32Crypto */ return wc_Pic32AesCrypt(aes->key, aes->keylen, NULL, 0, - outBlock, inBlock, AES_BLOCK_SIZE, + outBlock, inBlock, WC_AES_BLOCK_SIZE, PIC32_ENCRYPTION, PIC32_ALGO_AES, PIC32_CRYPTOALGO_RECB); } #endif @@ -511,7 +511,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits #endif /* Thread mutex protection handled in Pic32Crypto */ return wc_Pic32AesCrypt(aes->key, aes->keylen, NULL, 0, - outBlock, inBlock, AES_BLOCK_SIZE, + outBlock, inBlock, WC_AES_BLOCK_SIZE, PIC32_DECRYPTION, PIC32_ALGO_AES, PIC32_CRYPTOALGO_RECB); } #endif @@ -951,7 +951,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits return ret; } #endif - return AES_ECB_encrypt(aes, inBlock, outBlock, AES_BLOCK_SIZE); + return AES_ECB_encrypt(aes, inBlock, outBlock, WC_AES_BLOCK_SIZE); } #endif @@ -966,7 +966,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits return ret; } #endif - return AES_ECB_decrypt(aes, inBlock, outBlock, AES_BLOCK_SIZE); + return AES_ECB_decrypt(aes, inBlock, outBlock, WC_AES_BLOCK_SIZE); } #endif @@ -2229,10 +2229,10 @@ static void AesEncryptBlocks_C(Aes* aes, const byte* in, byte* out, word32 sz) { word32 i; - for (i = 0; i < sz; i += AES_BLOCK_SIZE) { + for (i = 0; i < sz; i += WC_AES_BLOCK_SIZE) { AesEncrypt_C(aes, in, out, aes->rounds >> 1); - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } } #endif @@ -2692,18 +2692,18 @@ static void bs_set_key(bs_word* rk, const byte* key, word32 keyLen, word32 rounds) { int i; - byte bs_key[15 * AES_BLOCK_SIZE]; - int ksSz = (rounds + 1) * AES_BLOCK_SIZE; + byte bs_key[15 * WC_AES_BLOCK_SIZE]; + int ksSz = (rounds + 1) * WC_AES_BLOCK_SIZE; bs_word block[AES_BLOCK_BITS]; /* Fist round. */ XMEMCPY(bs_key, key, keyLen); bs_expand_key(bs_key, ksSz); - for (i = 0; i < ksSz; i += AES_BLOCK_SIZE) { + for (i = 0; i < ksSz; i += WC_AES_BLOCK_SIZE) { int k; - XMEMCPY(block, bs_key + i, AES_BLOCK_SIZE); + XMEMCPY(block, bs_key + i, WC_AES_BLOCK_SIZE); for (k = BS_BLOCK_WORDS; k < AES_BLOCK_BITS; k += BS_BLOCK_WORDS) { int l; for (l = 0; l < BS_BLOCK_WORDS; l++) { @@ -2751,12 +2751,12 @@ static void AesEncrypt_C(Aes* aes, const byte* inBlock, byte* outBlock, (void)r; - XMEMCPY(state, inBlock, AES_BLOCK_SIZE); - XMEMSET(((byte*)state) + AES_BLOCK_SIZE, 0, sizeof(state) - AES_BLOCK_SIZE); + XMEMCPY(state, inBlock, WC_AES_BLOCK_SIZE); + XMEMSET(((byte*)state) + WC_AES_BLOCK_SIZE, 0, sizeof(state) - WC_AES_BLOCK_SIZE); bs_encrypt(state, aes->bs_key, aes->rounds); - XMEMCPY(outBlock, state, AES_BLOCK_SIZE); + XMEMCPY(outBlock, state, WC_AES_BLOCK_SIZE); } #if defined(HAVE_AES_ECB) && !(defined(WOLFSSL_IMX6_CAAM) && \ @@ -2838,13 +2838,13 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt( printf("out = %p\n", outBlock); printf("aes->key = %p\n", aes->key); printf("aes->rounds = %d\n", aes->rounds); - printf("sz = %d\n", AES_BLOCK_SIZE); + printf("sz = %d\n", WC_AES_BLOCK_SIZE); #endif /* check alignment, decrypt doesn't need alignment */ if ((wc_ptr_t)inBlock % AESNI_ALIGN) { #ifndef NO_WOLFSSL_ALLOC_ALIGN - byte* tmp = (byte*)XMALLOC(AES_BLOCK_SIZE + AESNI_ALIGN, aes->heap, + byte* tmp = (byte*)XMALLOC(WC_AES_BLOCK_SIZE + AESNI_ALIGN, aes->heap, DYNAMIC_TYPE_TMP_BUFFER); byte* tmp_align; if (tmp == NULL) @@ -2852,10 +2852,10 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt( tmp_align = tmp + (AESNI_ALIGN - ((wc_ptr_t)tmp % AESNI_ALIGN)); - XMEMCPY(tmp_align, inBlock, AES_BLOCK_SIZE); - AES_ECB_encrypt_AESNI(tmp_align, tmp_align, AES_BLOCK_SIZE, + XMEMCPY(tmp_align, inBlock, WC_AES_BLOCK_SIZE); + AES_ECB_encrypt_AESNI(tmp_align, tmp_align, WC_AES_BLOCK_SIZE, (byte*)aes->key, (int)aes->rounds); - XMEMCPY(outBlock, tmp_align, AES_BLOCK_SIZE); + XMEMCPY(outBlock, tmp_align, WC_AES_BLOCK_SIZE); XFREE(tmp, aes->heap, DYNAMIC_TYPE_TMP_BUFFER); return 0; #else @@ -2865,7 +2865,7 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt( #endif } - AES_ECB_encrypt_AESNI(inBlock, outBlock, AES_BLOCK_SIZE, (byte*)aes->key, + AES_ECB_encrypt_AESNI(inBlock, outBlock, WC_AES_BLOCK_SIZE, (byte*)aes->key, (int)aes->rounds); return 0; @@ -2877,20 +2877,20 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt( } #endif /* WOLFSSL_AESNI */ #if defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_AES) - AES_ECB_encrypt(aes, inBlock, outBlock, AES_BLOCK_SIZE); + AES_ECB_encrypt(aes, inBlock, outBlock, WC_AES_BLOCK_SIZE); return 0; #endif #if defined(WOLFSSL_IMXRT_DCP) if (aes->keylen == 16) { - DCPAesEcbEncrypt(aes, outBlock, inBlock, AES_BLOCK_SIZE); + DCPAesEcbEncrypt(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE); return 0; } #endif #if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) if (aes->useSWCrypt == 0) { - return se050_aes_crypt(aes, inBlock, outBlock, AES_BLOCK_SIZE, + return se050_aes_crypt(aes, inBlock, outBlock, WC_AES_BLOCK_SIZE, AES_ENCRYPTION, kAlgorithm_SSS_AES_ECB); } #endif @@ -2913,7 +2913,7 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt( #if defined(MAX3266X_AES) if (wc_AesGetKeySize(aes, &keySize) == 0) { return wc_MXC_TPU_AesEncrypt(inBlock, (byte*)aes->reg, (byte*)aes->key, - MXC_TPU_MODE_ECB, AES_BLOCK_SIZE, + MXC_TPU_MODE_ECB, WC_AES_BLOCK_SIZE, outBlock, (unsigned int)keySize); } #endif @@ -2923,7 +2923,7 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt( #endif { ret_cb = wc_CryptoCb_AesEcbEncrypt(aes, outBlock, inBlock, - AES_BLOCK_SIZE); + WC_AES_BLOCK_SIZE); if (ret_cb != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) return ret_cb; /* fall-through when unavailable */ @@ -3223,10 +3223,10 @@ static void AesDecryptBlocks_C(Aes* aes, const byte* in, byte* out, word32 sz) { word32 i; - for (i = 0; i < sz; i += AES_BLOCK_SIZE) { + for (i = 0; i < sz; i += WC_AES_BLOCK_SIZE) { AesDecrypt_C(aes, in, out, aes->rounds >> 1); - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } } #endif @@ -3532,12 +3532,12 @@ static void AesDecrypt_C(Aes* aes, const byte* inBlock, byte* outBlock, (void)r; - XMEMCPY(state, inBlock, AES_BLOCK_SIZE); - XMEMSET(((byte*)state) + AES_BLOCK_SIZE, 0, sizeof(state) - AES_BLOCK_SIZE); + XMEMCPY(state, inBlock, WC_AES_BLOCK_SIZE); + XMEMSET(((byte*)state) + WC_AES_BLOCK_SIZE, 0, sizeof(state) - WC_AES_BLOCK_SIZE); bs_decrypt(state, aes->bs_key, aes->rounds); - XMEMCPY(outBlock, state, AES_BLOCK_SIZE); + XMEMCPY(outBlock, state, WC_AES_BLOCK_SIZE); } #endif @@ -3615,13 +3615,13 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( printf("out = %p\n", outBlock); printf("aes->key = %p\n", aes->key); printf("aes->rounds = %d\n", aes->rounds); - printf("sz = %d\n", AES_BLOCK_SIZE); + printf("sz = %d\n", WC_AES_BLOCK_SIZE); #endif /* if input and output same will overwrite input iv */ if ((const byte*)aes->tmp != inBlock) - XMEMCPY(aes->tmp, inBlock, AES_BLOCK_SIZE); - AES_ECB_decrypt_AESNI(inBlock, outBlock, AES_BLOCK_SIZE, (byte*)aes->key, + XMEMCPY(aes->tmp, inBlock, WC_AES_BLOCK_SIZE); + AES_ECB_decrypt_AESNI(inBlock, outBlock, WC_AES_BLOCK_SIZE, (byte*)aes->key, (int)aes->rounds); return 0; } @@ -3632,17 +3632,17 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( } #endif /* WOLFSSL_AESNI */ #if defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_AES) - return AES_ECB_decrypt(aes, inBlock, outBlock, AES_BLOCK_SIZE); + return AES_ECB_decrypt(aes, inBlock, outBlock, WC_AES_BLOCK_SIZE); #endif #if defined(WOLFSSL_IMXRT_DCP) if (aes->keylen == 16) { - DCPAesEcbDecrypt(aes, outBlock, inBlock, AES_BLOCK_SIZE); + DCPAesEcbDecrypt(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE); return 0; } #endif #if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) if (aes->useSWCrypt == 0) { - return se050_aes_crypt(aes, inBlock, outBlock, AES_BLOCK_SIZE, + return se050_aes_crypt(aes, inBlock, outBlock, WC_AES_BLOCK_SIZE, AES_DECRYPTION, kAlgorithm_SSS_AES_ECB); } #endif @@ -3663,7 +3663,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( #if defined(MAX3266X_AES) if (wc_AesGetKeySize(aes, &keySize) == 0) { return wc_MXC_TPU_AesDecrypt(inBlock, (byte*)aes->reg, (byte*)aes->key, - MXC_TPU_MODE_ECB, AES_BLOCK_SIZE, + MXC_TPU_MODE_ECB, WC_AES_BLOCK_SIZE, outBlock, (unsigned int)keySize); } #endif @@ -3674,7 +3674,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( #endif { ret_cb = wc_CryptoCb_AesEcbDecrypt(aes, outBlock, inBlock, - AES_BLOCK_SIZE); + WC_AES_BLOCK_SIZE); if (ret_cb != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) return ret_cb; /* fall-through when unavailable */ @@ -3746,7 +3746,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( extern TX_BYTE_POOL mp_ncached; /* Non Cached memory pool */ #endif - #define AES_BUFFER_SIZE (AES_BLOCK_SIZE * 64) + #define AES_BUFFER_SIZE (WC_AES_BLOCK_SIZE * 64) static unsigned char *AESBuffIn = NULL; static unsigned char *AESBuffOut = NULL; static byte *secReg; @@ -3773,9 +3773,9 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( s2 = tx_byte_allocate(&mp_ncached, (void *)&AESBuffOut, AES_BUFFER_SIZE, TX_NO_WAIT); s3 = tx_byte_allocate(&mp_ncached, (void *)&secKey, - AES_BLOCK_SIZE*2, TX_NO_WAIT); + WC_AES_BLOCK_SIZE*2, TX_NO_WAIT); s4 = tx_byte_allocate(&mp_ncached, (void *)&secReg, - AES_BLOCK_SIZE, TX_NO_WAIT); + WC_AES_BLOCK_SIZE, TX_NO_WAIT); if (s1 || s2 || s3 || s4 || s5) return BAD_FUNC_ARG; @@ -3805,7 +3805,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( XMEMCPY(aes->key, userKey, keylen); if (iv) - XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, iv, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS) @@ -4103,9 +4103,9 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt( ret = wc_AesSetIV(aes, iv); if (iv) - XMEMCPY(iv_aes, iv, AES_BLOCK_SIZE); + XMEMCPY(iv_aes, iv, WC_AES_BLOCK_SIZE); else - XMEMSET(iv_aes, 0, AES_BLOCK_SIZE); + XMEMSET(iv_aes, 0, WC_AES_BLOCK_SIZE); ret = SaSi_AesSetIv(&aes->ctx.user_ctx, iv_aes); @@ -4474,9 +4474,9 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir) wc_FreeRng(&rng); if (iv) - XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, iv, WC_AES_BLOCK_SIZE); else - XMEMSET(aes->reg, 0, AES_BLOCK_SIZE); + XMEMSET(aes->reg, 0, WC_AES_BLOCK_SIZE); switch (keylen) { case AES_128_KEY_SIZE: keyType = CAAM_KEYTYPE_AES128; break; @@ -4743,9 +4743,9 @@ int wc_AesSetIV(Aes* aes, const byte* iv) #endif if (iv) - XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, iv, WC_AES_BLOCK_SIZE); else - XMEMSET(aes->reg, 0, AES_BLOCK_SIZE); + XMEMSET(aes->reg, 0, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS) @@ -4875,10 +4875,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv) { int ret = 0; CRYP_HandleTypeDef hcryp; - word32 blocks = (sz / AES_BLOCK_SIZE); + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -4896,7 +4896,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) #if defined(STM32_HAL_V2) hcryp.Init.Algorithm = CRYP_AES_CBC; - ByteReverseWords(aes->reg, aes->reg, AES_BLOCK_SIZE); + ByteReverseWords(aes->reg, aes->reg, WC_AES_BLOCK_SIZE); #elif defined(STM32_CRYPTO_AES_ONLY) hcryp.Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT; hcryp.Init.ChainingMode = CRYP_CHAINMODE_AES_CBC; @@ -4906,14 +4906,14 @@ int wc_AesSetIV(Aes* aes, const byte* iv) HAL_CRYP_Init(&hcryp); #if defined(STM32_HAL_V2) - ret = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)in, blocks * AES_BLOCK_SIZE, + ret = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)in, blocks * WC_AES_BLOCK_SIZE, (uint32_t*)out, STM32_HAL_TIMEOUT); #elif defined(STM32_CRYPTO_AES_ONLY) - ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)in, blocks * AES_BLOCK_SIZE, + ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)in, blocks * WC_AES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT); #else ret = HAL_CRYP_AESCBC_Encrypt(&hcryp, (uint8_t*)in, - blocks * AES_BLOCK_SIZE, + blocks * WC_AES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT); #endif if (ret != HAL_OK) { @@ -4921,7 +4921,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } /* store iv for next call */ - XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, out + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); HAL_CRYP_DeInit(&hcryp); @@ -4935,10 +4935,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv) { int ret = 0; CRYP_HandleTypeDef hcryp; - word32 blocks = (sz / AES_BLOCK_SIZE); + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -4955,11 +4955,11 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } /* if input and output same will overwrite input iv */ - XMEMCPY(aes->tmp, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->tmp, in + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); #if defined(STM32_HAL_V2) hcryp.Init.Algorithm = CRYP_AES_CBC; - ByteReverseWords(aes->reg, aes->reg, AES_BLOCK_SIZE); + ByteReverseWords(aes->reg, aes->reg, WC_AES_BLOCK_SIZE); #elif defined(STM32_CRYPTO_AES_ONLY) hcryp.Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT; hcryp.Init.ChainingMode = CRYP_CHAINMODE_AES_CBC; @@ -4970,14 +4970,14 @@ int wc_AesSetIV(Aes* aes, const byte* iv) HAL_CRYP_Init(&hcryp); #if defined(STM32_HAL_V2) - ret = HAL_CRYP_Decrypt(&hcryp, (uint32_t*)in, blocks * AES_BLOCK_SIZE, + ret = HAL_CRYP_Decrypt(&hcryp, (uint32_t*)in, blocks * WC_AES_BLOCK_SIZE, (uint32_t*)out, STM32_HAL_TIMEOUT); #elif defined(STM32_CRYPTO_AES_ONLY) - ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)in, blocks * AES_BLOCK_SIZE, + ret = HAL_CRYPEx_AES(&hcryp, (uint8_t*)in, blocks * WC_AES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT); #else ret = HAL_CRYP_AESCBC_Decrypt(&hcryp, (uint8_t*)in, - blocks * AES_BLOCK_SIZE, + blocks * WC_AES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT); #endif if (ret != HAL_OK) { @@ -4985,7 +4985,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } /* store iv for next call */ - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); HAL_CRYP_DeInit(&hcryp); wolfSSL_CryptHwMutexUnLock(); @@ -5003,10 +5003,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv) CRYP_InitTypeDef cryptInit; CRYP_KeyInitTypeDef keyInit; CRYP_IVInitTypeDef ivInit; - word32 blocks = (sz / AES_BLOCK_SIZE); + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -5031,7 +5031,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) /* set iv */ iv = aes->reg; CRYP_IVStructInit(&ivInit); - ByteReverseWords(iv, iv, AES_BLOCK_SIZE); + ByteReverseWords(iv, iv, WC_AES_BLOCK_SIZE); ivInit.CRYP_IV0Left = iv[0]; ivInit.CRYP_IV0Right = iv[1]; ivInit.CRYP_IV1Left = iv[2]; @@ -5064,11 +5064,11 @@ int wc_AesSetIV(Aes* aes, const byte* iv) *(uint32_t*)&out[12] = CRYP_DataOut(); /* store iv for next call */ - XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, out + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); - sz -= AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + sz -= WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } /* disable crypto processor */ @@ -5087,10 +5087,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv) CRYP_InitTypeDef cryptInit; CRYP_KeyInitTypeDef keyInit; CRYP_IVInitTypeDef ivInit; - word32 blocks = (sz / AES_BLOCK_SIZE); + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -5107,7 +5107,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } /* if input and output same will overwrite input iv */ - XMEMCPY(aes->tmp, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->tmp, in + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); /* reset registers to their default values */ CRYP_DeInit(); @@ -5132,7 +5132,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) /* set iv */ iv = aes->reg; CRYP_IVStructInit(&ivInit); - ByteReverseWords(iv, iv, AES_BLOCK_SIZE); + ByteReverseWords(iv, iv, WC_AES_BLOCK_SIZE); ivInit.CRYP_IV0Left = iv[0]; ivInit.CRYP_IV0Right = iv[1]; ivInit.CRYP_IV1Left = iv[2]; @@ -5160,10 +5160,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv) *(uint32_t*)&out[12] = CRYP_DataOut(); /* store iv for next call */ - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } /* disable crypto processor */ @@ -5191,7 +5191,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) return BAD_FUNC_ARG; /*wrong pointer*/ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -5202,7 +5202,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) secDesc->length1 = 0x0; secDesc->pointer1 = NULL; - secDesc->length2 = AES_BLOCK_SIZE; + secDesc->length2 = WC_AES_BLOCK_SIZE; secDesc->pointer2 = (byte *)secReg; /* Initial Vector */ switch(aes->rounds) { @@ -5226,7 +5226,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) #endif while (sz) { secDesc->header = descHeader; - XMEMCPY(secReg, aes->reg, AES_BLOCK_SIZE); + XMEMCPY(secReg, aes->reg, WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS sz -= AES_BUFFER_SIZE; #else @@ -5244,8 +5244,8 @@ int wc_AesSetIV(Aes* aes, const byte* iv) XMEMCPY(AESBuffIn, pi, size); if(descHeader == SEC_DESC_AES_CBC_DECRYPT) { - XMEMCPY((void*)aes->tmp, (void*)&(pi[size-AES_BLOCK_SIZE]), - AES_BLOCK_SIZE); + XMEMCPY((void*)aes->tmp, (void*)&(pi[size-WC_AES_BLOCK_SIZE]), + WC_AES_BLOCK_SIZE); } /* Point SEC to the location of the descriptor */ @@ -5270,10 +5270,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv) XMEMCPY(po, AESBuffOut, size); if (descHeader == SEC_DESC_AES_CBC_ENCRYPT) { - XMEMCPY((void*)aes->reg, (void*)&(po[size-AES_BLOCK_SIZE]), - AES_BLOCK_SIZE); + XMEMCPY((void*)aes->reg, (void*)&(po[size-WC_AES_BLOCK_SIZE]), + WC_AES_BLOCK_SIZE); } else { - XMEMCPY((void*)aes->reg, (void*)aes->tmp, AES_BLOCK_SIZE); + XMEMCPY((void*)aes->reg, (void*)aes->tmp, WC_AES_BLOCK_SIZE); } pi += size; @@ -5302,10 +5302,10 @@ int wc_AesSetIV(Aes* aes, const byte* iv) word32 keySize; status_t status; byte *iv, *enc_key; - word32 blocks = (sz / AES_BLOCK_SIZE); + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -5323,13 +5323,13 @@ int wc_AesSetIV(Aes* aes, const byte* iv) status = wolfSSL_CryptHwMutexLock(); if (status != 0) return status; - status = LTC_AES_EncryptCbc(LTC_BASE, in, out, blocks * AES_BLOCK_SIZE, + status = LTC_AES_EncryptCbc(LTC_BASE, in, out, blocks * WC_AES_BLOCK_SIZE, iv, enc_key, keySize); wolfSSL_CryptHwMutexUnLock(); /* store iv for next call */ if (status == kStatus_Success) { - XMEMCPY(iv, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(iv, out + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); } return (status == kStatus_Success) ? 0 : -1; @@ -5341,11 +5341,11 @@ int wc_AesSetIV(Aes* aes, const byte* iv) word32 keySize; status_t status; byte* iv, *dec_key; - byte temp_block[AES_BLOCK_SIZE]; - word32 blocks = (sz / AES_BLOCK_SIZE); + byte temp_block[WC_AES_BLOCK_SIZE]; + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -5361,18 +5361,18 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } /* get IV for next call */ - XMEMCPY(temp_block, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(temp_block, in + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); status = wolfSSL_CryptHwMutexLock(); if (status != 0) return status; - status = LTC_AES_DecryptCbc(LTC_BASE, in, out, blocks * AES_BLOCK_SIZE, + status = LTC_AES_DecryptCbc(LTC_BASE, in, out, blocks * WC_AES_BLOCK_SIZE, iv, dec_key, keySize, kLTC_EncryptKey); wolfSSL_CryptHwMutexUnLock(); /* store IV for next call */ if (status == kStatus_Success) { - XMEMCPY(iv, temp_block, AES_BLOCK_SIZE); + XMEMCPY(iv, temp_block, WC_AES_BLOCK_SIZE); } return (status == kStatus_Success) ? 0 : -1; @@ -5384,12 +5384,12 @@ int wc_AesSetIV(Aes* aes, const byte* iv) { int offset = 0; byte *iv; - byte temp_block[AES_BLOCK_SIZE]; - word32 blocks = (sz / AES_BLOCK_SIZE); + byte temp_block[WC_AES_BLOCK_SIZE]; + word32 blocks = (sz / WC_AES_BLOCK_SIZE); int ret; #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -5399,19 +5399,19 @@ int wc_AesSetIV(Aes* aes, const byte* iv) iv = (byte*)aes->reg; while (blocks--) { - XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE); + XMEMCPY(temp_block, in + offset, WC_AES_BLOCK_SIZE); /* XOR block with IV for CBC */ - xorbuf(temp_block, iv, AES_BLOCK_SIZE); + xorbuf(temp_block, iv, WC_AES_BLOCK_SIZE); ret = wc_AesEncrypt(aes, temp_block, out + offset); if (ret != 0) return ret; - offset += AES_BLOCK_SIZE; + offset += WC_AES_BLOCK_SIZE; /* store IV for next block */ - XMEMCPY(iv, out + offset - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(iv, out + offset - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); } return 0; @@ -5422,11 +5422,11 @@ int wc_AesSetIV(Aes* aes, const byte* iv) int ret; int offset = 0; byte* iv; - byte temp_block[AES_BLOCK_SIZE]; - word32 blocks = (sz / AES_BLOCK_SIZE); + byte temp_block[WC_AES_BLOCK_SIZE]; + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { return BAD_LENGTH_E; } #endif @@ -5436,19 +5436,19 @@ int wc_AesSetIV(Aes* aes, const byte* iv) iv = (byte*)aes->reg; while (blocks--) { - XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE); + XMEMCPY(temp_block, in + offset, WC_AES_BLOCK_SIZE); ret = wc_AesDecrypt(aes, in + offset, out + offset); if (ret != 0) return ret; /* XOR block with IV for CBC */ - xorbuf(out + offset, iv, AES_BLOCK_SIZE); + xorbuf(out + offset, iv, WC_AES_BLOCK_SIZE); /* store IV for next block */ - XMEMCPY(iv, temp_block, AES_BLOCK_SIZE); + XMEMCPY(iv, temp_block, WC_AES_BLOCK_SIZE); - offset += AES_BLOCK_SIZE; + offset += WC_AES_BLOCK_SIZE; } return 0; @@ -5467,7 +5467,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } /* Always enforce a length check */ - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS return BAD_LENGTH_E; #else @@ -5489,7 +5489,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) (unsigned int)keySize); /* store iv for next call */ if (status == 0) { - XMEMCPY(iv, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(iv, out + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); } return (status == 0) ? 0 : -1; } @@ -5500,14 +5500,14 @@ int wc_AesSetIV(Aes* aes, const byte* iv) word32 keySize; int status; byte *iv; - byte temp_block[AES_BLOCK_SIZE]; + byte temp_block[WC_AES_BLOCK_SIZE]; if ((in == NULL) || (out == NULL) || (aes == NULL)) { return BAD_FUNC_ARG; } /* Always enforce a length check */ - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS return BAD_LENGTH_E; #else @@ -5525,14 +5525,14 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } /* get IV for next call */ - XMEMCPY(temp_block, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(temp_block, in + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); status = wc_MXC_TPU_AesDecrypt(in, iv, (byte*)aes->key, MXC_TPU_MODE_CBC, sz, out, keySize); /* store iv for next call */ if (status == 0) { - XMEMCPY(iv, temp_block, AES_BLOCK_SIZE); + XMEMCPY(iv, temp_block, WC_AES_BLOCK_SIZE); } return (status == 0) ? 0 : -1; } @@ -5550,7 +5550,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) return 0; /* hardware fails on input that is not a multiple of AES block size */ - if (sz % AES_BLOCK_SIZE != 0) { + if (sz % WC_AES_BLOCK_SIZE != 0) { #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS return BAD_LENGTH_E; #else @@ -5559,13 +5559,13 @@ int wc_AesSetIV(Aes* aes, const byte* iv) } ret = wc_Pic32AesCrypt( - aes->key, aes->keylen, aes->reg, AES_BLOCK_SIZE, + aes->key, aes->keylen, aes->reg, WC_AES_BLOCK_SIZE, out, in, sz, PIC32_ENCRYPTION, PIC32_ALGO_AES, PIC32_CRYPTOALGO_RCBC); /* store iv for next call */ if (ret == 0) { - XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, out + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); } return ret; @@ -5574,29 +5574,29 @@ int wc_AesSetIV(Aes* aes, const byte* iv) int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz) { int ret; - byte scratch[AES_BLOCK_SIZE]; + byte scratch[WC_AES_BLOCK_SIZE]; if (sz == 0) return 0; /* hardware fails on input that is not a multiple of AES block size */ - if (sz % AES_BLOCK_SIZE != 0) { + if (sz % WC_AES_BLOCK_SIZE != 0) { #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS return BAD_LENGTH_E; #else return BAD_FUNC_ARG; #endif } - XMEMCPY(scratch, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(scratch, in + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); ret = wc_Pic32AesCrypt( - aes->key, aes->keylen, aes->reg, AES_BLOCK_SIZE, + aes->key, aes->keylen, aes->reg, WC_AES_BLOCK_SIZE, out, in, sz, PIC32_DECRYPTION, PIC32_ALGO_AES, PIC32_CRYPTOALGO_RCBC); /* store iv for next call */ if (ret == 0) { - XMEMCPY((byte*)aes->reg, scratch, AES_BLOCK_SIZE); + XMEMCPY((byte*)aes->reg, scratch, WC_AES_BLOCK_SIZE); } return ret; @@ -5661,9 +5661,9 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) return 0; } - blocks = sz / AES_BLOCK_SIZE; + blocks = sz / WC_AES_BLOCK_SIZE; #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS - if (sz % AES_BLOCK_SIZE) { + if (sz % WC_AES_BLOCK_SIZE) { WOLFSSL_ERROR_VERBOSE(BAD_LENGTH_E); return BAD_LENGTH_E; } @@ -5695,7 +5695,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) #elif defined(HAVE_INTEL_QA) return IntelQaSymAesCbcEncrypt(&aes->asyncDev, out, in, sz, (const byte*)aes->devKey, aes->keylen, - (byte*)aes->reg, AES_BLOCK_SIZE); + (byte*)aes->reg, WC_AES_BLOCK_SIZE); #elif defined(WOLFSSL_ASYNC_CRYPT_SW) if (wc_AsyncSwInit(&aes->asyncDev, ASYNC_SW_AES_CBC_ENCRYPT)) { WC_ASYNC_SW* sw = &aes->asyncDev.sw; @@ -5745,7 +5745,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) /* check alignment, decrypt doesn't need alignment */ if ((wc_ptr_t)in % AESNI_ALIGN) { #ifndef NO_WOLFSSL_ALLOC_ALIGN - byte* tmp = (byte*)XMALLOC(sz + AES_BLOCK_SIZE + AESNI_ALIGN, + byte* tmp = (byte*)XMALLOC(sz + WC_AES_BLOCK_SIZE + AESNI_ALIGN, aes->heap, DYNAMIC_TYPE_TMP_BUFFER); byte* tmp_align; if (tmp == NULL) @@ -5756,7 +5756,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) AES_CBC_encrypt_AESNI(tmp_align, tmp_align, (byte*)aes->reg, sz, (byte*)aes->key, (int)aes->rounds); /* store iv for next call */ - XMEMCPY(aes->reg, tmp_align + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, tmp_align + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); XMEMCPY(out, tmp_align, sz); XFREE(tmp, aes->heap, DYNAMIC_TYPE_TMP_BUFFER); @@ -5771,7 +5771,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) AES_CBC_encrypt_AESNI(in, out, (byte*)aes->reg, sz, (byte*)aes->key, (int)aes->rounds); /* store iv for next call */ - XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, out + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); ret = 0; } @@ -5781,14 +5781,14 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { ret = 0; while (blocks--) { - xorbuf((byte*)aes->reg, in, AES_BLOCK_SIZE); + xorbuf((byte*)aes->reg, in, WC_AES_BLOCK_SIZE); ret = wc_AesEncrypt(aes, (byte*)aes->reg, (byte*)aes->reg); if (ret != 0) break; - XMEMCPY(out, aes->reg, AES_BLOCK_SIZE); + XMEMCPY(out, aes->reg, WC_AES_BLOCK_SIZE); - out += AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; } } @@ -5829,8 +5829,8 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) } #endif - blocks = sz / AES_BLOCK_SIZE; - if (sz % AES_BLOCK_SIZE) { + blocks = sz / WC_AES_BLOCK_SIZE; + if (sz % WC_AES_BLOCK_SIZE) { #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS return BAD_LENGTH_E; #else @@ -5864,7 +5864,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) #elif defined(HAVE_INTEL_QA) return IntelQaSymAesCbcDecrypt(&aes->asyncDev, out, in, sz, (const byte*)aes->devKey, aes->keylen, - (byte*)aes->reg, AES_BLOCK_SIZE); + (byte*)aes->reg, WC_AES_BLOCK_SIZE); #elif defined(WOLFSSL_ASYNC_CRYPT_SW) if (wc_AsyncSwInit(&aes->asyncDev, ASYNC_SW_AES_CBC_DECRYPT)) { WC_ASYNC_SW* sw = &aes->asyncDev.sw; @@ -5901,7 +5901,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) #endif /* if input and output same will overwrite input iv */ - XMEMCPY(aes->tmp, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + XMEMCPY(aes->tmp, in + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_AESNI_BY4) || defined(WOLFSSL_X86_BUILD) AES_CBC_decrypt_AESNI_by4(in, out, (byte*)aes->reg, sz, (byte*)aes->key, aes->rounds); @@ -5913,7 +5913,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) (int)aes->rounds); #endif /* WOLFSSL_AESNI_BYx */ /* store iv for next call */ - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); ret = 0; } else @@ -5922,76 +5922,76 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) ret = 0; #ifdef WC_AES_BITSLICED if (in != out) { - unsigned char dec[AES_BLOCK_SIZE * BS_WORD_SIZE]; + unsigned char dec[WC_AES_BLOCK_SIZE * BS_WORD_SIZE]; while (blocks > BS_WORD_SIZE) { - AesDecryptBlocks_C(aes, in, dec, AES_BLOCK_SIZE * BS_WORD_SIZE); - xorbufout(out, dec, aes->reg, AES_BLOCK_SIZE); - xorbufout(out + AES_BLOCK_SIZE, dec + AES_BLOCK_SIZE, in, - AES_BLOCK_SIZE * (BS_WORD_SIZE - 1)); - XMEMCPY(aes->reg, in + (AES_BLOCK_SIZE * (BS_WORD_SIZE - 1)), - AES_BLOCK_SIZE); - in += AES_BLOCK_SIZE * BS_WORD_SIZE; - out += AES_BLOCK_SIZE * BS_WORD_SIZE; + AesDecryptBlocks_C(aes, in, dec, WC_AES_BLOCK_SIZE * BS_WORD_SIZE); + xorbufout(out, dec, aes->reg, WC_AES_BLOCK_SIZE); + xorbufout(out + WC_AES_BLOCK_SIZE, dec + WC_AES_BLOCK_SIZE, in, + WC_AES_BLOCK_SIZE * (BS_WORD_SIZE - 1)); + XMEMCPY(aes->reg, in + (WC_AES_BLOCK_SIZE * (BS_WORD_SIZE - 1)), + WC_AES_BLOCK_SIZE); + in += WC_AES_BLOCK_SIZE * BS_WORD_SIZE; + out += WC_AES_BLOCK_SIZE * BS_WORD_SIZE; blocks -= BS_WORD_SIZE; } if (blocks > 0) { - AesDecryptBlocks_C(aes, in, dec, blocks * AES_BLOCK_SIZE); - xorbufout(out, dec, aes->reg, AES_BLOCK_SIZE); - xorbufout(out + AES_BLOCK_SIZE, dec + AES_BLOCK_SIZE, in, - AES_BLOCK_SIZE * (blocks - 1)); - XMEMCPY(aes->reg, in + (AES_BLOCK_SIZE * (blocks - 1)), - AES_BLOCK_SIZE); + AesDecryptBlocks_C(aes, in, dec, blocks * WC_AES_BLOCK_SIZE); + xorbufout(out, dec, aes->reg, WC_AES_BLOCK_SIZE); + xorbufout(out + WC_AES_BLOCK_SIZE, dec + WC_AES_BLOCK_SIZE, in, + WC_AES_BLOCK_SIZE * (blocks - 1)); + XMEMCPY(aes->reg, in + (WC_AES_BLOCK_SIZE * (blocks - 1)), + WC_AES_BLOCK_SIZE); blocks = 0; } } else { - unsigned char dec[AES_BLOCK_SIZE * BS_WORD_SIZE]; + unsigned char dec[WC_AES_BLOCK_SIZE * BS_WORD_SIZE]; int i; while (blocks > BS_WORD_SIZE) { - AesDecryptBlocks_C(aes, in, dec, AES_BLOCK_SIZE * BS_WORD_SIZE); - XMEMCPY(aes->tmp, in + (BS_WORD_SIZE - 1) * AES_BLOCK_SIZE, - AES_BLOCK_SIZE); + AesDecryptBlocks_C(aes, in, dec, WC_AES_BLOCK_SIZE * BS_WORD_SIZE); + XMEMCPY(aes->tmp, in + (BS_WORD_SIZE - 1) * WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE); for (i = BS_WORD_SIZE-1; i >= 1; i--) { - xorbufout(out + i * AES_BLOCK_SIZE, - dec + i * AES_BLOCK_SIZE, in + (i - 1) * AES_BLOCK_SIZE, - AES_BLOCK_SIZE); + xorbufout(out + i * WC_AES_BLOCK_SIZE, + dec + i * WC_AES_BLOCK_SIZE, in + (i - 1) * WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE); } - xorbufout(out, dec, aes->reg, AES_BLOCK_SIZE); - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + xorbufout(out, dec, aes->reg, WC_AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); - in += AES_BLOCK_SIZE * BS_WORD_SIZE; - out += AES_BLOCK_SIZE * BS_WORD_SIZE; + in += WC_AES_BLOCK_SIZE * BS_WORD_SIZE; + out += WC_AES_BLOCK_SIZE * BS_WORD_SIZE; blocks -= BS_WORD_SIZE; } if (blocks > 0) { - AesDecryptBlocks_C(aes, in, dec, blocks * AES_BLOCK_SIZE); - XMEMCPY(aes->tmp, in + (blocks - 1) * AES_BLOCK_SIZE, - AES_BLOCK_SIZE); + AesDecryptBlocks_C(aes, in, dec, blocks * WC_AES_BLOCK_SIZE); + XMEMCPY(aes->tmp, in + (blocks - 1) * WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE); for (i = blocks-1; i >= 1; i--) { - xorbufout(out + i * AES_BLOCK_SIZE, - dec + i * AES_BLOCK_SIZE, in + (i - 1) * AES_BLOCK_SIZE, - AES_BLOCK_SIZE); + xorbufout(out + i * WC_AES_BLOCK_SIZE, + dec + i * WC_AES_BLOCK_SIZE, in + (i - 1) * WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE); } - xorbufout(out, dec, aes->reg, AES_BLOCK_SIZE); - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + xorbufout(out, dec, aes->reg, WC_AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); blocks = 0; } } #else while (blocks--) { - XMEMCPY(aes->tmp, in, AES_BLOCK_SIZE); + XMEMCPY(aes->tmp, in, WC_AES_BLOCK_SIZE); ret = wc_AesDecrypt(aes, in, out); if (ret != 0) return ret; - xorbuf(out, (byte*)aes->reg, AES_BLOCK_SIZE); + xorbuf(out, (byte*)aes->reg, WC_AES_BLOCK_SIZE); /* store iv for next call */ - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); - out += AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; } #endif } @@ -6018,7 +6018,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) #ifdef WOLFSSL_STM32_CUBEMX CRYP_HandleTypeDef hcryp; #ifdef STM32_HAL_V2 - word32 iv[AES_BLOCK_SIZE/sizeof(word32)]; + word32 iv[WC_AES_BLOCK_SIZE/sizeof(word32)]; #endif #else word32 *iv; @@ -6040,7 +6040,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) #if defined(STM32_HAL_V2) hcryp.Init.Algorithm = CRYP_AES_CTR; - ByteReverseWords(iv, aes->reg, AES_BLOCK_SIZE); + ByteReverseWords(iv, aes->reg, WC_AES_BLOCK_SIZE); hcryp.Init.pInitVect = (STM_CRYPT_TYPE*)iv; #elif defined(STM32_CRYPTO_AES_ONLY) hcryp.Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT; @@ -6053,13 +6053,13 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) HAL_CRYP_Init(&hcryp); #if defined(STM32_HAL_V2) - ret = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)in, AES_BLOCK_SIZE, + ret = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)in, WC_AES_BLOCK_SIZE, (uint32_t*)out, STM32_HAL_TIMEOUT); #elif defined(STM32_CRYPTO_AES_ONLY) - ret = HAL_CRYPEx_AES(&hcryp, (byte*)in, AES_BLOCK_SIZE, + ret = HAL_CRYPEx_AES(&hcryp, (byte*)in, WC_AES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT); #else - ret = HAL_CRYP_AESCTR_Encrypt(&hcryp, (byte*)in, AES_BLOCK_SIZE, + ret = HAL_CRYP_AESCTR_Encrypt(&hcryp, (byte*)in, WC_AES_BLOCK_SIZE, out, STM32_HAL_TIMEOUT); #endif if (ret != HAL_OK) { @@ -6134,11 +6134,11 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) int wc_AesCtrEncryptBlock(Aes* aes, byte* out, const byte* in) { - word32 tmpIv[AES_BLOCK_SIZE / sizeof(word32)]; - XMEMCPY(tmpIv, aes->reg, AES_BLOCK_SIZE); + word32 tmpIv[WC_AES_BLOCK_SIZE / sizeof(word32)]; + XMEMCPY(tmpIv, aes->reg, WC_AES_BLOCK_SIZE); return wc_Pic32AesCrypt( - aes->key, aes->keylen, tmpIv, AES_BLOCK_SIZE, - out, in, AES_BLOCK_SIZE, + aes->key, aes->keylen, tmpIv, WC_AES_BLOCK_SIZE, + out, in, WC_AES_BLOCK_SIZE, PIC32_ENCRYPTION, PIC32_ALGO_AES, PIC32_CRYPTOALGO_RCTR); } @@ -6158,7 +6158,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) } /* consume any unused bytes left in aes->tmp */ - tmp = (byte*)aes->tmp + AES_BLOCK_SIZE - aes->left; + tmp = (byte*)aes->tmp + WC_AES_BLOCK_SIZE - aes->left; while (aes->left && sz) { *(out++) = *(in++) ^ *(tmp++); aes->left--; @@ -6215,7 +6215,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { /* in network byte order so start at end and work back */ int i; - for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) { + for (i = WC_AES_BLOCK_SIZE - 1; i >= 0; i--) { if (++inOutCtr[i]) /* we're done unless we overflow */ return; } @@ -6224,7 +6224,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) /* Software AES - CTR Encrypt */ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { - byte scratch[AES_BLOCK_SIZE]; + byte scratch[WC_AES_BLOCK_SIZE]; int ret = 0; word32 processed; @@ -6248,7 +6248,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) /* consume any unused bytes left in aes->tmp */ processed = min(aes->left, sz); - xorbufout(out, in, (byte*)aes->tmp + AES_BLOCK_SIZE - aes->left, + xorbufout(out, in, (byte*)aes->tmp + WC_AES_BLOCK_SIZE - aes->left, processed); out += processed; in += processed; @@ -6259,50 +6259,50 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) #if defined(HAVE_AES_ECB) && !defined(WOLFSSL_PIC32MZ_CRYPT) && \ !defined(XTRANSFORM_AESCTRBLOCK) - if (in != out && sz >= AES_BLOCK_SIZE) { - word32 blocks = sz / AES_BLOCK_SIZE; + if (in != out && sz >= WC_AES_BLOCK_SIZE) { + word32 blocks = sz / WC_AES_BLOCK_SIZE; byte* counter = (byte*)aes->reg; byte* c = out; while (blocks--) { - XMEMCPY(c, counter, AES_BLOCK_SIZE); - c += AES_BLOCK_SIZE; + XMEMCPY(c, counter, WC_AES_BLOCK_SIZE); + c += WC_AES_BLOCK_SIZE; IncrementAesCounter(counter); } /* reset number of blocks and then do encryption */ - blocks = sz / AES_BLOCK_SIZE; - wc_AesEcbEncrypt(aes, out, out, AES_BLOCK_SIZE * blocks); - xorbuf(out, in, AES_BLOCK_SIZE * blocks); - in += AES_BLOCK_SIZE * blocks; - out += AES_BLOCK_SIZE * blocks; - sz -= blocks * AES_BLOCK_SIZE; + blocks = sz / WC_AES_BLOCK_SIZE; + wc_AesEcbEncrypt(aes, out, out, WC_AES_BLOCK_SIZE * blocks); + xorbuf(out, in, WC_AES_BLOCK_SIZE * blocks); + in += WC_AES_BLOCK_SIZE * blocks; + out += WC_AES_BLOCK_SIZE * blocks; + sz -= blocks * WC_AES_BLOCK_SIZE; } else #endif { #ifdef WOLFSSL_CHECK_MEM_ZERO wc_MemZero_Add("wc_AesCtrEncrypt scratch", scratch, - AES_BLOCK_SIZE); + WC_AES_BLOCK_SIZE); #endif /* do as many block size ops as possible */ - while (sz >= AES_BLOCK_SIZE) { + while (sz >= WC_AES_BLOCK_SIZE) { #ifdef XTRANSFORM_AESCTRBLOCK XTRANSFORM_AESCTRBLOCK(aes, out, in); #else ret = wc_AesEncrypt(aes, (byte*)aes->reg, scratch); if (ret != 0) break; - xorbuf(scratch, in, AES_BLOCK_SIZE); - XMEMCPY(out, scratch, AES_BLOCK_SIZE); + xorbuf(scratch, in, WC_AES_BLOCK_SIZE); + XMEMCPY(out, scratch, WC_AES_BLOCK_SIZE); #endif IncrementAesCounter((byte*)aes->reg); - out += AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; - sz -= AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + sz -= WC_AES_BLOCK_SIZE; aes->left = 0; } - ForceZero(scratch, AES_BLOCK_SIZE); + ForceZero(scratch, WC_AES_BLOCK_SIZE); } /* handle non block size remaining and store unused byte count in left */ @@ -6310,16 +6310,16 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) ret = wc_AesEncrypt(aes, (byte*)aes->reg, (byte*)aes->tmp); if (ret == 0) { IncrementAesCounter((byte*)aes->reg); - aes->left = AES_BLOCK_SIZE - sz; + aes->left = WC_AES_BLOCK_SIZE - sz; xorbufout(out, in, aes->tmp, sz); } } if (ret < 0) - ForceZero(scratch, AES_BLOCK_SIZE); + ForceZero(scratch, WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_CHECK_MEM_ZERO - wc_MemZero_Check(scratch, AES_BLOCK_SIZE); + wc_MemZero_Check(scratch, WC_AES_BLOCK_SIZE); #endif VECTOR_REGISTERS_POP; @@ -6374,15 +6374,15 @@ static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz) #ifdef WOLFSSL_AESGCM_STREAM /* Access initialization counter data. */ - #define AES_INITCTR(aes) ((aes)->streamData + 0 * AES_BLOCK_SIZE) + #define AES_INITCTR(aes) ((aes)->streamData + 0 * WC_AES_BLOCK_SIZE) /* Access counter data. */ - #define AES_COUNTER(aes) ((aes)->streamData + 1 * AES_BLOCK_SIZE) + #define AES_COUNTER(aes) ((aes)->streamData + 1 * WC_AES_BLOCK_SIZE) /* Access tag data. */ - #define AES_TAG(aes) ((aes)->streamData + 2 * AES_BLOCK_SIZE) + #define AES_TAG(aes) ((aes)->streamData + 2 * WC_AES_BLOCK_SIZE) /* Access last GHASH block. */ - #define AES_LASTGBLOCK(aes) ((aes)->streamData + 3 * AES_BLOCK_SIZE) + #define AES_LASTGBLOCK(aes) ((aes)->streamData + 3 * WC_AES_BLOCK_SIZE) /* Access last encrypted block. */ - #define AES_LASTBLOCK(aes) ((aes)->streamData + 4 * AES_BLOCK_SIZE) + #define AES_LASTBLOCK(aes) ((aes)->streamData + 4 * WC_AES_BLOCK_SIZE) #endif #if defined(HAVE_COLDFIRE_SEC) @@ -6413,7 +6413,7 @@ static WC_INLINE void IncrementGcmCounter(byte* inOutCtr) int i; /* in network byte order so start at end and work back */ - for (i = AES_BLOCK_SIZE - 1; i >= AES_BLOCK_SIZE - CTR_SZ; i--) { + for (i = WC_AES_BLOCK_SIZE - 1; i >= WC_AES_BLOCK_SIZE - CTR_SZ; i--) { if (++inOutCtr[i]) /* we're done unless we overflow */ return; } @@ -6446,7 +6446,7 @@ static WC_INLINE void RIGHTSHIFTX(byte* x) int carryIn = 0; byte borrow = (0x00 - (x[15] & 0x01)) & 0xE1; - for (i = 0; i < AES_BLOCK_SIZE; i++) { + for (i = 0; i < WC_AES_BLOCK_SIZE; i++) { int carryOut = (x[i] & 0x01) << 7; x[i] = (byte) ((x[i] >> 1) | carryIn); carryIn = carryOut; @@ -6462,23 +6462,23 @@ static WC_INLINE void RIGHTSHIFTX(byte* x) void GenerateM0(Gcm* gcm) { int i, j; - byte (*m)[AES_BLOCK_SIZE] = gcm->M0; + byte (*m)[WC_AES_BLOCK_SIZE] = gcm->M0; - XMEMCPY(m[128], gcm->H, AES_BLOCK_SIZE); + XMEMCPY(m[128], gcm->H, WC_AES_BLOCK_SIZE); for (i = 64; i > 0; i /= 2) { - XMEMCPY(m[i], m[i*2], AES_BLOCK_SIZE); + XMEMCPY(m[i], m[i*2], WC_AES_BLOCK_SIZE); RIGHTSHIFTX(m[i]); } for (i = 2; i < 256; i *= 2) { for (j = 1; j < i; j++) { - XMEMCPY(m[i+j], m[i], AES_BLOCK_SIZE); - xorbuf(m[i+j], m[j], AES_BLOCK_SIZE); + XMEMCPY(m[i+j], m[i], WC_AES_BLOCK_SIZE); + xorbuf(m[i+j], m[j], WC_AES_BLOCK_SIZE); } } - XMEMSET(m[0], 0, AES_BLOCK_SIZE); + XMEMSET(m[0], 0, WC_AES_BLOCK_SIZE); } #elif defined(GCM_TABLE_4BIT) @@ -6498,49 +6498,49 @@ void GenerateM0(Gcm* gcm) #if !defined(BIG_ENDIAN_ORDER) && !defined(WC_16BIT_CPU) int i; #endif - byte (*m)[AES_BLOCK_SIZE] = gcm->M0; + byte (*m)[WC_AES_BLOCK_SIZE] = gcm->M0; /* 0 times -> 0x0 */ - XMEMSET(m[0x0], 0, AES_BLOCK_SIZE); + XMEMSET(m[0x0], 0, WC_AES_BLOCK_SIZE); /* 1 times -> 0x8 */ - XMEMCPY(m[0x8], gcm->H, AES_BLOCK_SIZE); + XMEMCPY(m[0x8], gcm->H, WC_AES_BLOCK_SIZE); /* 2 times -> 0x4 */ - XMEMCPY(m[0x4], m[0x8], AES_BLOCK_SIZE); + XMEMCPY(m[0x4], m[0x8], WC_AES_BLOCK_SIZE); RIGHTSHIFTX(m[0x4]); /* 4 times -> 0x2 */ - XMEMCPY(m[0x2], m[0x4], AES_BLOCK_SIZE); + XMEMCPY(m[0x2], m[0x4], WC_AES_BLOCK_SIZE); RIGHTSHIFTX(m[0x2]); /* 8 times -> 0x1 */ - XMEMCPY(m[0x1], m[0x2], AES_BLOCK_SIZE); + XMEMCPY(m[0x1], m[0x2], WC_AES_BLOCK_SIZE); RIGHTSHIFTX(m[0x1]); /* 0x3 */ - XMEMCPY(m[0x3], m[0x2], AES_BLOCK_SIZE); - xorbuf (m[0x3], m[0x1], AES_BLOCK_SIZE); + XMEMCPY(m[0x3], m[0x2], WC_AES_BLOCK_SIZE); + xorbuf (m[0x3], m[0x1], WC_AES_BLOCK_SIZE); /* 0x5 -> 0x7 */ - XMEMCPY(m[0x5], m[0x4], AES_BLOCK_SIZE); - xorbuf (m[0x5], m[0x1], AES_BLOCK_SIZE); - XMEMCPY(m[0x6], m[0x4], AES_BLOCK_SIZE); - xorbuf (m[0x6], m[0x2], AES_BLOCK_SIZE); - XMEMCPY(m[0x7], m[0x4], AES_BLOCK_SIZE); - xorbuf (m[0x7], m[0x3], AES_BLOCK_SIZE); + XMEMCPY(m[0x5], m[0x4], WC_AES_BLOCK_SIZE); + xorbuf (m[0x5], m[0x1], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0x6], m[0x4], WC_AES_BLOCK_SIZE); + xorbuf (m[0x6], m[0x2], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0x7], m[0x4], WC_AES_BLOCK_SIZE); + xorbuf (m[0x7], m[0x3], WC_AES_BLOCK_SIZE); /* 0x9 -> 0xf */ - XMEMCPY(m[0x9], m[0x8], AES_BLOCK_SIZE); - xorbuf (m[0x9], m[0x1], AES_BLOCK_SIZE); - XMEMCPY(m[0xa], m[0x8], AES_BLOCK_SIZE); - xorbuf (m[0xa], m[0x2], AES_BLOCK_SIZE); - XMEMCPY(m[0xb], m[0x8], AES_BLOCK_SIZE); - xorbuf (m[0xb], m[0x3], AES_BLOCK_SIZE); - XMEMCPY(m[0xc], m[0x8], AES_BLOCK_SIZE); - xorbuf (m[0xc], m[0x4], AES_BLOCK_SIZE); - XMEMCPY(m[0xd], m[0x8], AES_BLOCK_SIZE); - xorbuf (m[0xd], m[0x5], AES_BLOCK_SIZE); - XMEMCPY(m[0xe], m[0x8], AES_BLOCK_SIZE); - xorbuf (m[0xe], m[0x6], AES_BLOCK_SIZE); - XMEMCPY(m[0xf], m[0x8], AES_BLOCK_SIZE); - xorbuf (m[0xf], m[0x7], AES_BLOCK_SIZE); + XMEMCPY(m[0x9], m[0x8], WC_AES_BLOCK_SIZE); + xorbuf (m[0x9], m[0x1], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0xa], m[0x8], WC_AES_BLOCK_SIZE); + xorbuf (m[0xa], m[0x2], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0xb], m[0x8], WC_AES_BLOCK_SIZE); + xorbuf (m[0xb], m[0x3], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0xc], m[0x8], WC_AES_BLOCK_SIZE); + xorbuf (m[0xc], m[0x4], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0xd], m[0x8], WC_AES_BLOCK_SIZE); + xorbuf (m[0xd], m[0x5], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0xe], m[0x8], WC_AES_BLOCK_SIZE); + xorbuf (m[0xe], m[0x6], WC_AES_BLOCK_SIZE); + XMEMCPY(m[0xf], m[0x8], WC_AES_BLOCK_SIZE); + xorbuf (m[0xf], m[0x7], WC_AES_BLOCK_SIZE); #if !defined(BIG_ENDIAN_ORDER) && !defined(WC_16BIT_CPU) for (i = 0; i < 16; i++) { @@ -6555,7 +6555,7 @@ void GenerateM0(Gcm* gcm) int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len) { int ret; - byte iv[AES_BLOCK_SIZE]; + byte iv[WC_AES_BLOCK_SIZE]; #ifdef WOLFSSL_IMX6_CAAM_BLOB byte local[32]; @@ -6587,7 +6587,7 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len) XMEMSET(aes->gcm.aadH, 0, sizeof(aes->gcm.aadH)); aes->gcm.aadLen = 0; #endif - XMEMSET(iv, 0, AES_BLOCK_SIZE); + XMEMSET(iv, 0, WC_AES_BLOCK_SIZE); ret = wc_AesSetKey(aes, key, len, iv, AES_ENCRYPTION); #ifdef WOLFSSL_AESGCM_STREAM aes->gcmKeySet = 1; @@ -6698,34 +6698,34 @@ void AES_GCM_decrypt_avx2(const unsigned char *in, unsigned char *out, #if defined(GCM_SMALL) static void GMULT(byte* X, byte* Y) { - byte Z[AES_BLOCK_SIZE]; - byte V[AES_BLOCK_SIZE]; + byte Z[WC_AES_BLOCK_SIZE]; + byte V[WC_AES_BLOCK_SIZE]; int i, j; - XMEMSET(Z, 0, AES_BLOCK_SIZE); - XMEMCPY(V, X, AES_BLOCK_SIZE); - for (i = 0; i < AES_BLOCK_SIZE; i++) + XMEMSET(Z, 0, WC_AES_BLOCK_SIZE); + XMEMCPY(V, X, WC_AES_BLOCK_SIZE); + for (i = 0; i < WC_AES_BLOCK_SIZE; i++) { byte y = Y[i]; for (j = 0; j < 8; j++) { if (y & 0x80) { - xorbuf(Z, V, AES_BLOCK_SIZE); + xorbuf(Z, V, WC_AES_BLOCK_SIZE); } RIGHTSHIFTX(V); y = y << 1; } } - XMEMCPY(X, Z, AES_BLOCK_SIZE); + XMEMCPY(X, Z, WC_AES_BLOCK_SIZE); } void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32 cSz, byte* s, word32 sSz) { - byte x[AES_BLOCK_SIZE]; - byte scratch[AES_BLOCK_SIZE]; + byte x[WC_AES_BLOCK_SIZE]; + byte scratch[WC_AES_BLOCK_SIZE]; word32 blocks, partial; byte* h; @@ -6734,38 +6734,38 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, } h = gcm->H; - XMEMSET(x, 0, AES_BLOCK_SIZE); + XMEMSET(x, 0, WC_AES_BLOCK_SIZE); /* Hash in A, the Additional Authentication Data */ if (aSz != 0 && a != NULL) { - blocks = aSz / AES_BLOCK_SIZE; - partial = aSz % AES_BLOCK_SIZE; + blocks = aSz / WC_AES_BLOCK_SIZE; + partial = aSz % WC_AES_BLOCK_SIZE; while (blocks--) { - xorbuf(x, a, AES_BLOCK_SIZE); + xorbuf(x, a, WC_AES_BLOCK_SIZE); GMULT(x, h); - a += AES_BLOCK_SIZE; + a += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(scratch, 0, AES_BLOCK_SIZE); + XMEMSET(scratch, 0, WC_AES_BLOCK_SIZE); XMEMCPY(scratch, a, partial); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, h); } } /* Hash in C, the Ciphertext */ if (cSz != 0 && c != NULL) { - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; while (blocks--) { - xorbuf(x, c, AES_BLOCK_SIZE); + xorbuf(x, c, WC_AES_BLOCK_SIZE); GMULT(x, h); - c += AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(scratch, 0, AES_BLOCK_SIZE); + XMEMSET(scratch, 0, WC_AES_BLOCK_SIZE); XMEMCPY(scratch, c, partial); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, h); } } @@ -6773,7 +6773,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, /* Hash in the lengths of A and C in bits */ FlattenSzInBits(&scratch[0], aSz); FlattenSzInBits(&scratch[8], cSz); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, h); /* Copy the result into s. */ @@ -6796,7 +6796,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, */ #define GHASH_ONE_BLOCK(aes, block) \ do { \ - xorbuf(AES_TAG(aes), block, AES_BLOCK_SIZE); \ + xorbuf(AES_TAG(aes), block, WC_AES_BLOCK_SIZE); \ GMULT(AES_TAG(aes), aes->gcm.H); \ } \ while (0) @@ -6871,17 +6871,17 @@ ALIGN16 static const byte R[256][2] = { {0xbc, 0xf8}, {0xbd, 0x3a}, {0xbf, 0x7c}, {0xbe, 0xbe} }; -static void GMULT(byte *x, byte m[256][AES_BLOCK_SIZE]) +static void GMULT(byte *x, byte m[256][WC_AES_BLOCK_SIZE]) { #if !defined(WORD64_AVAILABLE) || defined(BIG_ENDIAN_ORDER) int i, j; - byte Z[AES_BLOCK_SIZE]; + byte Z[WC_AES_BLOCK_SIZE]; byte a; XMEMSET(Z, 0, sizeof(Z)); for (i = 15; i > 0; i--) { - xorbuf(Z, m[x[i]], AES_BLOCK_SIZE); + xorbuf(Z, m[x[i]], WC_AES_BLOCK_SIZE); a = Z[15]; for (j = 15; j > 0; j--) { @@ -6891,11 +6891,11 @@ static void GMULT(byte *x, byte m[256][AES_BLOCK_SIZE]) Z[0] = R[a][0]; Z[1] ^= R[a][1]; } - xorbuf(Z, m[x[0]], AES_BLOCK_SIZE); + xorbuf(Z, m[x[0]], WC_AES_BLOCK_SIZE); - XMEMCPY(x, Z, AES_BLOCK_SIZE); + XMEMCPY(x, Z, WC_AES_BLOCK_SIZE); #elif defined(WC_32BIT_CPU) - byte Z[AES_BLOCK_SIZE + AES_BLOCK_SIZE]; + byte Z[WC_AES_BLOCK_SIZE + WC_AES_BLOCK_SIZE]; byte a; word32* pZ; word32* pm; @@ -6927,7 +6927,7 @@ static void GMULT(byte *x, byte m[256][AES_BLOCK_SIZE]) px[0] = pZ[0] ^ pm[0]; px[1] = pZ[1] ^ pm[1]; px[2] = pZ[2] ^ pm[2]; px[3] = pZ[3] ^ pm[3]; #else - byte Z[AES_BLOCK_SIZE + AES_BLOCK_SIZE]; + byte Z[WC_AES_BLOCK_SIZE + WC_AES_BLOCK_SIZE]; byte a; word64* pZ; word64* pm; @@ -6959,46 +6959,46 @@ static void GMULT(byte *x, byte m[256][AES_BLOCK_SIZE]) void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32 cSz, byte* s, word32 sSz) { - byte x[AES_BLOCK_SIZE]; - byte scratch[AES_BLOCK_SIZE]; + byte x[WC_AES_BLOCK_SIZE]; + byte scratch[WC_AES_BLOCK_SIZE]; word32 blocks, partial; if (gcm == NULL) { return; } - XMEMSET(x, 0, AES_BLOCK_SIZE); + XMEMSET(x, 0, WC_AES_BLOCK_SIZE); /* Hash in A, the Additional Authentication Data */ if (aSz != 0 && a != NULL) { - blocks = aSz / AES_BLOCK_SIZE; - partial = aSz % AES_BLOCK_SIZE; + blocks = aSz / WC_AES_BLOCK_SIZE; + partial = aSz % WC_AES_BLOCK_SIZE; while (blocks--) { - xorbuf(x, a, AES_BLOCK_SIZE); + xorbuf(x, a, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); - a += AES_BLOCK_SIZE; + a += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(scratch, 0, AES_BLOCK_SIZE); + XMEMSET(scratch, 0, WC_AES_BLOCK_SIZE); XMEMCPY(scratch, a, partial); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); } } /* Hash in C, the Ciphertext */ if (cSz != 0 && c != NULL) { - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; while (blocks--) { - xorbuf(x, c, AES_BLOCK_SIZE); + xorbuf(x, c, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); - c += AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(scratch, 0, AES_BLOCK_SIZE); + XMEMSET(scratch, 0, WC_AES_BLOCK_SIZE); XMEMCPY(scratch, c, partial); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); } } @@ -7006,7 +7006,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, /* Hash in the lengths of A and C in bits */ FlattenSzInBits(&scratch[0], aSz); FlattenSzInBits(&scratch[8], cSz); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); /* Copy the result into s. */ @@ -7029,7 +7029,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, */ #define GHASH_ONE_BLOCK(aes, block) \ do { \ - xorbuf(AES_TAG(aes), block, AES_BLOCK_SIZE); \ + xorbuf(AES_TAG(aes), block, WC_AES_BLOCK_SIZE); \ GMULT(AES_TAG(aes), aes->gcm.M0); \ } \ while (0) @@ -7082,10 +7082,10 @@ static const word16 R[32] = { * [0..15] * H */ #if defined(BIG_ENDIAN_ORDER) || defined(WC_16BIT_CPU) -static void GMULT(byte *x, byte m[16][AES_BLOCK_SIZE]) +static void GMULT(byte *x, byte m[16][WC_AES_BLOCK_SIZE]) { int i, j, n; - byte Z[AES_BLOCK_SIZE]; + byte Z[WC_AES_BLOCK_SIZE]; byte a; XMEMSET(Z, 0, sizeof(Z)); @@ -7093,9 +7093,9 @@ static void GMULT(byte *x, byte m[16][AES_BLOCK_SIZE]) for (i = 15; i >= 0; i--) { for (n = 0; n < 2; n++) { if (n == 0) - xorbuf(Z, m[x[i] & 0xf], AES_BLOCK_SIZE); + xorbuf(Z, m[x[i] & 0xf], WC_AES_BLOCK_SIZE); else { - xorbuf(Z, m[x[i] >> 4], AES_BLOCK_SIZE); + xorbuf(Z, m[x[i] >> 4], WC_AES_BLOCK_SIZE); if (i == 0) break; } @@ -7110,10 +7110,10 @@ static void GMULT(byte *x, byte m[16][AES_BLOCK_SIZE]) } } - XMEMCPY(x, Z, AES_BLOCK_SIZE); + XMEMCPY(x, Z, WC_AES_BLOCK_SIZE); } #elif defined(WC_32BIT_CPU) -static WC_INLINE void GMULT(byte *x, byte m[32][AES_BLOCK_SIZE]) +static WC_INLINE void GMULT(byte *x, byte m[32][WC_AES_BLOCK_SIZE]) { int i; word32 z8[4] = {0, 0, 0, 0}; @@ -7187,7 +7187,7 @@ static WC_INLINE void GMULT(byte *x, byte m[32][AES_BLOCK_SIZE]) x8[0] = z8[0]; x8[1] = z8[1]; x8[2] = z8[2]; x8[3] = z8[3]; } #else -static WC_INLINE void GMULT(byte *x, byte m[32][AES_BLOCK_SIZE]) +static WC_INLINE void GMULT(byte *x, byte m[32][WC_AES_BLOCK_SIZE]) { int i; word64 z8[2] = {0, 0}; @@ -7259,46 +7259,46 @@ static WC_INLINE void GMULT(byte *x, byte m[32][AES_BLOCK_SIZE]) void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32 cSz, byte* s, word32 sSz) { - byte x[AES_BLOCK_SIZE]; - byte scratch[AES_BLOCK_SIZE]; + byte x[WC_AES_BLOCK_SIZE]; + byte scratch[WC_AES_BLOCK_SIZE]; word32 blocks, partial; if (gcm == NULL) { return; } - XMEMSET(x, 0, AES_BLOCK_SIZE); + XMEMSET(x, 0, WC_AES_BLOCK_SIZE); /* Hash in A, the Additional Authentication Data */ if (aSz != 0 && a != NULL) { - blocks = aSz / AES_BLOCK_SIZE; - partial = aSz % AES_BLOCK_SIZE; + blocks = aSz / WC_AES_BLOCK_SIZE; + partial = aSz % WC_AES_BLOCK_SIZE; while (blocks--) { - xorbuf(x, a, AES_BLOCK_SIZE); + xorbuf(x, a, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); - a += AES_BLOCK_SIZE; + a += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(scratch, 0, AES_BLOCK_SIZE); + XMEMSET(scratch, 0, WC_AES_BLOCK_SIZE); XMEMCPY(scratch, a, partial); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); } } /* Hash in C, the Ciphertext */ if (cSz != 0 && c != NULL) { - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; while (blocks--) { - xorbuf(x, c, AES_BLOCK_SIZE); + xorbuf(x, c, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); - c += AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(scratch, 0, AES_BLOCK_SIZE); + XMEMSET(scratch, 0, WC_AES_BLOCK_SIZE); XMEMCPY(scratch, c, partial); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); } } @@ -7306,7 +7306,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, /* Hash in the lengths of A and C in bits */ FlattenSzInBits(&scratch[0], aSz); FlattenSzInBits(&scratch[8], cSz); - xorbuf(x, scratch, AES_BLOCK_SIZE); + xorbuf(x, scratch, WC_AES_BLOCK_SIZE); GMULT(x, gcm->M0); /* Copy the result into s. */ @@ -7329,7 +7329,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, */ #define GHASH_ONE_BLOCK(aes, block) \ do { \ - xorbuf(AES_TAG(aes), block, AES_BLOCK_SIZE); \ + xorbuf(AES_TAG(aes), block, WC_AES_BLOCK_SIZE); \ GMULT(AES_TAG(aes), (aes)->gcm.M0); \ } \ while (0) @@ -7385,31 +7385,31 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, return; } - XMEMCPY(bigH, gcm->H, AES_BLOCK_SIZE); + XMEMCPY(bigH, gcm->H, WC_AES_BLOCK_SIZE); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords64(bigH, bigH, AES_BLOCK_SIZE); + ByteReverseWords64(bigH, bigH, WC_AES_BLOCK_SIZE); #endif /* Hash in A, the Additional Authentication Data */ if (aSz != 0 && a != NULL) { word64 bigA[2]; - blocks = aSz / AES_BLOCK_SIZE; - partial = aSz % AES_BLOCK_SIZE; + blocks = aSz / WC_AES_BLOCK_SIZE; + partial = aSz % WC_AES_BLOCK_SIZE; while (blocks--) { - XMEMCPY(bigA, a, AES_BLOCK_SIZE); + XMEMCPY(bigA, a, WC_AES_BLOCK_SIZE); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords64(bigA, bigA, AES_BLOCK_SIZE); + ByteReverseWords64(bigA, bigA, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigA[0]; x[1] ^= bigA[1]; GMULT(x, bigH); - a += AES_BLOCK_SIZE; + a += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(bigA, 0, AES_BLOCK_SIZE); + XMEMSET(bigA, 0, WC_AES_BLOCK_SIZE); XMEMCPY(bigA, a, partial); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords64(bigA, bigA, AES_BLOCK_SIZE); + ByteReverseWords64(bigA, bigA, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigA[0]; x[1] ^= bigA[1]; @@ -7427,8 +7427,8 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, /* Hash in C, the Ciphertext */ if (cSz != 0 && c != NULL) { word64 bigC[2]; - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; #ifdef OPENSSL_EXTRA /* Start from last AAD partial tag */ if(gcm->aadLen) { @@ -7437,20 +7437,20 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, } #endif while (blocks--) { - XMEMCPY(bigC, c, AES_BLOCK_SIZE); + XMEMCPY(bigC, c, WC_AES_BLOCK_SIZE); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords64(bigC, bigC, AES_BLOCK_SIZE); + ByteReverseWords64(bigC, bigC, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigC[0]; x[1] ^= bigC[1]; GMULT(x, bigH); - c += AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(bigC, 0, AES_BLOCK_SIZE); + XMEMSET(bigC, 0, WC_AES_BLOCK_SIZE); XMEMCPY(bigC, c, partial); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords64(bigC, bigC, AES_BLOCK_SIZE); + ByteReverseWords64(bigC, bigC, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigC[0]; x[1] ^= bigC[1]; @@ -7475,7 +7475,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, GMULT(x, bigH); } #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords64(x, x, AES_BLOCK_SIZE); + ByteReverseWords64(x, x, WC_AES_BLOCK_SIZE); #endif XMEMCPY(s, x, sSz); } @@ -7490,7 +7490,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, * @param [in] aes AES GCM object. */ #define GHASH_INIT_EXTRA(aes) \ - ByteReverseWords64((word64*)aes->gcm.H, (word64*)aes->gcm.H, AES_BLOCK_SIZE) + ByteReverseWords64((word64*)aes->gcm.H, (word64*)aes->gcm.H, WC_AES_BLOCK_SIZE) /* GHASH one block of data.. * @@ -7504,8 +7504,8 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word64* x = (word64*)AES_TAG(aes); \ word64* h = (word64*)aes->gcm.H; \ word64 block64[2]; \ - XMEMCPY(block64, block, AES_BLOCK_SIZE); \ - ByteReverseWords64(block64, block64, AES_BLOCK_SIZE); \ + XMEMCPY(block64, block, WC_AES_BLOCK_SIZE); \ + ByteReverseWords64(block64, block64, WC_AES_BLOCK_SIZE); \ x[0] ^= block64[0]; \ x[1] ^= block64[1]; \ GMULT(x, h); \ @@ -7534,7 +7534,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, x[0] ^= len[0]; \ x[1] ^= len[1]; \ GMULT(x, h); \ - ByteReverseWords64(x, x, AES_BLOCK_SIZE); \ + ByteReverseWords64(x, x, WC_AES_BLOCK_SIZE); \ } \ while (0) #else @@ -7557,7 +7557,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, x[0] ^= len[0]; \ x[1] ^= len[1]; \ GMULT(x, h); \ - ByteReverseWords64(x, x, AES_BLOCK_SIZE); \ + ByteReverseWords64(x, x, WC_AES_BLOCK_SIZE); \ } \ while (0) #endif @@ -7582,7 +7582,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word64* x = (word64*)AES_TAG(aes); \ word64* h = (word64*)aes->gcm.H; \ word64 block64[2]; \ - XMEMCPY(block64, block, AES_BLOCK_SIZE); \ + XMEMCPY(block64, block, WC_AES_BLOCK_SIZE); \ x[0] ^= block64[0]; \ x[1] ^= block64[1]; \ GMULT(x, h); \ @@ -7702,33 +7702,33 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, return; } - XMEMCPY(bigH, gcm->H, AES_BLOCK_SIZE); + XMEMCPY(bigH, gcm->H, WC_AES_BLOCK_SIZE); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords(bigH, bigH, AES_BLOCK_SIZE); + ByteReverseWords(bigH, bigH, WC_AES_BLOCK_SIZE); #endif /* Hash in A, the Additional Authentication Data */ if (aSz != 0 && a != NULL) { word32 bigA[4]; - blocks = aSz / AES_BLOCK_SIZE; - partial = aSz % AES_BLOCK_SIZE; + blocks = aSz / WC_AES_BLOCK_SIZE; + partial = aSz % WC_AES_BLOCK_SIZE; while (blocks--) { - XMEMCPY(bigA, a, AES_BLOCK_SIZE); + XMEMCPY(bigA, a, WC_AES_BLOCK_SIZE); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords(bigA, bigA, AES_BLOCK_SIZE); + ByteReverseWords(bigA, bigA, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigA[0]; x[1] ^= bigA[1]; x[2] ^= bigA[2]; x[3] ^= bigA[3]; GMULT(x, bigH); - a += AES_BLOCK_SIZE; + a += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(bigA, 0, AES_BLOCK_SIZE); + XMEMSET(bigA, 0, WC_AES_BLOCK_SIZE); XMEMCPY(bigA, a, partial); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords(bigA, bigA, AES_BLOCK_SIZE); + ByteReverseWords(bigA, bigA, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigA[0]; x[1] ^= bigA[1]; @@ -7741,25 +7741,25 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, /* Hash in C, the Ciphertext */ if (cSz != 0 && c != NULL) { word32 bigC[4]; - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; while (blocks--) { - XMEMCPY(bigC, c, AES_BLOCK_SIZE); + XMEMCPY(bigC, c, WC_AES_BLOCK_SIZE); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords(bigC, bigC, AES_BLOCK_SIZE); + ByteReverseWords(bigC, bigC, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigC[0]; x[1] ^= bigC[1]; x[2] ^= bigC[2]; x[3] ^= bigC[3]; GMULT(x, bigH); - c += AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } if (partial != 0) { - XMEMSET(bigC, 0, AES_BLOCK_SIZE); + XMEMSET(bigC, 0, WC_AES_BLOCK_SIZE); XMEMCPY(bigC, c, partial); #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords(bigC, bigC, AES_BLOCK_SIZE); + ByteReverseWords(bigC, bigC, WC_AES_BLOCK_SIZE); #endif x[0] ^= bigC[0]; x[1] ^= bigC[1]; @@ -7786,7 +7786,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, GMULT(x, bigH); } #ifdef LITTLE_ENDIAN_ORDER - ByteReverseWords(x, x, AES_BLOCK_SIZE); + ByteReverseWords(x, x, WC_AES_BLOCK_SIZE); #endif XMEMCPY(s, x, sSz); } @@ -7800,7 +7800,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, * @param [in, out] aes AES GCM object. */ #define GHASH_INIT_EXTRA(aes) \ - ByteReverseWords((word32*)aes->gcm.H, (word32*)aes->gcm.H, AES_BLOCK_SIZE) + ByteReverseWords((word32*)aes->gcm.H, (word32*)aes->gcm.H, WC_AES_BLOCK_SIZE) /* GHASH one block of data.. * @@ -7814,8 +7814,8 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32* x = (word32*)AES_TAG(aes); \ word32* h = (word32*)aes->gcm.H; \ word32 bigEnd[4]; \ - XMEMCPY(bigEnd, block, AES_BLOCK_SIZE); \ - ByteReverseWords(bigEnd, bigEnd, AES_BLOCK_SIZE); \ + XMEMCPY(bigEnd, block, WC_AES_BLOCK_SIZE); \ + ByteReverseWords(bigEnd, bigEnd, WC_AES_BLOCK_SIZE); \ x[0] ^= bigEnd[0]; \ x[1] ^= bigEnd[1]; \ x[2] ^= bigEnd[2]; \ @@ -7844,7 +7844,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, x[2] ^= len[2]; \ x[3] ^= len[3]; \ GMULT(x, h); \ - ByteReverseWords(x, x, AES_BLOCK_SIZE); \ + ByteReverseWords(x, x, WC_AES_BLOCK_SIZE); \ } \ while (0) #else @@ -7866,7 +7866,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32* x = (word32*)AES_TAG(aes); \ word32* h = (word32*)aes->gcm.H; \ word32 block32[4]; \ - XMEMCPY(block32, block, AES_BLOCK_SIZE); \ + XMEMCPY(block32, block, WC_AES_BLOCK_SIZE); \ x[0] ^= block32[0]; \ x[1] ^= block32[1]; \ x[2] ^= block32[2]; \ @@ -7910,7 +7910,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, */ #define GHASH_LEN_BLOCK(aes) \ do { \ - byte scratch[AES_BLOCK_SIZE]; \ + byte scratch[WC_AES_BLOCK_SIZE]; \ FlattenSzInBits(&scratch[0], (aes)->aSz); \ FlattenSzInBits(&scratch[8], (aes)->cSz); \ GHASH_ONE_BLOCK(aes, scratch); \ @@ -7924,7 +7924,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, */ static void GHASH_INIT(Aes* aes) { /* Set tag to all zeros as initial value. */ - XMEMSET(AES_TAG(aes), 0, AES_BLOCK_SIZE); + XMEMSET(AES_TAG(aes), 0, WC_AES_BLOCK_SIZE); /* Reset counts of AAD and cipher text. */ aes->aOver = 0; aes->cOver = 0; @@ -7953,14 +7953,14 @@ static void GHASH_UPDATE(Aes* aes, const byte* a, word32 aSz, const byte* c, /* Check if we have unprocessed data. */ if (aes->aOver > 0) { /* Calculate amount we can use - fill up the block. */ - byte sz = AES_BLOCK_SIZE - aes->aOver; + byte sz = WC_AES_BLOCK_SIZE - aes->aOver; if (sz > aSz) { sz = (byte)aSz; } /* Copy extra into last GHASH block array and update count. */ XMEMCPY(AES_LASTGBLOCK(aes) + aes->aOver, a, sz); aes->aOver += sz; - if (aes->aOver == AES_BLOCK_SIZE) { + if (aes->aOver == WC_AES_BLOCK_SIZE) { /* We have filled up the block and can process. */ GHASH_ONE_BLOCK(aes, AES_LASTGBLOCK(aes)); /* Reset count. */ @@ -7972,12 +7972,12 @@ static void GHASH_UPDATE(Aes* aes, const byte* a, word32 aSz, const byte* c, } /* Calculate number of blocks of AAD and the leftover. */ - blocks = aSz / AES_BLOCK_SIZE; - partial = aSz % AES_BLOCK_SIZE; + blocks = aSz / WC_AES_BLOCK_SIZE; + partial = aSz % WC_AES_BLOCK_SIZE; /* GHASH full blocks now. */ while (blocks--) { GHASH_ONE_BLOCK(aes, a); - a += AES_BLOCK_SIZE; + a += WC_AES_BLOCK_SIZE; } if (partial != 0) { /* Cache the partial block. */ @@ -7988,7 +7988,7 @@ static void GHASH_UPDATE(Aes* aes, const byte* a, word32 aSz, const byte* c, if (aes->aOver > 0 && cSz > 0 && c != NULL) { /* No more AAD coming and we have a partial block. */ /* Fill the rest of the block with zeros. */ - byte sz = AES_BLOCK_SIZE - aes->aOver; + byte sz = WC_AES_BLOCK_SIZE - aes->aOver; XMEMSET(AES_LASTGBLOCK(aes) + aes->aOver, 0, sz); /* GHASH last AAD block. */ GHASH_ONE_BLOCK(aes, AES_LASTGBLOCK(aes)); @@ -8002,14 +8002,14 @@ static void GHASH_UPDATE(Aes* aes, const byte* a, word32 aSz, const byte* c, aes->cSz += cSz; if (aes->cOver > 0) { /* Calculate amount we can use - fill up the block. */ - byte sz = AES_BLOCK_SIZE - aes->cOver; + byte sz = WC_AES_BLOCK_SIZE - aes->cOver; if (sz > cSz) { sz = (byte)cSz; } XMEMCPY(AES_LASTGBLOCK(aes) + aes->cOver, c, sz); /* Update count of unused encrypted counter. */ aes->cOver += sz; - if (aes->cOver == AES_BLOCK_SIZE) { + if (aes->cOver == WC_AES_BLOCK_SIZE) { /* We have filled up the block and can process. */ GHASH_ONE_BLOCK(aes, AES_LASTGBLOCK(aes)); /* Reset count. */ @@ -8021,12 +8021,12 @@ static void GHASH_UPDATE(Aes* aes, const byte* a, word32 aSz, const byte* c, } /* Calculate number of blocks of cipher text and the leftover. */ - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; /* GHASH full blocks now. */ while (blocks--) { GHASH_ONE_BLOCK(aes, c); - c += AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } if (partial != 0) { /* Cache the partial block. */ @@ -8055,7 +8055,7 @@ static void GHASH_FINAL(Aes* aes, byte* s, word32 sSz) } if (over > 0) { /* Zeroize the unused part of the block. */ - XMEMSET(AES_LASTGBLOCK(aes) + over, 0, AES_BLOCK_SIZE - over); + XMEMSET(AES_LASTGBLOCK(aes) + over, 0, WC_AES_BLOCK_SIZE - over); /* Hash the last block of cipher text. */ GHASH_ONE_BLOCK(aes, AES_LASTGBLOCK(aes)); } @@ -8079,7 +8079,7 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, word32 keySize; /* argument checks */ - if (aes == NULL || authTagSz > AES_BLOCK_SIZE || ivSz == 0) { + if (aes == NULL || authTagSz > WC_AES_BLOCK_SIZE || ivSz == 0) { return BAD_FUNC_ARG; } @@ -8125,16 +8125,16 @@ static WARN_UNUSED_RESULT int wc_AesGcmEncrypt_STM32( word32 keySize; #ifdef WOLFSSL_STM32_CUBEMX int status = HAL_OK; - word32 blocks = sz / AES_BLOCK_SIZE; - word32 partialBlock[AES_BLOCK_SIZE/sizeof(word32)]; + word32 blocks = sz / WC_AES_BLOCK_SIZE; + word32 partialBlock[WC_AES_BLOCK_SIZE/sizeof(word32)]; #else int status = SUCCESS; #endif - word32 partial = sz % AES_BLOCK_SIZE; - word32 tag[AES_BLOCK_SIZE/sizeof(word32)]; - word32 ctrInit[AES_BLOCK_SIZE/sizeof(word32)]; - word32 ctr[AES_BLOCK_SIZE/sizeof(word32)]; - word32 authhdr[AES_BLOCK_SIZE/sizeof(word32)]; + word32 partial = sz % WC_AES_BLOCK_SIZE; + word32 tag[WC_AES_BLOCK_SIZE/sizeof(word32)]; + word32 ctrInit[WC_AES_BLOCK_SIZE/sizeof(word32)]; + word32 ctr[WC_AES_BLOCK_SIZE/sizeof(word32)]; + word32 authhdr[WC_AES_BLOCK_SIZE/sizeof(word32)]; byte* authInPadded = NULL; int authPadSz, wasAlloc = 0, useSwGhash = 0; @@ -8148,14 +8148,14 @@ static WARN_UNUSED_RESULT int wc_AesGcmEncrypt_STM32( return ret; #endif - XMEMSET(ctr, 0, AES_BLOCK_SIZE); + XMEMSET(ctr, 0, WC_AES_BLOCK_SIZE); if (ivSz == GCM_NONCE_MID_SZ) { byte* pCtr = (byte*)ctr; XMEMCPY(ctr, iv, ivSz); - pCtr[AES_BLOCK_SIZE - 1] = 1; + pCtr[WC_AES_BLOCK_SIZE - 1] = 1; } else { - GHASH(&aes->gcm, NULL, 0, iv, ivSz, (byte*)ctr, AES_BLOCK_SIZE); + GHASH(&aes->gcm, NULL, 0, iv, ivSz, (byte*)ctr, WC_AES_BLOCK_SIZE); } XMEMCPY(ctrInit, ctr, sizeof(ctr)); /* save off initial counter for GMAC */ @@ -8220,27 +8220,27 @@ static WARN_UNUSED_RESULT int wc_AesGcmEncrypt_STM32( /* allows repeated calls to HAL_CRYP_Encrypt */ hcryp.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ONCE; #endif - ByteReverseWords(ctr, ctr, AES_BLOCK_SIZE); + ByteReverseWords(ctr, ctr, WC_AES_BLOCK_SIZE); hcryp.Init.pInitVect = (STM_CRYPT_TYPE*)ctr; HAL_CRYP_Init(&hcryp); #ifndef CRYP_KEYIVCONFIG_ONCE /* GCM payload phase - can handle partial blocks */ status = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)in, - (blocks * AES_BLOCK_SIZE) + partial, (uint32_t*)out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE) + partial, (uint32_t*)out, STM32_HAL_TIMEOUT); #else /* GCM payload phase - blocks */ if (blocks) { status = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)in, - (blocks * AES_BLOCK_SIZE), (uint32_t*)out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE), (uint32_t*)out, STM32_HAL_TIMEOUT); } /* GCM payload phase - partial remainder */ if (status == HAL_OK && (partial != 0 || blocks == 0)) { XMEMSET(partialBlock, 0, sizeof(partialBlock)); - XMEMCPY(partialBlock, in + (blocks * AES_BLOCK_SIZE), partial); + XMEMCPY(partialBlock, in + (blocks * WC_AES_BLOCK_SIZE), partial); status = HAL_CRYP_Encrypt(&hcryp, (uint32_t*)partialBlock, partial, (uint32_t*)partialBlock, STM32_HAL_TIMEOUT); - XMEMCPY(out + (blocks * AES_BLOCK_SIZE), partialBlock, partial); + XMEMCPY(out + (blocks * WC_AES_BLOCK_SIZE), partialBlock, partial); } #endif if (status == HAL_OK && !useSwGhash) { @@ -8270,16 +8270,16 @@ static WARN_UNUSED_RESULT int wc_AesGcmEncrypt_STM32( hcryp.Init.GCMCMACPhase = CRYP_PAYLOAD_PHASE; if (blocks) { status = HAL_CRYPEx_AES_Auth(&hcryp, (byte*)in, - (blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); } } if (status == HAL_OK && (partial != 0 || (sz > 0 && blocks == 0))) { /* GCM payload phase - partial remainder */ XMEMSET(partialBlock, 0, sizeof(partialBlock)); - XMEMCPY(partialBlock, in + (blocks * AES_BLOCK_SIZE), partial); + XMEMCPY(partialBlock, in + (blocks * WC_AES_BLOCK_SIZE), partial); status = HAL_CRYPEx_AES_Auth(&hcryp, (uint8_t*)partialBlock, partial, (uint8_t*)partialBlock, STM32_HAL_TIMEOUT); - XMEMCPY(out + (blocks * AES_BLOCK_SIZE), partialBlock, partial); + XMEMCPY(out + (blocks * WC_AES_BLOCK_SIZE), partialBlock, partial); } if (status == HAL_OK && !useSwGhash) { /* GCM final phase */ @@ -8292,15 +8292,15 @@ static WARN_UNUSED_RESULT int wc_AesGcmEncrypt_STM32( if (blocks) { /* GCM payload phase - blocks */ status = HAL_CRYPEx_AESGCM_Encrypt(&hcryp, (byte*)in, - (blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); } if (status == HAL_OK && (partial != 0 || blocks == 0)) { /* GCM payload phase - partial remainder */ XMEMSET(partialBlock, 0, sizeof(partialBlock)); - XMEMCPY(partialBlock, in + (blocks * AES_BLOCK_SIZE), partial); + XMEMCPY(partialBlock, in + (blocks * WC_AES_BLOCK_SIZE), partial); status = HAL_CRYPEx_AESGCM_Encrypt(&hcryp, (uint8_t*)partialBlock, partial, (uint8_t*)partialBlock, STM32_HAL_TIMEOUT); - XMEMCPY(out + (blocks * AES_BLOCK_SIZE), partialBlock, partial); + XMEMCPY(out + (blocks * WC_AES_BLOCK_SIZE), partialBlock, partial); } if (status == HAL_OK && !useSwGhash) { /* Compute the authTag */ @@ -8369,20 +8369,20 @@ WARN_UNUSED_RESULT int AES_GCM_encrypt_C( const byte* authIn, word32 authInSz) { int ret = 0; - word32 blocks = sz / AES_BLOCK_SIZE; - word32 partial = sz % AES_BLOCK_SIZE; + word32 blocks = sz / WC_AES_BLOCK_SIZE; + word32 partial = sz % WC_AES_BLOCK_SIZE; const byte* p = in; byte* c = out; - ALIGN16 byte counter[AES_BLOCK_SIZE]; - ALIGN16 byte initialCounter[AES_BLOCK_SIZE]; - ALIGN16 byte scratch[AES_BLOCK_SIZE]; + ALIGN16 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN16 byte initialCounter[WC_AES_BLOCK_SIZE]; + ALIGN16 byte scratch[WC_AES_BLOCK_SIZE]; if (ivSz == GCM_NONCE_MID_SZ) { /* Counter is IV with bottom 4 bytes set to: 0x00,0x00,0x00,0x01. */ XMEMCPY(counter, iv, ivSz); XMEMSET(counter + GCM_NONCE_MID_SZ, 0, - AES_BLOCK_SIZE - GCM_NONCE_MID_SZ - 1); - counter[AES_BLOCK_SIZE - 1] = 1; + WC_AES_BLOCK_SIZE - GCM_NONCE_MID_SZ - 1); + counter[WC_AES_BLOCK_SIZE - 1] = 1; } else { /* Counter is GHASH of IV. */ @@ -8390,21 +8390,21 @@ WARN_UNUSED_RESULT int AES_GCM_encrypt_C( word32 aadTemp = aes->gcm.aadLen; aes->gcm.aadLen = 0; #endif - GHASH(&aes->gcm, NULL, 0, iv, ivSz, counter, AES_BLOCK_SIZE); + GHASH(&aes->gcm, NULL, 0, iv, ivSz, counter, WC_AES_BLOCK_SIZE); #ifdef OPENSSL_EXTRA aes->gcm.aadLen = aadTemp; #endif } - XMEMCPY(initialCounter, counter, AES_BLOCK_SIZE); + XMEMCPY(initialCounter, counter, WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_PIC32MZ_CRYPT if (blocks) { /* use initial IV for HW, but don't use it below */ - XMEMCPY(aes->reg, counter, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, counter, WC_AES_BLOCK_SIZE); ret = wc_Pic32AesCrypt( - aes->key, aes->keylen, aes->reg, AES_BLOCK_SIZE, - out, in, (blocks * AES_BLOCK_SIZE), + aes->key, aes->keylen, aes->reg, WC_AES_BLOCK_SIZE, + out, in, (blocks * WC_AES_BLOCK_SIZE), PIC32_ENCRYPTION, PIC32_ALGO_AES, PIC32_CRYPTOALGO_AES_GCM); if (ret != 0) return ret; @@ -8418,15 +8418,15 @@ WARN_UNUSED_RESULT int AES_GCM_encrypt_C( if (c != p && blocks > 0) { /* can not handle inline encryption */ while (blocks--) { IncrementGcmCounter(counter); - XMEMCPY(c, counter, AES_BLOCK_SIZE); - c += AES_BLOCK_SIZE; + XMEMCPY(c, counter, WC_AES_BLOCK_SIZE); + c += WC_AES_BLOCK_SIZE; } /* reset number of blocks and then do encryption */ - blocks = sz / AES_BLOCK_SIZE; - wc_AesEcbEncrypt(aes, out, out, AES_BLOCK_SIZE * blocks); - xorbuf(out, p, AES_BLOCK_SIZE * blocks); - p += AES_BLOCK_SIZE * blocks; + blocks = sz / WC_AES_BLOCK_SIZE; + wc_AesEcbEncrypt(aes, out, out, WC_AES_BLOCK_SIZE * blocks); + xorbuf(out, p, WC_AES_BLOCK_SIZE * blocks); + p += WC_AES_BLOCK_SIZE * blocks; } else #endif /* HAVE_AES_ECB && !WOLFSSL_PIC32MZ_CRYPT */ @@ -8437,10 +8437,10 @@ WARN_UNUSED_RESULT int AES_GCM_encrypt_C( ret = wc_AesEncrypt(aes, counter, scratch); if (ret != 0) return ret; - xorbufout(c, scratch, p, AES_BLOCK_SIZE); + xorbufout(c, scratch, p, WC_AES_BLOCK_SIZE); #endif - p += AES_BLOCK_SIZE; - c += AES_BLOCK_SIZE; + p += WC_AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } } @@ -8476,7 +8476,7 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, int ret; /* argument checks */ - if (aes == NULL || authTagSz > AES_BLOCK_SIZE || ivSz == 0 || + if (aes == NULL || authTagSz > WC_AES_BLOCK_SIZE || ivSz == 0 || ((authTagSz > 0) && (authTag == NULL)) || ((authInSz > 0) && (authIn == NULL))) { @@ -8607,7 +8607,7 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, /* If the sz is non-zero, both in and out must be set. If sz is 0, * in and out are don't cares, as this is is the GMAC case. */ if (aes == NULL || iv == NULL || (sz != 0 && (in == NULL || out == NULL)) || - authTag == NULL || authTagSz > AES_BLOCK_SIZE || authTagSz == 0 || + authTag == NULL || authTagSz > WC_AES_BLOCK_SIZE || authTagSz == 0 || ivSz == 0 || ((authInSz > 0) && (authIn == NULL))) { return BAD_FUNC_ARG; @@ -8644,18 +8644,18 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32( #ifdef WOLFSSL_STM32_CUBEMX int status = HAL_OK; CRYP_HandleTypeDef hcryp; - word32 blocks = sz / AES_BLOCK_SIZE; + word32 blocks = sz / WC_AES_BLOCK_SIZE; #else int status = SUCCESS; word32 keyCopy[AES_256_KEY_SIZE/sizeof(word32)]; #endif word32 keySize; - word32 partial = sz % AES_BLOCK_SIZE; - word32 tag[AES_BLOCK_SIZE/sizeof(word32)]; - word32 tagExpected[AES_BLOCK_SIZE/sizeof(word32)]; - word32 partialBlock[AES_BLOCK_SIZE/sizeof(word32)]; - word32 ctr[AES_BLOCK_SIZE/sizeof(word32)]; - word32 authhdr[AES_BLOCK_SIZE/sizeof(word32)]; + word32 partial = sz % WC_AES_BLOCK_SIZE; + word32 tag[WC_AES_BLOCK_SIZE/sizeof(word32)]; + word32 tagExpected[WC_AES_BLOCK_SIZE/sizeof(word32)]; + word32 partialBlock[WC_AES_BLOCK_SIZE/sizeof(word32)]; + word32 ctr[WC_AES_BLOCK_SIZE/sizeof(word32)]; + word32 authhdr[WC_AES_BLOCK_SIZE/sizeof(word32)]; byte* authInPadded = NULL; int authPadSz, wasAlloc = 0, tagComputed = 0; @@ -8669,14 +8669,14 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32( return ret; #endif - XMEMSET(ctr, 0, AES_BLOCK_SIZE); + XMEMSET(ctr, 0, WC_AES_BLOCK_SIZE); if (ivSz == GCM_NONCE_MID_SZ) { byte* pCtr = (byte*)ctr; XMEMCPY(ctr, iv, ivSz); - pCtr[AES_BLOCK_SIZE - 1] = 1; + pCtr[WC_AES_BLOCK_SIZE - 1] = 1; } else { - GHASH(&aes->gcm, NULL, 0, iv, ivSz, (byte*)ctr, AES_BLOCK_SIZE); + GHASH(&aes->gcm, NULL, 0, iv, ivSz, (byte*)ctr, WC_AES_BLOCK_SIZE); } /* Make copy of expected authTag, which could get corrupted in some @@ -8756,26 +8756,26 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32( /* allows repeated calls to HAL_CRYP_Decrypt */ hcryp.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ONCE; #endif - ByteReverseWords(ctr, ctr, AES_BLOCK_SIZE); + ByteReverseWords(ctr, ctr, WC_AES_BLOCK_SIZE); hcryp.Init.pInitVect = (STM_CRYPT_TYPE*)ctr; HAL_CRYP_Init(&hcryp); #ifndef CRYP_KEYIVCONFIG_ONCE status = HAL_CRYP_Decrypt(&hcryp, (uint32_t*)in, - (blocks * AES_BLOCK_SIZE) + partial, (uint32_t*)out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE) + partial, (uint32_t*)out, STM32_HAL_TIMEOUT); #else /* GCM payload phase - blocks */ if (blocks) { status = HAL_CRYP_Decrypt(&hcryp, (uint32_t*)in, - (blocks * AES_BLOCK_SIZE), (uint32_t*)out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE), (uint32_t*)out, STM32_HAL_TIMEOUT); } /* GCM payload phase - partial remainder */ if (status == HAL_OK && (partial != 0 || blocks == 0)) { XMEMSET(partialBlock, 0, sizeof(partialBlock)); - XMEMCPY(partialBlock, in + (blocks * AES_BLOCK_SIZE), partial); + XMEMCPY(partialBlock, in + (blocks * WC_AES_BLOCK_SIZE), partial); status = HAL_CRYP_Decrypt(&hcryp, (uint32_t*)partialBlock, partial, (uint32_t*)partialBlock, STM32_HAL_TIMEOUT); - XMEMCPY(out + (blocks * AES_BLOCK_SIZE), partialBlock, partial); + XMEMCPY(out + (blocks * WC_AES_BLOCK_SIZE), partialBlock, partial); } #endif if (status == HAL_OK && !tagComputed) { @@ -8805,16 +8805,16 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32( hcryp.Init.GCMCMACPhase = CRYP_PAYLOAD_PHASE; if (blocks) { status = HAL_CRYPEx_AES_Auth(&hcryp, (byte*)in, - (blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); } } if (status == HAL_OK && (partial != 0 || (sz > 0 && blocks == 0))) { /* GCM payload phase - partial remainder */ XMEMSET(partialBlock, 0, sizeof(partialBlock)); - XMEMCPY(partialBlock, in + (blocks * AES_BLOCK_SIZE), partial); + XMEMCPY(partialBlock, in + (blocks * WC_AES_BLOCK_SIZE), partial); status = HAL_CRYPEx_AES_Auth(&hcryp, (byte*)partialBlock, partial, (byte*)partialBlock, STM32_HAL_TIMEOUT); - XMEMCPY(out + (blocks * AES_BLOCK_SIZE), partialBlock, partial); + XMEMCPY(out + (blocks * WC_AES_BLOCK_SIZE), partialBlock, partial); } if (status == HAL_OK && tagComputed == 0) { /* GCM final phase */ @@ -8827,15 +8827,15 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32( if (blocks) { /* GCM payload phase - blocks */ status = HAL_CRYPEx_AESGCM_Decrypt(&hcryp, (byte*)in, - (blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); + (blocks * WC_AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT); } if (status == HAL_OK && (partial != 0 || blocks == 0)) { /* GCM payload phase - partial remainder */ XMEMSET(partialBlock, 0, sizeof(partialBlock)); - XMEMCPY(partialBlock, in + (blocks * AES_BLOCK_SIZE), partial); + XMEMCPY(partialBlock, in + (blocks * WC_AES_BLOCK_SIZE), partial); status = HAL_CRYPEx_AESGCM_Decrypt(&hcryp, (byte*)partialBlock, partial, (byte*)partialBlock, STM32_HAL_TIMEOUT); - XMEMCPY(out + (blocks * AES_BLOCK_SIZE), partialBlock, partial); + XMEMCPY(out + (blocks * WC_AES_BLOCK_SIZE), partialBlock, partial); } if (status == HAL_OK && tagComputed == 0) { /* Compute the authTag */ @@ -8900,22 +8900,22 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C( const byte* authIn, word32 authInSz) { int ret; - word32 blocks = sz / AES_BLOCK_SIZE; - word32 partial = sz % AES_BLOCK_SIZE; + word32 blocks = sz / WC_AES_BLOCK_SIZE; + word32 partial = sz % WC_AES_BLOCK_SIZE; const byte* c = in; byte* p = out; - ALIGN16 byte counter[AES_BLOCK_SIZE]; - ALIGN16 byte scratch[AES_BLOCK_SIZE]; - ALIGN16 byte Tprime[AES_BLOCK_SIZE]; - ALIGN16 byte EKY0[AES_BLOCK_SIZE]; + ALIGN16 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN16 byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN16 byte Tprime[WC_AES_BLOCK_SIZE]; + ALIGN16 byte EKY0[WC_AES_BLOCK_SIZE]; sword32 res; if (ivSz == GCM_NONCE_MID_SZ) { /* Counter is IV with bottom 4 bytes set to: 0x00,0x00,0x00,0x01. */ XMEMCPY(counter, iv, ivSz); XMEMSET(counter + GCM_NONCE_MID_SZ, 0, - AES_BLOCK_SIZE - GCM_NONCE_MID_SZ - 1); - counter[AES_BLOCK_SIZE - 1] = 1; + WC_AES_BLOCK_SIZE - GCM_NONCE_MID_SZ - 1); + counter[WC_AES_BLOCK_SIZE - 1] = 1; } else { /* Counter is GHASH of IV. */ @@ -8923,7 +8923,7 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C( word32 aadTemp = aes->gcm.aadLen; aes->gcm.aadLen = 0; #endif - GHASH(&aes->gcm, NULL, 0, iv, ivSz, counter, AES_BLOCK_SIZE); + GHASH(&aes->gcm, NULL, 0, iv, ivSz, counter, WC_AES_BLOCK_SIZE); #ifdef OPENSSL_EXTRA aes->gcm.aadLen = aadTemp; #endif @@ -8960,11 +8960,11 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C( #if defined(WOLFSSL_PIC32MZ_CRYPT) if (blocks) { /* use initial IV for HW, but don't use it below */ - XMEMCPY(aes->reg, counter, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, counter, WC_AES_BLOCK_SIZE); ret = wc_Pic32AesCrypt( - aes->key, aes->keylen, aes->reg, AES_BLOCK_SIZE, - out, in, (blocks * AES_BLOCK_SIZE), + aes->key, aes->keylen, aes->reg, WC_AES_BLOCK_SIZE, + out, in, (blocks * WC_AES_BLOCK_SIZE), PIC32_DECRYPTION, PIC32_ALGO_AES, PIC32_CRYPTOALGO_AES_GCM); if (ret != 0) return ret; @@ -8978,16 +8978,16 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C( if (c != p && blocks > 0) { /* can not handle inline decryption */ while (blocks--) { IncrementGcmCounter(counter); - XMEMCPY(p, counter, AES_BLOCK_SIZE); - p += AES_BLOCK_SIZE; + XMEMCPY(p, counter, WC_AES_BLOCK_SIZE); + p += WC_AES_BLOCK_SIZE; } /* reset number of blocks and then do encryption */ - blocks = sz / AES_BLOCK_SIZE; + blocks = sz / WC_AES_BLOCK_SIZE; - wc_AesEcbEncrypt(aes, out, out, AES_BLOCK_SIZE * blocks); - xorbuf(out, c, AES_BLOCK_SIZE * blocks); - c += AES_BLOCK_SIZE * blocks; + wc_AesEcbEncrypt(aes, out, out, WC_AES_BLOCK_SIZE * blocks); + xorbuf(out, c, WC_AES_BLOCK_SIZE * blocks); + c += WC_AES_BLOCK_SIZE * blocks; } else #endif /* HAVE_AES_ECB && !PIC32MZ */ @@ -8998,10 +8998,10 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C( ret = wc_AesEncrypt(aes, counter, scratch); if (ret != 0) return ret; - xorbufout(p, scratch, c, AES_BLOCK_SIZE); + xorbufout(p, scratch, c, WC_AES_BLOCK_SIZE); #endif - p += AES_BLOCK_SIZE; - c += AES_BLOCK_SIZE; + p += WC_AES_BLOCK_SIZE; + c += WC_AES_BLOCK_SIZE; } } @@ -9046,7 +9046,7 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, /* If the sz is non-zero, both in and out must be set. If sz is 0, * in and out are don't cares, as this is is the GMAC case. */ if (aes == NULL || iv == NULL || (sz != 0 && (in == NULL || out == NULL)) || - authTag == NULL || authTagSz > AES_BLOCK_SIZE || authTagSz == 0 || + authTag == NULL || authTagSz > WC_AES_BLOCK_SIZE || authTagSz == 0 || ivSz == 0) { return BAD_FUNC_ARG; @@ -9175,15 +9175,15 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, */ static WARN_UNUSED_RESULT int AesGcmInit_C(Aes* aes, const byte* iv, word32 ivSz) { - ALIGN32 byte counter[AES_BLOCK_SIZE]; + ALIGN32 byte counter[WC_AES_BLOCK_SIZE]; int ret; if (ivSz == GCM_NONCE_MID_SZ) { /* Counter is IV with bottom 4 bytes set to: 0x00,0x00,0x00,0x01. */ XMEMCPY(counter, iv, ivSz); XMEMSET(counter + GCM_NONCE_MID_SZ, 0, - AES_BLOCK_SIZE - GCM_NONCE_MID_SZ - 1); - counter[AES_BLOCK_SIZE - 1] = 1; + WC_AES_BLOCK_SIZE - GCM_NONCE_MID_SZ - 1); + counter[WC_AES_BLOCK_SIZE - 1] = 1; } else { /* Counter is GHASH of IV. */ @@ -9191,14 +9191,14 @@ static WARN_UNUSED_RESULT int AesGcmInit_C(Aes* aes, const byte* iv, word32 ivSz word32 aadTemp = aes->gcm.aadLen; aes->gcm.aadLen = 0; #endif - GHASH(&aes->gcm, NULL, 0, iv, ivSz, counter, AES_BLOCK_SIZE); + GHASH(&aes->gcm, NULL, 0, iv, ivSz, counter, WC_AES_BLOCK_SIZE); #ifdef OPENSSL_EXTRA aes->gcm.aadLen = aadTemp; #endif } /* Copy in the counter for use with cipher. */ - XMEMCPY(AES_COUNTER(aes), counter, AES_BLOCK_SIZE); + XMEMCPY(AES_COUNTER(aes), counter, WC_AES_BLOCK_SIZE); /* Encrypt initial counter into a buffer for GCM. */ ret = wc_AesEncrypt(aes, counter, AES_INITCTR(aes)); if (ret != 0) @@ -9231,12 +9231,12 @@ static WARN_UNUSED_RESULT int AesGcmCryptUpdate_C( /* Check if previous encrypted block was not used up. */ if (aes->over > 0) { - byte pSz = AES_BLOCK_SIZE - aes->over; + byte pSz = WC_AES_BLOCK_SIZE - aes->over; if (pSz > sz) pSz = (byte)sz; /* Use some/all of last encrypted block. */ xorbufout(out, AES_LASTBLOCK(aes) + aes->over, in, pSz); - aes->over = (aes->over + pSz) & (AES_BLOCK_SIZE - 1); + aes->over = (aes->over + pSz) & (WC_AES_BLOCK_SIZE - 1); /* Some data used. */ sz -= pSz; @@ -9246,8 +9246,8 @@ static WARN_UNUSED_RESULT int AesGcmCryptUpdate_C( /* Calculate the number of blocks needing to be encrypted and any leftover. */ - blocks = sz / AES_BLOCK_SIZE; - partial = sz & (AES_BLOCK_SIZE - 1); + blocks = sz / WC_AES_BLOCK_SIZE; + partial = sz & (WC_AES_BLOCK_SIZE - 1); #if defined(HAVE_AES_ECB) /* Some hardware acceleration can gain performance from doing AES encryption @@ -9259,33 +9259,33 @@ static WARN_UNUSED_RESULT int AesGcmCryptUpdate_C( /* Place incrementing counter blocks into cipher text. */ for (b = 0; b < blocks; b++) { IncrementGcmCounter(AES_COUNTER(aes)); - XMEMCPY(out + b * AES_BLOCK_SIZE, AES_COUNTER(aes), AES_BLOCK_SIZE); + XMEMCPY(out + b * WC_AES_BLOCK_SIZE, AES_COUNTER(aes), WC_AES_BLOCK_SIZE); } /* Encrypt counter blocks. */ - wc_AesEcbEncrypt(aes, out, out, AES_BLOCK_SIZE * blocks); + wc_AesEcbEncrypt(aes, out, out, WC_AES_BLOCK_SIZE * blocks); /* XOR in plaintext. */ - xorbuf(out, in, AES_BLOCK_SIZE * blocks); + xorbuf(out, in, WC_AES_BLOCK_SIZE * blocks); /* Skip over processed data. */ - in += AES_BLOCK_SIZE * blocks; - out += AES_BLOCK_SIZE * blocks; + in += WC_AES_BLOCK_SIZE * blocks; + out += WC_AES_BLOCK_SIZE * blocks; } else #endif /* HAVE_AES_ECB */ { /* Encrypt block by block. */ while (blocks--) { - ALIGN32 byte scratch[AES_BLOCK_SIZE]; + ALIGN32 byte scratch[WC_AES_BLOCK_SIZE]; IncrementGcmCounter(AES_COUNTER(aes)); /* Encrypt counter into a buffer. */ ret = wc_AesEncrypt(aes, AES_COUNTER(aes), scratch); if (ret != 0) return ret; /* XOR plain text into encrypted counter into cipher text buffer. */ - xorbufout(out, scratch, in, AES_BLOCK_SIZE); + xorbufout(out, scratch, in, WC_AES_BLOCK_SIZE); /* Data complete. */ - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } } @@ -9323,7 +9323,7 @@ static WARN_UNUSED_RESULT int AesGcmFinal_C( aes->gcm.aadLen = aes->aSz; #endif /* Zeroize last block to protect sensitive data. */ - ForceZero(AES_LASTBLOCK(aes), AES_BLOCK_SIZE); + ForceZero(AES_LASTBLOCK(aes), WC_AES_BLOCK_SIZE); return 0; } @@ -9408,7 +9408,7 @@ static WARN_UNUSED_RESULT int AesGcmInit_aesni( aes->aSz = 0; aes->cSz = 0; /* Set tag to all zeros as initial value. */ - XMEMSET(AES_TAG(aes), 0, AES_BLOCK_SIZE); + XMEMSET(AES_TAG(aes), 0, WC_AES_BLOCK_SIZE); /* Reset counts of AAD and cipher text. */ aes->aOver = 0; aes->cOver = 0; @@ -9458,14 +9458,14 @@ static WARN_UNUSED_RESULT int AesGcmAadUpdate_aesni( /* Check if we have unprocessed data. */ if (aes->aOver > 0) { /* Calculate amount we can use - fill up the block. */ - byte sz = AES_BLOCK_SIZE - aes->aOver; + byte sz = WC_AES_BLOCK_SIZE - aes->aOver; if (sz > aSz) { sz = (byte)aSz; } /* Copy extra into last GHASH block array and update count. */ XMEMCPY(AES_LASTGBLOCK(aes) + aes->aOver, a, sz); aes->aOver += sz; - if (aes->aOver == AES_BLOCK_SIZE) { + if (aes->aOver == WC_AES_BLOCK_SIZE) { /* We have filled up the block and can process. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { @@ -9494,30 +9494,30 @@ static WARN_UNUSED_RESULT int AesGcmAadUpdate_aesni( } /* Calculate number of blocks of AAD and the leftover. */ - blocks = aSz / AES_BLOCK_SIZE; - partial = aSz % AES_BLOCK_SIZE; + blocks = aSz / WC_AES_BLOCK_SIZE; + partial = aSz % WC_AES_BLOCK_SIZE; if (blocks > 0) { /* GHASH full blocks now. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { - AES_GCM_aad_update_avx2(a, blocks * AES_BLOCK_SIZE, + AES_GCM_aad_update_avx2(a, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H); } else #endif #ifdef HAVE_INTEL_AVX1 if (IS_INTEL_AVX1(intel_flags)) { - AES_GCM_aad_update_avx1(a, blocks * AES_BLOCK_SIZE, + AES_GCM_aad_update_avx1(a, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H); } else #endif { - AES_GCM_aad_update_aesni(a, blocks * AES_BLOCK_SIZE, + AES_GCM_aad_update_aesni(a, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H); } /* Skip over to end of AAD blocks. */ - a += blocks * AES_BLOCK_SIZE; + a += blocks * WC_AES_BLOCK_SIZE; } if (partial != 0) { /* Cache the partial block. */ @@ -9529,7 +9529,7 @@ static WARN_UNUSED_RESULT int AesGcmAadUpdate_aesni( /* No more AAD coming and we have a partial block. */ /* Fill the rest of the block with zeros. */ XMEMSET(AES_LASTGBLOCK(aes) + aes->aOver, 0, - AES_BLOCK_SIZE - aes->aOver); + WC_AES_BLOCK_SIZE - aes->aOver); /* GHASH last AAD block. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { @@ -9587,7 +9587,7 @@ static WARN_UNUSED_RESULT int AesGcmEncryptUpdate_aesni( aes->cSz += cSz; if (aes->cOver > 0) { /* Calculate amount we can use - fill up the block. */ - byte sz = AES_BLOCK_SIZE - aes->cOver; + byte sz = WC_AES_BLOCK_SIZE - aes->cOver; if (sz > cSz) { sz = (byte)cSz; } @@ -9596,7 +9596,7 @@ static WARN_UNUSED_RESULT int AesGcmEncryptUpdate_aesni( XMEMCPY(c, AES_LASTGBLOCK(aes) + aes->cOver, sz); /* Update count of unused encrypted counter. */ aes->cOver += sz; - if (aes->cOver == AES_BLOCK_SIZE) { + if (aes->cOver == WC_AES_BLOCK_SIZE) { /* We have filled up the block and can process. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { @@ -9626,14 +9626,14 @@ static WARN_UNUSED_RESULT int AesGcmEncryptUpdate_aesni( } /* Calculate number of blocks of plaintext and the leftover. */ - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; if (blocks > 0) { /* Encrypt and GHASH full blocks now. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { AES_GCM_encrypt_update_avx2((byte*)aes->key, (int)aes->rounds, - c, p, blocks * AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, + c, p, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, AES_COUNTER(aes)); } else @@ -9641,23 +9641,23 @@ static WARN_UNUSED_RESULT int AesGcmEncryptUpdate_aesni( #ifdef HAVE_INTEL_AVX1 if (IS_INTEL_AVX1(intel_flags)) { AES_GCM_encrypt_update_avx1((byte*)aes->key, (int)aes->rounds, - c, p, blocks * AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, + c, p, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, AES_COUNTER(aes)); } else #endif { AES_GCM_encrypt_update_aesni((byte*)aes->key, (int)aes->rounds, - c, p, blocks * AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, + c, p, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, AES_COUNTER(aes)); } /* Skip over to end of blocks. */ - p += blocks * AES_BLOCK_SIZE; - c += blocks * AES_BLOCK_SIZE; + p += blocks * WC_AES_BLOCK_SIZE; + c += blocks * WC_AES_BLOCK_SIZE; } if (partial != 0) { /* Encrypt the counter - XOR in zeros as proxy for plaintext. */ - XMEMSET(AES_LASTGBLOCK(aes), 0, AES_BLOCK_SIZE); + XMEMSET(AES_LASTGBLOCK(aes), 0, WC_AES_BLOCK_SIZE); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { AES_GCM_encrypt_block_avx2((byte*)aes->key, (int)aes->rounds, @@ -9711,7 +9711,7 @@ static WARN_UNUSED_RESULT int AesGcmEncryptFinal_aesni( } if (over > 0) { /* Fill the rest of the block with zeros. */ - XMEMSET(AES_LASTGBLOCK(aes) + over, 0, AES_BLOCK_SIZE - over); + XMEMSET(AES_LASTGBLOCK(aes) + over, 0, WC_AES_BLOCK_SIZE - over); /* GHASH last cipher block. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { @@ -9818,7 +9818,7 @@ static WARN_UNUSED_RESULT int AesGcmDecryptUpdate_aesni( aes->cSz += cSz; if (aes->cOver > 0) { /* Calculate amount we can use - fill up the block. */ - byte sz = AES_BLOCK_SIZE - aes->cOver; + byte sz = WC_AES_BLOCK_SIZE - aes->cOver; if (sz > cSz) { sz = (byte)cSz; } @@ -9829,7 +9829,7 @@ static WARN_UNUSED_RESULT int AesGcmDecryptUpdate_aesni( XMEMCPY(p, AES_LASTGBLOCK(aes) + aes->cOver, sz); /* Update count of unused encrypted counter. */ aes->cOver += sz; - if (aes->cOver == AES_BLOCK_SIZE) { + if (aes->cOver == WC_AES_BLOCK_SIZE) { /* We have filled up the block and can process. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { @@ -9859,14 +9859,14 @@ static WARN_UNUSED_RESULT int AesGcmDecryptUpdate_aesni( } /* Calculate number of blocks of plaintext and the leftover. */ - blocks = cSz / AES_BLOCK_SIZE; - partial = cSz % AES_BLOCK_SIZE; + blocks = cSz / WC_AES_BLOCK_SIZE; + partial = cSz % WC_AES_BLOCK_SIZE; if (blocks > 0) { /* Decrypt and GHASH full blocks now. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { AES_GCM_decrypt_update_avx2((byte*)aes->key, (int)aes->rounds, - p, c, blocks * AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, + p, c, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, AES_COUNTER(aes)); } else @@ -9874,23 +9874,23 @@ static WARN_UNUSED_RESULT int AesGcmDecryptUpdate_aesni( #ifdef HAVE_INTEL_AVX1 if (IS_INTEL_AVX1(intel_flags)) { AES_GCM_decrypt_update_avx1((byte*)aes->key, (int)aes->rounds, - p, c, blocks * AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, + p, c, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, AES_COUNTER(aes)); } else #endif { AES_GCM_decrypt_update_aesni((byte*)aes->key, (int)aes->rounds, - p, c, blocks * AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, + p, c, blocks * WC_AES_BLOCK_SIZE, AES_TAG(aes), aes->gcm.H, AES_COUNTER(aes)); } /* Skip over to end of blocks. */ - c += blocks * AES_BLOCK_SIZE; - p += blocks * AES_BLOCK_SIZE; + c += blocks * WC_AES_BLOCK_SIZE; + p += blocks * WC_AES_BLOCK_SIZE; } if (partial != 0) { /* Encrypt the counter - XOR in zeros as proxy for cipher text. */ - XMEMSET(AES_LASTGBLOCK(aes), 0, AES_BLOCK_SIZE); + XMEMSET(AES_LASTGBLOCK(aes), 0, WC_AES_BLOCK_SIZE); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { AES_GCM_encrypt_block_avx2((byte*)aes->key, (int)aes->rounds, @@ -9951,7 +9951,7 @@ static WARN_UNUSED_RESULT int AesGcmDecryptFinal_aesni( } if (over > 0) { /* Zeroize the unused part of the block. */ - XMEMSET(lastBlock + over, 0, AES_BLOCK_SIZE - over); + XMEMSET(lastBlock + over, 0, WC_AES_BLOCK_SIZE - over); /* Hash the last block of cipher text. */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { @@ -10029,7 +10029,7 @@ int wc_AesGcmInit(Aes* aes, const byte* key, word32 len, const byte* iv, #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_AESNI) if ((ret == 0) && (aes->streamData == NULL)) { /* Allocate buffers for streaming. */ - aes->streamData_sz = 5 * AES_BLOCK_SIZE; + aes->streamData_sz = 5 * WC_AES_BLOCK_SIZE; aes->streamData = (byte*)XMALLOC(aes->streamData_sz, aes->heap, DYNAMIC_TYPE_AES); if (aes->streamData == NULL) { @@ -10045,7 +10045,7 @@ int wc_AesGcmInit(Aes* aes, const byte* key, word32 len, const byte* iv, if (ret == 0) { /* Set the IV passed in if it is smaller than a block. */ - if ((iv != NULL) && (ivSz <= AES_BLOCK_SIZE)) { + if ((iv != NULL) && (ivSz <= WC_AES_BLOCK_SIZE)) { XMEMMOVE((byte*)aes->reg, iv, ivSz); aes->nonceSz = ivSz; } @@ -10222,7 +10222,7 @@ int wc_AesGcmEncryptFinal(Aes* aes, byte* authTag, word32 authTagSz) int ret = 0; /* Check validity of parameters. */ - if ((aes == NULL) || (authTag == NULL) || (authTagSz > AES_BLOCK_SIZE) || + if ((aes == NULL) || (authTag == NULL) || (authTagSz > WC_AES_BLOCK_SIZE) || (authTagSz == 0)) { ret = BAD_FUNC_ARG; } @@ -10356,7 +10356,7 @@ int wc_AesGcmDecryptFinal(Aes* aes, const byte* authTag, word32 authTagSz) int ret = 0; /* Check validity of parameters. */ - if ((aes == NULL) || (authTag == NULL) || (authTagSz > AES_BLOCK_SIZE) || + if ((aes == NULL) || (authTag == NULL) || (authTagSz > WC_AES_BLOCK_SIZE) || (authTagSz == 0)) { ret = BAD_FUNC_ARG; } @@ -10381,7 +10381,7 @@ int wc_AesGcmDecryptFinal(Aes* aes, const byte* authTag, word32 authTagSz) else #endif { - ALIGN32 byte calcTag[AES_BLOCK_SIZE]; + ALIGN32 byte calcTag[WC_AES_BLOCK_SIZE]; /* Calculate authentication tag. */ ret = AesGcmFinal_C(aes, calcTag, authTagSz); if (ret == 0) { @@ -10567,7 +10567,7 @@ int wc_GmacVerify(const byte* key, word32 keySz, #endif if (key == NULL || iv == NULL || (authIn == NULL && authInSz != 0) || - authTag == NULL || authTagSz == 0 || authTagSz > AES_BLOCK_SIZE) { + authTag == NULL || authTagSz == 0 || authTagSz > WC_AES_BLOCK_SIZE) { return BAD_FUNC_ARG; } @@ -10786,10 +10786,10 @@ static WARN_UNUSED_RESULT int roll_x( int ret; /* process the bulk of the data */ - while (inSz >= AES_BLOCK_SIZE) { - xorbuf(out, in, AES_BLOCK_SIZE); - in += AES_BLOCK_SIZE; - inSz -= AES_BLOCK_SIZE; + while (inSz >= WC_AES_BLOCK_SIZE) { + xorbuf(out, in, WC_AES_BLOCK_SIZE); + in += WC_AES_BLOCK_SIZE; + inSz -= WC_AES_BLOCK_SIZE; ret = wc_AesEncrypt(aes, out, out); if (ret != 0) @@ -10835,7 +10835,7 @@ static WARN_UNUSED_RESULT int roll_auth( */ /* start fill out the rest of the first block */ - remainder = AES_BLOCK_SIZE - authLenSz; + remainder = WC_AES_BLOCK_SIZE - authLenSz; if (inSz >= remainder) { /* plenty of bulk data to fill the remainder of this block */ xorbuf(out + authLenSz, in, remainder); @@ -10862,7 +10862,7 @@ static WC_INLINE void AesCcmCtrInc(byte* B, word32 lenSz) word32 i; for (i = 0; i < lenSz; i++) { - if (++B[AES_BLOCK_SIZE - 1 - i] != 0) return; + if (++B[WC_AES_BLOCK_SIZE - 1 - i] != 0) return; } } @@ -10872,23 +10872,23 @@ static WC_INLINE void AesCcmCtrIncSet4(byte* B, word32 lenSz) word32 i; /* B+1 = B */ - XMEMCPY(B + AES_BLOCK_SIZE * 1, B, AES_BLOCK_SIZE); + XMEMCPY(B + WC_AES_BLOCK_SIZE * 1, B, WC_AES_BLOCK_SIZE); /* B+2,B+3 = B,B+1 */ - XMEMCPY(B + AES_BLOCK_SIZE * 2, B, AES_BLOCK_SIZE * 2); + XMEMCPY(B + WC_AES_BLOCK_SIZE * 2, B, WC_AES_BLOCK_SIZE * 2); for (i = 0; i < lenSz; i++) { - if (++B[AES_BLOCK_SIZE * 2 - 1 - i] != 0) break; + if (++B[WC_AES_BLOCK_SIZE * 2 - 1 - i] != 0) break; } - B[AES_BLOCK_SIZE * 3 - 1] += 2; - if (B[AES_BLOCK_SIZE * 3 - 1] < 2) { + B[WC_AES_BLOCK_SIZE * 3 - 1] += 2; + if (B[WC_AES_BLOCK_SIZE * 3 - 1] < 2) { for (i = 1; i < lenSz; i++) { - if (++B[AES_BLOCK_SIZE * 3 - 1 - i] != 0) break; + if (++B[WC_AES_BLOCK_SIZE * 3 - 1 - i] != 0) break; } } - B[AES_BLOCK_SIZE * 4 - 1] += 3; - if (B[AES_BLOCK_SIZE * 4 - 1] < 3) { + B[WC_AES_BLOCK_SIZE * 4 - 1] += 3; + if (B[WC_AES_BLOCK_SIZE * 4 - 1] < 3) { for (i = 1; i < lenSz; i++) { - if (++B[AES_BLOCK_SIZE * 4 - 1 - i] != 0) break; + if (++B[WC_AES_BLOCK_SIZE * 4 - 1 - i] != 0) break; } } } @@ -10897,10 +10897,10 @@ static WC_INLINE void AesCcmCtrInc4(byte* B, word32 lenSz) { word32 i; - B[AES_BLOCK_SIZE - 1] += 4; - if (B[AES_BLOCK_SIZE - 1] < 4) { + B[WC_AES_BLOCK_SIZE - 1] += 4; + if (B[WC_AES_BLOCK_SIZE - 1] < 4) { for (i = 1; i < lenSz; i++) { - if (++B[AES_BLOCK_SIZE - 1 - i] != 0) break; + if (++B[WC_AES_BLOCK_SIZE - 1 - i] != 0) break; } } } @@ -10914,11 +10914,11 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, const byte* authIn, word32 authInSz) { #ifdef WOLFSSL_AESNI - ALIGN128 byte A[AES_BLOCK_SIZE * 4]; - ALIGN128 byte B[AES_BLOCK_SIZE * 4]; + ALIGN128 byte A[WC_AES_BLOCK_SIZE * 4]; + ALIGN128 byte B[WC_AES_BLOCK_SIZE * 4]; #else - byte A[AES_BLOCK_SIZE]; - byte B[AES_BLOCK_SIZE]; + byte A[WC_AES_BLOCK_SIZE]; + byte B[WC_AES_BLOCK_SIZE]; #endif byte lenSz; word32 i; @@ -10929,7 +10929,7 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, /* sanity check on arguments */ if (aes == NULL || (inSz != 0 && (in == NULL || out == NULL)) || nonce == NULL || authTag == NULL || nonceSz < 7 || nonceSz > 13 || - authTagSz > AES_BLOCK_SIZE) + authTagSz > WC_AES_BLOCK_SIZE) return BAD_FUNC_ARG; /* Sanity check on authIn to prevent segfault in xorbuf() where @@ -10958,14 +10958,14 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, XMEMSET(A, 0, sizeof(A)); XMEMCPY(B+1, nonce, nonceSz); - lenSz = AES_BLOCK_SIZE - 1 - (byte)nonceSz; + lenSz = WC_AES_BLOCK_SIZE - 1 - (byte)nonceSz; B[0] = (byte)((authInSz > 0 ? 64 : 0) + (8 * (((byte)authTagSz - 2) / 2)) + (lenSz - 1)); for (i = 0; i < lenSz; i++) { if (mask && i >= wordSz) mask = 0x00; - B[AES_BLOCK_SIZE - 1 - i] = (byte)((inSz >> ((8 * i) & mask)) & mask); + B[WC_AES_BLOCK_SIZE - 1 - i] = (byte)((inSz >> ((8 * i) & mask)) & mask); } #ifdef WOLFSSL_CHECK_MEM_ZERO @@ -10990,7 +10990,7 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, B[0] = lenSz - 1; for (i = 0; i < lenSz; i++) - B[AES_BLOCK_SIZE - 1 - i] = 0; + B[WC_AES_BLOCK_SIZE - 1 - i] = 0; ret = wc_AesEncrypt(aes, B, A); } @@ -11000,35 +11000,35 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, } #ifdef WOLFSSL_AESNI if ((ret == 0) && aes->use_aesni) { - while (inSz >= AES_BLOCK_SIZE * 4) { + while (inSz >= WC_AES_BLOCK_SIZE * 4) { AesCcmCtrIncSet4(B, lenSz); - AES_ECB_encrypt_AESNI(B, A, AES_BLOCK_SIZE * 4, (byte*)aes->key, + AES_ECB_encrypt_AESNI(B, A, WC_AES_BLOCK_SIZE * 4, (byte*)aes->key, (int)aes->rounds); - xorbuf(A, in, AES_BLOCK_SIZE * 4); - XMEMCPY(out, A, AES_BLOCK_SIZE * 4); + xorbuf(A, in, WC_AES_BLOCK_SIZE * 4); + XMEMCPY(out, A, WC_AES_BLOCK_SIZE * 4); - inSz -= AES_BLOCK_SIZE * 4; - in += AES_BLOCK_SIZE * 4; - out += AES_BLOCK_SIZE * 4; + inSz -= WC_AES_BLOCK_SIZE * 4; + in += WC_AES_BLOCK_SIZE * 4; + out += WC_AES_BLOCK_SIZE * 4; AesCcmCtrInc4(B, lenSz); } } #endif if (ret == 0) { - while (inSz >= AES_BLOCK_SIZE) { + while (inSz >= WC_AES_BLOCK_SIZE) { ret = wc_AesEncrypt(aes, B, A); if (ret != 0) break; - xorbuf(A, in, AES_BLOCK_SIZE); - XMEMCPY(out, A, AES_BLOCK_SIZE); + xorbuf(A, in, WC_AES_BLOCK_SIZE); + XMEMCPY(out, A, WC_AES_BLOCK_SIZE); AesCcmCtrInc(B, lenSz); - inSz -= AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + inSz -= WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } } if ((ret == 0) && (inSz > 0)) { @@ -11060,11 +11060,11 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, const byte* authIn, word32 authInSz) { #ifdef WOLFSSL_AESNI - ALIGN128 byte B[AES_BLOCK_SIZE * 4]; - ALIGN128 byte A[AES_BLOCK_SIZE * 4]; + ALIGN128 byte B[WC_AES_BLOCK_SIZE * 4]; + ALIGN128 byte A[WC_AES_BLOCK_SIZE * 4]; #else - byte A[AES_BLOCK_SIZE]; - byte B[AES_BLOCK_SIZE]; + byte A[WC_AES_BLOCK_SIZE]; + byte B[WC_AES_BLOCK_SIZE]; #endif byte* o; byte lenSz; @@ -11076,7 +11076,7 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, /* sanity check on arguments */ if (aes == NULL || (inSz != 0 && (in == NULL || out == NULL)) || nonce == NULL || authTag == NULL || nonceSz < 7 || nonceSz > 13 || - authTagSz > AES_BLOCK_SIZE) + authTagSz > WC_AES_BLOCK_SIZE) return BAD_FUNC_ARG; /* Sanity check on authIn to prevent segfault in xorbuf() where @@ -11107,11 +11107,11 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, oSz = inSz; XMEMSET(A, 0, sizeof A); XMEMCPY(B+1, nonce, nonceSz); - lenSz = AES_BLOCK_SIZE - 1 - (byte)nonceSz; + lenSz = WC_AES_BLOCK_SIZE - 1 - (byte)nonceSz; B[0] = lenSz - 1; for (i = 0; i < lenSz; i++) - B[AES_BLOCK_SIZE - 1 - i] = 0; + B[WC_AES_BLOCK_SIZE - 1 - i] = 0; B[15] = 1; #ifdef WOLFSSL_CHECK_MEM_ZERO @@ -11123,34 +11123,34 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, #ifdef WOLFSSL_AESNI if (aes->use_aesni) { - while (oSz >= AES_BLOCK_SIZE * 4) { + while (oSz >= WC_AES_BLOCK_SIZE * 4) { AesCcmCtrIncSet4(B, lenSz); - AES_ECB_encrypt_AESNI(B, A, AES_BLOCK_SIZE * 4, (byte*)aes->key, + AES_ECB_encrypt_AESNI(B, A, WC_AES_BLOCK_SIZE * 4, (byte*)aes->key, (int)aes->rounds); - xorbuf(A, in, AES_BLOCK_SIZE * 4); - XMEMCPY(o, A, AES_BLOCK_SIZE * 4); + xorbuf(A, in, WC_AES_BLOCK_SIZE * 4); + XMEMCPY(o, A, WC_AES_BLOCK_SIZE * 4); - oSz -= AES_BLOCK_SIZE * 4; - in += AES_BLOCK_SIZE * 4; - o += AES_BLOCK_SIZE * 4; + oSz -= WC_AES_BLOCK_SIZE * 4; + in += WC_AES_BLOCK_SIZE * 4; + o += WC_AES_BLOCK_SIZE * 4; AesCcmCtrInc4(B, lenSz); } } #endif - while (oSz >= AES_BLOCK_SIZE) { + while (oSz >= WC_AES_BLOCK_SIZE) { ret = wc_AesEncrypt(aes, B, A); if (ret != 0) break; - xorbuf(A, in, AES_BLOCK_SIZE); - XMEMCPY(o, A, AES_BLOCK_SIZE); + xorbuf(A, in, WC_AES_BLOCK_SIZE); + XMEMCPY(o, A, WC_AES_BLOCK_SIZE); AesCcmCtrInc(B, lenSz); - oSz -= AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; - o += AES_BLOCK_SIZE; + oSz -= WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + o += WC_AES_BLOCK_SIZE; } if ((ret == 0) && (inSz > 0)) @@ -11160,7 +11160,7 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, xorbuf(A, in, oSz); XMEMCPY(o, A, oSz); for (i = 0; i < lenSz; i++) - B[AES_BLOCK_SIZE - 1 - i] = 0; + B[WC_AES_BLOCK_SIZE - 1 - i] = 0; ret = wc_AesEncrypt(aes, B, A); } @@ -11174,7 +11174,7 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, for (i = 0; i < lenSz; i++) { if (mask && i >= wordSz) mask = 0x00; - B[AES_BLOCK_SIZE - 1 - i] = (byte)((inSz >> ((8 * i) & mask)) & mask); + B[WC_AES_BLOCK_SIZE - 1 - i] = (byte)((inSz >> ((8 * i) & mask)) & mask); } ret = wc_AesEncrypt(aes, B, A); @@ -11190,7 +11190,7 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, if (ret == 0) { B[0] = lenSz - 1; for (i = 0; i < lenSz; i++) - B[AES_BLOCK_SIZE - 1 - i] = 0; + B[WC_AES_BLOCK_SIZE - 1 - i] = 0; ret = wc_AesEncrypt(aes, B, B); } @@ -11671,12 +11671,12 @@ static WARN_UNUSED_RESULT int _AesEcbEncrypt( #else word32 i; - for (i = 0; i < sz; i += AES_BLOCK_SIZE) { + for (i = 0; i < sz; i += WC_AES_BLOCK_SIZE) { ret = wc_AesEncryptDirect(aes, out, in); if (ret != 0) break; - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } #endif } @@ -11723,12 +11723,12 @@ static WARN_UNUSED_RESULT int _AesEcbDecrypt( #else word32 i; - for (i = 0; i < sz; i += AES_BLOCK_SIZE) { + for (i = 0; i < sz; i += WC_AES_BLOCK_SIZE) { ret = wc_AesDecryptDirect(aes, out, in); if (ret != 0) break; - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; } #endif } @@ -11743,7 +11743,7 @@ int wc_AesEcbEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { if ((in == NULL) || (out == NULL) || (aes == NULL)) return BAD_FUNC_ARG; - if ((sz % AES_BLOCK_SIZE) != 0) { + if ((sz % WC_AES_BLOCK_SIZE) != 0) { return BAD_LENGTH_E; } @@ -11755,7 +11755,7 @@ int wc_AesEcbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz) { if ((in == NULL) || (out == NULL) || (aes == NULL)) return BAD_FUNC_ARG; - if ((sz % AES_BLOCK_SIZE) != 0) { + if ((sz % WC_AES_BLOCK_SIZE) != 0) { return BAD_LENGTH_E; } @@ -11791,10 +11791,10 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackEncrypt( /* consume any unused bytes left in aes->tmp */ processed = min(aes->left, sz); - xorbufout(out, in, (byte*)aes->tmp + AES_BLOCK_SIZE - aes->left, processed); + xorbufout(out, in, (byte*)aes->tmp + WC_AES_BLOCK_SIZE - aes->left, processed); #ifdef WOLFSSL_AES_CFB if (mode == AES_CFB_MODE) { - XMEMCPY((byte*)aes->reg + AES_BLOCK_SIZE - aes->left, out, processed); + XMEMCPY((byte*)aes->reg + WC_AES_BLOCK_SIZE - aes->left, out, processed); } #endif aes->left -= processed; @@ -11804,26 +11804,26 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackEncrypt( VECTOR_REGISTERS_PUSH; - while (sz >= AES_BLOCK_SIZE) { + while (sz >= WC_AES_BLOCK_SIZE) { /* Using aes->tmp here for inline case i.e. in=out */ ret = wc_AesEncryptDirect(aes, (byte*)aes->tmp, (byte*)aes->reg); if (ret != 0) break; #ifdef WOLFSSL_AES_OFB if (mode == AES_OFB_MODE) { - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); } #endif - xorbuf((byte*)aes->tmp, in, AES_BLOCK_SIZE); + xorbuf((byte*)aes->tmp, in, WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CFB if (mode == AES_CFB_MODE) { - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); } #endif - XMEMCPY(out, aes->tmp, AES_BLOCK_SIZE); - out += AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; - sz -= AES_BLOCK_SIZE; + XMEMCPY(out, aes->tmp, WC_AES_BLOCK_SIZE); + out += WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + sz -= WC_AES_BLOCK_SIZE; aes->left = 0; } @@ -11832,11 +11832,11 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackEncrypt( ret = wc_AesEncryptDirect(aes, (byte*)aes->tmp, (byte*)aes->reg); } if ((ret == 0) && sz) { - aes->left = AES_BLOCK_SIZE; + aes->left = WC_AES_BLOCK_SIZE; tmp = (byte*)aes->tmp; #ifdef WOLFSSL_AES_OFB if (mode == AES_OFB_MODE) { - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); } #endif @@ -11881,13 +11881,13 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackDecrypt( /* check if more input needs copied over to aes->reg */ if (aes->left && sz && mode == AES_CFB_MODE) { word32 size = min(aes->left, sz); - XMEMCPY((byte*)aes->reg + AES_BLOCK_SIZE - aes->left, in, size); + XMEMCPY((byte*)aes->reg + WC_AES_BLOCK_SIZE - aes->left, in, size); } #endif /* consume any unused bytes left in aes->tmp */ processed = min(aes->left, sz); - xorbufout(out, in, (byte*)aes->tmp + AES_BLOCK_SIZE - aes->left, processed); + xorbufout(out, in, (byte*)aes->tmp + WC_AES_BLOCK_SIZE - aes->left, processed); aes->left -= processed; out += processed; in += processed; @@ -11895,26 +11895,26 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackDecrypt( VECTOR_REGISTERS_PUSH; - while (sz > AES_BLOCK_SIZE) { + while (sz > WC_AES_BLOCK_SIZE) { /* Using aes->tmp here for inline case i.e. in=out */ ret = wc_AesEncryptDirect(aes, (byte*)aes->tmp, (byte*)aes->reg); if (ret != 0) break; #ifdef WOLFSSL_AES_OFB if (mode == AES_OFB_MODE) { - XMEMCPY((byte*)aes->reg, (byte*)aes->tmp, AES_BLOCK_SIZE); + XMEMCPY((byte*)aes->reg, (byte*)aes->tmp, WC_AES_BLOCK_SIZE); } #endif - xorbuf((byte*)aes->tmp, in, AES_BLOCK_SIZE); + xorbuf((byte*)aes->tmp, in, WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_AES_CFB if (mode == AES_CFB_MODE) { - XMEMCPY(aes->reg, in, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, in, WC_AES_BLOCK_SIZE); } #endif - XMEMCPY(out, (byte*)aes->tmp, AES_BLOCK_SIZE); - out += AES_BLOCK_SIZE; - in += AES_BLOCK_SIZE; - sz -= AES_BLOCK_SIZE; + XMEMCPY(out, (byte*)aes->tmp, WC_AES_BLOCK_SIZE); + out += WC_AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + sz -= WC_AES_BLOCK_SIZE; aes->left = 0; } @@ -11930,11 +11930,11 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackDecrypt( #endif #ifdef WOLFSSL_AES_OFB if (mode == AES_OFB_MODE) { - XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE); + XMEMCPY(aes->reg, aes->tmp, WC_AES_BLOCK_SIZE); } #endif - aes->left = AES_BLOCK_SIZE - sz; + aes->left = WC_AES_BLOCK_SIZE - sz; xorbufout(out, in, aes->tmp, sz); } @@ -11982,21 +11982,21 @@ int wc_AesCfbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz) #endif /* HAVE_AES_DECRYPT */ -/* shift the whole AES_BLOCK_SIZE array left by 8 or 1 bits */ +/* shift the whole WC_AES_BLOCK_SIZE array left by 8 or 1 bits */ static void shiftLeftArray(byte* ary, byte shift) { int i; if (shift == WOLFSSL_BIT_SIZE) { /* shifting over by 8 bits */ - for (i = 0; i < AES_BLOCK_SIZE - 1; i++) { + for (i = 0; i < WC_AES_BLOCK_SIZE - 1; i++) { ary[i] = ary[i+1]; } ary[i] = 0; } else { /* shifting over by 7 or less bits */ - for (i = 0; i < AES_BLOCK_SIZE - 1; i++) { + for (i = 0; i < WC_AES_BLOCK_SIZE - 1; i++) { byte carry = ary[i+1] & (0XFF << (WOLFSSL_BIT_SIZE - shift)); carry >>= (WOLFSSL_BIT_SIZE - shift); ary[i] = (byte)((ary[i] << shift) + carry); @@ -12032,12 +12032,12 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackCFB8( /* LSB + CAT */ shiftLeftArray(pt, WOLFSSL_BIT_SIZE); - pt[AES_BLOCK_SIZE - 1] = in[0]; + pt[WC_AES_BLOCK_SIZE - 1] = in[0]; } /* MSB + XOR */ #ifdef BIG_ENDIAN_ORDER - ByteReverseWords(aes->tmp, aes->tmp, AES_BLOCK_SIZE); + ByteReverseWords(aes->tmp, aes->tmp, WC_AES_BLOCK_SIZE); #endif out[0] = (byte)(aes->tmp[0] ^ in[0]); if (dir == AES_ENCRYPTION) { @@ -12045,7 +12045,7 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackCFB8( /* LSB + CAT */ shiftLeftArray(pt, WOLFSSL_BIT_SIZE); - pt[AES_BLOCK_SIZE - 1] = out[0]; + pt[WC_AES_BLOCK_SIZE - 1] = out[0]; } out += 1; @@ -12091,7 +12091,7 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackCFB1( tmp = tmp >> bit; tmp &= 0x01; shiftLeftArray((byte*)aes->reg, 1); - pt[AES_BLOCK_SIZE - 1] |= tmp; + pt[WC_AES_BLOCK_SIZE - 1] |= tmp; } /* MSB + XOR */ @@ -12107,7 +12107,7 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackCFB1( /* LSB + CAT */ shiftLeftArray((byte*)aes->reg, 1); - pt[AES_BLOCK_SIZE - 1] |= tmp; + pt[WC_AES_BLOCK_SIZE - 1] |= tmp; } bit--; @@ -12286,7 +12286,7 @@ int wc_AesKeyWrap_ex(Aes *aes, const byte* in, word32 inSz, byte* out, int ret = 0; byte t[KEYWRAP_BLOCK_SIZE]; - byte tmp[AES_BLOCK_SIZE]; + byte tmp[WC_AES_BLOCK_SIZE]; /* n must be at least 2 64-bit blocks, output size is (n + 1) 8 bytes (64-bit) */ if (aes == NULL || in == NULL || inSz < 2*KEYWRAP_BLOCK_SIZE || @@ -12394,7 +12394,7 @@ int wc_AesKeyUnWrap_ex(Aes *aes, const byte* in, word32 inSz, byte* out, int ret = 0; byte t[KEYWRAP_BLOCK_SIZE]; - byte tmp[AES_BLOCK_SIZE]; + byte tmp[WC_AES_BLOCK_SIZE]; const byte* expIv; const byte defaultIV[] = { @@ -12715,16 +12715,16 @@ int wc_AesXtsEncryptSector(XtsAes* aes, byte* out, const byte* in, word32 sz, word64 sector) { byte* pt; - byte i[AES_BLOCK_SIZE]; + byte i[WC_AES_BLOCK_SIZE]; - XMEMSET(i, 0, AES_BLOCK_SIZE); + XMEMSET(i, 0, WC_AES_BLOCK_SIZE); #ifdef BIG_ENDIAN_ORDER sector = ByteReverseWord64(sector); #endif pt = (byte*)§or; XMEMCPY(i, pt, sizeof(word64)); - return wc_AesXtsEncrypt(aes, out, in, sz, (const byte*)i, AES_BLOCK_SIZE); + return wc_AesXtsEncrypt(aes, out, in, sz, (const byte*)i, WC_AES_BLOCK_SIZE); } @@ -12743,16 +12743,16 @@ int wc_AesXtsDecryptSector(XtsAes* aes, byte* out, const byte* in, word32 sz, word64 sector) { byte* pt; - byte i[AES_BLOCK_SIZE]; + byte i[WC_AES_BLOCK_SIZE]; - XMEMSET(i, 0, AES_BLOCK_SIZE); + XMEMSET(i, 0, WC_AES_BLOCK_SIZE); #ifdef BIG_ENDIAN_ORDER sector = ByteReverseWord64(sector); #endif pt = (byte*)§or; XMEMCPY(i, pt, sizeof(word64)); - return wc_AesXtsDecrypt(aes, out, in, sz, (const byte*)i, AES_BLOCK_SIZE); + return wc_AesXtsDecrypt(aes, out, in, sz, (const byte*)i, WC_AES_BLOCK_SIZE); } #ifdef WOLFSSL_AESNI @@ -12823,28 +12823,28 @@ static WARN_UNUSED_RESULT int _AesXtsHelper( Aes* aes, byte* out, const byte* in, word32 sz, int dir) { word32 outSz = sz; - word32 totalSz = (sz / AES_BLOCK_SIZE) * AES_BLOCK_SIZE; /* total bytes */ + word32 totalSz = (sz / WC_AES_BLOCK_SIZE) * WC_AES_BLOCK_SIZE; /* total bytes */ byte* pt = out; - outSz -= AES_BLOCK_SIZE; + outSz -= WC_AES_BLOCK_SIZE; while (outSz > 0) { word32 j; byte carry = 0; /* multiply by shift left and propagate carry */ - for (j = 0; j < AES_BLOCK_SIZE && outSz > 0; j++, outSz--) { + for (j = 0; j < WC_AES_BLOCK_SIZE && outSz > 0; j++, outSz--) { byte tmpC; tmpC = (pt[j] >> 7) & 0x01; - pt[j+AES_BLOCK_SIZE] = (byte)((pt[j] << 1) + carry); + pt[j+WC_AES_BLOCK_SIZE] = (byte)((pt[j] << 1) + carry); carry = tmpC; } if (carry) { - pt[AES_BLOCK_SIZE] ^= GF_XTS; + pt[WC_AES_BLOCK_SIZE] ^= GF_XTS; } - pt += AES_BLOCK_SIZE; + pt += WC_AES_BLOCK_SIZE; } xorbuf(out, in, totalSz); @@ -12885,7 +12885,7 @@ static int AesXtsEncrypt_sw(XtsAes* xaes, byte* out, const byte* in, word32 sz, const byte* i) { int ret; - byte tweak_block[AES_BLOCK_SIZE]; + byte tweak_block[WC_AES_BLOCK_SIZE]; ret = wc_AesEncryptDirect(&xaes->tweak, tweak_block, i); if (ret != 0) @@ -12927,13 +12927,13 @@ static int AesXtsEncryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, byte *i) { int ret = 0; - word32 blocks = (sz / AES_BLOCK_SIZE); + word32 blocks = (sz / WC_AES_BLOCK_SIZE); Aes *aes = &xaes->aes; #ifdef HAVE_AES_ECB /* encrypt all of buffer at once when possible */ if (in != out) { /* can not handle inline */ - XMEMCPY(out, i, AES_BLOCK_SIZE); + XMEMCPY(out, i, WC_AES_BLOCK_SIZE); if ((ret = _AesXtsHelper(aes, out, in, sz, AES_ENCRYPTION)) != 0) return ret; } @@ -12947,18 +12947,18 @@ static int AesXtsEncryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, if (in == out) #endif { /* check for if inline */ - byte buf[AES_BLOCK_SIZE]; + byte buf[WC_AES_BLOCK_SIZE]; - XMEMCPY(buf, in, AES_BLOCK_SIZE); - xorbuf(buf, i, AES_BLOCK_SIZE); + XMEMCPY(buf, in, WC_AES_BLOCK_SIZE); + xorbuf(buf, i, WC_AES_BLOCK_SIZE); ret = wc_AesEncryptDirect(aes, out, buf); if (ret != 0) return ret; } - xorbuf(out, i, AES_BLOCK_SIZE); + xorbuf(out, i, WC_AES_BLOCK_SIZE); /* multiply by shift left and propagate carry */ - for (j = 0; j < AES_BLOCK_SIZE; j++) { + for (j = 0; j < WC_AES_BLOCK_SIZE; j++) { byte tmpC; tmpC = (i[j] >> 7) & 0x01; @@ -12969,18 +12969,18 @@ static int AesXtsEncryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, i[0] ^= GF_XTS; } - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; - sz -= AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; + sz -= WC_AES_BLOCK_SIZE; blocks--; } /* stealing operation of XTS to handle left overs */ if (sz > 0) { - byte buf[AES_BLOCK_SIZE]; + byte buf[WC_AES_BLOCK_SIZE]; - XMEMCPY(buf, out - AES_BLOCK_SIZE, AES_BLOCK_SIZE); - if (sz >= AES_BLOCK_SIZE) { /* extra sanity check before copy */ + XMEMCPY(buf, out - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); + if (sz >= WC_AES_BLOCK_SIZE) { /* extra sanity check before copy */ return BUFFER_E; } if (in != out) { @@ -12988,17 +12988,17 @@ static int AesXtsEncryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, XMEMCPY(buf, in, sz); } else { - byte buf2[AES_BLOCK_SIZE]; + byte buf2[WC_AES_BLOCK_SIZE]; XMEMCPY(buf2, buf, sz); XMEMCPY(buf, in, sz); XMEMCPY(out, buf2, sz); } - xorbuf(buf, i, AES_BLOCK_SIZE); - ret = wc_AesEncryptDirect(aes, out - AES_BLOCK_SIZE, buf); + xorbuf(buf, i, WC_AES_BLOCK_SIZE); + ret = wc_AesEncryptDirect(aes, out - WC_AES_BLOCK_SIZE, buf); if (ret == 0) - xorbuf(out - AES_BLOCK_SIZE, i, AES_BLOCK_SIZE); + xorbuf(out - WC_AES_BLOCK_SIZE, i, WC_AES_BLOCK_SIZE); } return ret; @@ -13011,7 +13011,7 @@ static int AesXtsEncryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, * in input plain text buffer to encrypt * sz size of both out and in buffers * i value to use for tweak - * iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input + * iSz size of i buffer, should always be WC_AES_BLOCK_SIZE but having this input * adds a sanity check on how the user calls the function. * * returns 0 on success @@ -13029,8 +13029,8 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, #if FIPS_VERSION3_GE(6,0,0) /* SP800-38E - Restrict data unit to 2^20 blocks per key. A block is - * AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to - * protect up to 1,048,576 blocks of AES_BLOCK_SIZE (16,777,216 bytes) + * WC_AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to + * protect up to 1,048,576 blocks of WC_AES_BLOCK_SIZE (16,777,216 bytes) */ if (sz > FIPS_AES_XTS_MAX_BYTES_PER_TWEAK) { WOLFSSL_MSG("Request exceeds allowed bytes per SP800-38E"); @@ -13045,11 +13045,11 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, return BAD_FUNC_ARG; } - if (iSz < AES_BLOCK_SIZE) { + if (iSz < WC_AES_BLOCK_SIZE) { return BAD_FUNC_ARG; } - if (sz < AES_BLOCK_SIZE) { + if (sz < WC_AES_BLOCK_SIZE) { WOLFSSL_MSG("Plain text input too small for encryption"); return BAD_FUNC_ARG; } @@ -13093,7 +13093,7 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, * * xaes AES keys to use for block encrypt/decrypt * i readwrite value to use for tweak - * iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input + * iSz size of i buffer, should always be WC_AES_BLOCK_SIZE but having this input * adds a sanity check on how the user calls the function. * * returns 0 on success @@ -13109,7 +13109,7 @@ int wc_AesXtsEncryptInit(XtsAes* xaes, const byte* i, word32 iSz, return BAD_FUNC_ARG; } - if (iSz < AES_BLOCK_SIZE) { + if (iSz < WC_AES_BLOCK_SIZE) { return BAD_FUNC_ARG; } @@ -13120,7 +13120,7 @@ int wc_AesXtsEncryptInit(XtsAes* xaes, const byte* i, word32 iSz, return BAD_FUNC_ARG; } - XMEMCPY(stream->tweak_block, i, AES_BLOCK_SIZE); + XMEMCPY(stream->tweak_block, i, WC_AES_BLOCK_SIZE); stream->bytes_crypted_with_this_tweak = 0; { @@ -13156,16 +13156,16 @@ int wc_AesXtsEncryptInit(XtsAes* xaes, const byte* i, word32 iSz, /* Block-streaming AES-XTS * - * Note that sz must be >= AES_BLOCK_SIZE in each call, and must be a multiple - * of AES_BLOCK_SIZE in each call to wc_AesXtsEncryptUpdate(). - * wc_AesXtsEncryptFinal() can handle any length >= AES_BLOCK_SIZE. + * Note that sz must be >= WC_AES_BLOCK_SIZE in each call, and must be a multiple + * of WC_AES_BLOCK_SIZE in each call to wc_AesXtsEncryptUpdate(). + * wc_AesXtsEncryptFinal() can handle any length >= WC_AES_BLOCK_SIZE. * * xaes AES keys to use for block encrypt/decrypt * out output buffer to hold cipher text * in input plain text buffer to encrypt - * sz size of both out and in buffers -- must be >= AES_BLOCK_SIZE. + * sz size of both out and in buffers -- must be >= WC_AES_BLOCK_SIZE. * i value to use for tweak - * iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input + * iSz size of i buffer, should always be WC_AES_BLOCK_SIZE but having this input * adds a sanity check on how the user calls the function. * * returns 0 on success @@ -13187,12 +13187,12 @@ static int AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 s aes = &xaes->aes; #endif - if (sz < AES_BLOCK_SIZE) { + if (sz < WC_AES_BLOCK_SIZE) { WOLFSSL_MSG("Plain text input too small for encryption"); return BAD_FUNC_ARG; } - if (stream->bytes_crypted_with_this_tweak & ((word32)AES_BLOCK_SIZE - 1U)) + if (stream->bytes_crypted_with_this_tweak & ((word32)WC_AES_BLOCK_SIZE - 1U)) { WOLFSSL_MSG("Call to AesXtsEncryptUpdate after previous finalizing call"); return BAD_FUNC_ARG; @@ -13204,8 +13204,8 @@ static int AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 s #endif #if FIPS_VERSION3_GE(6,0,0) /* SP800-38E - Restrict data unit to 2^20 blocks per key. A block is - * AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to - * protect up to 1,048,576 blocks of AES_BLOCK_SIZE (16,777,216 bytes) + * WC_AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to + * protect up to 1,048,576 blocks of WC_AES_BLOCK_SIZE (16,777,216 bytes) */ if (stream->bytes_crypted_with_this_tweak > FIPS_AES_XTS_MAX_BYTES_PER_TWEAK) @@ -13252,7 +13252,7 @@ int wc_AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, { if (stream == NULL) return BAD_FUNC_ARG; - if (sz & ((word32)AES_BLOCK_SIZE - 1U)) + if (sz & ((word32)WC_AES_BLOCK_SIZE - 1U)) return BAD_FUNC_ARG; return AesXtsEncryptUpdate(xaes, out, in, sz, stream); } @@ -13271,9 +13271,9 @@ int wc_AesXtsEncryptFinal(XtsAes* xaes, byte* out, const byte* in, word32 sz, * after finalization. */ stream->bytes_crypted_with_this_tweak |= 1U; - ForceZero(stream->tweak_block, AES_BLOCK_SIZE); + ForceZero(stream->tweak_block, WC_AES_BLOCK_SIZE); #ifdef WOLFSSL_CHECK_MEM_ZERO - wc_MemZero_Check(stream->tweak_block, AES_BLOCK_SIZE); + wc_MemZero_Check(stream->tweak_block, WC_AES_BLOCK_SIZE); #endif return ret; } @@ -13300,7 +13300,7 @@ static int AesXtsDecrypt_sw(XtsAes* xaes, byte* out, const byte* in, word32 sz, const byte* i) { int ret; - byte tweak_block[AES_BLOCK_SIZE]; + byte tweak_block[WC_AES_BLOCK_SIZE]; ret = wc_AesEncryptDirect(&xaes->tweak, tweak_block, i); if (ret != 0) @@ -13329,7 +13329,7 @@ static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, word32 sz, byte *i) { int ret = 0; - word32 blocks = (sz / AES_BLOCK_SIZE); + word32 blocks = (sz / WC_AES_BLOCK_SIZE); #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS Aes *aes = &xaes->aes_decrypt; #else @@ -13337,7 +13337,7 @@ static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, #endif word32 j; byte carry = 0; - byte stl = (sz % AES_BLOCK_SIZE); + byte stl = (sz % WC_AES_BLOCK_SIZE); /* if Stealing then break out of loop one block early to handle special * case */ @@ -13348,7 +13348,7 @@ static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, #ifdef HAVE_AES_ECB /* decrypt all of buffer at once when possible */ if (in != out) { /* can not handle inline */ - XMEMCPY(out, i, AES_BLOCK_SIZE); + XMEMCPY(out, i, WC_AES_BLOCK_SIZE); if ((ret = _AesXtsHelper(aes, out, in, sz, AES_DECRYPTION)) != 0) return ret; } @@ -13359,18 +13359,18 @@ static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, if (in == out) #endif { /* check for if inline */ - byte buf[AES_BLOCK_SIZE]; + byte buf[WC_AES_BLOCK_SIZE]; - XMEMCPY(buf, in, AES_BLOCK_SIZE); - xorbuf(buf, i, AES_BLOCK_SIZE); + XMEMCPY(buf, in, WC_AES_BLOCK_SIZE); + xorbuf(buf, i, WC_AES_BLOCK_SIZE); ret = wc_AesDecryptDirect(aes, out, buf); if (ret != 0) return ret; } - xorbuf(out, i, AES_BLOCK_SIZE); + xorbuf(out, i, WC_AES_BLOCK_SIZE); /* multiply by shift left and propagate carry */ - for (j = 0; j < AES_BLOCK_SIZE; j++) { + for (j = 0; j < WC_AES_BLOCK_SIZE; j++) { byte tmpC; tmpC = (i[j] >> 7) & 0x01; @@ -13382,19 +13382,19 @@ static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, } carry = 0; - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; - sz -= AES_BLOCK_SIZE; + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; + sz -= WC_AES_BLOCK_SIZE; blocks--; } /* stealing operation of XTS to handle left overs */ - if (sz >= AES_BLOCK_SIZE) { - byte buf[AES_BLOCK_SIZE]; - byte tmp2[AES_BLOCK_SIZE]; + if (sz >= WC_AES_BLOCK_SIZE) { + byte buf[WC_AES_BLOCK_SIZE]; + byte tmp2[WC_AES_BLOCK_SIZE]; /* multiply by shift left and propagate carry */ - for (j = 0; j < AES_BLOCK_SIZE; j++) { + for (j = 0; j < WC_AES_BLOCK_SIZE; j++) { byte tmpC; tmpC = (i[j] >> 7) & 0x01; @@ -13405,33 +13405,33 @@ static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, tmp2[0] ^= GF_XTS; } - XMEMCPY(buf, in, AES_BLOCK_SIZE); - xorbuf(buf, tmp2, AES_BLOCK_SIZE); + XMEMCPY(buf, in, WC_AES_BLOCK_SIZE); + xorbuf(buf, tmp2, WC_AES_BLOCK_SIZE); ret = wc_AesDecryptDirect(aes, out, buf); if (ret != 0) return ret; - xorbuf(out, tmp2, AES_BLOCK_SIZE); + xorbuf(out, tmp2, WC_AES_BLOCK_SIZE); /* tmp2 holds partial | last */ - XMEMCPY(tmp2, out, AES_BLOCK_SIZE); - in += AES_BLOCK_SIZE; - out += AES_BLOCK_SIZE; - sz -= AES_BLOCK_SIZE; + XMEMCPY(tmp2, out, WC_AES_BLOCK_SIZE); + in += WC_AES_BLOCK_SIZE; + out += WC_AES_BLOCK_SIZE; + sz -= WC_AES_BLOCK_SIZE; /* Make buffer with end of cipher text | last */ - XMEMCPY(buf, tmp2, AES_BLOCK_SIZE); - if (sz >= AES_BLOCK_SIZE) { /* extra sanity check before copy */ + XMEMCPY(buf, tmp2, WC_AES_BLOCK_SIZE); + if (sz >= WC_AES_BLOCK_SIZE) { /* extra sanity check before copy */ return BUFFER_E; } XMEMCPY(buf, in, sz); XMEMCPY(out, tmp2, sz); - xorbuf(buf, i, AES_BLOCK_SIZE); + xorbuf(buf, i, WC_AES_BLOCK_SIZE); ret = wc_AesDecryptDirect(aes, tmp2, buf); if (ret != 0) return ret; - xorbuf(tmp2, i, AES_BLOCK_SIZE); - XMEMCPY(out - AES_BLOCK_SIZE, tmp2, AES_BLOCK_SIZE); + xorbuf(tmp2, i, WC_AES_BLOCK_SIZE); + XMEMCPY(out - WC_AES_BLOCK_SIZE, tmp2, WC_AES_BLOCK_SIZE); } return ret; @@ -13444,7 +13444,7 @@ static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, * in input cipher text buffer to decrypt * sz size of both out and in buffers * i value to use for tweak - * iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input + * iSz size of i buffer, should always be WC_AES_BLOCK_SIZE but having this input * adds a sanity check on how the user calls the function. * * returns 0 on success @@ -13466,10 +13466,10 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, #endif /* FIPS TODO: SP800-38E - Restrict data unit to 2^20 blocks per key. A block is - * AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to - * protect up to 1,048,576 blocks of AES_BLOCK_SIZE (16,777,216 bytes or + * WC_AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to + * protect up to 1,048,576 blocks of WC_AES_BLOCK_SIZE (16,777,216 bytes or * 134,217,728-bits) Add helpful printout and message along with BAD_FUNC_ARG - * return whenever sz / AES_BLOCK_SIZE > 1,048,576 or equal to that and sz is + * return whenever sz / WC_AES_BLOCK_SIZE > 1,048,576 or equal to that and sz is * not a sequence of complete blocks. */ @@ -13478,11 +13478,11 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, return BAD_FUNC_ARG; } - if (iSz < AES_BLOCK_SIZE) { + if (iSz < WC_AES_BLOCK_SIZE) { return BAD_FUNC_ARG; } - if (sz < AES_BLOCK_SIZE) { + if (sz < WC_AES_BLOCK_SIZE) { WOLFSSL_MSG("Cipher text input too small for decryption"); return BAD_FUNC_ARG; } @@ -13526,7 +13526,7 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, * * xaes AES keys to use for block encrypt/decrypt * i readwrite value to use for tweak - * iSz size of i buffer, should always be AES_BLOCK_SIZE but having this input + * iSz size of i buffer, should always be WC_AES_BLOCK_SIZE but having this input * adds a sanity check on how the user calls the function. * * returns 0 on success @@ -13552,11 +13552,11 @@ int wc_AesXtsDecryptInit(XtsAes* xaes, const byte* i, word32 iSz, return BAD_FUNC_ARG; } - if (iSz < AES_BLOCK_SIZE) { + if (iSz < WC_AES_BLOCK_SIZE) { return BAD_FUNC_ARG; } - XMEMCPY(stream->tweak_block, i, AES_BLOCK_SIZE); + XMEMCPY(stream->tweak_block, i, WC_AES_BLOCK_SIZE); stream->bytes_crypted_with_this_tweak = 0; { @@ -13593,15 +13593,15 @@ int wc_AesXtsDecryptInit(XtsAes* xaes, const byte* i, word32 iSz, /* Block-streaming AES-XTS * - * Note that sz must be >= AES_BLOCK_SIZE in each call, and must be a multiple - * of AES_BLOCK_SIZE in each call to wc_AesXtsDecryptUpdate(). - * wc_AesXtsDecryptFinal() can handle any length >= AES_BLOCK_SIZE. + * Note that sz must be >= WC_AES_BLOCK_SIZE in each call, and must be a multiple + * of WC_AES_BLOCK_SIZE in each call to wc_AesXtsDecryptUpdate(). + * wc_AesXtsDecryptFinal() can handle any length >= WC_AES_BLOCK_SIZE. * * xaes AES keys to use for block encrypt/decrypt * out output buffer to hold plain text * in input cipher text buffer to decrypt * sz size of both out and in buffers - * i tweak buffer of size AES_BLOCK_SIZE. + * i tweak buffer of size WC_AES_BLOCK_SIZE. * * returns 0 on success */ @@ -13625,12 +13625,12 @@ static int AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 s #endif #endif - if (sz < AES_BLOCK_SIZE) { + if (sz < WC_AES_BLOCK_SIZE) { WOLFSSL_MSG("Cipher text input too small for decryption"); return BAD_FUNC_ARG; } - if (stream->bytes_crypted_with_this_tweak & ((word32)AES_BLOCK_SIZE - 1U)) + if (stream->bytes_crypted_with_this_tweak & ((word32)WC_AES_BLOCK_SIZE - 1U)) { WOLFSSL_MSG("Call to AesXtsDecryptUpdate after previous finalizing call"); return BAD_FUNC_ARG; @@ -13680,7 +13680,7 @@ int wc_AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz, { if (stream == NULL) return BAD_FUNC_ARG; - if (sz & ((word32)AES_BLOCK_SIZE - 1U)) + if (sz & ((word32)WC_AES_BLOCK_SIZE - 1U)) return BAD_FUNC_ARG; return AesXtsDecryptUpdate(xaes, out, in, sz, stream); } @@ -13695,13 +13695,13 @@ int wc_AesXtsDecryptFinal(XtsAes* xaes, byte* out, const byte* in, word32 sz, ret = AesXtsDecryptUpdate(xaes, out, in, sz, stream); else ret = 0; - ForceZero(stream->tweak_block, AES_BLOCK_SIZE); + ForceZero(stream->tweak_block, WC_AES_BLOCK_SIZE); /* force the count odd, to assure error on attempt to AesXtsEncryptUpdate() * after finalization. */ stream->bytes_crypted_with_this_tweak |= 1U; #ifdef WOLFSSL_CHECK_MEM_ZERO - wc_MemZero_Check(stream->tweak_block, AES_BLOCK_SIZE); + wc_MemZero_Check(stream->tweak_block, WC_AES_BLOCK_SIZE); #endif return ret; } @@ -13734,7 +13734,7 @@ int wc_AesXtsEncryptConsecutiveSectors(XtsAes* aes, byte* out, const byte* in, return BAD_FUNC_ARG; } - if (sz < AES_BLOCK_SIZE) { + if (sz < WC_AES_BLOCK_SIZE) { WOLFSSL_MSG("Cipher text input too small for encryption"); return BAD_FUNC_ARG; } @@ -13783,7 +13783,7 @@ int wc_AesXtsDecryptConsecutiveSectors(XtsAes* aes, byte* out, const byte* in, return BAD_FUNC_ARG; } - if (sz < AES_BLOCK_SIZE) { + if (sz < WC_AES_BLOCK_SIZE) { WOLFSSL_MSG("Cipher text input too small for decryption"); return BAD_FUNC_ARG; } @@ -13825,10 +13825,10 @@ static WARN_UNUSED_RESULT int S2V( int i; Cmac* cmac; #else - byte tmp[3][AES_BLOCK_SIZE]; + byte tmp[3][WC_AES_BLOCK_SIZE]; Cmac cmac[1]; #endif - word32 macSz = AES_BLOCK_SIZE; + word32 macSz = WC_AES_BLOCK_SIZE; int ret = 0; byte tmpi = 0; word32 ai; @@ -13836,7 +13836,7 @@ static WARN_UNUSED_RESULT int S2V( #ifdef WOLFSSL_SMALL_STACK for (i = 0; i < 3; ++i) { - tmp[i] = (byte*)XMALLOC(AES_BLOCK_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); + tmp[i] = (byte*)XMALLOC(WC_AES_BLOCK_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tmp[i] == NULL) { ret = MEMORY_E; break; @@ -13853,10 +13853,10 @@ static WARN_UNUSED_RESULT int S2V( } if (ret == 0) { - XMEMSET(tmp[1], 0, AES_BLOCK_SIZE); - XMEMSET(tmp[2], 0, AES_BLOCK_SIZE); + XMEMSET(tmp[1], 0, WC_AES_BLOCK_SIZE); + XMEMSET(tmp[2], 0, WC_AES_BLOCK_SIZE); - ret = wc_AesCmacGenerate(tmp[0], &macSz, tmp[1], AES_BLOCK_SIZE, + ret = wc_AesCmacGenerate(tmp[0], &macSz, tmp[1], WC_AES_BLOCK_SIZE, key, keySz); } @@ -13868,7 +13868,7 @@ static WARN_UNUSED_RESULT int S2V( assoc[ai].assocSz, key, keySz); if (ret != 0) break; - xorbuf(tmp[1-tmpi], tmp[tmpi], AES_BLOCK_SIZE); + xorbuf(tmp[1-tmpi], tmp[tmpi], WC_AES_BLOCK_SIZE); tmpi = 1 - tmpi; } @@ -13878,7 +13878,7 @@ static WARN_UNUSED_RESULT int S2V( ret = wc_AesCmacGenerate(tmp[tmpi], &macSz, nonce, nonceSz, key, keySz); if (ret == 0) { - xorbuf(tmp[1-tmpi], tmp[tmpi], AES_BLOCK_SIZE); + xorbuf(tmp[1-tmpi], tmp[tmpi], WC_AES_BLOCK_SIZE); } tmpi = 1 - tmpi; } @@ -13886,12 +13886,12 @@ static WARN_UNUSED_RESULT int S2V( /* For simplicity of the remaining code, make sure the "final" result is always in tmp[0]. */ if (tmpi == 1) { - XMEMCPY(tmp[0], tmp[1], AES_BLOCK_SIZE); + XMEMCPY(tmp[0], tmp[1], WC_AES_BLOCK_SIZE); } } if (ret == 0) { - if (dataSz >= AES_BLOCK_SIZE) { + if (dataSz >= WC_AES_BLOCK_SIZE) { #ifdef WOLFSSL_SMALL_STACK cmac = (Cmac*)XMALLOC(sizeof(Cmac), NULL, DYNAMIC_TYPE_CMAC); @@ -13907,14 +13907,14 @@ static WARN_UNUSED_RESULT int S2V( ((unsigned char *)cmac) + sizeof(Aes), sizeof(Cmac) - sizeof(Aes)); #endif - xorbuf(tmp[0], data + (dataSz - AES_BLOCK_SIZE), - AES_BLOCK_SIZE); + xorbuf(tmp[0], data + (dataSz - WC_AES_BLOCK_SIZE), + WC_AES_BLOCK_SIZE); ret = wc_InitCmac(cmac, key, keySz, WC_CMAC_AES, NULL); if (ret == 0) { - ret = wc_CmacUpdate(cmac, data, dataSz - AES_BLOCK_SIZE); + ret = wc_CmacUpdate(cmac, data, dataSz - WC_AES_BLOCK_SIZE); } if (ret == 0) { - ret = wc_CmacUpdate(cmac, tmp[0], AES_BLOCK_SIZE); + ret = wc_CmacUpdate(cmac, tmp[0], WC_AES_BLOCK_SIZE); } if (ret == 0) { ret = wc_CmacFinal(cmac, out, &macSz); @@ -13929,13 +13929,13 @@ static WARN_UNUSED_RESULT int S2V( else { XMEMCPY(tmp[2], data, dataSz); tmp[2][dataSz] |= 0x80; - zeroBytes = AES_BLOCK_SIZE - (dataSz + 1); + zeroBytes = WC_AES_BLOCK_SIZE - (dataSz + 1); if (zeroBytes != 0) { XMEMSET(tmp[2] + dataSz + 1, 0, zeroBytes); } ShiftAndXorRb(tmp[1], tmp[0]); - xorbuf(tmp[1], tmp[2], AES_BLOCK_SIZE); - ret = wc_AesCmacGenerate(out, &macSz, tmp[1], AES_BLOCK_SIZE, key, + xorbuf(tmp[1], tmp[2], WC_AES_BLOCK_SIZE); + ret = wc_AesCmacGenerate(out, &macSz, tmp[1], WC_AES_BLOCK_SIZE, key, keySz); } } @@ -13963,7 +13963,7 @@ static WARN_UNUSED_RESULT int AesSivCipher( #else Aes aes[1]; #endif - byte sivTmp[AES_BLOCK_SIZE]; + byte sivTmp[WC_AES_BLOCK_SIZE]; if (key == NULL || siv == NULL || out == NULL) { WOLFSSL_MSG("Bad parameter"); @@ -13983,11 +13983,11 @@ static WARN_UNUSED_RESULT int AesSivCipher( WOLFSSL_MSG("S2V failed."); } else { - XMEMCPY(siv, sivTmp, AES_BLOCK_SIZE); + XMEMCPY(siv, sivTmp, WC_AES_BLOCK_SIZE); } } else { - XMEMCPY(sivTmp, siv, AES_BLOCK_SIZE); + XMEMCPY(sivTmp, siv, WC_AES_BLOCK_SIZE); } } @@ -14025,7 +14025,7 @@ static WARN_UNUSED_RESULT int AesSivCipher( WOLFSSL_MSG("S2V failed."); } - if (XMEMCMP(siv, sivTmp, AES_BLOCK_SIZE) != 0) { + if (XMEMCMP(siv, sivTmp, WC_AES_BLOCK_SIZE) != 0) { WOLFSSL_MSG("Computed SIV doesn't match received SIV."); ret = AES_SIV_AUTH_E; } @@ -14283,7 +14283,7 @@ int wc_AesEaxInit(AesEax* eax, goto out; } - cmacSize = AES_BLOCK_SIZE; + cmacSize = WC_AES_BLOCK_SIZE; if ((ret = wc_CmacFinal(&eax->nonceCmac, eax->nonceCmacFinal, &cmacSize)) != 0) { @@ -14300,7 +14300,7 @@ int wc_AesEaxInit(AesEax* eax, * provided * H' = OMAC^1_K(H) */ - eax->prefixBuf[AES_BLOCK_SIZE-1] = 1; + eax->prefixBuf[WC_AES_BLOCK_SIZE-1] = 1; if ((ret = wc_InitCmac(&eax->aadCmac, key, keySz, @@ -14327,7 +14327,7 @@ int wc_AesEaxInit(AesEax* eax, * updated in subsequent calls to encrypt/decrypt * C' = OMAC^2_K(C) */ - eax->prefixBuf[AES_BLOCK_SIZE-1] = 2; + eax->prefixBuf[WC_AES_BLOCK_SIZE-1] = 2; if ((ret = wc_InitCmac(&eax->ciphertextCmac, key, keySz, @@ -14475,12 +14475,12 @@ int wc_AesEaxEncryptFinal(AesEax* eax, byte* authTag, word32 authTagSz) int ret; word32 i; - if (eax == NULL || authTag == NULL || authTagSz > AES_BLOCK_SIZE) { + if (eax == NULL || authTag == NULL || authTagSz > WC_AES_BLOCK_SIZE) { return BAD_FUNC_ARG; } /* Complete the OMAC for the ciphertext */ - cmacSize = AES_BLOCK_SIZE; + cmacSize = WC_AES_BLOCK_SIZE; if ((ret = wc_CmacFinalNoFree(&eax->ciphertextCmac, eax->ciphertextCmacFinal, &cmacSize)) != 0) { @@ -14488,7 +14488,7 @@ int wc_AesEaxEncryptFinal(AesEax* eax, byte* authTag, word32 authTagSz) } /* Complete the OMAC for auth data */ - cmacSize = AES_BLOCK_SIZE; + cmacSize = WC_AES_BLOCK_SIZE; if ((ret = wc_CmacFinalNoFree(&eax->aadCmac, eax->aadCmacFinal, &cmacSize)) != 0) { @@ -14529,15 +14529,15 @@ int wc_AesEaxDecryptFinal(AesEax* eax, #if defined(WOLFSSL_SMALL_STACK) byte *authTag; #else - byte authTag[AES_BLOCK_SIZE]; + byte authTag[WC_AES_BLOCK_SIZE]; #endif - if (eax == NULL || authIn == NULL || authInSz > AES_BLOCK_SIZE) { + if (eax == NULL || authIn == NULL || authInSz > WC_AES_BLOCK_SIZE) { return BAD_FUNC_ARG; } /* Complete the OMAC for the ciphertext */ - cmacSize = AES_BLOCK_SIZE; + cmacSize = WC_AES_BLOCK_SIZE; if ((ret = wc_CmacFinalNoFree(&eax->ciphertextCmac, eax->ciphertextCmacFinal, &cmacSize)) != 0) { @@ -14545,7 +14545,7 @@ int wc_AesEaxDecryptFinal(AesEax* eax, } /* Complete the OMAC for auth data */ - cmacSize = AES_BLOCK_SIZE; + cmacSize = WC_AES_BLOCK_SIZE; if ((ret = wc_CmacFinalNoFree(&eax->aadCmac, eax->aadCmacFinal, &cmacSize)) != 0) { @@ -14553,7 +14553,7 @@ int wc_AesEaxDecryptFinal(AesEax* eax, } #if defined(WOLFSSL_SMALL_STACK) - authTag = (byte*)XMALLOC(AES_BLOCK_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); + authTag = (byte*)XMALLOC(WC_AES_BLOCK_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (authTag == NULL) { return MEMORY_E; } diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index a80bf5c41d..e70174e28a 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -8150,7 +8150,7 @@ static int CheckAlgoV2(int oid, int* id, int* blockSz) case AES256CBCb: *id = PBE_AES256_CBC; if (blockSz != NULL) { - *blockSz = AES_BLOCK_SIZE; + *blockSz = WC_AES_BLOCK_SIZE; } break; #endif @@ -8158,7 +8158,7 @@ static int CheckAlgoV2(int oid, int* id, int* blockSz) case AES128CBCb: *id = PBE_AES128_CBC; if (blockSz != NULL) { - *blockSz = AES_BLOCK_SIZE; + *blockSz = WC_AES_BLOCK_SIZE; } break; #endif @@ -16632,7 +16632,7 @@ static int HashForSignature(const byte* buf, word32 bufSz, word32 sigOID, } else if ((ret = wc_Md2Hash(buf, bufSz, digest)) == 0) { *typeH = MD2h; - *digestSz = MD2_DIGEST_SIZE; + *digestSz = WC_MD2_DIGEST_SIZE; } break; #endif @@ -25816,9 +25816,9 @@ int PemToDer(const unsigned char* buff, long longSz, int type, #if !defined(NO_AES) && defined(HAVE_AES_CBC) && \ defined(HAVE_AES_DECRYPT) if (info->cipherType == WC_CIPHER_AES_CBC) { - if (der->length > AES_BLOCK_SIZE) { + if (der->length > WC_AES_BLOCK_SIZE) { padVal = der->buffer[der->length-1]; - if (padVal <= AES_BLOCK_SIZE) { + if (padVal <= WC_AES_BLOCK_SIZE) { der->length -= (word32)padVal; } } diff --git a/wolfcrypt/src/camellia.c b/wolfcrypt/src/camellia.c index 3425177e56..bd9ae1bd7f 100644 --- a/wolfcrypt/src/camellia.c +++ b/wolfcrypt/src/camellia.c @@ -1466,7 +1466,7 @@ static void camellia_decrypt256(const u32 *subkey, u32 *io) static void Camellia_EncryptBlock(const word32 keyBitLength, const unsigned char *plaintext, - const KEY_TABLE_TYPE keyTable, + const WC_CAMELLIA_KEY_TABLE_TYPE keyTable, unsigned char *ciphertext) { u32 tmp[4]; @@ -1497,7 +1497,7 @@ static void Camellia_EncryptBlock(const word32 keyBitLength, static void Camellia_DecryptBlock(const word32 keyBitLength, const unsigned char *ciphertext, - const KEY_TABLE_TYPE keyTable, + const WC_CAMELLIA_KEY_TABLE_TYPE keyTable, unsigned char *plaintext) { u32 tmp[4]; @@ -1529,13 +1529,13 @@ static void Camellia_DecryptBlock(const word32 keyBitLength, /* wolfCrypt wrappers to the Camellia code */ -int wc_CamelliaSetKey(Camellia* cam, const byte* key, word32 len, const byte* iv) +int wc_CamelliaSetKey(wc_Camellia* cam, const byte* key, word32 len, const byte* iv) { int ret = 0; if (cam == NULL) return BAD_FUNC_ARG; - XMEMSET(cam->key, 0, CAMELLIA_TABLE_BYTE_LEN); + XMEMSET(cam->key, 0, WC_CAMELLIA_TABLE_BYTE_LEN); switch (len) { case 16: @@ -1560,21 +1560,21 @@ int wc_CamelliaSetKey(Camellia* cam, const byte* key, word32 len, const byte* iv } -int wc_CamelliaSetIV(Camellia* cam, const byte* iv) +int wc_CamelliaSetIV(wc_Camellia* cam, const byte* iv) { if (cam == NULL) return BAD_FUNC_ARG; if (iv) - XMEMCPY(cam->reg, iv, CAMELLIA_BLOCK_SIZE); + XMEMCPY(cam->reg, iv, WC_CAMELLIA_BLOCK_SIZE); else - XMEMSET(cam->reg, 0, CAMELLIA_BLOCK_SIZE); + XMEMSET(cam->reg, 0, WC_CAMELLIA_BLOCK_SIZE); return 0; } -int wc_CamelliaEncryptDirect(Camellia* cam, byte* out, const byte* in) +int wc_CamelliaEncryptDirect(wc_Camellia* cam, byte* out, const byte* in) { if (cam == NULL || out == NULL || in == NULL) { return BAD_FUNC_ARG; @@ -1585,7 +1585,7 @@ int wc_CamelliaEncryptDirect(Camellia* cam, byte* out, const byte* in) } -int wc_CamelliaDecryptDirect(Camellia* cam, byte* out, const byte* in) +int wc_CamelliaDecryptDirect(wc_Camellia* cam, byte* out, const byte* in) { if (cam == NULL || out == NULL || in == NULL) { return BAD_FUNC_ARG; @@ -1596,44 +1596,44 @@ int wc_CamelliaDecryptDirect(Camellia* cam, byte* out, const byte* in) } -int wc_CamelliaCbcEncrypt(Camellia* cam, byte* out, const byte* in, word32 sz) +int wc_CamelliaCbcEncrypt(wc_Camellia* cam, byte* out, const byte* in, word32 sz) { word32 blocks; if (cam == NULL || out == NULL || in == NULL) { return BAD_FUNC_ARG; } - blocks = sz / CAMELLIA_BLOCK_SIZE; + blocks = sz / WC_CAMELLIA_BLOCK_SIZE; while (blocks--) { - xorbuf((byte*)cam->reg, in, CAMELLIA_BLOCK_SIZE); + xorbuf((byte*)cam->reg, in, WC_CAMELLIA_BLOCK_SIZE); Camellia_EncryptBlock(cam->keySz, (byte*)cam->reg, cam->key, (byte*)cam->reg); - XMEMCPY(out, cam->reg, CAMELLIA_BLOCK_SIZE); + XMEMCPY(out, cam->reg, WC_CAMELLIA_BLOCK_SIZE); - out += CAMELLIA_BLOCK_SIZE; - in += CAMELLIA_BLOCK_SIZE; + out += WC_CAMELLIA_BLOCK_SIZE; + in += WC_CAMELLIA_BLOCK_SIZE; } return 0; } -int wc_CamelliaCbcDecrypt(Camellia* cam, byte* out, const byte* in, word32 sz) +int wc_CamelliaCbcDecrypt(wc_Camellia* cam, byte* out, const byte* in, word32 sz) { word32 blocks; if (cam == NULL || out == NULL || in == NULL) { return BAD_FUNC_ARG; } - blocks = sz / CAMELLIA_BLOCK_SIZE; + blocks = sz / WC_CAMELLIA_BLOCK_SIZE; while (blocks--) { - XMEMCPY(cam->tmp, in, CAMELLIA_BLOCK_SIZE); + XMEMCPY(cam->tmp, in, WC_CAMELLIA_BLOCK_SIZE); Camellia_DecryptBlock(cam->keySz, (byte*)cam->tmp, cam->key, out); - xorbuf(out, (byte*)cam->reg, CAMELLIA_BLOCK_SIZE); - XMEMCPY(cam->reg, cam->tmp, CAMELLIA_BLOCK_SIZE); + xorbuf(out, (byte*)cam->reg, WC_CAMELLIA_BLOCK_SIZE); + XMEMCPY(cam->reg, cam->tmp, WC_CAMELLIA_BLOCK_SIZE); - out += CAMELLIA_BLOCK_SIZE; - in += CAMELLIA_BLOCK_SIZE; + out += WC_CAMELLIA_BLOCK_SIZE; + in += WC_CAMELLIA_BLOCK_SIZE; } return 0; diff --git a/wolfcrypt/src/cmac.c b/wolfcrypt/src/cmac.c index 52c1d2ddc7..2f5d5d40f5 100644 --- a/wolfcrypt/src/cmac.c +++ b/wolfcrypt/src/cmac.c @@ -90,7 +90,7 @@ void ShiftAndXorRb(byte* out, byte* in) xorRb = (in[0] & 0x80) != 0; - for (i = 1, j = AES_BLOCK_SIZE - 1; i <= AES_BLOCK_SIZE; i++, j--) { + for (i = 1, j = WC_AES_BLOCK_SIZE - 1; i <= WC_AES_BLOCK_SIZE; i++, j--) { last = (in[j] & 0x80) ? 1 : 0; out[j] = (byte)((in[j] << 1) | mask); mask = last; @@ -165,14 +165,14 @@ int wc_InitCmac_ex(Cmac* cmac, const byte* key, word32 keySz, } if (ret == 0) { - byte l[AES_BLOCK_SIZE]; + byte l[WC_AES_BLOCK_SIZE]; - XMEMSET(l, 0, AES_BLOCK_SIZE); + XMEMSET(l, 0, WC_AES_BLOCK_SIZE); ret = wc_AesEncryptDirect(&cmac->aes, l, l); if (ret == 0) { ShiftAndXorRb(cmac->k1, l); ShiftAndXorRb(cmac->k2, cmac->k1); - ForceZero(l, AES_BLOCK_SIZE); + ForceZero(l, WC_AES_BLOCK_SIZE); } } break; @@ -227,21 +227,21 @@ int wc_CmacUpdate(Cmac* cmac, const byte* in, word32 inSz) case WC_CMAC_AES: { while ((ret == 0) && (inSz != 0)) { - word32 add = min(inSz, AES_BLOCK_SIZE - cmac->bufferSz); + word32 add = min(inSz, WC_AES_BLOCK_SIZE - cmac->bufferSz); XMEMCPY(&cmac->buffer[cmac->bufferSz], in, add); cmac->bufferSz += add; in += add; inSz -= add; - if (cmac->bufferSz == AES_BLOCK_SIZE && inSz != 0) { + if (cmac->bufferSz == WC_AES_BLOCK_SIZE && inSz != 0) { if (cmac->totalSz != 0) { - xorbuf(cmac->buffer, cmac->digest, AES_BLOCK_SIZE); + xorbuf(cmac->buffer, cmac->digest, WC_AES_BLOCK_SIZE); } ret = wc_AesEncryptDirect(&cmac->aes, cmac->digest, cmac->buffer); if (ret == 0) { - cmac->totalSz += AES_BLOCK_SIZE; + cmac->totalSz += WC_AES_BLOCK_SIZE; cmac->bufferSz = 0; } } @@ -313,30 +313,30 @@ int wc_CmacFinalNoFree(Cmac* cmac, byte* out, word32* outSz) const byte* subKey; word32 remainder; - if (cmac->bufferSz == AES_BLOCK_SIZE) { + if (cmac->bufferSz == WC_AES_BLOCK_SIZE) { subKey = cmac->k1; } else { /* ensure we will have a valid remainder value */ - if (cmac->bufferSz > AES_BLOCK_SIZE) { + if (cmac->bufferSz > WC_AES_BLOCK_SIZE) { ret = BAD_STATE_E; break; } - remainder = AES_BLOCK_SIZE - cmac->bufferSz; + remainder = WC_AES_BLOCK_SIZE - cmac->bufferSz; if (remainder == 0) { - remainder = AES_BLOCK_SIZE; + remainder = WC_AES_BLOCK_SIZE; } if (remainder > 1) { - XMEMSET(cmac->buffer + AES_BLOCK_SIZE - remainder, 0, + XMEMSET(cmac->buffer + WC_AES_BLOCK_SIZE - remainder, 0, remainder); } - cmac->buffer[AES_BLOCK_SIZE - remainder] = 0x80; + cmac->buffer[WC_AES_BLOCK_SIZE - remainder] = 0x80; subKey = cmac->k2; } - xorbuf(cmac->buffer, cmac->digest, AES_BLOCK_SIZE); - xorbuf(cmac->buffer, subKey, AES_BLOCK_SIZE); + xorbuf(cmac->buffer, cmac->digest, WC_AES_BLOCK_SIZE); + xorbuf(cmac->buffer, subKey, WC_AES_BLOCK_SIZE); ret = wc_AesEncryptDirect(&cmac->aes, cmac->digest, cmac->buffer); if (ret == 0) { XMEMCPY(out, cmac->digest, *outSz); @@ -473,7 +473,7 @@ int wc_AesCmacVerify_ex(Cmac* cmac, void* heap, int devId) { int ret = 0; - byte a[AES_BLOCK_SIZE]; + byte a[WC_AES_BLOCK_SIZE]; word32 aSz = sizeof(a); int compareRet; diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 5476e1494d..612ef0f736 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -14073,12 +14073,12 @@ static int ecc_get_key_sizes(ecEncCtx* ctx, int* encKeySz, int* ivSz, case ecAES_128_CBC: *encKeySz = KEY_SIZE_128; *ivSz = IV_SIZE_128; - *blockSz = AES_BLOCK_SIZE; + *blockSz = WC_AES_BLOCK_SIZE; break; case ecAES_256_CBC: *encKeySz = KEY_SIZE_256; *ivSz = IV_SIZE_128; - *blockSz = AES_BLOCK_SIZE; + *blockSz = WC_AES_BLOCK_SIZE; break; #endif #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) @@ -14375,7 +14375,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg, case ecAES_256_CTR: { #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) - byte ctr_iv[AES_BLOCK_SIZE]; + byte ctr_iv[WC_AES_BLOCK_SIZE]; #ifndef WOLFSSL_SMALL_STACK Aes aes[1]; #else @@ -14390,7 +14390,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg, /* Include 4 byte counter starting at all zeros. */ XMEMCPY(ctr_iv, encIv, WOLFSSL_ECIES_GEN_IV_SIZE); XMEMSET(ctr_iv + WOLFSSL_ECIES_GEN_IV_SIZE, 0, - AES_BLOCK_SIZE - WOLFSSL_ECIES_GEN_IV_SIZE); + WC_AES_BLOCK_SIZE - WOLFSSL_ECIES_GEN_IV_SIZE); ret = wc_AesInit(aes, NULL, INVALID_DEVID); if (ret == 0) { @@ -14852,11 +14852,11 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, #endif ret = wc_AesInit(aes, NULL, INVALID_DEVID); if (ret == 0) { - byte ctr_iv[AES_BLOCK_SIZE]; + byte ctr_iv[WC_AES_BLOCK_SIZE]; /* Make a 16 byte IV from the bytes passed in. */ XMEMCPY(ctr_iv, encIv, WOLFSSL_ECIES_GEN_IV_SIZE); XMEMSET(ctr_iv + WOLFSSL_ECIES_GEN_IV_SIZE, 0, - AES_BLOCK_SIZE - WOLFSSL_ECIES_GEN_IV_SIZE); + WC_AES_BLOCK_SIZE - WOLFSSL_ECIES_GEN_IV_SIZE); ret = wc_AesSetKey(aes, encKey, (word32)encKeySz, ctr_iv, AES_ENCRYPTION); if (ret == 0) { diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 87e8e57d9f..519a56ae82 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -1346,7 +1346,7 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, } else { /* Clear IV, since IV reuse is not recommended for AES GCM. */ - XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE); + XMEMSET(ctx->iv, 0, WC_AES_BLOCK_SIZE); } if (wolfSSL_StoreExternalIV(ctx) != WOLFSSL_SUCCESS) { ret = WOLFSSL_FAILURE; @@ -1405,7 +1405,7 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, else { /* Clear IV, since IV reuse is not recommended * for AES CCM. */ - XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE); + XMEMSET(ctx->iv, 0, WC_AES_BLOCK_SIZE); } if (wolfSSL_StoreExternalIV(ctx) != WOLFSSL_SUCCESS) { ret = WOLFSSL_FAILURE; @@ -2053,7 +2053,7 @@ int wolfSSL_EVP_CIPHER_block_size(const WOLFSSL_EVP_CIPHER *cipher) case WC_AES_128_CBC_TYPE: case WC_AES_192_CBC_TYPE: case WC_AES_256_CBC_TYPE: - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #if defined(HAVE_AESGCM) case WC_AES_128_GCM_TYPE: @@ -2077,7 +2077,7 @@ int wolfSSL_EVP_CIPHER_block_size(const WOLFSSL_EVP_CIPHER *cipher) case WC_AES_128_ECB_TYPE: case WC_AES_192_ECB_TYPE: case WC_AES_256_ECB_TYPE: - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #if defined(WOLFSSL_AES_CFB) case WC_AES_128_CFB1_TYPE: @@ -6031,7 +6031,7 @@ void wolfSSL_EVP_init(void) else #endif { - if (arg <= 0 || arg > AES_BLOCK_SIZE) + if (arg <= 0 || arg > WC_AES_BLOCK_SIZE) break; } ret = wolfSSL_EVP_CIPHER_CTX_set_iv_length(ctx, arg); @@ -6215,7 +6215,7 @@ void wolfSSL_EVP_init(void) else #endif { - if (arg <= 0 || arg > AES_BLOCK_SIZE) + if (arg <= 0 || arg > WC_AES_BLOCK_SIZE) break; } @@ -6462,7 +6462,7 @@ void wolfSSL_EVP_init(void) /* wc_AesSetKey clear aes.reg if iv == NULL. Keep IV for openSSL compatibility */ if (iv == NULL) - XMEMCPY((byte *)aes->tmp, (byte *)aes->reg, AES_BLOCK_SIZE); + XMEMCPY((byte *)aes->tmp, (byte *)aes->reg, WC_AES_BLOCK_SIZE); if (direct) { #if defined(WOLFSSL_AES_DIRECT) ret = wc_AesSetKeyDirect(aes, key, len, iv, dir); @@ -6474,7 +6474,7 @@ void wolfSSL_EVP_init(void) ret = wc_AesSetKey(aes, key, len, iv, dir); } if (iv == NULL) - XMEMCPY((byte *)aes->reg, (byte *)aes->tmp, AES_BLOCK_SIZE); + XMEMCPY((byte *)aes->reg, (byte *)aes->tmp, WC_AES_BLOCK_SIZE); return ret; } #endif /* AES_ANY_SIZE && AES_SET_KEY */ @@ -6492,8 +6492,8 @@ void wolfSSL_EVP_init(void) ctx->authIn = NULL; ctx->authInSz = 0; - ctx->block_size = AES_BLOCK_SIZE; - ctx->authTagSz = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; + ctx->authTagSz = WC_AES_BLOCK_SIZE; if (ctx->ivSz == 0) { ctx->ivSz = GCM_NONCE_MID_SZ; } @@ -6697,8 +6697,8 @@ void wolfSSL_EVP_init(void) ctx->authIn = NULL; ctx->authInSz = 0; - ctx->block_size = AES_BLOCK_SIZE; - ctx->authTagSz = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; + ctx->authTagSz = WC_AES_BLOCK_SIZE; if (ctx->ivSz == 0) { ctx->ivSz = GCM_NONCE_MID_SZ; } @@ -6846,8 +6846,8 @@ void wolfSSL_EVP_init(void) ctx->authIn = NULL; ctx->authInSz = 0; - ctx->block_size = AES_BLOCK_SIZE; - ctx->authTagSz = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; + ctx->authTagSz = WC_AES_BLOCK_SIZE; if (ctx->ivSz == 0) { ctx->ivSz = GCM_NONCE_MID_SZ; } @@ -6938,8 +6938,8 @@ void wolfSSL_EVP_init(void) ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 16; - ctx->block_size = AES_BLOCK_SIZE; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) { @@ -6968,8 +6968,8 @@ void wolfSSL_EVP_init(void) ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 24; - ctx->block_size = AES_BLOCK_SIZE; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) { @@ -6998,8 +6998,8 @@ void wolfSSL_EVP_init(void) ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 32; - ctx->block_size = AES_BLOCK_SIZE; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) { @@ -7083,7 +7083,7 @@ void wolfSSL_EVP_init(void) ctx->flags |= WOLFSSL_EVP_CIPH_CTR_MODE; ctx->keyLen = 16; ctx->block_size = WOLFSSL_NO_PADDING_BLOCK_SIZE; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; #if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) ctx->cipher.aes.left = 0; #endif @@ -7116,7 +7116,7 @@ void wolfSSL_EVP_init(void) ctx->flags |= WOLFSSL_EVP_CIPH_CTR_MODE; ctx->keyLen = 24; ctx->block_size = WOLFSSL_NO_PADDING_BLOCK_SIZE; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; #if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) ctx->cipher.aes.left = 0; #endif @@ -7149,7 +7149,7 @@ void wolfSSL_EVP_init(void) ctx->flags |= WOLFSSL_EVP_CIPH_CTR_MODE; ctx->keyLen = 32; ctx->block_size = WOLFSSL_NO_PADDING_BLOCK_SIZE; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; #if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) ctx->cipher.aes.left = 0; #endif @@ -7183,7 +7183,7 @@ void wolfSSL_EVP_init(void) ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 16; - ctx->block_size = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) { @@ -7207,7 +7207,7 @@ void wolfSSL_EVP_init(void) ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 24; - ctx->block_size = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) { @@ -7231,7 +7231,7 @@ void wolfSSL_EVP_init(void) ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 32; - ctx->block_size = AES_BLOCK_SIZE; + ctx->block_size = WC_AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) { @@ -7627,14 +7627,14 @@ void wolfSSL_EVP_init(void) ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE; ctx->keyLen = 32; ctx->block_size = 1; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; if (iv != NULL) { if (iv != ctx->iv) /* Valgrind error when src == dst */ XMEMCPY(ctx->iv, iv, (size_t)ctx->ivSz); } else - XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE); + XMEMSET(ctx->iv, 0, WC_AES_BLOCK_SIZE); if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; @@ -7668,14 +7668,14 @@ void wolfSSL_EVP_init(void) ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE; ctx->keyLen = 64; ctx->block_size = 1; - ctx->ivSz = AES_BLOCK_SIZE; + ctx->ivSz = WC_AES_BLOCK_SIZE; if (iv != NULL) { if (iv != ctx->iv) /* Valgrind error when src == dst */ XMEMCPY(ctx->iv, iv, (size_t)ctx->ivSz); } else - XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE); + XMEMSET(ctx->iv, 0, WC_AES_BLOCK_SIZE); if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; @@ -8312,7 +8312,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesCbcDecrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = (int)((len / AES_BLOCK_SIZE) * AES_BLOCK_SIZE); + ret = (int)((len / WC_AES_BLOCK_SIZE) * WC_AES_BLOCK_SIZE); break; #endif /* HAVE_AES_CBC */ @@ -8411,7 +8411,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesEcbDecrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = (int)((len / AES_BLOCK_SIZE) * AES_BLOCK_SIZE); + ret = (int)((len / WC_AES_BLOCK_SIZE) * WC_AES_BLOCK_SIZE); break; #endif #ifdef WOLFSSL_AES_COUNTER @@ -8861,7 +8861,7 @@ int wolfSSL_EVP_PKEY_set1_DSA(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DSA *key) dsa = (DsaKey*)key->internal; /* 4 > size of pub, priv, p, q, g + ASN.1 additional information */ - derMax = 4 * wolfSSL_BN_num_bytes(key->g) + AES_BLOCK_SIZE; + derMax = 4 * wolfSSL_BN_num_bytes(key->g) + WC_AES_BLOCK_SIZE; derBuf = (byte*)XMALLOC((size_t)derMax, pkey->heap, DYNAMIC_TYPE_TMP_BUFFER); @@ -9405,7 +9405,7 @@ int wolfSSL_EVP_CIPHER_CTX_iv_length(const WOLFSSL_EVP_CIPHER_CTX* ctx) case WC_AES_192_CBC_TYPE : case WC_AES_256_CBC_TYPE : WOLFSSL_MSG("AES CBC"); - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) @@ -9435,7 +9435,7 @@ int wolfSSL_EVP_CIPHER_CTX_iv_length(const WOLFSSL_EVP_CIPHER_CTX* ctx) case WC_AES_192_CTR_TYPE : case WC_AES_256_CTR_TYPE : WOLFSSL_MSG("AES CTR"); - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #ifndef NO_DES3 case WC_DES_CBC_TYPE : @@ -9457,31 +9457,31 @@ int wolfSSL_EVP_CIPHER_CTX_iv_length(const WOLFSSL_EVP_CIPHER_CTX* ctx) case WC_AES_192_CFB1_TYPE: case WC_AES_256_CFB1_TYPE: WOLFSSL_MSG("AES CFB1"); - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; case WC_AES_128_CFB8_TYPE: case WC_AES_192_CFB8_TYPE: case WC_AES_256_CFB8_TYPE: WOLFSSL_MSG("AES CFB8"); - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif /* !HAVE_SELFTEST && !HAVE_FIPS */ case WC_AES_128_CFB128_TYPE: case WC_AES_192_CFB128_TYPE: case WC_AES_256_CFB128_TYPE: WOLFSSL_MSG("AES CFB128"); - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif /* WOLFSSL_AES_CFB */ #if defined(WOLFSSL_AES_OFB) case WC_AES_128_OFB_TYPE: case WC_AES_192_OFB_TYPE: case WC_AES_256_OFB_TYPE: WOLFSSL_MSG("AES OFB"); - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif /* WOLFSSL_AES_OFB */ #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) case WC_AES_128_XTS_TYPE: case WC_AES_256_XTS_TYPE: WOLFSSL_MSG("AES XTS"); - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif /* WOLFSSL_AES_XTS && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) */ #ifdef HAVE_ARIA case WC_ARIA_128_GCM_TYPE : @@ -9550,15 +9550,15 @@ int wolfSSL_EVP_CIPHER_iv_length(const WOLFSSL_EVP_CIPHER* cipher) #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT) #ifdef WOLFSSL_AES_128 if (XSTRCMP(name, EVP_AES_128_CBC) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #ifdef WOLFSSL_AES_192 if (XSTRCMP(name, EVP_AES_192_CBC) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #ifdef WOLFSSL_AES_256 if (XSTRCMP(name, EVP_AES_256_CBC) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */ #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ @@ -9595,26 +9595,26 @@ int wolfSSL_EVP_CIPHER_iv_length(const WOLFSSL_EVP_CIPHER* cipher) #ifdef WOLFSSL_AES_COUNTER #ifdef WOLFSSL_AES_128 if (XSTRCMP(name, EVP_AES_128_CTR) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #ifdef WOLFSSL_AES_192 if (XSTRCMP(name, EVP_AES_192_CTR) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #ifdef WOLFSSL_AES_256 if (XSTRCMP(name, EVP_AES_256_CTR) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif #endif #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) #ifdef WOLFSSL_AES_128 if (XSTRCMP(name, EVP_AES_128_XTS) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif /* WOLFSSL_AES_128 */ #ifdef WOLFSSL_AES_256 if (XSTRCMP(name, EVP_AES_256_XTS) == 0) - return AES_BLOCK_SIZE; + return WC_AES_BLOCK_SIZE; #endif /* WOLFSSL_AES_256 */ #endif /* WOLFSSL_AES_XTS && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) */ @@ -10618,14 +10618,14 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type) switch (macType) { case WC_HASH_TYPE_MD4: #ifndef NO_MD4 - wolfSSL_MD4_Update((MD4_CTX*)&ctx->hash, data, + wolfSSL_MD4_Update((WOLFSSL_MD4_CTX*)&ctx->hash, data, (unsigned long)sz); ret = WOLFSSL_SUCCESS; #endif break; case WC_HASH_TYPE_MD5: #ifndef NO_MD5 - ret = wolfSSL_MD5_Update((MD5_CTX*)&ctx->hash, data, + ret = wolfSSL_MD5_Update((WOLFSSL_MD5_CTX*)&ctx->hash, data, (unsigned long)sz); #endif break; @@ -10745,14 +10745,14 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type) switch (macType) { case WC_HASH_TYPE_MD4: #ifndef NO_MD4 - wolfSSL_MD4_Final(md, (MD4_CTX*)&ctx->hash); - if (s) *s = MD4_DIGEST_SIZE; + wolfSSL_MD4_Final(md, (WOLFSSL_MD4_CTX*)&ctx->hash); + if (s) *s = WC_MD4_DIGEST_SIZE; ret = WOLFSSL_SUCCESS; #endif break; case WC_HASH_TYPE_MD5: #ifndef NO_MD5 - ret = wolfSSL_MD5_Final(md, (MD5_CTX*)&ctx->hash); + ret = wolfSSL_MD5_Final(md, (WOLFSSL_MD5_CTX*)&ctx->hash); if (s) *s = WC_MD5_DIGEST_SIZE; #endif break; @@ -10931,7 +10931,7 @@ int wolfSSL_EVP_MD_block_size(const WOLFSSL_EVP_MD* type) #endif #ifndef NO_MD4 if (XSTRCMP(type, "MD4") == 0) { - return MD4_BLOCK_SIZE; + return WC_MD4_BLOCK_SIZE; } else #endif #ifndef NO_MD5 @@ -11006,7 +11006,7 @@ int wolfSSL_EVP_MD_size(const WOLFSSL_EVP_MD* type) #endif #ifndef NO_MD4 if (XSTRCMP(type, "MD4") == 0) { - return MD4_DIGEST_SIZE; + return WC_MD4_DIGEST_SIZE; } else #endif #ifndef NO_MD5 diff --git a/wolfcrypt/src/hash.c b/wolfcrypt/src/hash.c index b16c47dcb1..4850a84249 100644 --- a/wolfcrypt/src/hash.c +++ b/wolfcrypt/src/hash.c @@ -322,12 +322,12 @@ int wc_HashGetDigestSize(enum wc_HashType hash_type) { case WC_HASH_TYPE_MD2: #ifdef WOLFSSL_MD2 - dig_size = MD2_DIGEST_SIZE; + dig_size = WC_MD2_DIGEST_SIZE; #endif break; case WC_HASH_TYPE_MD4: #ifndef NO_MD4 - dig_size = MD4_DIGEST_SIZE; + dig_size = WC_MD4_DIGEST_SIZE; #endif break; case WC_HASH_TYPE_MD5: @@ -441,12 +441,12 @@ int wc_HashGetBlockSize(enum wc_HashType hash_type) { case WC_HASH_TYPE_MD2: #ifdef WOLFSSL_MD2 - block_size = MD2_BLOCK_SIZE; + block_size = WC_MD2_BLOCK_SIZE; #endif break; case WC_HASH_TYPE_MD4: #ifndef NO_MD4 - block_size = MD4_BLOCK_SIZE; + block_size = WC_MD4_BLOCK_SIZE; #endif break; case WC_HASH_TYPE_MD5: diff --git a/wolfcrypt/src/hpke.c b/wolfcrypt/src/hpke.c index 450ee73173..02e189be41 100644 --- a/wolfcrypt/src/hpke.c +++ b/wolfcrypt/src/hpke.c @@ -256,13 +256,13 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap) case HPKE_AES_128_GCM: hpke->Nk = AES_128_KEY_SIZE; hpke->Nn = GCM_NONCE_MID_SZ; - hpke->Nt = AES_BLOCK_SIZE; + hpke->Nt = WC_AES_BLOCK_SIZE; break; case HPKE_AES_256_GCM: hpke->Nk = AES_256_KEY_SIZE; hpke->Nn = GCM_NONCE_MID_SZ; - hpke->Nt = AES_BLOCK_SIZE; + hpke->Nt = WC_AES_BLOCK_SIZE; break; default: diff --git a/wolfcrypt/src/kdf.c b/wolfcrypt/src/kdf.c index 1bb338e80e..302cabc1b8 100644 --- a/wolfcrypt/src/kdf.c +++ b/wolfcrypt/src/kdf.c @@ -968,7 +968,7 @@ static int wc_srtp_kdf_derive_key(byte* block, int indexSz, byte label, int i; int ret = 0; /* Calculate the number of full blocks needed for derived key. */ - int blocks = (int)(keySz / AES_BLOCK_SIZE); + int blocks = (int)(keySz / WC_AES_BLOCK_SIZE); /* XOR in label. */ block[WC_SRTP_MAX_SALT - indexSz - 1] ^= label; @@ -976,19 +976,19 @@ static int wc_srtp_kdf_derive_key(byte* block, int indexSz, byte label, /* Set counter. */ block[15] = (byte)i; /* Encrypt block into key buffer. */ - ret = wc_AesEcbEncrypt(aes, key, block, AES_BLOCK_SIZE); + ret = wc_AesEcbEncrypt(aes, key, block, WC_AES_BLOCK_SIZE); /* Reposition for more derived key. */ - key += AES_BLOCK_SIZE; + key += WC_AES_BLOCK_SIZE; /* Reduce the count of key bytes required. */ - keySz -= AES_BLOCK_SIZE; + keySz -= WC_AES_BLOCK_SIZE; } /* Do any partial blocks. */ if ((ret == 0) && (keySz > 0)) { - byte enc[AES_BLOCK_SIZE]; + byte enc[WC_AES_BLOCK_SIZE]; /* Set counter. */ block[15] = (byte)i; /* Encrypt block into temporary. */ - ret = wc_AesEcbEncrypt(aes, enc, block, AES_BLOCK_SIZE); + ret = wc_AesEcbEncrypt(aes, enc, block, WC_AES_BLOCK_SIZE); if (ret == 0) { /* Copy into key required amount. */ XMEMCPY(key, enc, keySz); @@ -1029,7 +1029,7 @@ int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz, word32 key2Sz, byte* key3, word32 key3Sz) { int ret = 0; - byte block[AES_BLOCK_SIZE]; + byte block[WC_AES_BLOCK_SIZE]; #ifdef WOLFSSL_SMALL_STACK Aes* aes = NULL; #else @@ -1124,7 +1124,7 @@ int wc_SRTCP_KDF_ex(const byte* key, word32 keySz, const byte* salt, word32 salt word32 key2Sz, byte* key3, word32 key3Sz, int idxLenIndicator) { int ret = 0; - byte block[AES_BLOCK_SIZE]; + byte block[WC_AES_BLOCK_SIZE]; #ifdef WOLFSSL_SMALL_STACK Aes* aes = NULL; #else @@ -1233,7 +1233,7 @@ int wc_SRTP_KDF_label(const byte* key, word32 keySz, const byte* salt, word32 outKeySz) { int ret = 0; - byte block[AES_BLOCK_SIZE]; + byte block[WC_AES_BLOCK_SIZE]; #ifdef WOLFSSL_SMALL_STACK Aes* aes = NULL; #else @@ -1316,7 +1316,7 @@ int wc_SRTCP_KDF_label(const byte* key, word32 keySz, const byte* salt, word32 outKeySz) { int ret = 0; - byte block[AES_BLOCK_SIZE]; + byte block[WC_AES_BLOCK_SIZE]; #ifdef WOLFSSL_SMALL_STACK Aes* aes = NULL; #else diff --git a/wolfcrypt/src/md2.c b/wolfcrypt/src/md2.c index c28a049d4f..07ad963dd4 100644 --- a/wolfcrypt/src/md2.c +++ b/wolfcrypt/src/md2.c @@ -40,16 +40,16 @@ #endif -void wc_InitMd2(Md2* md2) +void wc_InitMd2(wc_Md2* md2) { - XMEMSET(md2->X, 0, MD2_X_SIZE); - XMEMSET(md2->C, 0, MD2_BLOCK_SIZE); - XMEMSET(md2->buffer, 0, MD2_BLOCK_SIZE); + XMEMSET(md2->X, 0, WC_MD2_X_SIZE); + XMEMSET(md2->C, 0, WC_MD2_BLOCK_SIZE); + XMEMSET(md2->buffer, 0, WC_MD2_BLOCK_SIZE); md2->count = 0; } -void wc_Md2Update(Md2* md2, const byte* data, word32 len) +void wc_Md2Update(wc_Md2* md2, const byte* data, word32 len) { static const byte S[256] = { @@ -74,30 +74,30 @@ void wc_Md2Update(Md2* md2, const byte* data, word32 len) }; while (len) { - word32 L = (MD2_PAD_SIZE - md2->count) < len ? - (MD2_PAD_SIZE - md2->count) : len; + word32 L = (WC_MD2_PAD_SIZE - md2->count) < len ? + (WC_MD2_PAD_SIZE - md2->count) : len; XMEMCPY(md2->buffer + md2->count, data, L); md2->count += L; data += L; len -= L; - if (md2->count == MD2_PAD_SIZE) { + if (md2->count == WC_MD2_PAD_SIZE) { int i; byte t; md2->count = 0; - XMEMCPY(md2->X + MD2_PAD_SIZE, md2->buffer, MD2_PAD_SIZE); + XMEMCPY(md2->X + WC_MD2_PAD_SIZE, md2->buffer, WC_MD2_PAD_SIZE); t = md2->C[15]; - for(i = 0; i < MD2_PAD_SIZE; i++) { - md2->X[32 + i] = md2->X[MD2_PAD_SIZE + i] ^ md2->X[i]; + for(i = 0; i < WC_MD2_PAD_SIZE; i++) { + md2->X[32 + i] = md2->X[WC_MD2_PAD_SIZE + i] ^ md2->X[i]; t = md2->C[i] ^= S[md2->buffer[i] ^ t]; } t=0; for(i = 0; i < 18; i++) { int j; - for(j = 0; j < MD2_X_SIZE; j += 8) { + for(j = 0; j < WC_MD2_X_SIZE; j += 8) { t = md2->X[j+0] ^= S[t]; t = md2->X[j+1] ^= S[t]; t = md2->X[j+2] ^= S[t]; @@ -114,19 +114,19 @@ void wc_Md2Update(Md2* md2, const byte* data, word32 len) } -void wc_Md2Final(Md2* md2, byte* hash) +void wc_Md2Final(wc_Md2* md2, byte* hash) { - byte padding[MD2_BLOCK_SIZE]; - word32 padLen = MD2_PAD_SIZE - md2->count; + byte padding[WC_MD2_BLOCK_SIZE]; + word32 padLen = WC_MD2_PAD_SIZE - md2->count; word32 i; for (i = 0; i < padLen; i++) padding[i] = (byte)padLen; wc_Md2Update(md2, padding, padLen); /* cppcheck-suppress uninitvar */ - wc_Md2Update(md2, md2->C, MD2_BLOCK_SIZE); + wc_Md2Update(md2, md2->C, WC_MD2_BLOCK_SIZE); - XMEMCPY(hash, md2->X, MD2_DIGEST_SIZE); + XMEMCPY(hash, md2->X, WC_MD2_DIGEST_SIZE); wc_InitMd2(md2); } @@ -135,13 +135,13 @@ void wc_Md2Final(Md2* md2, byte* hash) int wc_Md2Hash(const byte* data, word32 len, byte* hash) { #ifdef WOLFSSL_SMALL_STACK - Md2* md2; + wc_Md2* md2; #else - Md2 md2[1]; + wc_Md2 md2[1]; #endif #ifdef WOLFSSL_SMALL_STACK - md2 = (Md2*)XMALLOC(sizeof(Md2), NULL, DYNAMIC_TYPE_TMP_BUFFER); + md2 = (wc_Md2*)XMALLOC(sizeof(wc_Md2), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (md2 == NULL) return MEMORY_E; #endif diff --git a/wolfcrypt/src/md4.c b/wolfcrypt/src/md4.c index 65b4dc23f6..592a0a3d32 100644 --- a/wolfcrypt/src/md4.c +++ b/wolfcrypt/src/md4.c @@ -37,7 +37,7 @@ #endif -void wc_InitMd4(Md4* md4) +void wc_InitMd4(wc_Md4* md4) { md4->digest[0] = 0x67452301L; md4->digest[1] = 0xefcdab89L; @@ -50,7 +50,7 @@ void wc_InitMd4(Md4* md4) } -static void Transform(Md4* md4) +static void Transform(wc_Md4* md4) { #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) @@ -130,7 +130,7 @@ static void Transform(Md4* md4) } -static WC_INLINE void AddLength(Md4* md4, word32 len) +static WC_INLINE void AddLength(wc_Md4* md4, word32 len) { word32 tmp = md4->loLen; if ( (md4->loLen += len) < tmp) @@ -138,32 +138,32 @@ static WC_INLINE void AddLength(Md4* md4, word32 len) } -void wc_Md4Update(Md4* md4, const byte* data, word32 len) +void wc_Md4Update(wc_Md4* md4, const byte* data, word32 len) { /* do block size increments */ byte* local = (byte*)md4->buffer; while (len) { - word32 add = min(len, MD4_BLOCK_SIZE - md4->buffLen); + word32 add = min(len, WC_MD4_BLOCK_SIZE - md4->buffLen); XMEMCPY(&local[md4->buffLen], data, add); md4->buffLen += add; data += add; len -= add; - if (md4->buffLen == MD4_BLOCK_SIZE) { + if (md4->buffLen == WC_MD4_BLOCK_SIZE) { #ifdef BIG_ENDIAN_ORDER - ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE); + ByteReverseWords(md4->buffer, md4->buffer, WC_MD4_BLOCK_SIZE); #endif Transform(md4); - AddLength(md4, MD4_BLOCK_SIZE); + AddLength(md4, WC_MD4_BLOCK_SIZE); md4->buffLen = 0; } } } -void wc_Md4Final(Md4* md4, byte* hash) +void wc_Md4Final(wc_Md4* md4, byte* hash) { byte* local = (byte*)md4->buffer; @@ -172,17 +172,17 @@ void wc_Md4Final(Md4* md4, byte* hash) local[md4->buffLen++] = 0x80; /* add 1 */ /* pad with zeros */ - if (md4->buffLen > MD4_PAD_SIZE) { - XMEMSET(&local[md4->buffLen], 0, MD4_BLOCK_SIZE - md4->buffLen); - md4->buffLen += MD4_BLOCK_SIZE - md4->buffLen; + if (md4->buffLen > WC_MD4_PAD_SIZE) { + XMEMSET(&local[md4->buffLen], 0, WC_MD4_BLOCK_SIZE - md4->buffLen); + md4->buffLen += WC_MD4_BLOCK_SIZE - md4->buffLen; #ifdef BIG_ENDIAN_ORDER - ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE); + ByteReverseWords(md4->buffer, md4->buffer, WC_MD4_BLOCK_SIZE); #endif Transform(md4); md4->buffLen = 0; } - XMEMSET(&local[md4->buffLen], 0, MD4_PAD_SIZE - md4->buffLen); + XMEMSET(&local[md4->buffLen], 0, WC_MD4_PAD_SIZE - md4->buffLen); /* put lengths in bits */ md4->hiLen = (md4->loLen >> (8*sizeof(md4->loLen) - 3)) + @@ -191,17 +191,17 @@ void wc_Md4Final(Md4* md4, byte* hash) /* store lengths */ #ifdef BIG_ENDIAN_ORDER - ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE); + ByteReverseWords(md4->buffer, md4->buffer, WC_MD4_BLOCK_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ - XMEMCPY(&local[MD4_PAD_SIZE], &md4->loLen, sizeof(word32)); - XMEMCPY(&local[MD4_PAD_SIZE + sizeof(word32)], &md4->hiLen, sizeof(word32)); + XMEMCPY(&local[WC_MD4_PAD_SIZE], &md4->loLen, sizeof(word32)); + XMEMCPY(&local[WC_MD4_PAD_SIZE + sizeof(word32)], &md4->hiLen, sizeof(word32)); Transform(md4); #ifdef BIG_ENDIAN_ORDER - ByteReverseWords(md4->digest, md4->digest, MD4_DIGEST_SIZE); + ByteReverseWords(md4->digest, md4->digest, WC_MD4_DIGEST_SIZE); #endif - XMEMCPY(hash, md4->digest, MD4_DIGEST_SIZE); + XMEMCPY(hash, md4->digest, WC_MD4_DIGEST_SIZE); wc_InitMd4(md4); /* reset state */ } diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index a2b5132980..8fa518c4f9 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -695,7 +695,7 @@ static int wc_PKCS7_GetOIDBlockSize(int oid) case AES256CCMb: #endif #endif - blockSz = AES_BLOCK_SIZE; + blockSz = WC_AES_BLOCK_SIZE; break; #endif /* !NO_AES */ @@ -8214,7 +8214,7 @@ static int wc_PKCS7_EncryptContent(wc_PKCS7* pkcs7, int encryptOID, byte* key, #ifdef WOLFSSL_AES_256 (encryptOID == AES256CBCb && keySz != 32 ) || #endif - (ivSz != AES_BLOCK_SIZE) ) + (ivSz != WC_AES_BLOCK_SIZE) ) return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK @@ -8453,7 +8453,7 @@ static int wc_PKCS7_DecryptContent(wc_PKCS7* pkcs7, int encryptOID, byte* key, #ifdef WOLFSSL_AES_256 (encryptOID == AES256CBCb && keySz != 32 ) || #endif - (ivSz != AES_BLOCK_SIZE) ) + (ivSz != WC_AES_BLOCK_SIZE) ) return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK if ((aes = (Aes *)XMALLOC(sizeof *aes, NULL, @@ -12600,7 +12600,7 @@ int wc_PKCS7_EncodeAuthEnvelopedData(wc_PKCS7* pkcs7, byte* output, byte encContentOctet[MAX_OCTET_STR_SZ]; byte macOctetString[MAX_OCTET_STR_SZ]; - byte authTag[AES_BLOCK_SIZE]; + byte authTag[WC_AES_BLOCK_SIZE]; byte nonce[GCM_NONCE_MID_SZ]; /* GCM nonce is larger than CCM */ byte macInt[MAX_VERSION_SZ]; byte algoParamSeq[MAX_SEQ_SZ]; @@ -13135,7 +13135,7 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(wc_PKCS7* pkcs7, byte* in, word32 pkiMsgSz = inSz; int expBlockSz = 0, blockKeySz = 0; - byte authTag[AES_BLOCK_SIZE]; + byte authTag[WC_AES_BLOCK_SIZE]; byte nonce[GCM_NONCE_MID_SZ]; /* GCM nonce is larger than CCM */ int nonceSz = 0, authTagSz = 0, macSz = 0; @@ -13653,7 +13653,7 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(wc_PKCS7* pkcs7, byte* in, if (pkcs7->stream->tagSz > 0) { authTagSz = (int)pkcs7->stream->tagSz; - if (authTagSz > AES_BLOCK_SIZE) { + if (authTagSz > WC_AES_BLOCK_SIZE) { WOLFSSL_MSG("PKCS7 saved tag is too large"); ret = BUFFER_E; break; diff --git a/wolfcrypt/src/wc_pkcs11.c b/wolfcrypt/src/wc_pkcs11.c index 42f71647eb..d7ef8d8c38 100644 --- a/wolfcrypt/src/wc_pkcs11.c +++ b/wolfcrypt/src/wc_pkcs11.c @@ -3671,7 +3671,7 @@ static int Pkcs11AesCbcEncrypt(Pkcs11Session* session, wc_CryptoInfo* info) if (ret == 0) { mech.mechanism = CKM_AES_CBC; - mech.ulParameterLen = AES_BLOCK_SIZE; + mech.ulParameterLen = WC_AES_BLOCK_SIZE; mech.pParameter = (CK_BYTE_PTR)info->cipher.aescbc.aes->reg; rv = session->func->C_EncryptInit(session->handle, &mech, key); @@ -3747,7 +3747,7 @@ static int Pkcs11AesCbcDecrypt(Pkcs11Session* session, wc_CryptoInfo* info) if (ret == 0) { mech.mechanism = CKM_AES_CBC; - mech.ulParameterLen = AES_BLOCK_SIZE; + mech.ulParameterLen = WC_AES_BLOCK_SIZE; mech.pParameter = (CK_BYTE_PTR)info->cipher.aescbc.aes->reg; rv = session->func->C_DecryptInit(session->handle, &mech, key); diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index bf4824c200..cfc618afa3 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -3077,8 +3077,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void) WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void) { wc_test_ret_t ret = 0; - Md2 md2; - byte hash[MD2_DIGEST_SIZE]; + wc_Md2 md2; + byte hash[WC_MD2_DIGEST_SIZE]; testVector a, b, c, d, e, f, g; testVector test_md2[7]; @@ -3089,45 +3089,45 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void) a.output = "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69" "\x27\x73"; a.inLen = XSTRLEN(a.input); - a.outLen = MD2_DIGEST_SIZE; + a.outLen = WC_MD2_DIGEST_SIZE; b.input = "a"; b.output = "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0" "\xb5\xd1"; b.inLen = XSTRLEN(b.input); - b.outLen = MD2_DIGEST_SIZE; + b.outLen = WC_MD2_DIGEST_SIZE; c.input = "abc"; c.output = "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde" "\xd6\xbb"; c.inLen = XSTRLEN(c.input); - c.outLen = MD2_DIGEST_SIZE; + c.outLen = WC_MD2_DIGEST_SIZE; d.input = "message digest"; d.output = "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe" "\x06\xb0"; d.inLen = XSTRLEN(d.input); - d.outLen = MD2_DIGEST_SIZE; + d.outLen = WC_MD2_DIGEST_SIZE; e.input = "abcdefghijklmnopqrstuvwxyz"; e.output = "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47" "\x94\x0b"; e.inLen = XSTRLEN(e.input); - e.outLen = MD2_DIGEST_SIZE; + e.outLen = WC_MD2_DIGEST_SIZE; f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345" "6789"; f.output = "\xda\x33\xde\xf2\xa4\x2d\xf1\x39\x75\x35\x28\x46\xc3\x03" "\x38\xcd"; f.inLen = XSTRLEN(f.input); - f.outLen = MD2_DIGEST_SIZE; + f.outLen = WC_MD2_DIGEST_SIZE; g.input = "1234567890123456789012345678901234567890123456789012345678" "9012345678901234567890"; g.output = "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3" "\xef\xd8"; g.inLen = XSTRLEN(g.input); - g.outLen = MD2_DIGEST_SIZE; + g.outLen = WC_MD2_DIGEST_SIZE; test_md2[0] = a; test_md2[1] = b; @@ -3143,7 +3143,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void) wc_Md2Update(&md2, (byte*)test_md2[i].input, (word32)test_md2[i].inLen); wc_Md2Final(&md2, hash); - if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) + if (XMEMCMP(hash, test_md2[i].output, WC_MD2_DIGEST_SIZE) != 0) return WC_TEST_RET_ENC_I(i); } @@ -3153,7 +3153,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void) return WC_TEST_RET_ENC_I(i); } - if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) { + if (XMEMCMP(hash, test_md2[i].output, WC_MD2_DIGEST_SIZE) != 0) { return WC_TEST_RET_ENC_I(i); } } @@ -3296,8 +3296,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void) WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void) { - Md4 md4; - byte hash[MD4_DIGEST_SIZE]; + wc_Md4 md4; + byte hash[WC_MD4_DIGEST_SIZE]; testVector a, b, c, d, e, f, g; testVector test_md4[7]; @@ -3308,45 +3308,45 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void) a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89" "\xc0"; a.inLen = XSTRLEN(a.input); - a.outLen = MD4_DIGEST_SIZE; + a.outLen = WC_MD4_DIGEST_SIZE; b.input = "a"; b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb" "\x24"; b.inLen = XSTRLEN(b.input); - b.outLen = MD4_DIGEST_SIZE; + b.outLen = WC_MD4_DIGEST_SIZE; c.input = "abc"; c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72" "\x9d"; c.inLen = XSTRLEN(c.input); - c.outLen = MD4_DIGEST_SIZE; + c.outLen = WC_MD4_DIGEST_SIZE; d.input = "message digest"; d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01" "\x4b"; d.inLen = XSTRLEN(d.input); - d.outLen = MD4_DIGEST_SIZE; + d.outLen = WC_MD4_DIGEST_SIZE; e.input = "abcdefghijklmnopqrstuvwxyz"; e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d" "\xa9"; e.inLen = XSTRLEN(e.input); - e.outLen = MD4_DIGEST_SIZE; + e.outLen = WC_MD4_DIGEST_SIZE; f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345" "6789"; f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0" "\xe4"; f.inLen = XSTRLEN(f.input); - f.outLen = MD4_DIGEST_SIZE; + f.outLen = WC_MD4_DIGEST_SIZE; g.input = "1234567890123456789012345678901234567890123456789012345678" "9012345678901234567890"; g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05" "\x36"; g.inLen = XSTRLEN(g.input); - g.outLen = MD4_DIGEST_SIZE; + g.outLen = WC_MD4_DIGEST_SIZE; test_md4[0] = a; test_md4[1] = b; @@ -3362,7 +3362,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void) wc_Md4Update(&md4, (byte*)test_md4[i].input, (word32)test_md4[i].inLen); wc_Md4Final(&md4, hash); - if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0) + if (XMEMCMP(hash, test_md4[i].output, WC_MD4_DIGEST_SIZE) != 0) return WC_TEST_RET_ENC_I(i); } @@ -6318,7 +6318,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void) #if !defined(NO_CERTS) && !defined(NO_ASN) #if defined(WOLFSSL_MD2) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) - ret = wc_GetCTC_HashOID(MD2); + ret = wc_GetCTC_HashOID(WC_HASH_TYPE_MD2); if (ret == 0) return WC_TEST_RET_ENC_EC(ret); #endif @@ -9041,15 +9041,15 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void) #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) /* test the same vectors with using compatibility layer */ for (i = 0; i < sizeof(vector); i += DES_BLOCK_SIZE){ - DES_key_schedule ks1; - DES_key_schedule ks2; - DES_key_schedule ks3; - DES_cblock iv4; + WOLFSSL_DES_key_schedule ks1; + WOLFSSL_DES_key_schedule ks2; + WOLFSSL_DES_key_schedule ks3; + WOLFSSL_DES_cblock iv4; byte tmp[sizeof(vector)]; - XMEMCPY(ks1, key3, sizeof(DES_key_schedule)); - XMEMCPY(ks2, key3 + 8, sizeof(DES_key_schedule)); - XMEMCPY(ks3, key3 + 16, sizeof(DES_key_schedule)); + XMEMCPY(ks1, key3, sizeof(WOLFSSL_DES_key_schedule)); + XMEMCPY(ks2, key3 + 8, sizeof(WOLFSSL_DES_key_schedule)); + XMEMCPY(ks3, key3 + 16, sizeof(WOLFSSL_DES_key_schedule)); XMEMSET(plain, 0, sizeof(plain)); XMEMSET(cipher, 0, sizeof(cipher)); @@ -9058,17 +9058,17 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void) XMEMCPY(tmp, vector, sizeof(vector)); /* Use i as the splitter */ - XMEMCPY(iv4, iv3, sizeof(DES_cblock)); - DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3, - &iv4, DES_ENCRYPT); - DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i), - &ks1, &ks2, &ks3, &iv4, DES_ENCRYPT); + XMEMCPY(iv4, iv3, sizeof(WOLFSSL_DES_cblock)); + wolfSSL_DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3, + &iv4, WC_DES_ENCRYPT); + wolfSSL_DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i), + &ks1, &ks2, &ks3, &iv4, WC_DES_ENCRYPT); XMEMCPY(cipher, tmp, sizeof(cipher)); - XMEMCPY(iv4, iv3, sizeof(DES_cblock)); - DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3, - &iv4, DES_DECRYPT); - DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i), - &ks1, &ks2, &ks3, &iv4, DES_DECRYPT); + XMEMCPY(iv4, iv3, sizeof(WOLFSSL_DES_cblock)); + wolfSSL_DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3, + &iv4, WC_DES_DECRYPT); + wolfSSL_DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i), + &ks1, &ks2, &ks3, &iv4, WC_DES_DECRYPT); XMEMCPY(plain, tmp, sizeof(plain)); if (XMEMCMP(plain, vector, sizeof(plain))) @@ -9309,14 +9309,14 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #else Aes enc[1]; #endif - byte cipher[AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) Aes *dec = NULL; #else Aes dec[1]; #endif - byte plain [AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #endif wc_test_ret_t ret = 0; @@ -9368,19 +9368,19 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #endif XMEMSET(cipher, 0, sizeof(cipher)); - ret = wc_AesOfbEncrypt(enc, cipher, plain2, AES_BLOCK_SIZE); + ret = wc_AesOfbEncrypt(enc, cipher, plain2, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, cipher2, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesOfbDecrypt(dec, plain, cipher2, AES_BLOCK_SIZE); + ret = wc_AesOfbDecrypt(dec, plain, cipher2, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, plain2, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, plain2, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_128 */ @@ -9407,19 +9407,19 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #endif XMEMSET(cipher, 0, sizeof(cipher)); - ret = wc_AesOfbEncrypt(enc, cipher, plain3, AES_BLOCK_SIZE); + ret = wc_AesOfbEncrypt(enc, cipher, plain3, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, cipher3, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesOfbDecrypt(dec, plain, cipher3, AES_BLOCK_SIZE); + ret = wc_AesOfbDecrypt(dec, plain, cipher3, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, plain3, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, plain3, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_192 */ @@ -9446,37 +9446,37 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #endif XMEMSET(cipher, 0, sizeof(cipher)); - ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE); + ret = wc_AesOfbEncrypt(enc, cipher, plain1, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - ret = wc_AesOfbEncrypt(enc, cipher + AES_BLOCK_SIZE, - plain1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE); + ret = wc_AesOfbEncrypt(enc, cipher + WC_AES_BLOCK_SIZE, + plain1 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher + AES_BLOCK_SIZE, cipher1 + AES_BLOCK_SIZE, - AES_BLOCK_SIZE)) + if (XMEMCMP(cipher + WC_AES_BLOCK_SIZE, cipher1 + WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE); + ret = wc_AesOfbDecrypt(dec, plain, cipher1, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, plain1, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - ret = wc_AesOfbDecrypt(dec, plain + AES_BLOCK_SIZE, - cipher1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE); + ret = wc_AesOfbDecrypt(dec, plain + WC_AES_BLOCK_SIZE, + cipher1 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain + AES_BLOCK_SIZE, plain1 + AES_BLOCK_SIZE, - AES_BLOCK_SIZE)) + if (XMEMCMP(plain + WC_AES_BLOCK_SIZE, plain1 + WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ @@ -9492,19 +9492,19 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #endif XMEMSET(cipher, 0, sizeof(cipher)); - ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE * 3); + ret = wc_AesOfbEncrypt(enc, cipher, plain1, WC_AES_BLOCK_SIZE * 3); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 3)) + if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE * 3)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE * 3); + ret = wc_AesOfbDecrypt(dec, plain, cipher1, WC_AES_BLOCK_SIZE * 3); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE * 3)) + if (XMEMCMP(plain, plain1, WC_AES_BLOCK_SIZE * 3)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ @@ -9519,20 +9519,20 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - XMEMCPY(cipher, plain1, AES_BLOCK_SIZE * 2); - ret = wc_AesOfbEncrypt(enc, cipher, cipher, AES_BLOCK_SIZE * 2); + XMEMCPY(cipher, plain1, WC_AES_BLOCK_SIZE * 2); + ret = wc_AesOfbEncrypt(enc, cipher, cipher, WC_AES_BLOCK_SIZE * 2); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2)) + if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE * 2)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesOfbDecrypt(dec, cipher, cipher, AES_BLOCK_SIZE * 2); + ret = wc_AesOfbDecrypt(dec, cipher, cipher, WC_AES_BLOCK_SIZE * 2); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, plain1, AES_BLOCK_SIZE * 2)) + if (XMEMCMP(cipher, plain1, WC_AES_BLOCK_SIZE * 2)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ @@ -9555,11 +9555,11 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, if (XMEMCMP(cipher, cipher1, 3)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - ret = wc_AesOfbEncrypt(enc, cipher + 3, plain1 + 3, AES_BLOCK_SIZE); + ret = wc_AesOfbEncrypt(enc, cipher + 3, plain1 + 3, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher + 3, cipher1 + 3, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher + 3, cipher1 + 3, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT @@ -9570,11 +9570,11 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, if (XMEMCMP(plain, plain1, 6)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - ret = wc_AesOfbDecrypt(dec, plain + 6, cipher1 + 6, AES_BLOCK_SIZE); + ret = wc_AesOfbDecrypt(dec, plain + 6, cipher1 + 6, WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain + 6, plain1 + 6, AES_BLOCK_SIZE)) + if (XMEMCMP(plain + 6, plain1 + 6, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ @@ -9610,14 +9610,14 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #else Aes enc[1]; #endif - byte cipher[AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) Aes *dec = NULL; #else Aes dec[1]; #endif - byte plain [AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #endif wc_test_ret_t ret = 0; @@ -9758,40 +9758,40 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, } #endif - ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(enc, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT /* decrypt uses AES_ENCRYPTION */ - ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(dec, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif XMEMSET(cipher, 0, sizeof(cipher)); - ret = wc_AesCfbEncrypt(enc, cipher, msg1, AES_BLOCK_SIZE * 2); + ret = wc_AesCfbEncrypt(enc, cipher, msg1, WC_AES_BLOCK_SIZE * 2); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2)) + if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE * 2)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* test restarting encryption process */ - ret = wc_AesCfbEncrypt(enc, cipher + (AES_BLOCK_SIZE * 2), - msg1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE); + ret = wc_AesCfbEncrypt(enc, cipher + (WC_AES_BLOCK_SIZE * 2), + msg1 + (WC_AES_BLOCK_SIZE * 2), WC_AES_BLOCK_SIZE); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher + (AES_BLOCK_SIZE * 2), - cipher1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE)) + if (XMEMCMP(cipher + (WC_AES_BLOCK_SIZE * 2), + cipher1 + (WC_AES_BLOCK_SIZE * 2), WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 3); + ret = wc_AesCfbDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE * 3); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, msg1, AES_BLOCK_SIZE * 3)) + if (XMEMCMP(plain, msg1, WC_AES_BLOCK_SIZE * 3)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_128 */ @@ -9818,19 +9818,19 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #endif XMEMSET(cipher, 0, sizeof(cipher)); - ret = wc_AesCfbEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE * 4); + ret = wc_AesCfbEncrypt(enc, cipher, msg2, WC_AES_BLOCK_SIZE * 4); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE * 4)) + if (XMEMCMP(cipher, cipher2, WC_AES_BLOCK_SIZE * 4)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 4); + ret = wc_AesCfbDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE * 4); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE * 4)) + if (XMEMCMP(plain, msg2, WC_AES_BLOCK_SIZE * 4)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_192 */ @@ -9872,11 +9872,11 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_AesCfbEncrypt(enc, cipher + 31, msg3 + 31, - (AES_BLOCK_SIZE * 4) - 31); + (WC_AES_BLOCK_SIZE * 4) - 31); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE * 4)) + if (XMEMCMP(cipher, cipher3, WC_AES_BLOCK_SIZE * 4)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT @@ -9899,11 +9899,11 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_AesCfbDecrypt(dec, plain + 31, cipher + 31, - (AES_BLOCK_SIZE * 4) - 31); + (WC_AES_BLOCK_SIZE * 4) - 31); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, msg3, AES_BLOCK_SIZE * 4)) + if (XMEMCMP(plain, msg3, WC_AES_BLOCK_SIZE * 4)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_256 */ @@ -9934,14 +9934,14 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #else Aes enc[1]; #endif - byte cipher[AES_BLOCK_SIZE]; + byte cipher[WC_AES_BLOCK_SIZE]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) Aes *dec = NULL; #else Aes dec[1]; #endif - byte plain [AES_BLOCK_SIZE]; + byte plain [WC_AES_BLOCK_SIZE]; #endif wc_test_ret_t ret = 0; @@ -10046,12 +10046,12 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #ifdef WOLFSSL_AES_128 /* 128 key tests */ - ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(enc, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT /* decrypt uses AES_ENCRYPTION */ - ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(dec, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif @@ -10083,7 +10083,7 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef OPENSSL_EXTRA - ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(enc, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); @@ -10195,14 +10195,14 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #else Aes enc[1]; #endif - byte cipher[AES_BLOCK_SIZE]; + byte cipher[WC_AES_BLOCK_SIZE]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) Aes *dec = NULL; #else Aes dec[1]; #endif - byte plain [AES_BLOCK_SIZE]; + byte plain [WC_AES_BLOCK_SIZE]; #endif wc_test_ret_t ret = 0; @@ -10311,12 +10311,12 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, return ret; } #endif - ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(enc, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT /* decrypt uses AES_ENCRYPTION */ - ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(dec, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif @@ -10552,8 +10552,8 @@ static wc_test_ret_t aes_xts_128_test(void) #endif int aes_inited = 0; wc_test_ret_t ret = 0; - unsigned char buf[AES_BLOCK_SIZE * 2 + 8]; - unsigned char cipher[AES_BLOCK_SIZE * 2 + 8]; + unsigned char buf[WC_AES_BLOCK_SIZE * 2 + 8]; + unsigned char cipher[WC_AES_BLOCK_SIZE * 2 + 8]; #ifdef WOLFSSL_AESXTS_STREAM struct XtsAesStreamData stream; #endif @@ -10698,14 +10698,14 @@ static wc_test_ret_t aes_xts_128_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -10741,7 +10741,7 @@ static wc_test_ret_t aes_xts_128_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef WOLFSSL_AESXTS_STREAM @@ -10780,7 +10780,7 @@ static wc_test_ret_t aes_xts_128_test(void) WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif @@ -10941,7 +10941,7 @@ static wc_test_ret_t aes_xts_128_test(void) WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif @@ -11003,14 +11003,14 @@ static wc_test_ret_t aes_xts_128_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, buf, p3, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p3 + WC_AES_BLOCK_SIZE, sizeof(p3) - WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -11045,14 +11045,14 @@ static wc_test_ret_t aes_xts_128_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptUpdate(aes, buf, c3, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptFinal(aes, buf + WC_AES_BLOCK_SIZE, c3 + WC_AES_BLOCK_SIZE, sizeof(c3) - WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -11134,17 +11134,17 @@ static wc_test_ret_t aes_xts_128_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } @@ -11196,11 +11196,11 @@ static wc_test_ret_t aes_xts_128_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, @@ -11211,7 +11211,7 @@ static wc_test_ret_t aes_xts_128_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } @@ -11256,8 +11256,8 @@ static wc_test_ret_t aes_xts_192_test(void) #endif int aes_inited = 0; wc_test_ret_t ret = 0; - unsigned char buf[AES_BLOCK_SIZE * 2 + 8]; - unsigned char cipher[AES_BLOCK_SIZE * 2 + 8]; + unsigned char buf[WC_AES_BLOCK_SIZE * 2 + 8]; + unsigned char cipher[WC_AES_BLOCK_SIZE * 2 + 8]; #ifdef WOLFSSL_AESXTS_STREAM struct XtsAesStreamData stream; #endif @@ -11398,14 +11398,14 @@ static wc_test_ret_t aes_xts_192_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -11441,7 +11441,7 @@ static wc_test_ret_t aes_xts_192_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef WOLFSSL_AESXTS_STREAM @@ -11480,7 +11480,7 @@ static wc_test_ret_t aes_xts_192_test(void) WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif @@ -11641,7 +11641,7 @@ static wc_test_ret_t aes_xts_192_test(void) WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif @@ -11703,14 +11703,14 @@ static wc_test_ret_t aes_xts_192_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, buf, p3, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p3 + WC_AES_BLOCK_SIZE, sizeof(p3) - WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -11745,14 +11745,14 @@ static wc_test_ret_t aes_xts_192_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptUpdate(aes, buf, c3, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptFinal(aes, buf + WC_AES_BLOCK_SIZE, c3 + WC_AES_BLOCK_SIZE, sizeof(c3) - WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -11834,17 +11834,17 @@ static wc_test_ret_t aes_xts_192_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } @@ -11896,11 +11896,11 @@ static wc_test_ret_t aes_xts_192_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, @@ -11911,7 +11911,7 @@ static wc_test_ret_t aes_xts_192_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } @@ -11957,8 +11957,8 @@ static wc_test_ret_t aes_xts_256_test(void) #endif int aes_inited = 0; wc_test_ret_t ret = 0; - unsigned char buf[AES_BLOCK_SIZE * 3]; - unsigned char cipher[AES_BLOCK_SIZE * 3]; + unsigned char buf[WC_AES_BLOCK_SIZE * 3]; + unsigned char cipher[WC_AES_BLOCK_SIZE * 3]; #ifdef WOLFSSL_AESXTS_STREAM struct XtsAesStreamData stream; #endif @@ -12086,14 +12086,14 @@ static wc_test_ret_t aes_xts_256_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -12114,7 +12114,7 @@ static wc_test_ret_t aes_xts_256_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef WOLFSSL_AESXTS_STREAM @@ -12290,17 +12290,17 @@ static wc_test_ret_t aes_xts_256_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } @@ -12351,11 +12351,11 @@ static wc_test_ret_t aes_xts_256_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - for (k = 0; k < j; k += AES_BLOCK_SIZE) { - if ((j - k) < AES_BLOCK_SIZE*2) + for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) { + if ((j - k) < WC_AES_BLOCK_SIZE*2) ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream); else - ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream); + ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream); #if defined(WOLFSSL_ASYNC_CRYPT) #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, @@ -12366,7 +12366,7 @@ static wc_test_ret_t aes_xts_256_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if ((j - k) < AES_BLOCK_SIZE*2) + if ((j - k) < WC_AES_BLOCK_SIZE*2) break; } @@ -12413,7 +12413,7 @@ static wc_test_ret_t aes_xts_sector_test(void) #endif int aes_inited = 0; wc_test_ret_t ret = 0; - unsigned char buf[AES_BLOCK_SIZE * 2]; + unsigned char buf[WC_AES_BLOCK_SIZE * 2]; /* 128 key tests */ WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = { @@ -12601,7 +12601,7 @@ static wc_test_ret_t aes_xts_sector_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* decrypt test */ @@ -12619,7 +12619,7 @@ static wc_test_ret_t aes_xts_sector_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) + if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* 256 bit key tests */ @@ -12717,7 +12717,7 @@ static wc_test_ret_t aes_xts_args_test(void) #endif int aes_inited = 0; wc_test_ret_t ret; - unsigned char buf[AES_BLOCK_SIZE * 2]; + unsigned char buf[WC_AES_BLOCK_SIZE * 2]; /* 128 key tests */ WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = { @@ -12819,8 +12819,8 @@ static wc_test_ret_t aes_xts_args_test(void) !defined(HAVE_RENESAS_SYNC) static wc_test_ret_t aes_cbc_oneshot_test(void) { - byte cipher[AES_BLOCK_SIZE]; - byte plain[AES_BLOCK_SIZE]; + byte cipher[WC_AES_BLOCK_SIZE]; + byte plain[WC_AES_BLOCK_SIZE]; wc_test_ret_t ret; WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */ 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74, @@ -12830,29 +12830,29 @@ static wc_test_ret_t aes_cbc_oneshot_test(void) byte key[] = "0123456789abcdef "; /* align */ 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); /* Parameter Validation testing. */ - ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL); + ret = wc_AesCbcEncryptWithKey(cipher, msg, WC_AES_BLOCK_SIZE, key, 17, NULL); if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_AES_DECRYPT - ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL); + ret = wc_AesCbcDecryptWithKey(plain, cipher, WC_AES_BLOCK_SIZE, key, 17, NULL); if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) return WC_TEST_RET_ENC_EC(ret); #endif - ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, - AES_BLOCK_SIZE, iv); + ret = wc_AesCbcEncryptWithKey(cipher, msg, WC_AES_BLOCK_SIZE, key, + WC_AES_BLOCK_SIZE, iv); if (ret != 0) return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_AES_DECRYPT - ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, - AES_BLOCK_SIZE, iv); + ret = wc_AesCbcDecryptWithKey(plain, cipher, WC_AES_BLOCK_SIZE, key, + WC_AES_BLOCK_SIZE, iv); if (ret != 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0) + if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE) != 0) return WC_TEST_RET_ENC_NC; #endif /* HAVE_AES_DECRYPT */ @@ -12871,8 +12871,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void) Aes enc[1]; Aes dec[1]; #endif - byte cipher[AES_BLOCK_SIZE * 4]; - byte plain [AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; wc_test_ret_t ret = 0; /* test vectors from "Recommendation for Block Cipher Modes of @@ -13602,15 +13602,15 @@ static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain) 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }; - WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[AES_BLOCK_SIZE] = { + WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[WC_AES_BLOCK_SIZE] = { 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6, 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1 }; - WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[AES_BLOCK_SIZE] = { + WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[WC_AES_BLOCK_SIZE] = { 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1, 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab }; - WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[AES_BLOCK_SIZE] = { + WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[WC_AES_BLOCK_SIZE] = { 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33, 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82 }; @@ -13657,26 +13657,26 @@ static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - XMEMSET(cipher, 0, AES_BLOCK_SIZE); - ret = wc_AesEcbEncrypt(enc, cipher, testVec[i].plain, AES_BLOCK_SIZE); + XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE); + ret = wc_AesEcbEncrypt(enc, cipher, testVec[i].plain, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher, testVec[i].verify, AES_BLOCK_SIZE)) { + if (XMEMCMP(cipher, testVec[i].verify, WC_AES_BLOCK_SIZE)) { WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!"); ERROR_OUT(WC_TEST_RET_ENC_I(i), out); } #ifdef HAVE_AES_DECRYPT - XMEMSET(plain, 0, AES_BLOCK_SIZE); - ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE); + XMEMSET(plain, 0, WC_AES_BLOCK_SIZE); + ret = wc_AesEcbDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, testVec[i].plain, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, testVec[i].plain, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_I(i), out); #endif /* HAVE_AES_DECRYPT */ (void)dec; @@ -13717,7 +13717,7 @@ static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* pla 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 }; - XMEMSET(cipher, 0, AES_BLOCK_SIZE); + XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE); ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); @@ -13731,11 +13731,11 @@ static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* pla #else wc_AesEncryptDirect(enc, cipher, niPlain); #endif - if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0) + if (XMEMCMP(cipher, niCipher, WC_AES_BLOCK_SIZE) != 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - XMEMSET(plain, 0, AES_BLOCK_SIZE); + XMEMSET(plain, 0, WC_AES_BLOCK_SIZE); ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); @@ -13749,7 +13749,7 @@ static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* pla #else wc_AesDecryptDirect(dec, plain, niCipher); #endif - if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0) + if (XMEMCMP(plain, niPlain, WC_AES_BLOCK_SIZE) != 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ } @@ -13778,9 +13778,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void) Aes dec[1]; #endif #endif - byte cipher[AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; #ifdef HAVE_AES_DECRYPT - byte plain [AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #endif wc_test_ret_t ret = 0; @@ -13832,17 +13832,17 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void) /* padded to 16-bytes */ WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef "; - ret = wc_AesSetKey(enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); + ret = wc_AesSetKey(enc, key, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - ret = wc_AesSetKey(dec, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION); + ret = wc_AesSetKey(dec, key, WC_AES_BLOCK_SIZE, iv, AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif XMEMSET(cipher, 0, sizeof(cipher)); - ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE); + ret = wc_AesCbcEncrypt(enc, cipher, msg, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -13850,7 +13850,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT XMEMSET(plain, 0, sizeof(plain)); - ret = wc_AesCbcDecrypt(dec, plain, cipher, AES_BLOCK_SIZE); + ret = wc_AesCbcDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -13859,14 +13859,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) { + if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) { WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare"); ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif /* HAVE_AES_DECRYPT */ /* skipped because wrapped key use in case of renesas sm */ #ifndef HAVE_RENESAS_SYNC - if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) { + if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) { WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare"); ERROR_OUT(WC_TEST_RET_ENC_NC, out); } @@ -13949,12 +13949,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void) byte bigPlain[sizeof(bigMsg)]; #endif - /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole - * message by AES_BLOCK_SIZE for each size of AES key. */ + /* Iterate from one WC_AES_BLOCK_SIZE of bigMsg through the whole + * message by WC_AES_BLOCK_SIZE for each size of AES key. */ for (keySz = 16; keySz <= 32; keySz += 8) { - for (msgSz = AES_BLOCK_SIZE; + for (msgSz = WC_AES_BLOCK_SIZE; msgSz <= sizeof(bigMsg); - msgSz += AES_BLOCK_SIZE) { + msgSz += WC_AES_BLOCK_SIZE) { XMEMSET(bigCipher, 0, sizeof(bigMsg)); XMEMSET(bigPlain, 0, sizeof(bigMsg)); @@ -13997,13 +13997,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void) } #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK) - /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole - * message by AES_BLOCK_SIZE for each size of AES key. */ + /* Iterate from one WC_AES_BLOCK_SIZE of bigMsg through the whole + * message by WC_AES_BLOCK_SIZE for each size of AES key. */ WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E)); for (keySz = 16; keySz <= 32; keySz += 8) { - for (msgSz = AES_BLOCK_SIZE; + for (msgSz = WC_AES_BLOCK_SIZE; msgSz <= sizeof(bigMsg); - msgSz += AES_BLOCK_SIZE) { + msgSz += WC_AES_BLOCK_SIZE) { XMEMSET(bigCipher, 0, sizeof(bigMsg)); XMEMSET(bigPlain, 0, sizeof(bigMsg)); @@ -14091,51 +14091,51 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void) ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - XMEMSET(cipher, 0, AES_BLOCK_SIZE * 2); - ret = wc_AesCbcEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE); + XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE * 2); + ret = wc_AesCbcEncrypt(enc, cipher, msg2, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifndef HAVE_RENESAS_SYNC - if (XMEMCMP(cipher, verify2, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, verify2, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif - ret = wc_AesCbcEncrypt(enc, cipher + AES_BLOCK_SIZE, - msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE); + ret = wc_AesCbcEncrypt(enc, cipher + WC_AES_BLOCK_SIZE, + msg2 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(cipher + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE, - AES_BLOCK_SIZE)) + if (XMEMCMP(cipher + WC_AES_BLOCK_SIZE, verify2 + WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #if defined(HAVE_AES_DECRYPT) ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - XMEMSET(plain, 0, AES_BLOCK_SIZE * 2); - ret = wc_AesCbcDecrypt(dec, plain, verify2, AES_BLOCK_SIZE); + XMEMSET(plain, 0, WC_AES_BLOCK_SIZE * 2); + ret = wc_AesCbcDecrypt(dec, plain, verify2, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, msg2, WC_AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - ret = wc_AesCbcDecrypt(dec, plain + AES_BLOCK_SIZE, - verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE); + ret = wc_AesCbcDecrypt(dec, plain + WC_AES_BLOCK_SIZE, + verify2 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(plain + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE, - AES_BLOCK_SIZE)) { + if (XMEMCMP(plain + WC_AES_BLOCK_SIZE, msg2 + WC_AES_BLOCK_SIZE, + WC_AES_BLOCK_SIZE)) { WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare"); ERROR_OUT(WC_TEST_RET_ENC_NC, out); } @@ -14178,8 +14178,8 @@ static wc_test_ret_t aes_ecb_direct_test(void) #else Aes dec[1]; #endif - byte cipher[AES_BLOCK_SIZE]; - byte plain [AES_BLOCK_SIZE]; + byte cipher[WC_AES_BLOCK_SIZE]; + byte plain [WC_AES_BLOCK_SIZE]; wc_test_ret_t ret = 0; WOLFSSL_ENTER("aes_ecb/direct_test"); @@ -14328,14 +14328,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void) #else Aes enc[1]; #endif - byte cipher[AES_BLOCK_SIZE]; + byte cipher[WC_AES_BLOCK_SIZE]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) Aes *dec = NULL; #else Aes dec[1]; #endif - byte plain[AES_BLOCK_SIZE]; + byte plain[WC_AES_BLOCK_SIZE]; #endif /* Test vectors from NIST Special Publication 800-38A, 2001 Edition @@ -14396,7 +14396,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - XMEMSET(cipher, 0, AES_BLOCK_SIZE); + XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE); ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); @@ -14407,7 +14407,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - XMEMSET(plain, 0, AES_BLOCK_SIZE); + XMEMSET(plain, 0, WC_AES_BLOCK_SIZE); ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); @@ -14449,14 +14449,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) #else Aes enc[1]; #endif - byte cipher[AES_BLOCK_SIZE]; + byte cipher[WC_AES_BLOCK_SIZE]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) Aes *dec = NULL; #else Aes dec[1]; #endif - byte plain[AES_BLOCK_SIZE]; + byte plain[WC_AES_BLOCK_SIZE]; #endif #endif /* HAVE_AES_CBC */ wc_test_ret_t ret = 0; @@ -14526,7 +14526,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - XMEMSET(cipher, 0, AES_BLOCK_SIZE); + XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE); ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); @@ -14534,7 +14534,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - XMEMSET(plain, 0, AES_BLOCK_SIZE); + XMEMSET(plain, 0, WC_AES_BLOCK_SIZE); ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); @@ -14560,7 +14560,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - XMEMSET(cipher, 0, AES_BLOCK_SIZE); + XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE); WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E)); ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -14570,7 +14570,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - XMEMSET(plain, 0, AES_BLOCK_SIZE); + XMEMSET(plain, 0, WC_AES_BLOCK_SIZE); WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E)); ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -14601,7 +14601,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - XMEMSET(cipher, 0, AES_BLOCK_SIZE); + XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE); ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); @@ -14609,7 +14609,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - XMEMSET(plain, 0, AES_BLOCK_SIZE); + XMEMSET(plain, 0, WC_AES_BLOCK_SIZE); ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); @@ -14664,9 +14664,9 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, Aes dec[1]; #endif - byte resultT[AES_BLOCK_SIZE]; - byte resultP[AES_BLOCK_SIZE * 3]; - byte resultC[AES_BLOCK_SIZE * 3]; + byte resultT[WC_AES_BLOCK_SIZE]; + byte resultP[WC_AES_BLOCK_SIZE * 3]; + byte resultC[WC_AES_BLOCK_SIZE * 3]; XMEMSET(resultT, 0, sizeof(resultT)); XMEMSET(resultC, 0, sizeof(resultC)); @@ -15059,15 +15059,15 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) #endif #endif - byte resultT[sizeof(t1) + AES_BLOCK_SIZE]; - byte resultP[sizeof(p) + AES_BLOCK_SIZE]; - byte resultC[sizeof(p) + AES_BLOCK_SIZE]; + byte resultT[sizeof(t1) + WC_AES_BLOCK_SIZE]; + byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE]; + byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE]; wc_test_ret_t ret = 0; int alen = 0; int plen = 0; #if defined(WOLFSSL_XILINX_CRYPT_VERSAL) - byte buf[sizeof(p) + AES_BLOCK_SIZE]; + byte buf[sizeof(p) + WC_AES_BLOCK_SIZE]; byte bufA[sizeof(a) + 1]; byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -15079,7 +15079,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) #ifndef WOLFSSL_NO_MALLOC byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); (void)alen; @@ -15090,12 +15090,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) #else byte large_input[BENCH_AESGCM_LARGE]; - byte large_output[BENCH_AESGCM_LARGE + AES_BLOCK_SIZE]; + byte large_output[BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE]; byte large_outdec[BENCH_AESGCM_LARGE]; #endif XMEMSET(large_input, 0, BENCH_AESGCM_LARGE); - XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + AES_BLOCK_SIZE); + XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE); XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE); #endif WOLFSSL_ENTER("aesgcm_test"); @@ -15600,7 +15600,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) #endif /* alen is the size to pass in with each update. */ - for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) { + for (alen = 1; alen < WC_AES_BLOCK_SIZE + 1; alen++) { ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); @@ -15632,7 +15632,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) } #ifdef HAVE_AES_DECRYPT - for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) { + for (alen = 1; alen < WC_AES_BLOCK_SIZE + 1; alen++) { ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); @@ -16256,15 +16256,15 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void) typedef struct { byte key[AES_256_KEY_SIZE]; int key_length; - byte iv[AES_BLOCK_SIZE]; + byte iv[WC_AES_BLOCK_SIZE]; int iv_length; - byte aad[AES_BLOCK_SIZE * 2]; + byte aad[WC_AES_BLOCK_SIZE * 2]; int aad_length; - byte msg[AES_BLOCK_SIZE * 2]; + byte msg[WC_AES_BLOCK_SIZE * 2]; int msg_length; - byte ct[AES_BLOCK_SIZE * 2]; + byte ct[WC_AES_BLOCK_SIZE * 2]; int ct_length; - byte tag[AES_BLOCK_SIZE]; + byte tag[WC_AES_BLOCK_SIZE]; int tag_length; int valid; } AadVector; @@ -16637,7 +16637,7 @@ WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo) 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6, 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF, 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B }; - byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[AES_BLOCK_SIZE]; + byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[WC_AES_BLOCK_SIZE]; word32 keySz, adSz = 256, authTagSz = sizeof(authTag); wc_Aria aria; @@ -16817,8 +16817,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void) 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA }; - byte out[CAMELLIA_BLOCK_SIZE]; - Camellia cam; + byte out[WC_CAMELLIA_BLOCK_SIZE]; + wc_Camellia cam; WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] = { {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114}, @@ -16849,28 +16849,28 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void) ret = wc_CamelliaEncryptDirect(&cam, out, testVectors[i].plaintext); if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext, - CAMELLIA_BLOCK_SIZE)) + WC_CAMELLIA_BLOCK_SIZE)) return testVectors[i].errorCode; break; case CAM_ECB_DEC: ret = wc_CamelliaDecryptDirect(&cam, out, testVectors[i].ciphertext); if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext, - CAMELLIA_BLOCK_SIZE)) + WC_CAMELLIA_BLOCK_SIZE)) return testVectors[i].errorCode; break; case CAM_CBC_ENC: ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext, - CAMELLIA_BLOCK_SIZE); + WC_CAMELLIA_BLOCK_SIZE); if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext, - CAMELLIA_BLOCK_SIZE)) + WC_CAMELLIA_BLOCK_SIZE)) return testVectors[i].errorCode; break; case CAM_CBC_DEC: ret = wc_CamelliaCbcDecrypt(&cam, out, - testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE); + testVectors[i].ciphertext, WC_CAMELLIA_BLOCK_SIZE); if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext, - CAMELLIA_BLOCK_SIZE)) + WC_CAMELLIA_BLOCK_SIZE)) return testVectors[i].errorCode; break; default: @@ -16882,14 +16882,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void) ret = wc_CamelliaSetIV(&cam, ivc); if (ret != 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE) != 0) + if (XMEMCMP(cam.reg, ivc, WC_CAMELLIA_BLOCK_SIZE) != 0) return WC_TEST_RET_ENC_NC; /* Setting the IV to NULL should be same as all zeros IV */ ret = wc_CamelliaSetIV(&cam, NULL); if (ret != 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE) != 0) + if (XMEMCMP(cam.reg, ive, WC_CAMELLIA_BLOCK_SIZE) != 0) return WC_TEST_RET_ENC_NC; /* First parameter should never be null */ @@ -23713,8 +23713,8 @@ static wc_test_ret_t openssl_aes_test(void) WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef "; /* align */ - byte cipher[AES_BLOCK_SIZE * 4]; - byte plain [AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new(); WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new(); @@ -23870,7 +23870,7 @@ static wc_test_ret_t openssl_aes_test(void) return WC_TEST_RET_ENC_NC; /* test byte by byte decrypt */ - for (i = 0; i < AES_BLOCK_SIZE * 3; i++) { + for (i = 0; i < WC_AES_BLOCK_SIZE * 3; i++) { plain[i] = i; } @@ -23882,15 +23882,15 @@ static wc_test_ret_t openssl_aes_test(void) (unsigned char*)key, (unsigned char*)iv, 1) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen, - (byte*)plain, AES_BLOCK_SIZE * 3) == 0) + (byte*)plain, WC_AES_BLOCK_SIZE * 3) == 0) return WC_TEST_RET_ENC_NC; - if (outlen != AES_BLOCK_SIZE * 3) + if (outlen != WC_AES_BLOCK_SIZE * 3) return WC_TEST_RET_ENC_NC; total += outlen; if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0) return WC_TEST_RET_ENC_NC; - if (outlen != AES_BLOCK_SIZE) + if (outlen != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; total += outlen; if (total != sizeof(plain)) @@ -23904,7 +23904,7 @@ static wc_test_ret_t openssl_aes_test(void) (unsigned char*)key, (unsigned char*)iv, 0) == 0) return WC_TEST_RET_ENC_NC; - for (i = 0; i < AES_BLOCK_SIZE * 4; i++) { + for (i = 0; i < WC_AES_BLOCK_SIZE * 4; i++) { if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain + total, &outlen, (byte*)cipher + i, 1) == 0) return WC_TEST_RET_ENC_NC; @@ -23924,10 +23924,10 @@ static wc_test_ret_t openssl_aes_test(void) if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0) return WC_TEST_RET_ENC_NC; total += outlen; - if (total != AES_BLOCK_SIZE * 3) { + if (total != WC_AES_BLOCK_SIZE * 3) { return WC_TEST_RET_ENC_NC; } - for (i = 0; i < AES_BLOCK_SIZE * 3; i++) { + for (i = 0; i < WC_AES_BLOCK_SIZE * 3; i++) { if (plain[i] != i) { return WC_TEST_RET_ENC_NC; } @@ -24097,8 +24097,8 @@ static wc_test_ret_t openssl_aes_test(void) WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef "; /* align */ - byte cipher[AES_BLOCK_SIZE * 4]; - byte plain [AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (ctx == NULL) @@ -24112,7 +24112,7 @@ static wc_test_ret_t openssl_aes_test(void) if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_cleanup(ctx); @@ -24124,7 +24124,7 @@ static wc_test_ret_t openssl_aes_test(void) if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_cleanup(ctx); @@ -24166,8 +24166,8 @@ static wc_test_ret_t openssl_aes_test(void) }; - byte cipher[AES_BLOCK_SIZE * 4]; - byte plain [AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (ctx == NULL) @@ -24181,7 +24181,7 @@ static wc_test_ret_t openssl_aes_test(void) if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(ctx); @@ -24191,7 +24191,7 @@ static wc_test_ret_t openssl_aes_test(void) if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -24205,14 +24205,14 @@ static wc_test_ret_t openssl_aes_test(void) { /* Test: AES_encrypt/decrypt/set Key */ #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES); + WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES); #ifdef HAVE_AES_DECRYPT - AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES); + WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES); #endif #else - AES_KEY enc[1]; + WOLFSSL_AES_KEY enc[1]; #ifdef HAVE_AES_DECRYPT - AES_KEY dec[1]; + WOLFSSL_AES_KEY dec[1]; #endif #endif @@ -24248,18 +24248,18 @@ static wc_test_ret_t openssl_aes_test(void) #endif #endif - AES_set_encrypt_key(key, sizeof(key)*8, enc); - AES_set_decrypt_key(key, sizeof(key)*8, dec); + wolfSSL_AES_set_encrypt_key(key, sizeof(key)*8, enc); + wolfSSL_AES_set_decrypt_key(key, sizeof(key)*8, dec); - AES_encrypt(msg, cipher, enc); + wolfSSL_AES_encrypt(msg, cipher, enc); #ifdef HAVE_AES_DECRYPT - AES_decrypt(cipher, plain, dec); - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) + wolfSSL_AES_decrypt(cipher, plain, dec); + if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; #endif /* HAVE_AES_DECRYPT */ - if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -24409,7 +24409,7 @@ static wc_test_ret_t openssl_aes_test(void) (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(de); if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(), @@ -24417,7 +24417,7 @@ static wc_test_ret_t openssl_aes_test(void) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) @@ -24425,9 +24425,9 @@ static wc_test_ret_t openssl_aes_test(void) if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) + if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) + if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -24442,14 +24442,14 @@ static wc_test_ret_t openssl_aes_test(void) (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) @@ -24461,9 +24461,9 @@ static wc_test_ret_t openssl_aes_test(void) wolfSSL_EVP_CIPHER_CTX_free(p_de); #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */ - if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) + if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) + if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(en); @@ -24508,7 +24508,7 @@ static wc_test_ret_t openssl_aes_test(void) (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(de); if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(), @@ -24517,7 +24517,7 @@ static wc_test_ret_t openssl_aes_test(void) XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain))) @@ -24537,7 +24537,7 @@ static wc_test_ret_t openssl_aes_test(void) (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(de); if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(), @@ -24546,7 +24546,7 @@ static wc_test_ret_t openssl_aes_test(void) XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain))) @@ -24573,11 +24573,11 @@ static wc_test_ret_t openssl_aes_test(void) #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128) { #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES); - AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES); + WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES); + WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES); #else - AES_KEY enc[1]; - AES_KEY dec[1]; + WOLFSSL_AES_KEY enc[1]; + WOLFSSL_AES_KEY dec[1]; #endif WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = { @@ -24607,8 +24607,8 @@ static wc_test_ret_t openssl_aes_test(void) 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51 }; - byte cipher[AES_BLOCK_SIZE * 2]; - byte iv[AES_BLOCK_SIZE]; /* iv buffer is updeated by API */ + byte cipher[WC_AES_BLOCK_SIZE * 2]; + byte iv[WC_AES_BLOCK_SIZE]; /* iv buffer is updeated by API */ int num = 0; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -24620,20 +24620,20 @@ static wc_test_ret_t openssl_aes_test(void) wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc); wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec); - wolfSSL_AES_cfb128_encrypt(msg, cipher, AES_BLOCK_SIZE - 1, enc, iv, - &num, AES_ENCRYPT); + wolfSSL_AES_cfb128_encrypt(msg, cipher, WC_AES_BLOCK_SIZE - 1, enc, iv, + &num, AES_ENCRYPTION); - if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE - 1)) + if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE - 1)) return WC_TEST_RET_ENC_NC; if (num != 15) /* should have used 15 of the 16 bytes */ return WC_TEST_RET_ENC_NC; - wolfSSL_AES_cfb128_encrypt(msg + AES_BLOCK_SIZE - 1, - cipher + AES_BLOCK_SIZE - 1, AES_BLOCK_SIZE + 1, enc, iv, - &num, AES_ENCRYPT); + wolfSSL_AES_cfb128_encrypt(msg + WC_AES_BLOCK_SIZE - 1, + cipher + WC_AES_BLOCK_SIZE - 1, WC_AES_BLOCK_SIZE + 1, enc, iv, + &num, AES_ENCRYPTION); - if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2)) + if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE * 2)) return WC_TEST_RET_ENC_NC; if (num != 0) @@ -25007,23 +25007,23 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) }; byte plain[24]; byte cipher[24]; - const_DES_cblock key = { + WOLFSSL_const_DES_cblock key = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef }; - DES_cblock iv = { + WOLFSSL_DES_cblock iv = { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef }; - DES_key_schedule sched; + WOLFSSL_DES_key_schedule sched; WOLFSSL_SMALL_STACK_STATIC const byte verify[] = { 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8, 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73, 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b }; - DES_key_sched(&key, &sched); + wolfSSL_DES_key_sched(&key, &sched); - DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, DES_ENCRYPT); - DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, DES_DECRYPT); + wolfSSL_DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, WC_DES_ENCRYPT); + wolfSSL_DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, WC_DES_DECRYPT); if (XMEMCMP(plain, vector, sizeof(vector)) != 0) return WC_TEST_RET_ENC_NC; @@ -25032,8 +25032,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) return WC_TEST_RET_ENC_NC; /* test changing iv */ - DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, DES_ENCRYPT); - DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, DES_ENCRYPT); + wolfSSL_DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, WC_DES_ENCRYPT); + wolfSSL_DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, WC_DES_ENCRYPT); if (XMEMCMP(cipher, verify, sizeof(verify)) != 0) return WC_TEST_RET_ENC_NC; @@ -25074,8 +25074,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) "0123456789abcdef "; /* align */ WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef "; /* align */ - byte cipher[AES_BLOCK_SIZE * 4]; - byte plain [AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (ctx == NULL) @@ -25147,7 +25147,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) wolfSSL_EVP_CIPHER_CTX_init(ctx); ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1); if (ret == WOLFSSL_SUCCESS) { - ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, msg, AES_BLOCK_SIZE); + ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, msg, WC_AES_BLOCK_SIZE); if (ret == WOLFSSL_SUCCESS) cipherSz += idx; } @@ -25189,8 +25189,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7, 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 }; - byte cipher[AES_BLOCK_SIZE * 4]; - byte plain [AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (ctx == NULL) @@ -25204,7 +25204,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) wolfSSL_EVP_CIPHER_CTX_cleanup(ctx); if (ret != 16) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(ctx); @@ -25214,7 +25214,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) wolfSSL_EVP_CIPHER_CTX_cleanup(ctx); if (ret != 16) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) + if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -25231,14 +25231,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) /* Test: AES_encrypt/decrypt/set Key */ #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES); + WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES); #ifdef HAVE_AES_DECRYPT - AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES); + WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES); #endif #else - AES_KEY enc[1]; + WOLFSSL_AES_KEY enc[1]; #ifdef HAVE_AES_DECRYPT - AES_KEY dec[1]; + WOLFSSL_AES_KEY dec[1]; #endif #endif @@ -25276,18 +25276,18 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) #endif #endif - AES_set_encrypt_key(key, sizeof(key)*8, enc); - AES_set_decrypt_key(key, sizeof(key)*8, dec); + wolfSSL_AES_set_encrypt_key(key, sizeof(key)*8, enc); + wolfSSL_AES_set_decrypt_key(key, sizeof(key)*8, dec); - AES_encrypt(msg, cipher, enc); + wolfSSL_AES_encrypt(msg, cipher, enc); #ifdef HAVE_AES_DECRYPT - AES_decrypt(cipher, plain, dec); - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) + wolfSSL_AES_decrypt(cipher, plain, dec); + if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; #endif /* HAVE_AES_DECRYPT */ - if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) + if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -25436,7 +25436,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(de); if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(), @@ -25444,12 +25444,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) + if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) + if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_cleanup(en); @@ -25467,14 +25467,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) + WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_cleanup(p_en); @@ -25484,9 +25484,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) wolfSSL_EVP_CIPHER_CTX_free(p_de); #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */ - if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) + if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; - if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) + if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(en); @@ -25529,7 +25529,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(de); if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(), @@ -25538,7 +25538,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain))) @@ -25556,7 +25556,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0) return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_init(de); if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(), @@ -25565,7 +25565,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, - AES_BLOCK_SIZE) != AES_BLOCK_SIZE) + WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain))) @@ -25604,8 +25604,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) byte key[] = "0123456789abcdef "; /* align */ byte iv[] = "1234567890abcdef "; /* align */ - byte cipher[AES_BLOCK_SIZE * 4]; - byte plain [AES_BLOCK_SIZE * 4]; + byte cipher[WC_AES_BLOCK_SIZE * 4]; + byte plain [WC_AES_BLOCK_SIZE * 4]; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new(); WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new(); @@ -25833,7 +25833,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) if (wolfSSL_EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE)) return WC_TEST_RET_ENC_NC; - if (wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_128_cbc()) != AES_BLOCK_SIZE) + if (wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_128_cbc()) != WC_AES_BLOCK_SIZE) return WC_TEST_RET_ENC_NC; if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0) @@ -27200,7 +27200,7 @@ static const SshKdfTestVector sshKdfTestVectors[] = { WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void) { - byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and AES_BLOCK_SIZE */ + byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and WC_AES_BLOCK_SIZE */ word32 i; word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector); const SshKdfTestVector* tv = NULL; @@ -33796,8 +33796,8 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b) XMEMSET(plaintext, 0, MAX_ECIES_TEST_SZ); XSTRLCPY((char *)plaintext, message, sizeof plaintext); - plaintextLen = (((word32)XSTRLEN(message) + AES_BLOCK_SIZE - 1) / - AES_BLOCK_SIZE) * AES_BLOCK_SIZE; + plaintextLen = (((word32)XSTRLEN(message) + WC_AES_BLOCK_SIZE - 1) / + WC_AES_BLOCK_SIZE) * WC_AES_BLOCK_SIZE; /* encrypt */ if (ret == 0) { @@ -49615,26 +49615,26 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void) const CMAC_Test_Case testCases[] = { #ifdef WOLFSSL_AES_128 - {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, WC_AES_BLOCK_SIZE}, #endif #ifdef WOLFSSL_AES_192 - {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, WC_AES_BLOCK_SIZE}, #endif #ifdef WOLFSSL_AES_256 - {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, AES_BLOCK_SIZE}, - {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, WC_AES_BLOCK_SIZE}, + {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, WC_AES_BLOCK_SIZE}, #endif #ifdef WOLFSSL_AES_128 - {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, AES_BLOCK_SIZE} + {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, WC_AES_BLOCK_SIZE} #endif }; @@ -49643,7 +49643,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void) #else Cmac cmac[1]; #endif - byte tag[AES_BLOCK_SIZE]; + byte tag[WC_AES_BLOCK_SIZE]; const CMAC_Test_Case* tc; word32 i, tagSz; wc_test_ret_t ret; @@ -49659,7 +49659,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void) i++, tc++) { XMEMSET(tag, 0, sizeof(tag)); - tagSz = AES_BLOCK_SIZE; + tagSz = WC_AES_BLOCK_SIZE; #if !defined(HAVE_FIPS) || \ defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3) @@ -49689,7 +49689,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void) ret = wc_CmacFinal(cmac, tag, &tagSz); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0) + if (XMEMCMP(tag, tc->t, WC_AES_BLOCK_SIZE) != 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); XMEMSET(tag, 0, sizeof(tag)); @@ -49703,7 +49703,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0) + if (XMEMCMP(tag, tc->t, WC_AES_BLOCK_SIZE) != 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0) ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz, @@ -50931,13 +50931,13 @@ static int myDecryptionFunc(wc_PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz, switch (encryptOID) { #ifdef WOLFSSL_AES_256 case AES256CBCb: - if ((keySz != 32 ) || (ivSz != AES_BLOCK_SIZE)) + if ((keySz != 32 ) || (ivSz != WC_AES_BLOCK_SIZE)) WARNING_OUT(BAD_FUNC_ARG, out); break; #endif #ifdef WOLFSSL_AES_128 case AES128CBCb: - if ((keySz != 16 ) || (ivSz != AES_BLOCK_SIZE)) + if ((keySz != 16 ) || (ivSz != WC_AES_BLOCK_SIZE)) ERROR_OUT(BAD_FUNC_ARG, out); break; #endif @@ -59644,7 +59644,7 @@ typedef struct { word32 assoc2Sz; const byte plaintext[83]; word32 plaintextSz; - const byte siv[AES_BLOCK_SIZE+1]; + const byte siv[WC_AES_BLOCK_SIZE+1]; const byte ciphertext[82]; word32 ciphertextSz; } AesSivTestVector; @@ -59780,7 +59780,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void) int i; byte computedCiphertext[82]; byte computedPlaintext[82]; - byte siv[AES_BLOCK_SIZE]; + byte siv[WC_AES_BLOCK_SIZE]; wc_test_ret_t ret = 0; WOLFSSL_ENTER("aes_siv_test"); @@ -59798,7 +59798,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void) if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); } - ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE); + ret = XMEMCMP(siv, testVectors[i].siv, WC_AES_BLOCK_SIZE); if (ret != 0) { return WC_TEST_RET_ENC_NC; } @@ -59838,7 +59838,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void) if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); } - ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE); + ret = XMEMCMP(siv, testVectors[i].siv, WC_AES_BLOCK_SIZE); if (ret != 0) { return WC_TEST_RET_ENC_NC; } diff --git a/wolfssl/internal.h b/wolfssl/internal.h index cb070baa31..f5ce5b02ef 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -1021,7 +1021,8 @@ #endif #if defined(NO_AES) || !defined(HAVE_AES_DECRYPT) - #define AES_BLOCK_SIZE 16 + #undef WC_AES_BLOCK_SIZE + #define WC_AES_BLOCK_SIZE 16 #undef BUILD_AES #else #undef BUILD_AES @@ -1755,7 +1756,7 @@ enum Misc { #endif #endif - MAX_IV_SZ = AES_BLOCK_SIZE, + MAX_IV_SZ = WC_AES_BLOCK_SIZE, AEAD_SEQ_OFFSET = 4, /* Auth Data: Sequence number */ AEAD_TYPE_OFFSET = 8, /* Auth Data: Type */ @@ -4372,7 +4373,7 @@ typedef struct Ciphers { byte* nonce; #endif #ifdef HAVE_CAMELLIA - Camellia* cam; + wc_Camellia* cam; #endif #ifdef HAVE_CHACHA ChaCha* chacha; diff --git a/wolfssl/openssl/aes.h b/wolfssl/openssl/aes.h index 2991ff07ae..25110c824c 100644 --- a/wolfssl/openssl/aes.h +++ b/wolfssl/openssl/aes.h @@ -53,27 +53,37 @@ typedef struct WOLFSSL_AES_KEY { ALIGN16 void *buf[(sizeof(Aes) / sizeof(void *)) + 1]; } WOLFSSL_AES_KEY; -typedef WOLFSSL_AES_KEY AES_KEY; WOLFSSL_API int wolfSSL_AES_set_encrypt_key( - const unsigned char *key, const int bits, AES_KEY *aes); + const unsigned char *key, const int bits, WOLFSSL_AES_KEY *aes); WOLFSSL_API int wolfSSL_AES_set_decrypt_key( - const unsigned char *key, const int bits, AES_KEY *aes); + const unsigned char *key, const int bits, WOLFSSL_AES_KEY *aes); WOLFSSL_API void wolfSSL_AES_cbc_encrypt( - const unsigned char *in, unsigned char* out, size_t len, AES_KEY *key, + const unsigned char *in, unsigned char* out, size_t len, WOLFSSL_AES_KEY *key, unsigned char* iv, const int enc); WOLFSSL_API void wolfSSL_AES_ecb_encrypt( - const unsigned char *in, unsigned char* out, AES_KEY *key, const int enc); + const unsigned char *in, unsigned char* out, WOLFSSL_AES_KEY *key, const int enc); WOLFSSL_API void wolfSSL_AES_cfb128_encrypt( - const unsigned char *in, unsigned char* out, size_t len, AES_KEY *key, + const unsigned char *in, unsigned char* out, size_t len, WOLFSSL_AES_KEY *key, unsigned char* iv, int* num, const int enc); WOLFSSL_API int wolfSSL_AES_wrap_key( - AES_KEY *key, const unsigned char *iv, unsigned char *out, + WOLFSSL_AES_KEY *key, const unsigned char *iv, unsigned char *out, const unsigned char *in, unsigned int inlen); WOLFSSL_API int wolfSSL_AES_unwrap_key( - AES_KEY *key, const unsigned char *iv, unsigned char *out, + WOLFSSL_AES_KEY *key, const unsigned char *iv, unsigned char *out, const unsigned char *in, unsigned int inlen); +#ifdef WOLFSSL_AES_DIRECT +WOLFSSL_API void wolfSSL_AES_encrypt( + const unsigned char* input, unsigned char* output, WOLFSSL_AES_KEY *key); +WOLFSSL_API void wolfSSL_AES_decrypt( + const unsigned char* input, unsigned char* output, WOLFSSL_AES_KEY *key); +#endif /* WOLFSSL_AES_DIRECT */ + +#ifndef OPENSSL_COEXIST + +typedef WOLFSSL_AES_KEY AES_KEY; + #define AES_cbc_encrypt wolfSSL_AES_cbc_encrypt #define AES_ecb_encrypt wolfSSL_AES_ecb_encrypt #define AES_cfb128_encrypt wolfSSL_AES_cfb128_encrypt @@ -83,11 +93,6 @@ WOLFSSL_API int wolfSSL_AES_unwrap_key( #define AES_unwrap_key wolfSSL_AES_unwrap_key #ifdef WOLFSSL_AES_DIRECT -WOLFSSL_API void wolfSSL_AES_encrypt( - const unsigned char* input, unsigned char* output, AES_KEY *key); -WOLFSSL_API void wolfSSL_AES_decrypt( - const unsigned char* input, unsigned char* output, AES_KEY *key); - #define AES_encrypt wolfSSL_AES_encrypt #define AES_decrypt wolfSSL_AES_decrypt #endif /* WOLFSSL_AES_DIRECT */ @@ -99,6 +104,8 @@ WOLFSSL_API void wolfSSL_AES_decrypt( #define AES_DECRYPT AES_DECRYPTION #endif +#endif /* !OPENSSL_COEXIST */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/openssl/cmac.h b/wolfssl/openssl/cmac.h index dd08497faa..120fd1dd70 100644 --- a/wolfssl/openssl/cmac.h +++ b/wolfssl/openssl/cmac.h @@ -34,8 +34,6 @@ typedef struct WOLFSSL_CMAC_CTX { WOLFSSL_EVP_CIPHER_CTX* cctx; } WOLFSSL_CMAC_CTX; -typedef WOLFSSL_CMAC_CTX CMAC_CTX; - WOLFSSL_API WOLFSSL_CMAC_CTX* wolfSSL_CMAC_CTX_new(void); WOLFSSL_API void wolfSSL_CMAC_CTX_free(WOLFSSL_CMAC_CTX *ctx); WOLFSSL_API WOLFSSL_EVP_CIPHER_CTX* wolfSSL_CMAC_CTX_get0_cipher_ctx( @@ -48,6 +46,10 @@ WOLFSSL_API int wolfSSL_CMAC_Update( WOLFSSL_API int wolfSSL_CMAC_Final( WOLFSSL_CMAC_CTX* ctx, unsigned char* out, size_t* len); +#ifndef OPENSSL_COEXIST + +typedef WOLFSSL_CMAC_CTX CMAC_CTX; + #define CMAC_CTX_new wolfSSL_CMAC_CTX_new #define CMAC_CTX_free wolfSSL_CMAC_CTX_free #define CMAC_CTX_get0_cipher_ctx wolfSSL_CMAC_CTX_get0_cipher_ctx @@ -55,6 +57,8 @@ WOLFSSL_API int wolfSSL_CMAC_Final( #define CMAC_Update wolfSSL_CMAC_Update #define CMAC_Final wolfSSL_CMAC_Final +#endif /* !OPENSSL_COEXIST */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/openssl/des.h b/wolfssl/openssl/des.h index 0f385a6d99..6db0df7787 100644 --- a/wolfssl/openssl/des.h +++ b/wolfssl/openssl/des.h @@ -49,8 +49,8 @@ typedef unsigned int WOLFSSL_DES_LONG; enum { - DES_ENCRYPT = 1, - DES_DECRYPT = 0 + WC_DES_ENCRYPT = 1, + WC_DES_DECRYPT = 0 }; @@ -87,6 +87,13 @@ WOLFSSL_API void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* desa, WOLFSSL_API int wolfSSL_DES_check_key_parity(WOLFSSL_DES_cblock *myDes); +#ifndef OPENSSL_COEXIST + +enum { + DES_ENCRYPT = WC_DES_ENCRYPT, + DES_DECRYPT = WC_DES_DECRYPT +}; + typedef WOLFSSL_DES_cblock DES_cblock; typedef WOLFSSL_const_DES_cblock const_DES_cblock; typedef WOLFSSL_DES_key_schedule DES_key_schedule; @@ -106,6 +113,8 @@ typedef WOLFSSL_DES_LONG DES_LONG; #define DES_cbc_cksum wolfSSL_DES_cbc_cksum #define DES_check_key_parity wolfSSL_DES_check_key_parity +#endif /* !OPENSSL_COEXIST */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/openssl/evp.h b/wolfssl/openssl/evp.h index 227146dc3e..02b5c8bcc1 100644 --- a/wolfssl/openssl/evp.h +++ b/wolfssl/openssl/evp.h @@ -689,7 +689,7 @@ struct WOLFSSL_EVP_CIPHER_CTX { unsigned char cipherType; #if !defined(NO_AES) /* working iv pointer into cipher */ - ALIGN16 unsigned char iv[AES_BLOCK_SIZE]; + ALIGN16 unsigned char iv[WC_AES_BLOCK_SIZE]; #elif defined(WOLFSSL_SM4) ALIGN16 unsigned char iv[SM4_BLOCK_SIZE]; #elif defined(HAVE_CHACHA) && defined(HAVE_POLY1305) @@ -722,7 +722,7 @@ struct WOLFSSL_EVP_CIPHER_CTX { defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM) || \ (defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || defined(HAVE_ARIA) - ALIGN16 unsigned char authTag[AES_BLOCK_SIZE]; + ALIGN16 unsigned char authTag[WC_AES_BLOCK_SIZE]; #elif defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM) ALIGN16 unsigned char authTag[SM4_BLOCK_SIZE]; #else diff --git a/wolfssl/openssl/md4.h b/wolfssl/openssl/md4.h index d478e9622b..9181e8d4eb 100644 --- a/wolfssl/openssl/md4.h +++ b/wolfssl/openssl/md4.h @@ -46,6 +46,7 @@ WOLFSSL_API void wolfSSL_MD4_Update(WOLFSSL_MD4_CTX* md4, const void* data, unsigned long len); WOLFSSL_API void wolfSSL_MD4_Final(unsigned char* digest, WOLFSSL_MD4_CTX* md4); +#ifndef OPENSSL_COEXIST typedef WOLFSSL_MD4_CTX MD4_CTX; @@ -53,6 +54,8 @@ typedef WOLFSSL_MD4_CTX MD4_CTX; #define MD4_Update wolfSSL_MD4_Update #define MD4_Final wolfSSL_MD4_Final +#endif /* !OPENSSL_COEXIST */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/openssl/md5.h b/wolfssl/openssl/md5.h index 62533a9ffc..452b6a4190 100644 --- a/wolfssl/openssl/md5.h +++ b/wolfssl/openssl/md5.h @@ -58,6 +58,8 @@ WOLFSSL_API int wolfSSL_MD5_Transform(WOLFSSL_MD5_CTX* md5, const unsigned char* WOLFSSL_API unsigned char *wolfSSL_MD5(const unsigned char* data, size_t len, unsigned char* hash); +#ifndef OPENSSL_COEXIST + typedef WOLFSSL_MD5_CTX MD5_CTX; #define MD5_Init wolfSSL_MD5_Init @@ -95,6 +97,8 @@ typedef WOLFSSL_MD5_CTX MD5_CTX; #define MD5_DIGEST_LENGTH MD5_DIGEST_SIZE #endif +#endif /* !OPENSSL_COEXIST */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/openssl/rc4.h b/wolfssl/openssl/rc4.h index cef9330e38..fb5112884b 100644 --- a/wolfssl/openssl/rc4.h +++ b/wolfssl/openssl/rc4.h @@ -41,16 +41,21 @@ typedef struct WOLFSSL_RC4_KEY { /* big enough for Arc4 from wolfssl/wolfcrypt/arc4.h */ void* holder[(272 + WC_ASYNC_DEV_SIZE) / sizeof(void*)]; } WOLFSSL_RC4_KEY; -typedef WOLFSSL_RC4_KEY RC4_KEY; WOLFSSL_API void wolfSSL_RC4_set_key(WOLFSSL_RC4_KEY* key, int len, const unsigned char* data); WOLFSSL_API void wolfSSL_RC4(WOLFSSL_RC4_KEY* key, size_t len, const unsigned char* in, unsigned char* out); +#ifndef OPENSSL_COEXIST + +typedef WOLFSSL_RC4_KEY RC4_KEY; + #define RC4 wolfSSL_RC4 #define RC4_set_key wolfSSL_RC4_set_key +#endif /* !OPENSSL_COEXIST */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/openssl/srp.h b/wolfssl/openssl/srp.h index 097cf51289..d0e6123fda 100644 --- a/wolfssl/openssl/srp.h +++ b/wolfssl/openssl/srp.h @@ -24,6 +24,10 @@ #include +#ifndef OPENSSL_COEXIST + #define SRP_MINIMAL_N SRP_MODULUS_MIN_BITS +#endif /* !OPENSSL_COEXIST */ + #endif /* WOLFSSL_SRP_H_ */ diff --git a/wolfssl/openssl/x509v3.h b/wolfssl/openssl/x509v3.h index 082ae4e777..a84077d54f 100644 --- a/wolfssl/openssl/x509v3.h +++ b/wolfssl/openssl/x509v3.h @@ -36,60 +36,45 @@ #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) -#define EXFLAG_KUSAGE 0x2 -#define EXFLAG_XKUSAGE 0x4 - -#define KU_DIGITAL_SIGNATURE KEYUSE_DIGITAL_SIG -#define KU_NON_REPUDIATION KEYUSE_CONTENT_COMMIT -#define KU_KEY_ENCIPHERMENT KEYUSE_KEY_ENCIPHER -#define KU_DATA_ENCIPHERMENT KEYUSE_DATA_ENCIPHER -#define KU_KEY_AGREEMENT KEYUSE_KEY_AGREE -#define KU_KEY_CERT_SIGN KEYUSE_KEY_CERT_SIGN -#define KU_CRL_SIGN KEYUSE_CRL_SIGN -#define KU_ENCIPHER_ONLY KEYUSE_ENCIPHER_ONLY -#define KU_DECIPHER_ONLY KEYUSE_DECIPHER_ONLY - -#define XKU_SSL_SERVER 0x1 -#define XKU_SSL_CLIENT 0x2 -#define XKU_SMIME 0x4 -#define XKU_CODE_SIGN 0x8 -#define XKU_SGC 0x10 -#define XKU_OCSP_SIGN 0x20 -#define XKU_TIMESTAMP 0x40 -#define XKU_DVCS 0x80 -#define XKU_ANYEKU 0x100 - -#define X509_PURPOSE_SSL_CLIENT 0 -#define X509_PURPOSE_SSL_SERVER 1 - -#define NS_SSL_CLIENT WC_NS_SSL_CLIENT -#define NS_SSL_SERVER WC_NS_SSL_SERVER - -/* Forward reference */ +#define WOLFSSL_EXFLAG_KUSAGE 0x2 +#define WOLFSSL_EXFLAG_XKUSAGE 0x4 + +#define WOLFSSL_XKU_SSL_SERVER 0x1 +#define WOLFSSL_XKU_SSL_CLIENT 0x2 +#define WOLFSSL_XKU_SMIME 0x4 +#define WOLFSSL_XKU_CODE_SIGN 0x8 +#define WOLFSSL_XKU_SGC 0x10 +#define WOLFSSL_XKU_OCSP_SIGN 0x20 +#define WOLFSSL_XKU_TIMESTAMP 0x40 +#define WOLFSSL_XKU_DVCS 0x80 +#define WOLFSSL_XKU_ANYEKU 0x100 + +#define WOLFSSL_X509_PURPOSE_SSL_CLIENT 0 +#define WOLFSSL_X509_PURPOSE_SSL_SERVER 1 #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x0090801fL -typedef void *(*X509V3_EXT_D2I)(void *, const unsigned char **, long); +typedef void *(*WOLFSSL_X509V3_EXT_D2I)(void *, const unsigned char **, long); #else -typedef void *(*X509V3_EXT_D2I)(void *, unsigned char **, long); +typedef void *(*WOLFSSL_X509V3_EXT_D2I)(void *, unsigned char **, long); #endif -typedef int (*X509V3_EXT_I2D) (void *, unsigned char **); -typedef WOLF_STACK_OF(CONF_VALUE) *(*X509V3_EXT_I2V) ( +typedef int (*WOLFSSL_X509V3_EXT_I2D) (void *, unsigned char **); +typedef WOLF_STACK_OF(CONF_VALUE) *(*WOLFSSL_X509V3_EXT_I2V) ( struct WOLFSSL_v3_ext_method *method, void *ext, WOLF_STACK_OF(CONF_VALUE) *extlist); -typedef char *(*X509V3_EXT_I2S)(struct WOLFSSL_v3_ext_method *method, void *ext); -typedef int (*X509V3_EXT_I2R) (struct WOLFSSL_v3_ext_method *method, +typedef char *(*WOLFSSL_X509V3_EXT_I2S)(struct WOLFSSL_v3_ext_method *method, void *ext); +typedef int (*WOLFSSL_X509V3_EXT_I2R) (struct WOLFSSL_v3_ext_method *method, void *ext, WOLFSSL_BIO *out, int indent); -typedef struct WOLFSSL_v3_ext_method X509V3_EXT_METHOD; +typedef struct WOLFSSL_v3_ext_method WOLFSSL_X509V3_EXT_METHOD; struct WOLFSSL_v3_ext_method { int ext_nid; int ext_flags; void *usr_data; - X509V3_EXT_D2I d2i; - X509V3_EXT_I2D i2d; - X509V3_EXT_I2V i2v; - X509V3_EXT_I2S i2s; - X509V3_EXT_I2R i2r; + WOLFSSL_X509V3_EXT_D2I d2i; + WOLFSSL_X509V3_EXT_I2D i2d; + WOLFSSL_X509V3_EXT_I2V i2v; + WOLFSSL_X509V3_EXT_I2S i2s; + WOLFSSL_X509V3_EXT_I2R i2r; }; struct WOLFSSL_X509_EXTENSION { @@ -113,31 +98,6 @@ struct WOLFSSL_X509_EXTENSION { #define WOLFSSL_GEN_RID 8 #define WOLFSSL_GEN_IA5 9 -#ifndef OPENSSL_COEXIST - -#define GEN_OTHERNAME WOLFSSL_GEN_OTHERNAME -#define GEN_EMAIL WOLFSSL_GEN_EMAIL -#define GEN_DNS WOLFSSL_GEN_DNS -#define GEN_X400 WOLFSSL_GEN_X400 -#define GEN_DIRNAME WOLFSSL_GEN_DIRNAME -#define GEN_EDIPARTY WOLFSSL_GEN_EDIPARTY -#define GEN_URI WOLFSSL_GEN_URI -#define GEN_IPADD WOLFSSL_GEN_IPADD -#define GEN_RID WOLFSSL_GEN_RID -#define GEN_IA5 WOLFSSL_GEN_IA5 - -#define GENERAL_NAME WOLFSSL_GENERAL_NAME - -#define X509V3_CTX WOLFSSL_X509V3_CTX - -#define CTX_TEST 0x1 - -typedef struct WOLFSSL_AUTHORITY_KEYID AUTHORITY_KEYID; -typedef struct WOLFSSL_BASIC_CONSTRAINTS BASIC_CONSTRAINTS; -typedef struct WOLFSSL_ACCESS_DESCRIPTION ACCESS_DESCRIPTION; - -#endif /* !OPENSSL_COEXIST */ - typedef WOLF_STACK_OF(WOLFSSL_ACCESS_DESCRIPTION) WOLFSSL_AUTHORITY_INFO_ACCESS; WOLFSSL_API WOLFSSL_BASIC_CONSTRAINTS* wolfSSL_BASIC_CONSTRAINTS_new(void); @@ -174,6 +134,67 @@ WOLFSSL_API int wolfSSL_X509V3_EXT_add_nconf(WOLFSSL_CONF *conf, WOLFSSL_X509V3_CTX *ctx, const char *section, WOLFSSL_X509 *cert); WOLFSSL_API WOLFSSL_ASN1_STRING* wolfSSL_a2i_IPADDRESS(const char* ipa); +#ifndef OPENSSL_COEXIST + +#define EXFLAG_KUSAGE WOLFSSL_EXFLAG_KUSAGE +#define EXFLAG_XKUSAGE WOLFSSL_EXFLAG_XKUSAGE + +#define KU_DIGITAL_SIGNATURE KEYUSE_DIGITAL_SIG +#define KU_NON_REPUDIATION KEYUSE_CONTENT_COMMIT +#define KU_KEY_ENCIPHERMENT KEYUSE_KEY_ENCIPHER +#define KU_DATA_ENCIPHERMENT KEYUSE_DATA_ENCIPHER +#define KU_KEY_AGREEMENT KEYUSE_KEY_AGREE +#define KU_KEY_CERT_SIGN KEYUSE_KEY_CERT_SIGN +#define KU_CRL_SIGN KEYUSE_CRL_SIGN +#define KU_ENCIPHER_ONLY KEYUSE_ENCIPHER_ONLY +#define KU_DECIPHER_ONLY KEYUSE_DECIPHER_ONLY + +#define XKU_SSL_SERVER WOLFSSL_XKU_SSL_SERVER +#define XKU_SSL_CLIENT WOLFSSL_XKU_SSL_CLIENT +#define XKU_SMIME WOLFSSL_XKU_SMIME +#define XKU_CODE_SIGN WOLFSSL_XKU_CODE_SIGN +#define XKU_SGC WOLFSSL_XKU_SGC +#define XKU_OCSP_SIGN WOLFSSL_XKU_OCSP_SIGN +#define XKU_TIMESTAMP WOLFSSL_XKU_TIMESTAMP +#define XKU_DVCS WOLFSSL_XKU_DVCS +#define XKU_ANYEKU WOLFSSL_XKU_ANYEKU + +#define X509_PURPOSE_SSL_CLIENT WOLFSSL_X509_PURPOSE_SSL_CLIENT +#define X509_PURPOSE_SSL_SERVER WOLFSSL_X509_PURPOSE_SSL_SERVER + +#define NS_SSL_CLIENT WC_NS_SSL_CLIENT +#define NS_SSL_SERVER WC_NS_SSL_SERVER + +/* Forward reference */ + +#define X509V3_EXT_D2I WOLFSSL_X509V3_EXT_D2I +#define X509V3_EXT_I2D WOLFSSL_X509V3_EXT_I2D +#define X509V3_EXT_I2V WOLFSSL_X509V3_EXT_I2V +#define X509V3_EXT_I2S WOLFSSL_X509V3_EXT_I2S +#define X509V3_EXT_I2R WOLFSSL_X509V3_EXT_I2R +typedef struct WOLFSSL_v3_ext_method X509V3_EXT_METHOD; + +#define GEN_OTHERNAME WOLFSSL_GEN_OTHERNAME +#define GEN_EMAIL WOLFSSL_GEN_EMAIL +#define GEN_DNS WOLFSSL_GEN_DNS +#define GEN_X400 WOLFSSL_GEN_X400 +#define GEN_DIRNAME WOLFSSL_GEN_DIRNAME +#define GEN_EDIPARTY WOLFSSL_GEN_EDIPARTY +#define GEN_URI WOLFSSL_GEN_URI +#define GEN_IPADD WOLFSSL_GEN_IPADD +#define GEN_RID WOLFSSL_GEN_RID +#define GEN_IA5 WOLFSSL_GEN_IA5 + +#define GENERAL_NAME WOLFSSL_GENERAL_NAME + +#define X509V3_CTX WOLFSSL_X509V3_CTX + +#define CTX_TEST 0x1 + +typedef struct WOLFSSL_AUTHORITY_KEYID AUTHORITY_KEYID; +typedef struct WOLFSSL_BASIC_CONSTRAINTS BASIC_CONSTRAINTS; +typedef struct WOLFSSL_ACCESS_DESCRIPTION ACCESS_DESCRIPTION; + #define BASIC_CONSTRAINTS_free wolfSSL_BASIC_CONSTRAINTS_free #define AUTHORITY_KEYID_free wolfSSL_AUTHORITY_KEYID_free #define SSL_CTX_get_cert_store(x) wolfSSL_CTX_get_cert_store ((x)) @@ -198,6 +219,8 @@ WOLFSSL_API WOLFSSL_ASN1_STRING* wolfSSL_a2i_IPADDRESS(const char* ipa); #define X509V3_set_ctx_nodb wolfSSL_X509V3_set_ctx_nodb #define X509v3_get_ext_count wolfSSL_sk_num +#endif /* !OPENSSL_COEXIST */ + #endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */ #ifdef __cplusplus diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 13a2f1e87a..22bb89f75f 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -117,6 +117,62 @@ #include #include #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include #endif #elif (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) @@ -231,7 +287,9 @@ typedef struct WOLFSSL_BIO_METHOD WOLFSSL_BIO_METHOD; typedef struct WOLFSSL_X509_EXTENSION WOLFSSL_X509_EXTENSION; typedef struct WOLFSSL_ASN1_OBJECT WOLFSSL_ASN1_OBJECT; typedef struct WOLFSSL_ASN1_OTHERNAME WOLFSSL_ASN1_OTHERNAME; +#ifndef OPENSSL_COEXIST typedef struct WOLFSSL_ASN1_OTHERNAME OTHERNAME; +#endif typedef struct WOLFSSL_X509V3_CTX WOLFSSL_X509V3_CTX; typedef struct WOLFSSL_v3_ext_method WOLFSSL_v3_ext_method; typedef struct WOLFSSL_OBJ_NAME WOLFSSL_OBJ_NAME; diff --git a/wolfssl/test.h b/wolfssl/test.h index 6b30f2375c..e70e141df2 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -4697,7 +4697,7 @@ static WC_INLINE int myTicketEncCb(WOLFSSL* ssl, mac); #elif defined(HAVE_AESGCM) ret = wc_AesGcmEncrypt(&tickCtx->aes, ticket, ticket, inLen, - iv, GCM_NONCE_MID_SZ, mac, AES_BLOCK_SIZE, + iv, GCM_NONCE_MID_SZ, mac, WC_AES_BLOCK_SIZE, tickCtx->aad, aadSz); #endif } @@ -4711,7 +4711,7 @@ static WC_INLINE int myTicketEncCb(WOLFSSL* ssl, ticket); #elif defined(HAVE_AESGCM) ret = wc_AesGcmDecrypt(&tickCtx->aes, ticket, ticket, inLen, - iv, GCM_NONCE_MID_SZ, mac, AES_BLOCK_SIZE, + iv, GCM_NONCE_MID_SZ, mac, WC_AES_BLOCK_SIZE, tickCtx->aad, aadSz); #endif } diff --git a/wolfssl/wolfcrypt/aes.h b/wolfssl/wolfcrypt/aes.h index eaa0c47150..a5399017ae 100644 --- a/wolfssl/wolfcrypt/aes.h +++ b/wolfssl/wolfcrypt/aes.h @@ -188,7 +188,10 @@ enum { AES_ENCRYPTION_AND_DECRYPTION = 2, #endif - AES_BLOCK_SIZE = 16, + WC_AES_BLOCK_SIZE = 16, +#ifndef OPENSSL_COEXIST + #define AES_BLOCK_SIZE WC_AES_BLOCK_SIZE +#endif KEYWRAP_BLOCK_SIZE = 8, @@ -227,9 +230,9 @@ enum { #endif /* Number of bits to a block. */ - #define AES_BLOCK_BITS (AES_BLOCK_SIZE * 8) + #define AES_BLOCK_BITS (WC_AES_BLOCK_SIZE * 8) /* Number of bytes of input that can be processed in one call. */ - #define BS_BLOCK_SIZE (AES_BLOCK_SIZE * BS_WORD_SIZE) + #define BS_BLOCK_SIZE (WC_AES_BLOCK_SIZE * BS_WORD_SIZE) /* Number of words in a block. */ #define BS_BLOCK_WORDS (AES_BLOCK_BITS / BS_WORD_SIZE) @@ -258,7 +261,7 @@ struct Aes { ALIGN16 word32 key[60]; #ifdef WC_AES_BITSLICED /* Extra key schedule space required for bit-slicing technique. */ - ALIGN16 bs_word bs_key[15 * AES_BLOCK_SIZE * BS_WORD_SIZE]; + ALIGN16 bs_word bs_key[15 * WC_AES_BLOCK_SIZE * BS_WORD_SIZE]; #endif word32 rounds; #ifdef WC_C_DYNAMIC_FALLBACK @@ -266,8 +269,8 @@ struct Aes { #endif int keylen; - ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ - ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */ + ALIGN16 word32 reg[WC_AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ + ALIGN16 word32 tmp[WC_AES_BLOCK_SIZE / sizeof(word32)]; /* same */ #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) word32 invokeCtr[2]; @@ -379,7 +382,7 @@ struct Aes { void* heap; /* memory hint to use */ #ifdef WOLFSSL_AESGCM_STREAM #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_AESNI) - ALIGN16 byte streamData[5 * AES_BLOCK_SIZE]; + ALIGN16 byte streamData[5 * WC_AES_BLOCK_SIZE]; #else byte* streamData; word32 streamData_sz; @@ -408,8 +411,8 @@ struct Aes { #ifdef WOLFSSL_AES_XTS #if FIPS_VERSION3_GE(6,0,0) /* SP800-38E - Restrict data unit to 2^20 blocks per key. A block is - * AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to - * protect up to 1,048,576 blocks of AES_BLOCK_SIZE (16,777,216 bytes) + * WC_AES_BLOCK_SIZE or 16-bytes (128-bits). So each key may only be used to + * protect up to 1,048,576 blocks of WC_AES_BLOCK_SIZE (16,777,216 bytes) */ #define FIPS_AES_XTS_MAX_BYTES_PER_TWEAK 16777216 #endif @@ -423,7 +426,7 @@ struct Aes { #ifdef WOLFSSL_AESXTS_STREAM struct XtsAesStreamData { - byte tweak_block[AES_BLOCK_SIZE]; + byte tweak_block[WC_AES_BLOCK_SIZE]; word32 bytes_crypted_with_this_tweak; }; #endif @@ -768,10 +771,10 @@ struct AesEax { Cmac nonceCmac; Cmac aadCmac; Cmac ciphertextCmac; - byte nonceCmacFinal[AES_BLOCK_SIZE]; - byte aadCmacFinal[AES_BLOCK_SIZE]; - byte ciphertextCmacFinal[AES_BLOCK_SIZE]; - byte prefixBuf[AES_BLOCK_SIZE]; + byte nonceCmacFinal[WC_AES_BLOCK_SIZE]; + byte aadCmacFinal[WC_AES_BLOCK_SIZE]; + byte ciphertextCmacFinal[WC_AES_BLOCK_SIZE]; + byte prefixBuf[WC_AES_BLOCK_SIZE]; }; #endif /* !defined(WOLF_CRYPT_CMAC_H) */ diff --git a/wolfssl/wolfcrypt/camellia.h b/wolfssl/wolfcrypt/camellia.h index bdba23bc90..efd187e3b7 100644 --- a/wolfssl/wolfcrypt/camellia.h +++ b/wolfssl/wolfcrypt/camellia.h @@ -63,34 +63,49 @@ #endif enum { - CAMELLIA_BLOCK_SIZE = 16 + WC_CAMELLIA_BLOCK_SIZE = 16 }; -#define CAMELLIA_TABLE_BYTE_LEN 272 -#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / sizeof(word32)) +#define WC_CAMELLIA_TABLE_BYTE_LEN 272 +#define WC_CAMELLIA_TABLE_WORD_LEN (WC_CAMELLIA_TABLE_BYTE_LEN / sizeof(word32)) -typedef word32 KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN]; +typedef word32 WC_CAMELLIA_KEY_TABLE_TYPE[WC_CAMELLIA_TABLE_WORD_LEN]; -typedef struct Camellia { +typedef struct wc_Camellia { word32 keySz; - KEY_TABLE_TYPE key; - word32 reg[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ - word32 tmp[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ -} Camellia; + WC_CAMELLIA_KEY_TABLE_TYPE key; + word32 reg[WC_CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ + word32 tmp[WC_CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ +} wc_Camellia; -WOLFSSL_API int wc_CamelliaSetKey(Camellia* cam, +WOLFSSL_API int wc_CamelliaSetKey(wc_Camellia* cam, const byte* key, word32 len, const byte* iv); -WOLFSSL_API int wc_CamelliaSetIV(Camellia* cam, const byte* iv); -WOLFSSL_API int wc_CamelliaEncryptDirect(Camellia* cam, byte* out, +WOLFSSL_API int wc_CamelliaSetIV(wc_Camellia* cam, const byte* iv); +WOLFSSL_API int wc_CamelliaEncryptDirect(wc_Camellia* cam, byte* out, const byte* in); -WOLFSSL_API int wc_CamelliaDecryptDirect(Camellia* cam, byte* out, +WOLFSSL_API int wc_CamelliaDecryptDirect(wc_Camellia* cam, byte* out, const byte* in); -WOLFSSL_API int wc_CamelliaCbcEncrypt(Camellia* cam, +WOLFSSL_API int wc_CamelliaCbcEncrypt(wc_Camellia* cam, byte* out, const byte* in, word32 sz); -WOLFSSL_API int wc_CamelliaCbcDecrypt(Camellia* cam, +WOLFSSL_API int wc_CamelliaCbcDecrypt(wc_Camellia* cam, byte* out, const byte* in, word32 sz); +#ifndef OPENSSL_COEXIST + +enum { + CAMELLIA_BLOCK_SIZE = WC_CAMELLIA_BLOCK_SIZE +}; + +#define CAMELLIA_TABLE_BYTE_LEN WC_CAMELLIA_TABLE_BYTE_LEN +#define CAMELLIA_TABLE_WORD_LEN WC_CAMELLIA_TABLE_WORD_LEN + +typedef word32 KEY_TABLE_TYPE[WC_CAMELLIA_TABLE_WORD_LEN]; + +typedef struct wc_Camellia Camellia; + +#endif /* !OPENSSL_COEXIST */ + #ifdef __cplusplus } /* extern "C" */ diff --git a/wolfssl/wolfcrypt/cmac.h b/wolfssl/wolfcrypt/cmac.h index a1c05f9f1c..3dc6d9c01f 100644 --- a/wolfssl/wolfcrypt/cmac.h +++ b/wolfssl/wolfcrypt/cmac.h @@ -54,10 +54,10 @@ typedef enum CmacType { struct Cmac { #ifndef NO_AES Aes aes; - byte buffer[AES_BLOCK_SIZE]; /* partially stored block */ - byte digest[AES_BLOCK_SIZE]; /* running digest */ - byte k1[AES_BLOCK_SIZE]; - byte k2[AES_BLOCK_SIZE]; + byte buffer[WC_AES_BLOCK_SIZE]; /* partially stored block */ + byte digest[WC_AES_BLOCK_SIZE]; /* running digest */ + byte k1[WC_AES_BLOCK_SIZE]; + byte k2[WC_AES_BLOCK_SIZE]; #endif word32 bufferSz; word32 totalSz; @@ -86,8 +86,8 @@ struct Cmac { #ifndef NO_AES -#define WC_CMAC_TAG_MAX_SZ AES_BLOCK_SIZE -#define WC_CMAC_TAG_MIN_SZ (AES_BLOCK_SIZE/4) +#define WC_CMAC_TAG_MAX_SZ WC_AES_BLOCK_SIZE +#define WC_CMAC_TAG_MIN_SZ (WC_AES_BLOCK_SIZE/4) #else /* Reasonable defaults */ #define WC_CMAC_TAG_MAX_SZ 16 diff --git a/wolfssl/wolfcrypt/md2.h b/wolfssl/wolfcrypt/md2.h index fe927561c5..73be11094c 100644 --- a/wolfssl/wolfcrypt/md2.h +++ b/wolfssl/wolfcrypt/md2.h @@ -37,28 +37,42 @@ /* in bytes */ enum { - MD2 = WC_HASH_TYPE_MD2, - MD2_BLOCK_SIZE = 16, - MD2_DIGEST_SIZE = 16, - MD2_PAD_SIZE = 16, - MD2_X_SIZE = 48 + WC_MD2_BLOCK_SIZE = 16, + WC_MD2_DIGEST_SIZE = 16, + WC_MD2_PAD_SIZE = 16, + WC_MD2_X_SIZE = 48 }; /* Md2 digest */ -typedef struct Md2 { +typedef struct wc_Md2 { word32 count; /* bytes % PAD_SIZE */ - byte X[MD2_X_SIZE]; - byte C[MD2_BLOCK_SIZE]; - byte buffer[MD2_BLOCK_SIZE]; -} Md2; + byte X[WC_MD2_X_SIZE]; + byte C[WC_MD2_BLOCK_SIZE]; + byte buffer[WC_MD2_BLOCK_SIZE]; +} wc_Md2; -WOLFSSL_API void wc_InitMd2(Md2* md2); -WOLFSSL_API void wc_Md2Update(Md2* md2, const byte* data, word32 len); -WOLFSSL_API void wc_Md2Final(Md2* md2, byte* hash); +WOLFSSL_API void wc_InitMd2(wc_Md2* md2); +WOLFSSL_API void wc_Md2Update(wc_Md2* md2, const byte* data, word32 len); +WOLFSSL_API void wc_Md2Final(wc_Md2* md2, byte* hash); WOLFSSL_API int wc_Md2Hash(const byte* data, word32 len, byte* hash); +#ifndef OPENSSL_COEXIST + +enum { + MD2 = WC_HASH_TYPE_MD2, + MD2_BLOCK_SIZE = WC_MD2_BLOCK_SIZE, + MD2_DIGEST_SIZE = WC_MD2_DIGEST_SIZE, + MD2_PAD_SIZE = WC_MD2_PAD_SIZE, + MD2_X_SIZE = WC_MD2_X_SIZE +}; + + +/* Md2 digest */ +typedef struct wc_Md2 Md2; + +#endif /* !OPENSSL_COEXIST */ #ifdef __cplusplus } /* extern "C" */ diff --git a/wolfssl/wolfcrypt/md4.h b/wolfssl/wolfcrypt/md4.h index c4bd266a26..b253f8d790 100644 --- a/wolfssl/wolfcrypt/md4.h +++ b/wolfssl/wolfcrypt/md4.h @@ -36,26 +36,36 @@ /* in bytes */ enum { - MD4 = WC_HASH_TYPE_MD4, - MD4_BLOCK_SIZE = 64, - MD4_DIGEST_SIZE = 16, - MD4_PAD_SIZE = 56 + WC_MD4_BLOCK_SIZE = 64, + WC_MD4_DIGEST_SIZE = 16, + WC_MD4_PAD_SIZE = 56 }; - /* MD4 digest */ -typedef struct Md4 { +typedef struct wc_Md4 { word32 buffLen; /* in bytes */ word32 loLen; /* length in bytes */ word32 hiLen; /* length in bytes */ - word32 digest[MD4_DIGEST_SIZE / sizeof(word32)]; - word32 buffer[MD4_BLOCK_SIZE / sizeof(word32)]; -} Md4; + word32 digest[WC_MD4_DIGEST_SIZE / sizeof(word32)]; + word32 buffer[WC_MD4_BLOCK_SIZE / sizeof(word32)]; +} wc_Md4; + +WOLFSSL_API void wc_InitMd4(wc_Md4* md4); +WOLFSSL_API void wc_Md4Update(wc_Md4* md4, const byte* data, word32 len); +WOLFSSL_API void wc_Md4Final(wc_Md4* md4, byte* hash); + +#ifndef OPENSSL_COEXIST + +enum { + MD4 = WC_HASH_TYPE_MD4, + MD4_BLOCK_SIZE = WC_MD4_BLOCK_SIZE, + MD4_DIGEST_SIZE = WC_MD4_DIGEST_SIZE, + MD4_PAD_SIZE = WC_MD4_PAD_SIZE +}; +typedef struct wc_Md4 Md4; -WOLFSSL_API void wc_InitMd4(Md4* md4); -WOLFSSL_API void wc_Md4Update(Md4* md4, const byte* data, word32 len); -WOLFSSL_API void wc_Md4Final(Md4* md4, byte* hash); +#endif /* !OPENSSL_COEXIST */ #ifdef __cplusplus diff --git a/wolfssl/wolfcrypt/pkcs7.h b/wolfssl/wolfcrypt/pkcs7.h index 4b086cc6b4..bc34147ab8 100644 --- a/wolfssl/wolfcrypt/pkcs7.h +++ b/wolfssl/wolfcrypt/pkcs7.h @@ -158,7 +158,7 @@ enum Pkcs7_Misc { MAX_CONTENT_KEY_LEN = 32, /* highest current cipher is AES-256-CBC */ MAX_CONTENT_IV_SIZE = 16, /* highest current is AES128 */ #ifndef NO_AES - MAX_CONTENT_BLOCK_LEN = AES_BLOCK_SIZE, + MAX_CONTENT_BLOCK_LEN = WC_AES_BLOCK_SIZE, #else MAX_CONTENT_BLOCK_LEN = DES_BLOCK_SIZE, #endif diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 4127636fdb..614bc0e988 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -415,6 +415,11 @@ #undef WC_RSA_BLINDING #endif +/* old FIPS has only AES_BLOCK_SIZE. */ +#if !defined(NO_AES) && (defined(HAVE_SELFTEST) || \ + (defined(HAVE_FIPS) && FIPS_VERSION3_LT(7,0,0))) + #define WC_AES_BLOCK_SIZE AES_BLOCK_SIZE +#endif /* !NO_AES && (HAVE_SELFTEST || FIPS_VERSION3_LT(7,0,0)) */ #ifdef WOLFSSL_HARDEN_TLS #if WOLFSSL_HARDEN_TLS != 112 && WOLFSSL_HARDEN_TLS != 128