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) {
|
||||
/* Default uses 96-bits IV length */
|
||||
#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)
|
||||
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)
|
||||
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
|
||||
}
|
||||
else {
|
||||
#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)
|
||||
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)
|
||||
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
|
||||
/* 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_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
|
||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i],
|
||||
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], ciphertxt, &len, plaintxt, plaintxtSz));
|
||||
AssertIntEQ(1, EVP_EncryptUpdate(&en[i],
|
||||
ciphertxt, &len, plaintxt, plaintxtSz));
|
||||
ciphertxtSz = len;
|
||||
AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &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);
|
||||
|
||||
EVP_CIPHER_CTX_init(&de[i]);
|
||||
if (i == 0) {
|
||||
/* Default uses 96-bits IV length */
|
||||
#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)
|
||||
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)
|
||||
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
|
||||
}
|
||||
else {
|
||||
#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)
|
||||
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)
|
||||
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
|
||||
/* 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_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;
|
||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG, AES_BLOCK_SIZE, tag));
|
||||
AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
|
||||
AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i],
|
||||
EVP_CTRL_CCM_SET_TAG, AES_BLOCK_SIZE, tag));
|
||||
AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i],
|
||||
decryptedtxt, &len));
|
||||
decryptedtxtSz += len;
|
||||
AssertIntEQ(ciphertxtSz, decryptedtxtSz);
|
||||
AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
|
||||
@ -52249,9 +52269,11 @@ static int test_wolfssl_EVP_aes_ccm(void)
|
||||
/* modify tag*/
|
||||
tag[AES_BLOCK_SIZE-1]+=0xBB;
|
||||
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 */
|
||||
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, len);
|
||||
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_192_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);
|
||||
#endif /* !defined(NO_AES) && defined(HAVE_AESCCM) */
|
||||
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
||||
@ -923,7 +924,8 @@ static int checkPad(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *buff)
|
||||
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)) && \
|
||||
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
|| FIPS_VERSION_GE(2,0))
|
||||
static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
|
||||
{
|
||||
@ -941,7 +943,8 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
{
|
||||
int fl;
|
||||
int ret = WOLFSSL_SUCCESS;
|
||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && \
|
||||
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
|| FIPS_VERSION_GE(2,0))
|
||||
byte tmp = 0;
|
||||
#endif
|
||||
@ -1082,7 +1085,8 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
ctx->authIncIv = 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (wolfSSL_StoreExternalIV(ctx) != WOLFSSL_SUCCESS) {
|
||||
@ -1165,7 +1169,8 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
}
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
#if (defined(HAVE_AESGCM) || defined(HAVE_AESCCM)) && \
|
||||
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
|| FIPS_VERSION_GE(2,0))
|
||||
/*
|
||||
* This flag needs to retain its value between wolfSSL_EVP_CipherFinal
|
||||
@ -1191,7 +1196,8 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
/* reset cipher state after final */
|
||||
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)) && \
|
||||
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
|| FIPS_VERSION_GE(2,0))
|
||||
if (FALSE
|
||||
#ifdef HAVE_AESGCM
|
||||
@ -5801,7 +5807,8 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
||||
case EVP_CTRL_SET_KEY_LENGTH:
|
||||
ret = wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, arg);
|
||||
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:
|
||||
if ((ctx->flags & WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER) == 0)
|
||||
break;
|
||||
@ -6587,7 +6594,8 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
||||
}
|
||||
#endif /* HAVE_AESGCM && ((!HAVE_FIPS && !HAVE_SELFTEST) ||
|
||||
* HAVE_FIPS_VERSION >= 2 */
|
||||
#if defined(HAVE_AESCCM) && ((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
#if defined(HAVE_AESCCM) && \
|
||||
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) \
|
||||
|| FIPS_VERSION_GE(2,0))
|
||||
if (FALSE
|
||||
#ifdef WOLFSSL_AES_128
|
||||
@ -7441,7 +7449,8 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
||||
}
|
||||
#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 */
|
||||
int wolfSSL_EVP_CIPHER_CTX_set_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* iv,
|
||||
int ivLen)
|
||||
|
@ -444,7 +444,8 @@ struct WOLFSSL_EVP_CIPHER_CTX {
|
||||
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
||||
byte* key; /* used in partial Init()s */
|
||||
#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)
|
||||
ALIGN16 unsigned char authTag[AES_BLOCK_SIZE];
|
||||
#else
|
||||
|
Reference in New Issue
Block a user