Files
wolfssl/tests/api/test_evp.c

71 lines
2.3 KiB
C
Raw Permalink Normal View History

/* test_evp.c
*
* Copyright (C) 2006-2025 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <tests/unit.h>
#include <wolfssl/openssl/evp.h>
#include <tests/api/test_evp.h>
/* Test for NULL_CIPHER_TYPE in wolfSSL_EVP_CipherUpdate() */
int test_wolfSSL_EVP_CipherUpdate_Null(void)
{
EXPECT_DECLS;
#ifdef OPENSSL_EXTRA
WOLFSSL_EVP_CIPHER_CTX* ctx;
const char* testData = "Test NULL cipher data";
unsigned char output[100];
int outputLen = 0;
int testDataLen = (int)XSTRLEN(testData);
/* Create and initialize the cipher context */
ctx = wolfSSL_EVP_CIPHER_CTX_new();
ExpectNotNull(ctx);
/* Initialize with NULL cipher */
2025-02-28 16:06:24 -07:00
ExpectIntEQ(wolfSSL_EVP_CipherInit_ex(ctx, wolfSSL_EVP_enc_null(),
NULL, NULL, NULL, 1), WOLFSSL_SUCCESS);
/* Test encryption (which should just copy the data) */
2025-02-28 16:06:24 -07:00
ExpectIntEQ(wolfSSL_EVP_CipherUpdate(ctx, output, &outputLen,
(const unsigned char*)testData,
testDataLen), WOLFSSL_SUCCESS);
2025-02-28 16:06:24 -07:00
/* Verify output length matches input length */
ExpectIntEQ(outputLen, testDataLen);
2025-02-28 16:06:24 -07:00
/* Verify output data matches input data (no encryption occurred) */
ExpectIntEQ(XMEMCMP(output, testData, testDataLen), 0);
/* Clean up */
wolfSSL_EVP_CIPHER_CTX_free(ctx);
#endif /* OPENSSL_EXTRA */
return EXPECT_RESULT();
}