mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 18:57:27 +02:00
Adding in @ejohnstown's suggested patch for line lengths
This commit is contained in:
66
tests/api.c
66
tests/api.c
@ -52186,62 +52186,82 @@ static int test_wolfssl_EVP_aes_ccm(void)
|
|||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
/* Default uses 96-bits IV length */
|
/* Default uses 96-bits IV length */
|
||||||
#ifdef WOLFSSL_AES_128
|
#ifdef WOLFSSL_AES_128
|
||||||
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL, key, iv));
|
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i],
|
||||||
|
EVP_aes_128_ccm(), NULL, key, iv));
|
||||||
#elif defined(WOLFSSL_AES_192)
|
#elif defined(WOLFSSL_AES_192)
|
||||||
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL, key, iv));
|
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i],
|
||||||
|
EVP_aes_192_ccm(), NULL, key, iv));
|
||||||
#elif defined(WOLFSSL_AES_256)
|
#elif defined(WOLFSSL_AES_256)
|
||||||
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL, key, iv));
|
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i],
|
||||||
|
EVP_aes_256_ccm(), NULL, key, iv));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef WOLFSSL_AES_128
|
#ifdef WOLFSSL_AES_128
|
||||||
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL, NULL, NULL));
|
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i],
|
||||||
|
EVP_aes_128_ccm(), NULL, NULL, NULL));
|
||||||
#elif defined(WOLFSSL_AES_192)
|
#elif defined(WOLFSSL_AES_192)
|
||||||
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL, NULL, NULL));
|
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i],
|
||||||
|
EVP_aes_192_ccm(), NULL, NULL, NULL));
|
||||||
#elif defined(WOLFSSL_AES_256)
|
#elif defined(WOLFSSL_AES_256)
|
||||||
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL, NULL, NULL));
|
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i],
|
||||||
|
EVP_aes_256_ccm(), NULL, NULL, NULL));
|
||||||
#endif
|
#endif
|
||||||
/* non-default must to set the IV length first */
|
/* non-default must to set the IV length first */
|
||||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
|
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i],
|
||||||
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
|
EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
|
||||||
|
AssertIntEQ(1, EVP_EncryptInit_ex(&en[i],
|
||||||
|
NULL, NULL, key, iv));
|
||||||
}
|
}
|
||||||
AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
|
AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
|
||||||
AssertIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt, plaintxtSz));
|
AssertIntEQ(1, EVP_EncryptUpdate(&en[i],
|
||||||
|
ciphertxt, &len, plaintxt, plaintxtSz));
|
||||||
ciphertxtSz = len;
|
ciphertxtSz = len;
|
||||||
AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
|
AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
|
||||||
ciphertxtSz += len;
|
ciphertxtSz += len;
|
||||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG, AES_BLOCK_SIZE, tag));
|
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i],
|
||||||
|
EVP_CTRL_CCM_GET_TAG, AES_BLOCK_SIZE, tag));
|
||||||
AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
|
AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
|
||||||
|
|
||||||
EVP_CIPHER_CTX_init(&de[i]);
|
EVP_CIPHER_CTX_init(&de[i]);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
/* Default uses 96-bits IV length */
|
/* Default uses 96-bits IV length */
|
||||||
#ifdef WOLFSSL_AES_128
|
#ifdef WOLFSSL_AES_128
|
||||||
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL, key, iv));
|
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i],
|
||||||
|
EVP_aes_128_ccm(), NULL, key, iv));
|
||||||
#elif defined(WOLFSSL_AES_192)
|
#elif defined(WOLFSSL_AES_192)
|
||||||
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL, key, iv));
|
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i],
|
||||||
|
EVP_aes_192_ccm(), NULL, key, iv));
|
||||||
#elif defined(WOLFSSL_AES_256)
|
#elif defined(WOLFSSL_AES_256)
|
||||||
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL, key, iv));
|
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i],
|
||||||
|
EVP_aes_256_ccm(), NULL, key, iv));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef WOLFSSL_AES_128
|
#ifdef WOLFSSL_AES_128
|
||||||
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL, NULL, NULL));
|
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i],
|
||||||
|
EVP_aes_128_ccm(), NULL, NULL, NULL));
|
||||||
#elif defined(WOLFSSL_AES_192)
|
#elif defined(WOLFSSL_AES_192)
|
||||||
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL, NULL, NULL));
|
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i],
|
||||||
|
EVP_aes_192_ccm(), NULL, NULL, NULL));
|
||||||
#elif defined(WOLFSSL_AES_256)
|
#elif defined(WOLFSSL_AES_256)
|
||||||
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL, NULL, NULL));
|
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i],
|
||||||
|
EVP_aes_256_ccm(), NULL, NULL, NULL));
|
||||||
#endif
|
#endif
|
||||||
/* non-default must to set the IV length first */
|
/* non-default must to set the IV length first */
|
||||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
|
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i],
|
||||||
|
EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
|
||||||
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
|
AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
|
||||||
|
|
||||||
}
|
}
|
||||||
AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
|
AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
|
||||||
AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
|
AssertIntEQ(1, EVP_DecryptUpdate(&de[i],
|
||||||
|
decryptedtxt, &len, ciphertxt, ciphertxtSz));
|
||||||
decryptedtxtSz = len;
|
decryptedtxtSz = len;
|
||||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG, AES_BLOCK_SIZE, tag));
|
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i],
|
||||||
AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
|
EVP_CTRL_CCM_SET_TAG, AES_BLOCK_SIZE, tag));
|
||||||
|
AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i],
|
||||||
|
decryptedtxt, &len));
|
||||||
decryptedtxtSz += len;
|
decryptedtxtSz += len;
|
||||||
AssertIntEQ(ciphertxtSz, decryptedtxtSz);
|
AssertIntEQ(ciphertxtSz, decryptedtxtSz);
|
||||||
AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
|
AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
|
||||||
@ -52249,9 +52269,11 @@ static int test_wolfssl_EVP_aes_ccm(void)
|
|||||||
/* modify tag*/
|
/* modify tag*/
|
||||||
tag[AES_BLOCK_SIZE-1]+=0xBB;
|
tag[AES_BLOCK_SIZE-1]+=0xBB;
|
||||||
AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
|
AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
|
||||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG, AES_BLOCK_SIZE, tag));
|
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i],
|
||||||
|
EVP_CTRL_CCM_SET_TAG, AES_BLOCK_SIZE, tag));
|
||||||
/* fail due to wrong tag */
|
/* fail due to wrong tag */
|
||||||
AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
|
AssertIntEQ(1, EVP_DecryptUpdate(&de[i],
|
||||||
|
decryptedtxt, &len, ciphertxt, ciphertxtSz));
|
||||||
AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
|
AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
|
||||||
AssertIntEQ(0, len);
|
AssertIntEQ(0, len);
|
||||||
AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
|
AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
|
||||||
|
@ -763,7 +763,8 @@ int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
|
|||||||
case AES_128_CCM_TYPE:
|
case AES_128_CCM_TYPE:
|
||||||
case AES_192_CCM_TYPE:
|
case AES_192_CCM_TYPE:
|
||||||
case AES_256_CCM_TYPE:
|
case AES_256_CCM_TYPE:
|
||||||
/* if out == NULL, in/inl contains the additional auth data */
|
/* if out == NULL, in/inl contains the
|
||||||
|
* additional auth data */
|
||||||
return wolfSSL_EVP_CipherUpdate_CCM(ctx, out, outl, in, inl);
|
return wolfSSL_EVP_CipherUpdate_CCM(ctx, out, outl, in, inl);
|
||||||
#endif /* !defined(NO_AES) && defined(HAVE_AESCCM) */
|
#endif /* !defined(NO_AES) && defined(HAVE_AESCCM) */
|
||||||
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
||||||
@ -923,8 +924,9 @@ static int checkPad(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *buff)
|
|||||||
return ctx->block_size - n;
|
return ctx->block_size - n;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && \
|
||||||
|| FIPS_VERSION_GE(2,0))
|
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||||
|
|| FIPS_VERSION_GE(2,0))
|
||||||
static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
|
static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -941,8 +943,9 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|||||||
{
|
{
|
||||||
int fl;
|
int fl;
|
||||||
int ret = WOLFSSL_SUCCESS;
|
int ret = WOLFSSL_SUCCESS;
|
||||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && \
|
||||||
|| FIPS_VERSION_GE(2,0))
|
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||||
|
|| FIPS_VERSION_GE(2,0))
|
||||||
byte tmp = 0;
|
byte tmp = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1082,7 +1085,8 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|||||||
ctx->authIncIv = 0;
|
ctx->authIncIv = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Clear IV, since IV reuse is not recommended for AES CCM. */
|
/* Clear IV, since IV reuse is not recommended
|
||||||
|
* for AES CCM. */
|
||||||
XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE);
|
XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
if (wolfSSL_StoreExternalIV(ctx) != WOLFSSL_SUCCESS) {
|
if (wolfSSL_StoreExternalIV(ctx) != WOLFSSL_SUCCESS) {
|
||||||
@ -1165,8 +1169,9 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ret == WOLFSSL_SUCCESS) {
|
if (ret == WOLFSSL_SUCCESS) {
|
||||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && \
|
||||||
|| FIPS_VERSION_GE(2,0))
|
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||||
|
|| FIPS_VERSION_GE(2,0))
|
||||||
/*
|
/*
|
||||||
* This flag needs to retain its value between wolfSSL_EVP_CipherFinal
|
* This flag needs to retain its value between wolfSSL_EVP_CipherFinal
|
||||||
* calls. wolfSSL_EVP_CipherInit will clear it, so we save and restore
|
* calls. wolfSSL_EVP_CipherInit will clear it, so we save and restore
|
||||||
@ -1191,8 +1196,9 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|||||||
/* reset cipher state after final */
|
/* reset cipher state after final */
|
||||||
ret = wolfSSL_EVP_CipherInit(ctx, NULL, NULL, NULL, -1);
|
ret = wolfSSL_EVP_CipherInit(ctx, NULL, NULL, NULL, -1);
|
||||||
|
|
||||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && \
|
||||||
|| FIPS_VERSION_GE(2,0))
|
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||||
|
|| FIPS_VERSION_GE(2,0))
|
||||||
if (FALSE
|
if (FALSE
|
||||||
#ifdef HAVE_AESGCM
|
#ifdef HAVE_AESGCM
|
||||||
|| ctx->cipherType == AES_128_GCM_TYPE ||
|
|| ctx->cipherType == AES_128_GCM_TYPE ||
|
||||||
@ -5801,7 +5807,8 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
|||||||
case EVP_CTRL_SET_KEY_LENGTH:
|
case EVP_CTRL_SET_KEY_LENGTH:
|
||||||
ret = wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, arg);
|
ret = wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, arg);
|
||||||
break;
|
break;
|
||||||
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
|
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
|
||||||
|
(defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
|
||||||
case EVP_CTRL_AEAD_SET_IVLEN:
|
case EVP_CTRL_AEAD_SET_IVLEN:
|
||||||
if ((ctx->flags & WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER) == 0)
|
if ((ctx->flags & WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER) == 0)
|
||||||
break;
|
break;
|
||||||
@ -6587,8 +6594,9 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_AESGCM && ((!HAVE_FIPS && !HAVE_SELFTEST) ||
|
#endif /* HAVE_AESGCM && ((!HAVE_FIPS && !HAVE_SELFTEST) ||
|
||||||
* HAVE_FIPS_VERSION >= 2 */
|
* HAVE_FIPS_VERSION >= 2 */
|
||||||
#if defined(HAVE_AESCCM) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
#if defined(HAVE_AESCCM) && \
|
||||||
|| FIPS_VERSION_GE(2,0))
|
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||||
|
|| FIPS_VERSION_GE(2,0))
|
||||||
if (FALSE
|
if (FALSE
|
||||||
#ifdef WOLFSSL_AES_128
|
#ifdef WOLFSSL_AES_128
|
||||||
|| ctx->cipherType == AES_128_CCM_TYPE ||
|
|| ctx->cipherType == AES_128_CCM_TYPE ||
|
||||||
@ -7441,7 +7449,8 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
|
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
|
||||||
|
(defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
|
||||||
/* returns WOLFSSL_SUCCESS on success, otherwise returns WOLFSSL_FAILURE */
|
/* returns WOLFSSL_SUCCESS on success, otherwise returns WOLFSSL_FAILURE */
|
||||||
int wolfSSL_EVP_CIPHER_CTX_set_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* iv,
|
int wolfSSL_EVP_CIPHER_CTX_set_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* iv,
|
||||||
int ivLen)
|
int ivLen)
|
||||||
|
@ -444,7 +444,8 @@ struct WOLFSSL_EVP_CIPHER_CTX {
|
|||||||
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
||||||
byte* key; /* used in partial Init()s */
|
byte* key; /* used in partial Init()s */
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
|
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
|
||||||
|
(defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
|
||||||
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
|
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
|
||||||
ALIGN16 unsigned char authTag[AES_BLOCK_SIZE];
|
ALIGN16 unsigned char authTag[AES_BLOCK_SIZE];
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user