From a98ef2c20d74218d6c47a545c1b7146a8343f708 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 17 Feb 2025 18:54:52 +0000 Subject: [PATCH] Fix: Remove old test files and update includes Co-Authored-By: kaleb@wolfssl.com --- tests/api/test_blake2.c | 114 ----- tests/api/test_blake2.h | 29 -- tests/api/test_hash.c | 230 --------- tests/api/test_hash.h | 29 -- tests/api/test_md5.c | 144 ------ tests/api/test_md5.h | 29 -- tests/api/test_ripemd.c | 139 ------ tests/api/test_ripemd.h | 29 -- tests/api/test_sha.c | 146 ------ tests/api/test_sha.h | 29 -- tests/api/test_sha256.c | 503 ------------------- tests/api/test_sha256.h | 43 -- tests/api/test_sha3.c | 730 ---------------------------- tests/api/test_sha3.h | 43 -- tests/api/test_sha512.c | 1021 --------------------------------------- tests/api/test_sha512.h | 61 --- 16 files changed, 3319 deletions(-) delete mode 100644 tests/api/test_blake2.c delete mode 100644 tests/api/test_blake2.h delete mode 100644 tests/api/test_hash.c delete mode 100644 tests/api/test_hash.h delete mode 100644 tests/api/test_md5.c delete mode 100644 tests/api/test_md5.h delete mode 100644 tests/api/test_ripemd.c delete mode 100644 tests/api/test_ripemd.h delete mode 100644 tests/api/test_sha.c delete mode 100644 tests/api/test_sha.h delete mode 100644 tests/api/test_sha256.c delete mode 100644 tests/api/test_sha256.h delete mode 100644 tests/api/test_sha3.c delete mode 100644 tests/api/test_sha3.h delete mode 100644 tests/api/test_sha512.c delete mode 100644 tests/api/test_sha512.h diff --git a/tests/api/test_blake2.c b/tests/api/test_blake2.c deleted file mode 100644 index d3931a55a..000000000 --- a/tests/api/test_blake2.c +++ /dev/null @@ -1,114 +0,0 @@ -/* test_blake2.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -/* - * Unit test for the wc_InitBlake2b() - */ -int test_wc_InitBlake2b(void) -{ - EXPECT_DECLS; -#ifdef HAVE_BLAKE2 - Blake2b blake; - - /* Test good arg. */ - ExpectIntEQ(wc_InitBlake2b(&blake, 64), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitBlake2b(NULL, 64), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2b(NULL, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2b(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2b(&blake, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitBlake2b*/ - -/* - * Unit test for the wc_InitBlake2b_WithKey() - */ -int test_wc_InitBlake2b_WithKey(void) -{ - EXPECT_DECLS; -#ifdef HAVE_BLAKE2 - Blake2b blake; - word32 digestSz = BLAKE2B_KEYBYTES; - byte key[BLAKE2B_KEYBYTES]; - word32 keylen = BLAKE2B_KEYBYTES; - - XMEMSET(key, 0, sizeof(key)); - - /* Test good arg. */ - ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0); - /* Test bad args. */ - ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, 256), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0); -#endif - return EXPECT_RESULT(); -} /* END wc_InitBlake2b_WithKey*/ - -/* - * Unit test for the wc_InitBlake2s_WithKey() - */ -int test_wc_InitBlake2s_WithKey(void) -{ - EXPECT_DECLS; -#ifdef HAVE_BLAKE2S - Blake2s blake; - word32 digestSz = BLAKE2S_KEYBYTES; - byte *key = (byte*)"01234567890123456789012345678901"; - word32 keylen = BLAKE2S_KEYBYTES; - - /* Test good arg. */ - ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0); - /* Test bad args. */ - ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, 256), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0); -#endif - return EXPECT_RESULT(); -} /* END wc_InitBlake2s_WithKey*/ - diff --git a/tests/api/test_blake2.h b/tests/api/test_blake2.h deleted file mode 100644 index 752256d47..000000000 --- a/tests/api/test_blake2.h +++ /dev/null @@ -1,29 +0,0 @@ -/* test_blake2.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_BLAKE2_H -#define WOLFCRYPT_TEST_BLAKE2_H - -int test_wc_InitBlake2b(void); -int test_wc_InitBlake2b_WithKey(void); -int test_wc_InitBlake2s_WithKey(void); - -#endif /* WOLFCRYPT_TEST_BLAKE2_H */ diff --git a/tests/api/test_hash.c b/tests/api/test_hash.c deleted file mode 100644 index 965aac575..000000000 --- a/tests/api/test_hash.c +++ /dev/null @@ -1,230 +0,0 @@ -/* test_hash.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -int test_wc_HashInit(void) -{ - EXPECT_DECLS; - int i; /* 0 indicates tests passed, 1 indicates failure */ - - wc_HashAlg hash; - - /* enum for holding supported algorithms, #ifndef's restrict if disabled */ - enum wc_HashType enumArray[] = { - #ifndef NO_MD5 - WC_HASH_TYPE_MD5, - #endif - #ifndef NO_SHA - WC_HASH_TYPE_SHA, - #endif - #ifdef WOLFSSL_SHA224 - WC_HASH_TYPE_SHA224, - #endif - #ifndef NO_SHA256 - WC_HASH_TYPE_SHA256, - #endif - #ifdef WOLFSSL_SHA384 - WC_HASH_TYPE_SHA384, - #endif - #ifdef WOLFSSL_SHA512 - WC_HASH_TYPE_SHA512, - #endif - }; - /* dynamically finds the length */ - int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType)); - - /* For loop to test various arguments... */ - for (i = 0; i < enumlen; i++) { - /* check for bad args */ - ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0); - wc_HashFree(&hash, enumArray[i]); - - /* check for null ptr */ - ExpectIntEQ(wc_HashInit(NULL, enumArray[i]), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - } /* end of for loop */ - - return EXPECT_RESULT(); -} /* end of test_wc_HashInit */ - -/* - * Unit test function for wc_HashSetFlags() - */ -int test_wc_HashSetFlags(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_HASH_FLAGS - wc_HashAlg hash; - word32 flags = 0; - int i, j; - int notSupportedLen; - - /* enum for holding supported algorithms, #ifndef's restrict if disabled */ - enum wc_HashType enumArray[] = { - #ifndef NO_MD5 - WC_HASH_TYPE_MD5, - #endif - #ifndef NO_SHA - WC_HASH_TYPE_SHA, - #endif - #ifdef WOLFSSL_SHA224 - WC_HASH_TYPE_SHA224, - #endif - #ifndef NO_SHA256 - WC_HASH_TYPE_SHA256, - #endif - #ifdef WOLFSSL_SHA384 - WC_HASH_TYPE_SHA384, - #endif - #ifdef WOLFSSL_SHA512 - WC_HASH_TYPE_SHA512, - #endif - #ifdef WOLFSSL_SHA3 - WC_HASH_TYPE_SHA3_224, - #endif - }; - enum wc_HashType notSupported[] = { - WC_HASH_TYPE_MD5_SHA, - WC_HASH_TYPE_MD2, - WC_HASH_TYPE_MD4, - WC_HASH_TYPE_BLAKE2B, - WC_HASH_TYPE_BLAKE2S, - WC_HASH_TYPE_NONE, - }; - - /* dynamically finds the length */ - int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType)); - - /* For loop to test various arguments... */ - for (i = 0; i < enumlen; i++) { - ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0); - ExpectIntEQ(wc_HashSetFlags(&hash, enumArray[i], flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - ExpectIntEQ(wc_HashSetFlags(NULL, enumArray[i], flags), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_HashFree(&hash, enumArray[i]); - - } - /* For loop to test not supported cases */ - notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType)); - for (j = 0; j < notSupportedLen; j++) { - ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_HashSetFlags(&hash, notSupported[j], flags), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - } -#endif - return EXPECT_RESULT(); -} /* END test_wc_HashSetFlags */ - -/* - * Unit test function for wc_HashGetFlags() - */ -int test_wc_HashGetFlags(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_HASH_FLAGS - wc_HashAlg hash; - word32 flags = 0; - int i, j; - - /* enum for holding supported algorithms, #ifndef's restrict if disabled */ - enum wc_HashType enumArray[] = { - #ifndef NO_MD5 - WC_HASH_TYPE_MD5, - #endif - #ifndef NO_SHA - WC_HASH_TYPE_SHA, - #endif - #ifdef WOLFSSL_SHA224 - WC_HASH_TYPE_SHA224, - #endif - #ifndef NO_SHA256 - WC_HASH_TYPE_SHA256, - #endif - #ifdef WOLFSSL_SHA384 - WC_HASH_TYPE_SHA384, - #endif - #ifdef WOLFSSL_SHA512 - WC_HASH_TYPE_SHA512, - #endif - #ifdef WOLFSSL_SHA3 - WC_HASH_TYPE_SHA3_224, - #endif - }; - enum wc_HashType notSupported[] = { - WC_HASH_TYPE_MD5_SHA, - WC_HASH_TYPE_MD2, - WC_HASH_TYPE_MD4, - WC_HASH_TYPE_BLAKE2B, - WC_HASH_TYPE_BLAKE2S, - WC_HASH_TYPE_NONE, - }; - int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType)); - int notSupportedLen; - - /* For loop to test various arguments... */ - for (i = 0; i < enumlen; i++) { - ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0); - ExpectIntEQ(wc_HashGetFlags(&hash, enumArray[i], &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - ExpectIntEQ(wc_HashGetFlags(NULL, enumArray[i], &flags), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_HashFree(&hash, enumArray[i]); - } - /* For loop to test not supported cases */ - notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType)); - for (j = 0; j < notSupportedLen; j++) { - ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_HashGetFlags(&hash, notSupported[j], &flags), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - } -#endif - return EXPECT_RESULT(); -} /* END test_wc_HashGetFlags */ - diff --git a/tests/api/test_hash.h b/tests/api/test_hash.h deleted file mode 100644 index 8d7be7104..000000000 --- a/tests/api/test_hash.h +++ /dev/null @@ -1,29 +0,0 @@ -/* test_hash.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_HASH_H -#define WOLFCRYPT_TEST_HASH_H - -int test_wc_HashInit(void); -int test_wc_HashSetFlags(void); -int test_wc_HashGetFlags(void); - -#endif /* WOLFCRYPT_TEST_HASH_H */ diff --git a/tests/api/test_md5.c b/tests/api/test_md5.c deleted file mode 100644 index 702263581..000000000 --- a/tests/api/test_md5.c +++ /dev/null @@ -1,144 +0,0 @@ -/* test_md5.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -/* - * Unit test for the wc_InitMd5() - */ -int test_wc_InitMd5(void) -{ - EXPECT_DECLS; -#ifndef NO_MD5 - wc_Md5 md5; - - /* Test good arg. */ - ExpectIntEQ(wc_InitMd5(&md5), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitMd5(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Md5Free(&md5); -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitMd5 */ - - -/* - * Testing wc_UpdateMd5() - */ -int test_wc_Md5Update(void) -{ - EXPECT_DECLS; -#ifndef NO_MD5 - wc_Md5 md5; - byte hash[WC_MD5_DIGEST_SIZE]; - testVector a, b, c; - - ExpectIntEQ(wc_InitMd5(&md5), 0); - - /* Input */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_Md5Update(&md5, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Md5Final(&md5, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f" - "\x72"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_Md5Update(&md5, (byte*) a.input, (word32) a.inLen), 0); - ExpectIntEQ(wc_Md5Final(&md5, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0); - - /* Pass in bad values. */ - b.input = NULL; - b.inLen = 0; - ExpectIntEQ(wc_Md5Update(&md5, (byte*)b.input, (word32)b.inLen), 0); - c.input = NULL; - c.inLen = WC_MD5_DIGEST_SIZE; - ExpectIntEQ(wc_Md5Update(&md5, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Md5Update(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Md5Free(&md5); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Md5Update() */ - -/* - * Unit test on wc_Md5Final() in wolfcrypt/src/md5.c - */ -int test_wc_Md5Final(void) -{ - EXPECT_DECLS; -#ifndef NO_MD5 - /* Instantiate */ - wc_Md5 md5; - byte* hash_test[3]; - byte hash1[WC_MD5_DIGEST_SIZE]; - byte hash2[2*WC_MD5_DIGEST_SIZE]; - byte hash3[5*WC_MD5_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitMd5(&md5), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test)/sizeof(byte*); - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Md5Final(&md5, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Md5Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Md5Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Md5Final(&md5, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Md5Free(&md5); -#endif - return EXPECT_RESULT(); -} - diff --git a/tests/api/test_md5.h b/tests/api/test_md5.h deleted file mode 100644 index f9c5e07ec..000000000 --- a/tests/api/test_md5.h +++ /dev/null @@ -1,29 +0,0 @@ -/* test_md5.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_MD5_H -#define WOLFCRYPT_TEST_MD5_H - -int test_wc_InitMd5(void); -int test_wc_Md5Update(void); -int test_wc_Md5Final(void); - -#endif /* WOLFCRYPT_TEST_MD5_H */ diff --git a/tests/api/test_ripemd.c b/tests/api/test_ripemd.c deleted file mode 100644 index 5b030cf31..000000000 --- a/tests/api/test_ripemd.c +++ /dev/null @@ -1,139 +0,0 @@ -/* test_ripemd.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -/* - * Testing wc_InitRipeMd() - */ -int test_wc_InitRipeMd(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_RIPEMD - RipeMd ripemd; - - /* Test good arg. */ - ExpectIntEQ(wc_InitRipeMd(&ripemd), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitRipeMd(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); -#endif - return EXPECT_RESULT(); - -} /* END test_wc_InitRipeMd */ - -/* - * Testing wc_RipeMdUpdate() - */ -int test_wc_RipeMdUpdate(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_RIPEMD - RipeMd ripemd; - byte hash[RIPEMD_DIGEST_SIZE]; - testVector a, b, c; - - ExpectIntEQ(wc_InitRipeMd(&ripemd), 0); - - /* Input */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6" - "\xb0\x87\xf1\x5a\x0b\xfc"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE), 0); - - /* Pass in bad values. */ - b.input = NULL; - b.inLen = 0; - ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen), 0); - c.input = NULL; - c.inLen = RIPEMD_DIGEST_SIZE; - ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); -#endif - return EXPECT_RESULT(); -} /* END test_wc_RipeMdUdpate */ - -/* - * Unit test function for wc_RipeMdFinal() - */ -int test_wc_RipeMdFinal(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_RIPEMD - RipeMd ripemd; - byte* hash_test[3]; - byte hash1[RIPEMD_DIGEST_SIZE]; - byte hash2[2*RIPEMD_DIGEST_SIZE]; - byte hash3[5*RIPEMD_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitRipeMd(&ripemd), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte*); - /* Testing oversized buffers. */ - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_RipeMdFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_RipeMdFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_RipeMdFinal(&ripemd, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); -#endif - return EXPECT_RESULT(); -} /* END test_wc_RipeMdFinal */ - - diff --git a/tests/api/test_ripemd.h b/tests/api/test_ripemd.h deleted file mode 100644 index 23cb0ac07..000000000 --- a/tests/api/test_ripemd.h +++ /dev/null @@ -1,29 +0,0 @@ -/* test_ripemd.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_RIPEMD_H -#define WOLFCRYPT_TEST_RIPEMD_H - -int test_wc_InitRipeMd(void); -int test_wc_RipeMdUpdate(void); -int test_wc_RipeMdFinal(void); - -#endif /* WOLFCRYPT_TEST_RIPEMD_H */ diff --git a/tests/api/test_sha.c b/tests/api/test_sha.c deleted file mode 100644 index 5fbcfc3a3..000000000 --- a/tests/api/test_sha.c +++ /dev/null @@ -1,146 +0,0 @@ -/* test_sha.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -/* - * Unit test for the wc_InitSha() - */ -int test_wc_InitSha(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA - wc_Sha sha; - - /* Test good arg. */ - ExpectIntEQ(wc_InitSha(&sha), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitSha(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_ShaFree(&sha); -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitSha */ - -/* - * Tesing wc_ShaUpdate() - */ -int test_wc_ShaUpdate(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA - wc_Sha sha; - byte hash[WC_SHA_DIGEST_SIZE]; - testVector a, b, c; - - ExpectIntEQ(wc_InitSha(&sha), 0); - - /* Input. */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - - ExpectIntEQ(wc_ShaUpdate(&sha, NULL, 0), 0); - ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, 0), 0); - ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_ShaFinal(&sha, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2" - "\x6C\x9C\xD0\xD8\x9D"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - - ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_ShaFinal(&sha, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0); - - /* Try passing in bad values. */ - b.input = NULL; - b.inLen = 0; - ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)b.input, (word32)b.inLen), 0); - c.input = NULL; - c.inLen = WC_SHA_DIGEST_SIZE; - ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_ShaUpdate(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_ShaFree(&sha); -#endif - return EXPECT_RESULT(); -} /* END test_wc_ShaUpdate() */ - -/* - * Unit test on wc_ShaFinal - */ -int test_wc_ShaFinal(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA - wc_Sha sha; - byte* hash_test[3]; - byte hash1[WC_SHA_DIGEST_SIZE]; - byte hash2[2*WC_SHA_DIGEST_SIZE]; - byte hash3[5*WC_SHA_DIGEST_SIZE]; - int times, i; - - /* Initialize*/ - ExpectIntEQ(wc_InitSha(&sha), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test)/sizeof(byte*); - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_ShaFinal(&sha, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_ShaFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_ShaFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_ShaFinal(&sha, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_ShaFree(&sha); -#endif - return EXPECT_RESULT(); -} /* END test_wc_ShaFinal */ - diff --git a/tests/api/test_sha.h b/tests/api/test_sha.h deleted file mode 100644 index 651ff459b..000000000 --- a/tests/api/test_sha.h +++ /dev/null @@ -1,29 +0,0 @@ -/* test_sha.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_SHA_H -#define WOLFCRYPT_TEST_SHA_H - -int test_wc_InitSha(void); -int test_wc_ShaUpdate(void); -int test_wc_ShaFinal(void); - -#endif /* WOLFCRYPT_TEST_SHA_H */ diff --git a/tests/api/test_sha256.c b/tests/api/test_sha256.c deleted file mode 100644 index 41176033a..000000000 --- a/tests/api/test_sha256.c +++ /dev/null @@ -1,503 +0,0 @@ -/* test_sha256.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -/******************************************************************************* - * SHA-256 - ******************************************************************************/ - -/* - * Unit test for wc_InitSha256() - */ -int test_wc_InitSha256(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA256 - wc_Sha256 sha256; - - /* Test good arg. */ - ExpectIntEQ(wc_InitSha256(&sha256), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitSha256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha256Free(&sha256); -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitSha256 */ - -/* - * Unit test for wc_Sha256Update() - */ -int test_wc_Sha256Update(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA256 - wc_Sha256 sha256; - byte hash[WC_SHA256_DIGEST_SIZE]; - byte hash_unaligned[WC_SHA256_DIGEST_SIZE+1]; - testVector a, b, c; - - ExpectIntEQ(wc_InitSha256(&sha256), 0); - - /* Input. */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_Sha256Update(&sha256, NULL, 0), 0); - ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, 0), 0); - ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22" - "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00" - "\x15\xAD"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0); - - /* Unaligned check. */ - ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input+1, (word32)a.inLen-1), - 0); - ExpectIntEQ(wc_Sha256Final(&sha256, hash_unaligned + 1), 0); - - /* Try passing in bad values */ - b.input = NULL; - b.inLen = 0; - ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)b.input, (word32)b.inLen), 0); - c.input = NULL; - c.inLen = WC_SHA256_DIGEST_SIZE; - ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256Update(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha256Free(&sha256); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha256Update */ - -/* - * Unit test function for wc_Sha256Final() - */ -int test_wc_Sha256Final(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA256 - wc_Sha256 sha256; - byte* hash_test[3]; - byte hash1[WC_SHA256_DIGEST_SIZE]; - byte hash2[2*WC_SHA256_DIGEST_SIZE]; - byte hash3[5*WC_SHA256_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitSha256(&sha256), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte*); - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Sha256Final(&sha256, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Sha256Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256Final(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha256Free(&sha256); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha256Final */ - -/* - * Unit test function for wc_Sha256FinalRaw() - */ -int test_wc_Sha256FinalRaw(void) -{ - EXPECT_DECLS; -#if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && \ - !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \ - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \ - !defined(WOLFSSL_NO_HASH_RAW) - wc_Sha256 sha256; - byte* hash_test[3]; - byte hash1[WC_SHA256_DIGEST_SIZE]; - byte hash2[2*WC_SHA256_DIGEST_SIZE]; - byte hash3[5*WC_SHA256_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitSha256(&sha256), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte*); - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Sha256FinalRaw(&sha256, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Sha256FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256FinalRaw(&sha256, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha256Free(&sha256); -#endif - return EXPECT_RESULT(); - -} /* END test_wc_Sha256FinalRaw */ - -/* - * Unit test function for wc_Sha256GetFlags() - */ -int test_wc_Sha256GetFlags(void) -{ - EXPECT_DECLS; -#if !defined(NO_SHA256) && defined(WOLFSSL_HASH_FLAGS) - wc_Sha256 sha256; - word32 flags = 0; - - /* Initialize */ - ExpectIntEQ(wc_InitSha256(&sha256), 0); - - ExpectIntEQ(wc_Sha256GetFlags(&sha256, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - wc_Sha256Free(&sha256); -#endif - return EXPECT_RESULT(); - -} /* END test_wc_Sha256GetFlags */ - -/* - * Unit test function for wc_Sha256Free() - */ -int test_wc_Sha256Free(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA256 - wc_Sha256Free(NULL); - /* Set result to SUCCESS. */ - ExpectTrue(1); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha256Free */ -/* - * Unit test function for wc_Sha256GetHash() - */ -int test_wc_Sha256GetHash(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA256 - wc_Sha256 sha256; - byte hash1[WC_SHA256_DIGEST_SIZE]; - - /* Initialize */ - ExpectIntEQ(wc_InitSha256(&sha256), 0); - - ExpectIntEQ(wc_Sha256GetHash(&sha256, hash1), 0); - - /* test bad arguments*/ - ExpectIntEQ(wc_Sha256GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256GetHash(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha256Free(&sha256); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha256GetHash */ - -/* - * Unit test function for wc_Sha256Copy() - */ -int test_wc_Sha256Copy(void) -{ - EXPECT_DECLS; -#ifndef NO_SHA256 - wc_Sha256 sha256; - wc_Sha256 temp; - - XMEMSET(&sha256, 0, sizeof(sha256)); - XMEMSET(&temp, 0, sizeof(temp)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha256(&sha256), 0); - ExpectIntEQ(wc_InitSha256(&temp), 0); - - ExpectIntEQ(wc_Sha256Copy(&sha256, &temp), 0); - - /* test bad arguments*/ - ExpectIntEQ(wc_Sha256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha256Copy(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha256Free(&sha256); - wc_Sha256Free(&temp); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha256Copy */ - - -/******************************************************************************* - * SHA-224 - ******************************************************************************/ - -/* - * Testing wc_InitSha224(); - */ -int test_wc_InitSha224(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA224 - wc_Sha224 sha224; - - /* Test good arg. */ - ExpectIntEQ(wc_InitSha224(&sha224), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitSha224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha224Free(&sha224); -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitSha224 */ - -/* - * Unit test on wc_Sha224Update - */ -int test_wc_Sha224Update(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA224 - wc_Sha224 sha224; - byte hash[WC_SHA224_DIGEST_SIZE]; - testVector a, b, c; - - ExpectIntEQ(wc_InitSha224(&sha224), 0); - - /* Input. */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_Sha224Update(&sha224, NULL, 0), 0); - ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, 0), 0); - ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2" - "\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0); - - /* Pass in bad values. */ - b.input = NULL; - b.inLen = 0; - ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen), 0); - c.input = NULL; - c.inLen = WC_SHA224_DIGEST_SIZE; - ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha224Free(&sha224); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha224Update */ - -/* - * Unit test for wc_Sha224Final(); - */ -int test_wc_Sha224Final(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA224 - wc_Sha224 sha224; - byte* hash_test[3]; - byte hash1[WC_SHA224_DIGEST_SIZE]; - byte hash2[2*WC_SHA224_DIGEST_SIZE]; - byte hash3[5*WC_SHA224_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitSha224(&sha224), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte*); - /* Good test args. */ - /* Testing oversized buffers. */ - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Sha224Final(&sha224, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Sha224Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha224Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha224Final(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha224Free(&sha224); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha224Final */ - -/* - * Unit test function for wc_Sha224SetFlags() - */ -int test_wc_Sha224SetFlags(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS) - wc_Sha224 sha224; - word32 flags = WC_HASH_FLAG_WILLCOPY; - - /* Initialize */ - ExpectIntEQ(wc_InitSha224(&sha224), 0); - - ExpectIntEQ(wc_Sha224SetFlags(&sha224, flags), 0); - flags = 0; - ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0); - ExpectTrue(flags == WC_HASH_FLAG_WILLCOPY); - - wc_Sha224Free(&sha224); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha224SetFlags */ - -/* - * Unit test function for wc_Sha224GetFlags() - */ -int test_wc_Sha224GetFlags(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS) - wc_Sha224 sha224; - word32 flags = 0; - - /* Initialize */ - ExpectIntEQ(wc_InitSha224(&sha224), 0); - - ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - - wc_Sha224Free(&sha224); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha224GetFlags */ -/* - * Unit test function for wc_Sha224Free() - */ -int test_wc_Sha224Free(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA224 - wc_Sha224Free(NULL); - /* Set result to SUCCESS. */ - ExpectTrue(1); -#endif - return EXPECT_RESULT(); - -} /* END test_wc_Sha224Free */ - -/* - * Unit test function for wc_Sha224GetHash() - */ -int test_wc_Sha224GetHash(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA224 - wc_Sha224 sha224; - byte hash1[WC_SHA224_DIGEST_SIZE]; - - /* Initialize */ - ExpectIntEQ(wc_InitSha224(&sha224), 0); - - ExpectIntEQ(wc_Sha224GetHash(&sha224, hash1), 0); - /* test bad arguments*/ - ExpectIntEQ(wc_Sha224GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha224GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha224GetHash(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha224Free(&sha224); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha224GetHash */ - -/* - * Unit test function for wc_Sha224Copy() - */ -int test_wc_Sha224Copy(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA224 - wc_Sha224 sha224; - wc_Sha224 temp; - - XMEMSET(&sha224, 0, sizeof(wc_Sha224)); - XMEMSET(&temp, 0, sizeof(wc_Sha224)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha224(&sha224), 0); - ExpectIntEQ(wc_InitSha224(&temp), 0); - - ExpectIntEQ(wc_Sha224Copy(&sha224, &temp), 0); - /* test bad arguments*/ - ExpectIntEQ(wc_Sha224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha224Copy(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha224Free(&sha224); - wc_Sha224Free(&temp); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha224Copy */ - diff --git a/tests/api/test_sha256.h b/tests/api/test_sha256.h deleted file mode 100644 index 068e21b06..000000000 --- a/tests/api/test_sha256.h +++ /dev/null @@ -1,43 +0,0 @@ -/* test_sha256.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_SHA256_H -#define WOLFCRYPT_TEST_SHA256_H - -int test_wc_InitSha256(void); -int test_wc_Sha256Update(void); -int test_wc_Sha256Final(void); -int test_wc_Sha256FinalRaw(void); -int test_wc_Sha256GetFlags(void); -int test_wc_Sha256Free(void); -int test_wc_Sha256GetHash(void); -int test_wc_Sha256Copy(void); - -int test_wc_InitSha224(void); -int test_wc_Sha224Update(void); -int test_wc_Sha224Final(void); -int test_wc_Sha224SetFlags(void); -int test_wc_Sha224GetFlags(void); -int test_wc_Sha224Free(void); -int test_wc_Sha224GetHash(void); -int test_wc_Sha224Copy(void); - -#endif /* WOLFCRYPT_TEST_SHA256_H */ diff --git a/tests/api/test_sha3.c b/tests/api/test_sha3.c deleted file mode 100644 index aa8faccf9..000000000 --- a/tests/api/test_sha3.c +++ /dev/null @@ -1,730 +0,0 @@ -/* test_sha3.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -/******************************************************************************* - * SHA-3 - ******************************************************************************/ - -/* - * Testing wc_InitSha3_224, wc_InitSha3_256, wc_InitSha3_384, and - * wc_InitSha3_512 - */ -int test_wc_InitSha3(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) - wc_Sha3 sha3; - - (void)sha3; - -#if !defined(WOLFSSL_NOSHA3_224) - ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0); - /* Test bad args. */ - ExpectIntEQ(wc_InitSha3_224(NULL, HEAP_HINT, testDevId), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_224_Free(&sha3); -#endif /* NOSHA3_224 */ -#if !defined(WOLFSSL_NOSHA3_256) - ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0); - /* Test bad args. */ - ExpectIntEQ(wc_InitSha3_256(NULL, HEAP_HINT, testDevId), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_256_Free(&sha3); -#endif /* NOSHA3_256 */ -#if !defined(WOLFSSL_NOSHA3_384) - ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0); - /* Test bad args. */ - ExpectIntEQ(wc_InitSha3_384(NULL, HEAP_HINT, testDevId), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_384_Free(&sha3); -#endif /* NOSHA3_384 */ -#if !defined(WOLFSSL_NOSHA3_512) - ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0); - /* Test bad args. */ - ExpectIntEQ(wc_InitSha3_512(NULL, HEAP_HINT, testDevId), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_512_Free(&sha3); -#endif /* NOSHA3_512 */ -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitSha3 */ - -/* - * Testing wc_Sha3_Update() - */ -int test_wc_Sha3_Update(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_XILINX_CRYPT) && \ - !defined(WOLFSSL_AFALG_XILINX) - wc_Sha3 sha3; - byte msg[] = "Everybody's working for the weekend."; - byte msg2[] = "Everybody gets Friday off."; - byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20" - "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74" - "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76" - "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20" - "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e"; - word32 msglen = sizeof(msg) - 1; - word32 msg2len = sizeof(msg2); - word32 msgCmplen = sizeof(msgCmp); - - #if !defined(WOLFSSL_NOSHA3_224) - ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg, msglen), 0); - ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0); - ExpectTrue(sha3.i == msglen); - - ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0); - - /* Pass bad args. */ - ExpectIntEQ(wc_Sha3_224_Update(NULL, msg2, msg2len), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 5), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_224_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 0), 0); - ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0); - wc_Sha3_224_Free(&sha3); - #endif /* SHA3_224 */ - - #if !defined(WOLFSSL_NOSHA3_256) - ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg, msglen), 0); - ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0); - ExpectTrue(sha3.i == msglen); - - ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0); - - /* Pass bad args. */ - ExpectIntEQ(wc_Sha3_256_Update(NULL, msg2, msg2len), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 5), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_256_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 0), 0); - ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0); - wc_Sha3_256_Free(&sha3); - #endif /* SHA3_256 */ - - #if !defined(WOLFSSL_NOSHA3_384) - ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg, msglen), 0); - ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0); - ExpectTrue(sha3.i == msglen); - - ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0); - - /* Pass bad args. */ - ExpectIntEQ(wc_Sha3_384_Update(NULL, msg2, msg2len), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 5), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_384_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 0), 0); - ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0); - wc_Sha3_384_Free(&sha3); - #endif /* SHA3_384 */ - - #if !defined(WOLFSSL_NOSHA3_512) - ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg, msglen), 0); - ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0); - ExpectTrue(sha3.i == msglen); - - ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0); - - /* Pass bad args. */ - ExpectIntEQ(wc_Sha3_512_Update(NULL, msg2, msg2len), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 5), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_512_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 0), 0); - ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0); - wc_Sha3_512_Free(&sha3); - #endif /* SHA3_512 */ -#endif /* WOLFSSL_SHA3 */ - return EXPECT_RESULT(); -} /* END test_wc_Sha3_Update */ - -/* - * Testing wc_Sha3_224_Final() - */ -int test_wc_Sha3_224_Final(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224) - wc_Sha3 sha3; - const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom" - "nopnopq"; - const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55" - "\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2" - "\x64\xea\xd0\xfc\xce\x33"; - byte hash[WC_SHA3_224_DIGEST_SIZE]; - byte hashRet[WC_SHA3_224_DIGEST_SIZE]; - - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - - ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_224_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_224_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_224_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0); - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashRet, 0, sizeof(hashRet)); - ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, hashRet), 0); - ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_224_GetHash(NULL, hashRet), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_224_Free(&sha3); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_224_Final */ - -/* - * Testing wc_Sha3_256_Final() - */ -int test_wc_Sha3_256_Final(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) - wc_Sha3 sha3; - const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom" - "nopnopq"; - const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8" - "\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32" - "\xdd\x97\x49\x6d\x33\x76"; - byte hash[WC_SHA3_256_DIGEST_SIZE]; - byte hashRet[WC_SHA3_256_DIGEST_SIZE]; - - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - - ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_256_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_256_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_256_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0); - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashRet, 0, sizeof(hashRet)); - ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, hashRet), 0); - ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_256_GetHash(NULL, hashRet), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_256_Free(&sha3); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_256_Final */ - -/* - * Testing wc_Sha3_384_Final() - */ -int test_wc_Sha3_384_Final(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384) - wc_Sha3 sha3; - const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom" - "nopnopq"; - const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7" - "\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd" - "\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe" - "\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22"; - byte hash[WC_SHA3_384_DIGEST_SIZE]; - byte hashRet[WC_SHA3_384_DIGEST_SIZE]; - - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - - ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_384_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_384_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_384_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0); - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashRet, 0, sizeof(hashRet)); - ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, hashRet), 0); - ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_384_GetHash(NULL, hashRet), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_384_Free(&sha3); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_384_Final */ - -/* - * Testing wc_Sha3_512_Final() - */ -int test_wc_Sha3_512_Final(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) && \ - !defined(WOLFSSL_NOSHA3_384) - wc_Sha3 sha3; - const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom" - "nopnopq"; - const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10" - "\xfc\xa8\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7" - "\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53" - "\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4" - "\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e"; - byte hash[WC_SHA3_512_DIGEST_SIZE]; - byte hashRet[WC_SHA3_512_DIGEST_SIZE]; - - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - - ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_512_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_512_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Sha3_512_Free(&sha3); - - ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0); - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashRet, 0, sizeof(hashRet)); - ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0); - ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, hashRet), 0); - ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0); - ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_512_GetHash(NULL, hashRet), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_512_Free(&sha3); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_512_Final */ - -/* - * Testing wc_Sha3_224_Copy() - */ -int test_wc_Sha3_224_Copy(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224) - wc_Sha3 sha3, sha3Cpy; - const char* msg = TEST_STRING; - word32 msglen = (word32)TEST_STRING_SZ; - byte hash[WC_SHA3_224_DIGEST_SIZE]; - byte hashCpy[WC_SHA3_224_DIGEST_SIZE]; - - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashCpy, 0, sizeof(hashCpy)); - XMEMSET(&sha3, 0, sizeof(wc_Sha3)); - XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3)); - - ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_InitSha3_224(&sha3Cpy, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, msglen), 0); - ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, &sha3), 0); - ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0); - ExpectIntEQ(wc_Sha3_224_Final(&sha3Cpy, hashCpy), 0); - ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_224_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_224_Free(&sha3); - wc_Sha3_224_Free(&sha3Cpy); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_224_Copy */ - -/* - * Testing wc_Sha3_256_Copy() - */ -int test_wc_Sha3_256_Copy(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) - wc_Sha3 sha3, sha3Cpy; - const char* msg = TEST_STRING; - word32 msglen = (word32)TEST_STRING_SZ; - byte hash[WC_SHA3_256_DIGEST_SIZE]; - byte hashCpy[WC_SHA3_256_DIGEST_SIZE]; - - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashCpy, 0, sizeof(hashCpy)); - XMEMSET(&sha3, 0, sizeof(wc_Sha3)); - XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3)); - - ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_InitSha3_256(&sha3Cpy, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, msglen), 0); - ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, &sha3), 0); - ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0); - ExpectIntEQ(wc_Sha3_256_Final(&sha3Cpy, hashCpy), 0); - ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_256_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_256_Free(&sha3); - wc_Sha3_256_Free(&sha3Cpy); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_256_Copy */ - -/* - * Testing wc_Sha3_384_Copy() - */ -int test_wc_Sha3_384_Copy(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384) - wc_Sha3 sha3, sha3Cpy; - const char* msg = TEST_STRING; - word32 msglen = (word32)TEST_STRING_SZ; - byte hash[WC_SHA3_384_DIGEST_SIZE]; - byte hashCpy[WC_SHA3_384_DIGEST_SIZE]; - - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashCpy, 0, sizeof(hashCpy)); - XMEMSET(&sha3, 0, sizeof(wc_Sha3)); - XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3)); - - ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_InitSha3_384(&sha3Cpy, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, msglen), 0); - ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, &sha3), 0); - ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0); - ExpectIntEQ(wc_Sha3_384_Final(&sha3Cpy, hashCpy), 0); - ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_384_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_384_Free(&sha3); - wc_Sha3_384_Free(&sha3Cpy); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_384_Copy */ - -/* - * Testing wc_Sha3_512_Copy() - */ -int test_wc_Sha3_512_Copy(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) - wc_Sha3 sha3, sha3Cpy; - const char* msg = TEST_STRING; - word32 msglen = (word32)TEST_STRING_SZ; - byte hash[WC_SHA3_512_DIGEST_SIZE]; - byte hashCpy[WC_SHA3_512_DIGEST_SIZE]; - - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashCpy, 0, sizeof(hashCpy)); - XMEMSET(&sha3, 0, sizeof(wc_Sha3)); - XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3)); - - ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_InitSha3_512(&sha3Cpy, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, msglen), 0); - ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, &sha3), 0); - ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0); - ExpectIntEQ(wc_Sha3_512_Final(&sha3Cpy, hashCpy), 0); - ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Sha3_512_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha3_512_Free(&sha3); - wc_Sha3_512_Free(&sha3Cpy); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_512_Copy */ - -/* - * Unit test function for wc_Sha3_GetFlags() - */ -int test_wc_Sha3_GetFlags(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_HASH_FLAGS) - wc_Sha3 sha3; - word32 flags = 0; - - /* Initialize */ - ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Sha3_GetFlags(&sha3, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - wc_Sha3_224_Free(&sha3); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha3_GetFlags */ - -/******************************************************************************* - * SHAKE-256 - ******************************************************************************/ - -int test_wc_InitShake256(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHAKE256 - wc_Shake shake; - - ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0); - /* Test bad args. */ - ExpectIntEQ(wc_InitShake256(NULL, HEAP_HINT, testDevId), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Shake256_Free(&shake); -#endif - return EXPECT_RESULT(); -} - - -int test_wc_Shake256_Update(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHAKE256 - wc_Shake shake; - byte msg[] = "Everybody's working for the weekend."; - byte msg2[] = "Everybody gets Friday off."; - byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20" - "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74" - "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76" - "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20" - "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e"; - word32 msglen = sizeof(msg) - 1; - word32 msg2len = sizeof(msg2); - word32 msgCmplen = sizeof(msgCmp); - - ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Shake256_Update(&shake, msg, msglen), 0); - ExpectIntEQ(XMEMCMP(msg, shake.t, msglen), 0); - ExpectTrue(shake.i == msglen); - - ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(shake.t, msgCmp, msgCmplen), 0); - - /* Pass bad args. */ - ExpectIntEQ(wc_Shake256_Update(NULL, msg2, msg2len), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 5), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_Shake256_Free(&shake); - - ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 0), 0); - ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0); - ExpectIntEQ(XMEMCMP(msg2, shake.t, msg2len), 0); - wc_Shake256_Free(&shake); -#endif /* WOLFSSL_SHAKE256 */ - return EXPECT_RESULT(); -} - -int test_wc_Shake256_Final(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHAKE256 - wc_Shake shake; - const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom" - "nopnopq"; - const char* expOut = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f" - "\x6f\x87\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b" - "\xe5\xd4\xfd\x2e\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59" - "\xaa\x80\x60\xf1\xf9\xbc\x99\x6c\x05\xac\xa3\xc6\x96" - "\xa8\xb6\x62\x79\xdc\x67\x2c\x74\x0b\xb2\x24\xec\x37" - "\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55\xf5\x1d\x97" - "\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a\xf2" - "\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67" - "\x60\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4"; - byte hash[114]; - - /* Init stack variables. */ - XMEMSET(hash, 0, sizeof(hash)); - - ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, (word32)XSTRLEN(msg)), - 0); - ExpectIntEQ(wc_Shake256_Final(&shake, hash, (word32)sizeof(hash)), 0); - ExpectIntEQ(XMEMCMP(expOut, hash, (word32)sizeof(hash)), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Shake256_Final(NULL, hash, (word32)sizeof(hash)), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Shake256_Final(&shake, NULL, (word32)sizeof(hash)), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Shake256_Free(&shake); -#endif - return EXPECT_RESULT(); -} - -/* - * Testing wc_Shake256_Copy() - */ -int test_wc_Shake256_Copy(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHAKE256 - wc_Shake shake, shakeCpy; - const char* msg = TEST_STRING; - word32 msglen = (word32)TEST_STRING_SZ; - byte hash[144]; - byte hashCpy[144]; - word32 hashLen = sizeof(hash); - word32 hashLenCpy = sizeof(hashCpy); - - XMEMSET(hash, 0, sizeof(hash)); - XMEMSET(hashCpy, 0, sizeof(hashCpy)); - - ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0); - ExpectIntEQ(wc_InitShake256(&shakeCpy, HEAP_HINT, testDevId), 0); - - ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, msglen), 0); - ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, &shake), 0); - ExpectIntEQ(wc_Shake256_Final(&shake, hash, hashLen), 0); - ExpectIntEQ(wc_Shake256_Final(&shakeCpy, hashCpy, hashLenCpy), 0); - ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0); - - /* Test bad args. */ - ExpectIntEQ(wc_Shake256_Copy(NULL, &shake), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Shake256_Free(&shake); - wc_Shake256_Free(&shakeCpy); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Shake256_Copy */ - -/* - * Unit test function for wc_Shake256Hash() - */ -int test_wc_Shake256Hash(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHAKE256 - const byte data[] = { /* Hello World */ - 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f, - 0x72,0x6c,0x64 - }; - word32 len = sizeof(data); - byte hash[144]; - word32 hashLen = sizeof(hash); - - ExpectIntEQ(wc_Shake256Hash(data, len, hash, hashLen), 0); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Shake256Hash */ - diff --git a/tests/api/test_sha3.h b/tests/api/test_sha3.h deleted file mode 100644 index 2da1fba7d..000000000 --- a/tests/api/test_sha3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* test_sha3.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_SHA3_H -#define WOLFCRYPT_TEST_SHA3_H - -int test_wc_InitSha3(void); -int test_wc_Sha3_Update(void); -int test_wc_Sha3_224_Final(void); -int test_wc_Sha3_256_Final(void); -int test_wc_Sha3_384_Final(void); -int test_wc_Sha3_512_Final(void); -int test_wc_Sha3_224_Copy(void); -int test_wc_Sha3_256_Copy(void); -int test_wc_Sha3_384_Copy(void); -int test_wc_Sha3_512_Copy(void); -int test_wc_Sha3_GetFlags(void); - -int test_wc_InitShake256(void); -int test_wc_Shake256_Update(void); -int test_wc_Shake256_Final(void); -int test_wc_Shake256_Copy(void); -int test_wc_Shake256Hash(void); - -#endif /* WOLFCRYPT_TEST_SHA3_H */ diff --git a/tests/api/test_sha512.c b/tests/api/test_sha512.c deleted file mode 100644 index df1602648..000000000 --- a/tests/api/test_sha512.c +++ /dev/null @@ -1,1021 +0,0 @@ -/* test_sha512.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 -#endif - -#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H) - #include -#endif -#include - -#ifdef NO_INLINE - #include -#else - #define WOLFSSL_MISC_INCLUDED - #include -#endif - -#include -#include -#include -#include -#include - -/******************************************************************************* - * SHA-512 - ******************************************************************************/ - -/* - * Testing wc_InitSha512() - */ -int test_wc_InitSha512(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA512 - wc_Sha512 sha512; - - /* Test good arg. */ - ExpectIntEQ(wc_InitSha512(&sha512), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitSha512(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512Free(&sha512); -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitSha512 */ - - -/* - * wc_Sha512Update() test. - */ -int test_wc_Sha512Update(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA512 - wc_Sha512 sha512; - byte hash[WC_SHA512_DIGEST_SIZE]; - byte hash_unaligned[WC_SHA512_DIGEST_SIZE + 1]; - testVector a, b, c; - - ExpectIntEQ(wc_InitSha512(&sha512), 0); - - /* Input. */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_Sha512Update(&sha512, NULL, 0), 0); - ExpectIntEQ(wc_Sha512Update(&sha512,(byte*)a.input, 0), 0); - ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41" - "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b" - "\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c" - "\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a" - "\x9a\xc9\x4f\xa5\x4c\xa4\x9f"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_Sha512Update(&sha512, (byte*) a.input, (word32) a.inLen), 0); - ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0); - - ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_DIGEST_SIZE), 0); - - /* Unaligned check. */ - ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input+1, (word32)a.inLen-1), - 0); - ExpectIntEQ(wc_Sha512Final(&sha512, hash_unaligned+1), 0); - - /* Try passing in bad values */ - b.input = NULL; - b.inLen = 0; - ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)b.input, (word32)b.inLen), 0); - c.input = NULL; - c.inLen = WC_SHA512_DIGEST_SIZE; - ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512Update(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512Free(&sha512); -#endif - return EXPECT_RESULT(); - -} /* END test_wc_Sha512Update */ - -#ifdef WOLFSSL_SHA512 -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \ - (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256)) -/* Performs test for - * - wc_Sha512Final/wc_Sha512FinalRaw - * - wc_Sha512_224Final/wc_Sha512_224Final - * - wc_Sha512_256Final/wc_Sha512_256Final - * parameter: - * - type : must be one of WC_HASH_TYPE_SHA512, WC_HASH_TYPE_SHA512_224 or - * WC_HASH_TYPE_SHA512_256 - * - isRaw: if is non-zero, xxxFinalRaw function will be tested - *return 0 on success - */ -static int test_Sha512_Family_Final(int type, int isRaw) -{ - EXPECT_DECLS; - wc_Sha512 sha512; - byte* hash_test[3]; - byte hash1[WC_SHA512_DIGEST_SIZE]; - byte hash2[2*WC_SHA512_DIGEST_SIZE]; - byte hash3[5*WC_SHA512_DIGEST_SIZE]; - int times, i; - - int(*initFp)(wc_Sha512*); - int(*finalFp)(wc_Sha512*, byte*); - void(*freeFp)(wc_Sha512*); - - if (type == WC_HASH_TYPE_SHA512) { - initFp = wc_InitSha512; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \ - !defined(WOLFSSL_NO_HASH_RAW) - finalFp = (isRaw)? wc_Sha512FinalRaw : wc_Sha512Final; -#else - finalFp = (isRaw)? NULL : wc_Sha512Final; -#endif - freeFp = wc_Sha512Free; - } -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if !defined(WOLFSSL_NOSHA512_224) - else if (type == WC_HASH_TYPE_SHA512_224) { - initFp = wc_InitSha512_224; - #if !defined(WOLFSSL_NO_HASH_RAW) - finalFp = (isRaw)? wc_Sha512_224FinalRaw : wc_Sha512_224Final; - #else - finalFp = (isRaw)? NULL : wc_Sha512_224Final; - #endif - freeFp = wc_Sha512_224Free; - } -#endif -#if !defined(WOLFSSL_NOSHA512_256) - else if (type == WC_HASH_TYPE_SHA512_256) { - initFp = wc_InitSha512_256; - #if !defined(WOLFSSL_NO_HASH_RAW) - finalFp = (isRaw)? wc_Sha512_256FinalRaw : wc_Sha512_256Final; - #else - finalFp = (isRaw)? NULL : wc_Sha512_256Final; - #endif - freeFp = wc_Sha512_256Free; - } -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - else - return TEST_FAIL; - - /* Initialize */ - ExpectIntEQ(initFp(&sha512), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte *); - -#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) || \ - defined(WOLFSSL_NO_HASH_RAW) - if (finalFp != NULL) -#endif - { - /* Good test args. */ - for (i = 0; i < times; i++) { - ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0); - } - /* Test bad args. */ - ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - } - - freeFp(&sha512); - - return EXPECT_RESULT(); -} -#endif /* !HAVE_FIPS && !HAVE_SELFTEST && - (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */ -#endif /* WOLFSSL_SHA512 */ -/* - * Unit test function for wc_Sha512Final() - */ -int test_wc_Sha512Final(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA512 - wc_Sha512 sha512; - byte* hash_test[3]; - byte hash1[WC_SHA512_DIGEST_SIZE]; - byte hash2[2*WC_SHA512_DIGEST_SIZE]; - byte hash3[5*WC_SHA512_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitSha512(&sha512), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte *); - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Sha512Final(&sha512, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Sha512Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512Final(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512Free(&sha512); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha512Final */ -/* - * Unit test function for wc_Sha512FinalRaw() - */ -int test_wc_Sha512FinalRaw(void) -{ - EXPECT_DECLS; -#if (defined(WOLFSSL_SHA512) && !defined(HAVE_SELFTEST) && \ - (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \ - (HAVE_FIPS_VERSION >= 3)))) && \ - !defined(WOLFSSL_NO_HASH_RAW) - wc_Sha512 sha512; - byte* hash_test[3]; - byte hash1[WC_SHA512_DIGEST_SIZE]; - byte hash2[2*WC_SHA512_DIGEST_SIZE]; - byte hash3[5*WC_SHA512_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitSha512(&sha512), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte*); - /* Good test args. */ - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Sha512FinalRaw(&sha512, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Sha512FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512FinalRaw(&sha512, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512Free(&sha512); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha512FinalRaw */ - -/* - * Unit test function for wc_Sha512GetFlags() - */ -int test_wc_Sha512GetFlags(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA512) && defined(WOLFSSL_HASH_FLAGS) - wc_Sha512 sha512; - word32 flags = 0; - - /* Initialize */ - ExpectIntEQ(wc_InitSha512(&sha512), 0); - - ExpectIntEQ(wc_Sha512GetFlags(&sha512, &flags), 0); - ExpectIntEQ((flags & WC_HASH_FLAG_ISCOPY), 0); - - wc_Sha512Free(&sha512); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha512GetFlags */ - -/* - * Unit test function for wc_Sha512Free() - */ -int test_wc_Sha512Free(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA512 - wc_Sha512Free(NULL); - /* Set result to SUCCESS. */ - ExpectTrue(1); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha512Free */ -#ifdef WOLFSSL_SHA512 - -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \ - (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256)) -static int test_Sha512_Family_GetHash(int type ) -{ - EXPECT_DECLS; - int(*initFp)(wc_Sha512*); - int(*ghashFp)(wc_Sha512*, byte*); - wc_Sha512 sha512; - byte hash1[WC_SHA512_DIGEST_SIZE]; - - if (type == WC_HASH_TYPE_SHA512) { - initFp = wc_InitSha512; - ghashFp = wc_Sha512GetHash; - } -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if !defined(WOLFSSL_NOSHA512_224) - else if (type == WC_HASH_TYPE_SHA512_224) { - initFp = wc_InitSha512_224; - ghashFp = wc_Sha512_224GetHash; - } -#endif -#if !defined(WOLFSSL_NOSHA512_256) - else if (type == WC_HASH_TYPE_SHA512_256) { - initFp = wc_InitSha512_256; - ghashFp = wc_Sha512_256GetHash; - } -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - else { - initFp = NULL; - ghashFp = NULL; - } - - if (initFp == NULL || ghashFp == NULL) - return TEST_FAIL; - - ExpectIntEQ(initFp(&sha512), 0); - ExpectIntEQ(ghashFp(&sha512, hash1), 0); - - /* test bad arguments*/ - ExpectIntEQ(ghashFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(ghashFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(ghashFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512Free(&sha512); - return EXPECT_RESULT(); -} -#endif /* !HAVE_FIPS && !HAVE_SELFTEST && - (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */ -#endif /* WOLFSSL_SHA512 */ - -/* - * Unit test function for wc_Sha512GetHash() - */ -int test_wc_Sha512GetHash(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA512 - wc_Sha512 sha512; - byte hash1[WC_SHA512_DIGEST_SIZE]; - - /* Initialize */ - ExpectIntEQ(wc_InitSha512(&sha512), 0); - - ExpectIntEQ(wc_Sha512GetHash(&sha512, hash1), 0); - - /* test bad arguments*/ - ExpectIntEQ(wc_Sha512GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512GetHash(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512Free(&sha512); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha512GetHash */ - -/* - * Unit test function for wc_Sha512Copy() - */ -int test_wc_Sha512Copy(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA512 - wc_Sha512 sha512; - wc_Sha512 temp; - - XMEMSET(&sha512, 0, sizeof(wc_Sha512)); - XMEMSET(&temp, 0, sizeof(wc_Sha512)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha512(&sha512), 0); - ExpectIntEQ(wc_InitSha512(&temp), 0); - - ExpectIntEQ(wc_Sha512Copy(&sha512, &temp), 0); - - /* test bad arguments*/ - ExpectIntEQ(wc_Sha512Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512Free(&sha512); - wc_Sha512Free(&temp); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha512Copy */ - -/******************************************************************************* - * SHA-512-224 - ******************************************************************************/ - -int test_wc_InitSha512_224(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) - wc_Sha512 sha512; - - /* Test good arg. */ - ExpectIntEQ(wc_InitSha512_224(&sha512), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitSha512_224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512_224Free(&sha512); -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_224Update(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) - wc_Sha512 sha512; - byte hash[WC_SHA512_DIGEST_SIZE]; - testVector a, c; - - ExpectIntEQ(wc_InitSha512_224(&sha512), 0); - - /* Input. */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_Sha512_224Update(&sha512, NULL, 0), 0); - ExpectIntEQ(wc_Sha512_224Update(&sha512,(byte*)a.input, 0), 0); - ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)a.input, (word32)a.inLen), - 0); - ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\x46\x34\x27\x0f\x70\x7b\x6a\x54\xda\xae\x75\x30\x46\x08" - "\x42\xe2\x0e\x37\xed\x26\x5c\xee\xe9\xa4\x3e\x89\x24\xaa"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*) a.input, (word32) a.inLen), - 0); - ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_224_DIGEST_SIZE), 0); - - c.input = NULL; - c.inLen = WC_SHA512_224_DIGEST_SIZE; - ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512_224Update(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512_224Free(&sha512); -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_224Final(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) - ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 0), - TEST_SUCCESS); -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_224FinalRaw(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \ - defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \ - !defined(WOLFSSL_NO_HASH_RAW) - ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 1), - TEST_SUCCESS); -#endif - return EXPECT_RESULT(); -} - -int test_wc_Sha512_224GetFlags(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \ - defined(WOLFSSL_HASH_FLAGS) - wc_Sha512 sha512; - wc_Sha512 copy; - word32 flags = 0; - - XMEMSET(&sha512, 0, sizeof(wc_Sha512)); - XMEMSET(©, 0, sizeof(wc_Sha512)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha512_224(&sha512), 0); - ExpectIntEQ(wc_InitSha512_224(©), 0); - - ExpectIntEQ(wc_Sha512_224GetFlags(&sha512, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - - ExpectIntEQ(wc_Sha512_224Copy(&sha512, ©), 0); - ExpectIntEQ(wc_Sha512_224GetFlags(©, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY); - - wc_Sha512_224Free(©); - wc_Sha512_224Free(&sha512); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_224Free(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) - wc_Sha512_224Free(NULL); - /* Set result to SUCCESS. */ - ExpectTrue(1); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_224GetHash(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) - ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_224), - TEST_SUCCESS); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} -int test_wc_Sha512_224Copy(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) - wc_Sha512 sha512; - wc_Sha512 temp; - - XMEMSET(&sha512, 0, sizeof(wc_Sha512)); - XMEMSET(&temp, 0, sizeof(wc_Sha512)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha512_224(&sha512), 0); - ExpectIntEQ(wc_InitSha512_224(&temp), 0); - - ExpectIntEQ(wc_Sha512_224Copy(&sha512, &temp), 0); - /* test bad arguments*/ - ExpectIntEQ(wc_Sha512_224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512_224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512_224Copy(&sha512, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512_224Free(&sha512); - wc_Sha512_224Free(&temp); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -/******************************************************************************* - * SHA-512-256 - ******************************************************************************/ - -int test_wc_InitSha512_256(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) - wc_Sha512 sha512; - - /* Test good arg. */ - ExpectIntEQ(wc_InitSha512_256(&sha512), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitSha512_256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512_256Free(&sha512); -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_256Update(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) - wc_Sha512 sha512; - byte hash[WC_SHA512_DIGEST_SIZE]; - testVector a, c; - - ExpectIntEQ(wc_InitSha512_256(&sha512), 0); - - /* Input. */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_Sha512_256Update(&sha512, NULL, 0), 0); - ExpectIntEQ(wc_Sha512_256Update(&sha512,(byte*)a.input, 0), 0); - ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)a.input, (word32)a.inLen), - 0); - ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\x53\x04\x8e\x26\x81\x94\x1e\xf9\x9b\x2e\x29\xb7\x6b\x4c" - "\x7d\xab\xe4\xc2\xd0\xc6\x34\xfc\x6d\x46\xe0\xe2\xf1\x31" - "\x07\xe7\xaf\x23"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*) a.input, (word32) a.inLen), - 0); - ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_256_DIGEST_SIZE), 0); - - c.input = NULL; - c.inLen = WC_SHA512_256_DIGEST_SIZE; - ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512_256Update(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512_256Free(&sha512); -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_256Final(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) - ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 0), - TEST_SUCCESS); -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_256FinalRaw(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \ - defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \ - !defined(WOLFSSL_NO_HASH_RAW) - ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 1), - TEST_SUCCESS); -#endif - return EXPECT_RESULT(); -} - -int test_wc_Sha512_256GetFlags(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \ - defined(WOLFSSL_HASH_FLAGS) - wc_Sha512 sha512, copy; - word32 flags = 0; - - XMEMSET(&sha512, 0, sizeof(wc_Sha512)); - XMEMSET(©, 0, sizeof(wc_Sha512)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha512_256(&sha512), 0); - ExpectIntEQ(wc_InitSha512_256(©), 0); - - ExpectIntEQ(wc_Sha512_256GetFlags(&sha512, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - - ExpectIntEQ(wc_Sha512_256Copy(&sha512, ©), 0); - ExpectIntEQ(wc_Sha512_256GetFlags(©, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY); - - wc_Sha512_256Free(&sha512); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_256Free(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) - wc_Sha512_256Free(NULL); - /* Set result to SUCCESS. */ - ExpectTrue(1); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -int test_wc_Sha512_256GetHash(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) - ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_256), - TEST_SUCCESS); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); - -} - -int test_wc_Sha512_256Copy(void) -{ - EXPECT_DECLS; -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) - wc_Sha512 sha512; - wc_Sha512 temp; - - XMEMSET(&sha512, 0, sizeof(wc_Sha512)); - XMEMSET(&temp, 0, sizeof(wc_Sha512)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha512_256(&sha512), 0); - ExpectIntEQ(wc_InitSha512_256(&temp), 0); - - ExpectIntEQ(wc_Sha512_256Copy(&sha512, &temp), 0); - /* test bad arguments*/ - ExpectIntEQ(wc_Sha512_256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512_256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha512_256Copy(&sha512, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha512_256Free(&sha512); - wc_Sha512_256Free(&temp); -#endif -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ - return EXPECT_RESULT(); -} - -/******************************************************************************* - * SHA-384 - ******************************************************************************/ - -/* - * Testing wc_InitSha384() - */ -int test_wc_InitSha384(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA384 - wc_Sha384 sha384; - - /* Test good arg. */ - ExpectIntEQ(wc_InitSha384(&sha384), 0); - /* Test bad arg. */ - ExpectIntEQ(wc_InitSha384(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha384Free(&sha384); -#endif - return EXPECT_RESULT(); -} /* END test_wc_InitSha384 */ - -/* - * test wc_Sha384Update() - */ -int test_wc_Sha384Update(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA384 - wc_Sha384 sha384; - byte hash[WC_SHA384_DIGEST_SIZE]; - testVector a, b, c; - - ExpectIntEQ(wc_InitSha384(&sha384), 0); - - /* Input */ - a.input = "a"; - a.inLen = XSTRLEN(a.input); - ExpectIntEQ(wc_Sha384Update(&sha384, NULL, 0), 0); - ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, 0), 0); - ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0); - - /* Update input. */ - a.input = "abc"; - a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50" - "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff" - "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34" - "\xc8\x25\xa7"; - a.inLen = XSTRLEN(a.input); - a.outLen = XSTRLEN(a.output); - ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0); - ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0); - ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0); - - /* Pass in bad values. */ - b.input = NULL; - b.inLen = 0; - ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)b.input, (word32)b.inLen), 0); - c.input = NULL; - c.inLen = WC_SHA384_DIGEST_SIZE; - ExpectIntEQ( wc_Sha384Update(&sha384, (byte*)c.input, (word32)c.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384Update(NULL, (byte*)a.input, (word32)a.inLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha384Free(&sha384); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha384Update */ - -/* - * Unit test function for wc_Sha384Final(); - */ -int test_wc_Sha384Final(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA384 - wc_Sha384 sha384; - byte* hash_test[3]; - byte hash1[WC_SHA384_DIGEST_SIZE]; - byte hash2[2*WC_SHA384_DIGEST_SIZE]; - byte hash3[5*WC_SHA384_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitSha384(&sha384), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte*); - /* Good test args. */ - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Sha384Final(&sha384, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Sha384Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384Final(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha384Free(&sha384); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha384Final */ - -/* - * Unit test function for wc_Sha384FinalRaw() - */ -int test_wc_Sha384FinalRaw(void) -{ - EXPECT_DECLS; -#if (defined(WOLFSSL_SHA384) && !defined(HAVE_SELFTEST) && \ - (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \ - (HAVE_FIPS_VERSION >= 3)))) && \ - !defined(WOLFSSL_NO_HASH_RAW) - wc_Sha384 sha384; - byte* hash_test[3]; - byte hash1[WC_SHA384_DIGEST_SIZE]; - byte hash2[2*WC_SHA384_DIGEST_SIZE]; - byte hash3[5*WC_SHA384_DIGEST_SIZE]; - int times, i; - - /* Initialize */ - ExpectIntEQ(wc_InitSha384(&sha384), 0); - - hash_test[0] = hash1; - hash_test[1] = hash2; - hash_test[2] = hash3; - times = sizeof(hash_test) / sizeof(byte*); - /* Good test args. */ - for (i = 0; i < times; i++) { - ExpectIntEQ(wc_Sha384FinalRaw(&sha384, hash_test[i]), 0); - } - - /* Test bad args. */ - ExpectIntEQ(wc_Sha384FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384FinalRaw(&sha384, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha384Free(&sha384); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha384FinalRaw */ - -/* - * Unit test function for wc_Sha384GetFlags() - */ -int test_wc_Sha384GetFlags(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_HASH_FLAGS) - wc_Sha384 sha384; - word32 flags = 0; - - /* Initialize */ - ExpectIntEQ(wc_InitSha384(&sha384), 0); - ExpectIntEQ(wc_Sha384GetFlags(&sha384, &flags), 0); - ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0); - - wc_Sha384Free(&sha384); -#endif - return EXPECT_RESULT(); - -} /* END test_wc_Sha384GetFlags */ - -/* - * Unit test function for wc_Sha384Free() - */ -int test_wc_Sha384Free(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA384 - wc_Sha384Free(NULL); - /* Set result to SUCCESS. */ - ExpectTrue(1); -#endif - return EXPECT_RESULT(); - -} /* END test_wc_Sha384Free */ - -/* - * Unit test function for wc_Sha384GetHash() - */ -int test_wc_Sha384GetHash(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA384 - wc_Sha384 sha384; - byte hash1[WC_SHA384_DIGEST_SIZE]; - - /* Initialize */ - ExpectIntEQ(wc_InitSha384(&sha384), 0); - - ExpectIntEQ(wc_Sha384GetHash(&sha384, hash1), 0); - /* test bad arguments*/ - ExpectIntEQ(wc_Sha384GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384GetHash(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha384Free(&sha384); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha384GetHash */ - -/* - * Unit test function for wc_Sha384Copy() - */ -int test_wc_Sha384Copy(void) -{ - EXPECT_DECLS; -#ifdef WOLFSSL_SHA384 - wc_Sha384 sha384; - wc_Sha384 temp; - - XMEMSET(&sha384, 0, sizeof(wc_Sha384)); - XMEMSET(&temp, 0, sizeof(wc_Sha384)); - - /* Initialize */ - ExpectIntEQ(wc_InitSha384(&sha384), 0); - ExpectIntEQ(wc_InitSha384(&temp), 0); - - ExpectIntEQ(wc_Sha384Copy(&sha384, &temp), 0); - /* test bad arguments*/ - ExpectIntEQ(wc_Sha384Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_Sha384Copy(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_Sha384Free(&sha384); - wc_Sha384Free(&temp); -#endif - return EXPECT_RESULT(); -} /* END test_wc_Sha384Copy */ - diff --git a/tests/api/test_sha512.h b/tests/api/test_sha512.h deleted file mode 100644 index d7ed7a82b..000000000 --- a/tests/api/test_sha512.h +++ /dev/null @@ -1,61 +0,0 @@ -/* test_sha512.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. - * - * 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 - */ - -#ifndef WOLFCRYPT_TEST_SHA512_H -#define WOLFCRYPT_TEST_SHA512_H - -int test_wc_InitSha512(void); -int test_wc_Sha512Update(void); -int test_wc_Sha512Final(void); -int test_wc_Sha512FinalRaw(void); -int test_wc_Sha512GetFlags(void); -int test_wc_Sha512Free(void); -int test_wc_Sha512GetHash(void); -int test_wc_Sha512Copy(void); - -int test_wc_InitSha512_224(void); -int test_wc_Sha512_224Update(void); -int test_wc_Sha512_224Final(void); -int test_wc_Sha512_224FinalRaw(void); -int test_wc_Sha512_224GetFlags(void); -int test_wc_Sha512_224Free(void); -int test_wc_Sha512_224GetHash(void); -int test_wc_Sha512_224Copy(void); - -int test_wc_InitSha512_256(void); -int test_wc_Sha512_256Update(void); -int test_wc_Sha512_256Final(void); -int test_wc_Sha512_256FinalRaw(void); -int test_wc_Sha512_256GetFlags(void); -int test_wc_Sha512_256Free(void); -int test_wc_Sha512_256GetHash(void); -int test_wc_Sha512_256Copy(void); - -int test_wc_InitSha384(void); -int test_wc_Sha384Update(void); -int test_wc_Sha384Final(void); -int test_wc_Sha384FinalRaw(void); -int test_wc_Sha384GetFlags(void); -int test_wc_Sha384Free(void); -int test_wc_Sha384GetHash(void); -int test_wc_Sha384Copy(void); - -#endif /* WOLFCRYPT_TEST_SHA512_H */