Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update test file paths in CMakeLists.txt #8462

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2500,17 +2500,17 @@ if(WOLFSSL_EXAMPLES)
# Build unit tests
add_executable(unit_test
tests/api.c
tests/api/test_dtls.c
tests/api/test_md5.c
tests/api/test_sha.c
tests/api/test_sha256.c
tests/api/test_sha512.c
tests/api/test_sha3.c
tests/api/test_blake2.c
tests/api/test_sm3.c
tests/api/test_ripemd.c
tests/api/test_hash.c
tests/api/test_ascon.c
tests/api/misc/test_dtls.c
tests/api/hash/test_md5.c
tests/api/hash/test_sha.c
tests/api/hash/test_sha256.c
tests/api/hash/test_sha512.c
tests/api/hash/test_sha3.c
tests/api/hash/test_blake2.c
tests/api/hash/test_sm3.c
tests/api/hash/test_ripemd.c
tests/api/hash/test_hash.c
tests/api/misc/test_ascon.c
tests/hash.c
tests/srp.c
tests/suites.c
Expand Down
37 changes: 26 additions & 11 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,32 @@
#include <tests/api/api.h>

/* Gather test declarations to include them in the testCases array */
#include <tests/api/test_md5.h>
#include <tests/api/test_sha.h>
#include <tests/api/test_sha256.h>
#include <tests/api/test_sha512.h>
#include <tests/api/test_sha3.h>
#include <tests/api/test_blake2.h>
#include <tests/api/test_sm3.h>
#include <tests/api/test_ripemd.h>
#include <tests/api/test_hash.h>
#include <tests/api/test_ascon.h>
#include <tests/api/test_dtls.h>
/* Core utilities */
#include <tests/api/core/test_utils.h>
#include <tests/api/core/test_data.h>
#include <tests/api/core/test_setup.h>

/* Hash tests */
#include <tests/api/hash/test_md5.h>
#include <tests/api/hash/test_sha.h>
#include <tests/api/hash/test_sha256.h>
#include <tests/api/hash/test_sha512.h>
#include <tests/api/hash/test_sha3.h>
#include <tests/api/hash/test_blake2.h>
#include <tests/api/hash/test_sm3.h>
#include <tests/api/hash/test_ripemd.h>
#include <tests/api/hash/test_hash.h>
/* Cipher tests */
#include <tests/api/cipher/test_aes.h>
#include <tests/api/cipher/test_des3.h>
#include <tests/api/cipher/test_camellia.h>
/* Public key tests */
#include <tests/api/pk/test_rsa.h>
#include <tests/api/pk/test_ecc.h>
#include <tests/api/pk/test_dsa.h>
/* Misc tests */
#include <tests/api/misc/test_ascon.h>
#include <tests/api/misc/test_dtls.h>

#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_TLS) && \
!defined(NO_RSA) && !defined(SINGLE_THREADED) && \
Expand Down
7 changes: 7 additions & 0 deletions tests/api/cipher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Cipher Algorithm Tests

This directory contains tests for cipher algorithms including:
- AES
- DES3
- Camellia
- ChaCha20
138 changes: 138 additions & 0 deletions tests/api/cipher/test_aes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* test_aes.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.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/aes.h>
#include <wolfssl/wolfcrypt/types.h>
#include <tests/unit.h>
#include <tests/api/test_aes.h>
#include "../core/test_utils.h"

/*******************************************************************************
* AES Tests
******************************************************************************/

int test_wc_AesInit(void)
{
#ifndef NO_AES
byte key[32];
byte iv[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[AES_BLOCK_SIZE];

return TEST_CRYPTO_OPERATION("AES",
wc_AesInit,
wc_AesSetKey,
wc_AesCbcEncrypt,
wc_AesFree,
plain, sizeof(plain), cipher);
#else
return EXPECT_RESULT();
#endif
}

int test_wc_AesSetKey(void)
{
EXPECT_DECLS;
#ifndef NO_AES
Aes aes;
byte key[32];
byte iv[AES_BLOCK_SIZE];

/* Test normal operation */
ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_AesSetKey(&aes, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION), 0);
ExpectIntEQ(wc_AesSetKey(&aes, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION), 0);

/* Test error cases */
ExpectIntEQ(wc_AesSetKey(NULL, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION),
BAD_FUNC_ARG);
ExpectIntEQ(wc_AesSetKey(&aes, NULL, AES_BLOCK_SIZE, iv, AES_ENCRYPTION),
BAD_FUNC_ARG);

wc_AesFree(&aes);
#endif
return EXPECT_RESULT();
}

int test_wc_AesCbcEncrypt(void)
{
EXPECT_DECLS;
#ifndef NO_AES
Aes aes;
byte key[32];
byte iv[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[AES_BLOCK_SIZE];

/* Test normal operation */
ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_AesSetKey(&aes, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION), 0);
ExpectIntEQ(wc_AesCbcEncrypt(&aes, cipher, plain, AES_BLOCK_SIZE), 0);

/* Test error cases */
ExpectIntEQ(wc_AesCbcEncrypt(NULL, cipher, plain, AES_BLOCK_SIZE),
BAD_FUNC_ARG);
ExpectIntEQ(wc_AesCbcEncrypt(&aes, NULL, plain, AES_BLOCK_SIZE),
BAD_FUNC_ARG);
ExpectIntEQ(wc_AesCbcEncrypt(&aes, cipher, NULL, AES_BLOCK_SIZE),
BAD_FUNC_ARG);

wc_AesFree(&aes);
#endif
return EXPECT_RESULT();
}

int test_wc_AesCbcDecrypt(void)
{
EXPECT_DECLS;
#ifndef NO_AES
Aes aes;
byte key[32];
byte iv[AES_BLOCK_SIZE];
byte plain[AES_BLOCK_SIZE];
byte cipher[AES_BLOCK_SIZE];

/* Test normal operation */
ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_AesSetKey(&aes, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION), 0);
ExpectIntEQ(wc_AesCbcDecrypt(&aes, plain, cipher, AES_BLOCK_SIZE), 0);

/* Test error cases */
ExpectIntEQ(wc_AesCbcDecrypt(NULL, plain, cipher, AES_BLOCK_SIZE),
BAD_FUNC_ARG);
ExpectIntEQ(wc_AesCbcDecrypt(&aes, NULL, cipher, AES_BLOCK_SIZE),
BAD_FUNC_ARG);
ExpectIntEQ(wc_AesCbcDecrypt(&aes, plain, NULL, AES_BLOCK_SIZE),
BAD_FUNC_ARG);

wc_AesFree(&aes);
#endif
return EXPECT_RESULT();
}

int test_wc_AesFree(void)
{
EXPECT_DECLS;
#ifndef NO_AES
Aes aes;
wc_AesInit(&aes, NULL, INVALID_DEVID);
wc_AesFree(&aes);
wc_AesFree(NULL); /* Test NULL case */
ExpectTrue(1);
#endif
return EXPECT_RESULT();
}
26 changes: 26 additions & 0 deletions tests/api/cipher/test_aes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* test_aes.h
*
* 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.
*/

#ifndef WOLFCRYPT_TEST_AES_H
#define WOLFCRYPT_TEST_AES_H

int test_wc_AesInit(void);
int test_wc_AesSetKey(void);
int test_wc_AesCbcEncrypt(void);
int test_wc_AesCbcDecrypt(void);
int test_wc_AesGcmSetKey(void);
int test_wc_AesGcmEncrypt(void);
int test_wc_AesGcmDecrypt(void);
int test_wc_AesCtrEncrypt(void);
int test_wc_AesFree(void);

#endif /* WOLFCRYPT_TEST_AES_H */
139 changes: 139 additions & 0 deletions tests/api/cipher/test_camellia.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/* test_camellia.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.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/camellia.h>
#include <wolfssl/wolfcrypt/types.h>
#include <tests/unit.h>
#include <tests/api/test_camellia.h>
#include "../core/test_utils.h"

/*******************************************************************************
* Camellia Tests
******************************************************************************/

int test_wc_CamelliaInit(void)
{
#ifdef HAVE_CAMELLIA
byte key[32];
byte iv[CAMELLIA_BLOCK_SIZE];
byte plain[CAMELLIA_BLOCK_SIZE];
byte cipher[CAMELLIA_BLOCK_SIZE];

return TEST_CRYPTO_OPERATION("CAMELLIA",
wc_CamelliaInit,
wc_CamelliaSetKey,
wc_CamelliaCbcEncrypt,
wc_CamelliaFree,
plain, sizeof(plain), cipher);
#else
return EXPECT_RESULT();
#endif
}

int test_wc_CamelliaSetKey(void)
{
EXPECT_DECLS;
#ifdef HAVE_CAMELLIA
Camellia camellia;
byte key[32];
byte iv[CAMELLIA_BLOCK_SIZE];

/* Test normal operation */
ExpectIntEQ(wc_CamelliaInit(&camellia, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_CamelliaSetKey(&camellia, key, 16, iv), 0);
ExpectIntEQ(wc_CamelliaSetKey(&camellia, key, 24, iv), 0);
ExpectIntEQ(wc_CamelliaSetKey(&camellia, key, 32, iv), 0);

/* Test error cases */
ExpectIntEQ(wc_CamelliaSetKey(NULL, key, 16, iv), BAD_FUNC_ARG);
ExpectIntEQ(wc_CamelliaSetKey(&camellia, NULL, 16, iv), BAD_FUNC_ARG);

wc_CamelliaFree(&camellia);
#endif
return EXPECT_RESULT();
}

int test_wc_CamelliaCbcEncrypt(void)
{
EXPECT_DECLS;
#ifdef HAVE_CAMELLIA
Camellia camellia;
byte key[32];
byte iv[CAMELLIA_BLOCK_SIZE];
byte plain[CAMELLIA_BLOCK_SIZE];
byte cipher[CAMELLIA_BLOCK_SIZE];

/* Test normal operation */
ExpectIntEQ(wc_CamelliaInit(&camellia, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_CamelliaSetKey(&camellia, key, 16, iv), 0);
ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, cipher, plain,
CAMELLIA_BLOCK_SIZE), 0);

/* Test error cases */
ExpectIntEQ(wc_CamelliaCbcEncrypt(NULL, cipher, plain,
CAMELLIA_BLOCK_SIZE), BAD_FUNC_ARG);
ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, NULL, plain,
CAMELLIA_BLOCK_SIZE), BAD_FUNC_ARG);
ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, cipher, NULL,
CAMELLIA_BLOCK_SIZE), BAD_FUNC_ARG);

wc_CamelliaFree(&camellia);
#endif
return EXPECT_RESULT();
}

int test_wc_CamelliaCbcDecrypt(void)
{
EXPECT_DECLS;
#ifdef HAVE_CAMELLIA
Camellia camellia;
byte key[32];
byte iv[CAMELLIA_BLOCK_SIZE];
byte plain[CAMELLIA_BLOCK_SIZE];
byte cipher[CAMELLIA_BLOCK_SIZE];

/* Test normal operation */
ExpectIntEQ(wc_CamelliaInit(&camellia, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_CamelliaSetKey(&camellia, key, 16, iv), 0);
ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, plain, cipher,
CAMELLIA_BLOCK_SIZE), 0);

/* Test error cases */
ExpectIntEQ(wc_CamelliaCbcDecrypt(NULL, plain, cipher,
CAMELLIA_BLOCK_SIZE), BAD_FUNC_ARG);
ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, NULL, cipher,
CAMELLIA_BLOCK_SIZE), BAD_FUNC_ARG);
ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, plain, NULL,
CAMELLIA_BLOCK_SIZE), BAD_FUNC_ARG);

wc_CamelliaFree(&camellia);
#endif
return EXPECT_RESULT();
}

int test_wc_CamelliaFree(void)
{
EXPECT_DECLS;
#ifdef HAVE_CAMELLIA
Camellia camellia;
wc_CamelliaInit(&camellia, NULL, INVALID_DEVID);
wc_CamelliaFree(&camellia);
wc_CamelliaFree(NULL); /* Test NULL case */
ExpectTrue(1);
#endif
return EXPECT_RESULT();
}
Loading
Loading