1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/* 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 3 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
*/
#include <tests/unit.h>
#ifdef NO_INLINE
#include <wolfssl/wolfcrypt/misc.h>
#else
#define WOLFSSL_MISC_INCLUDED
#include <wolfcrypt/src/misc.c>
#endif
#include <wolfssl/wolfcrypt/sha.h>
#include <wolfssl/wolfcrypt/types.h>
#include <tests/api/api.h>
#include <tests/api/test_sha.h>
#include <tests/api/test_digest.h>
/*
* Unit test for the wc_InitSha()
*/
int test_wc_InitSha(void)
{
EXPECT_DECLS;
#ifndef NO_SHA
DIGEST_INIT_AND_INIT_EX_TEST(wc_Sha, Sha);
#endif
return EXPECT_RESULT();
} /* END test_wc_InitSha */
/*
* Tesing wc_ShaUpdate()
*/
int test_wc_ShaUpdate(void)
{
EXPECT_DECLS;
#ifndef NO_SHA
DIGEST_UPDATE_TEST(wc_Sha, Sha);
#endif
return EXPECT_RESULT();
} /* END test_wc_ShaUpdate() */
/*
* Unit test on wc_ShaFinal
*/
int test_wc_ShaFinal(void)
{
EXPECT_DECLS;
#ifndef NO_SHA
DIGEST_FINAL_TEST(wc_Sha, Sha, SHA);
#endif
return EXPECT_RESULT();
} /* END test_wc_ShaFinal */
/*
* Unit test on wc_ShaFinalRaw
*/
int test_wc_ShaFinalRaw(void)
{
EXPECT_DECLS;
#if !defined(NO_SHA) && !defined(HAVE_SELFTEST) && \
!defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
!defined(WOLFSSL_NO_HASH_RAW)
DIGEST_FINAL_RAW_TEST(wc_Sha, Sha, SHA,
"\x67\x45\x23\x01\xef\xcd\xab\x89"
"\x98\xba\xdc\xfe\x10\x32\x54\x76"
"\xc3\xd2\xe1\xf0");
#endif
return EXPECT_RESULT();
} /* END test_wc_ShaFinal */
#define SHA_KAT_CNT 7
int test_wc_Sha_KATs(void)
{
EXPECT_DECLS;
#ifndef NO_SHA
DIGEST_KATS_TEST_VARS(wc_Sha, SHA);
DIGEST_KATS_ADD("", 0,
"\xda\x39\xa3\xee\x5e\x6b\x4b\x0d"
"\x32\x55\xbf\xef\x95\x60\x18\x90"
"\xaf\xd8\x07\x09");
DIGEST_KATS_ADD("a", 1,
"\x86\xf7\xe4\x37\xfa\xa5\xa7\xfc"
"\xe1\x5d\x1d\xdc\xb9\xea\xea\xea"
"\x37\x76\x67\xb8");
DIGEST_KATS_ADD("abc", 3,
"\xa9\x99\x3e\x36\x47\x06\x81\x6a"
"\xba\x3e\x25\x71\x78\x50\xc2\x6c"
"\x9c\xd0\xd8\x9d");
DIGEST_KATS_ADD("message digest", 14,
"\xc1\x22\x52\xce\xda\x8b\xe8\x99"
"\x4d\x5f\xa0\x29\x0a\x47\x23\x1c"
"\x1d\x16\xaa\xe3");
DIGEST_KATS_ADD("abcdefghijklmnopqrstuvwxyz", 26,
"\x32\xd1\x0c\x7b\x8c\xf9\x65\x70"
"\xca\x04\xce\x37\xf2\xa1\x9d\x84"
"\x24\x0d\x3a\x89");
DIGEST_KATS_ADD("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789", 62,
"\x76\x1c\x45\x7b\xf7\x3b\x14\xd2"
"\x7e\x9e\x92\x65\xc4\x6f\x4b\x4d"
"\xda\x11\xf9\x40");
DIGEST_KATS_ADD("1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890", 80,
"\x50\xab\xf5\x70\x6a\x15\x09\x90"
"\xa0\x8b\x2c\x5e\xa4\x0f\xa0\xe5"
"\x85\x55\x47\x32");
DIGEST_KATS_TEST(Sha, SHA);
#endif
return EXPECT_RESULT();
} /* END test_wc_ShaFinal */
int test_wc_Sha_other(void)
{
EXPECT_DECLS;
#ifndef NO_SHA
DIGEST_OTHER_TEST(wc_Sha, Sha, SHA,
"\xf0\xc2\x3f\xeb\xe0\xb0\xd9\x8c"
"\x01\x23\x6c\x4c\x3b\x72\x7b\x01"
"\xc7\x0d\x2b\x60");
#endif
return EXPECT_RESULT();
} /* END test_wc_ShaFinal */
int test_wc_ShaCopy(void)
{
EXPECT_DECLS;
#ifndef NO_SHA
DIGEST_COPY_TEST(wc_Sha, Sha, SHA,
"\xda\x39\xa3\xee\x5e\x6b\x4b\x0d"
"\x32\x55\xbf\xef\x95\x60\x18\x90"
"\xaf\xd8\x07\x09",
"\xa9\x99\x3e\x36\x47\x06\x81\x6a"
"\xba\x3e\x25\x71\x78\x50\xc2\x6c"
"\x9c\xd0\xd8\x9d");
#endif
return EXPECT_RESULT();
}
int test_wc_ShaGetHash(void)
{
EXPECT_DECLS;
#ifndef NO_SHA
DIGEST_GET_HASH_TEST(wc_Sha, Sha, SHA,
"\xda\x39\xa3\xee\x5e\x6b\x4b\x0d"
"\x32\x55\xbf\xef\x95\x60\x18\x90"
"\xaf\xd8\x07\x09",
"\xa9\x99\x3e\x36\x47\x06\x81\x6a"
"\xba\x3e\x25\x71\x78\x50\xc2\x6c"
"\x9c\xd0\xd8\x9d");
#endif
return EXPECT_RESULT();
}
int test_wc_ShaTransform(void)
{
EXPECT_DECLS;
#if !defined(NO_SHA) && (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && \
!defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))
DIGEST_TRANSFORM_FINAL_RAW_TEST(wc_Sha, Sha, SHA,
"\x80\x63\x62\x61\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x18\x00\x00\x00",
"\xa9\x99\x3e\x36\x47\x06\x81\x6a"
"\xba\x3e\x25\x71\x78\x50\xc2\x6c"
"\x9c\xd0\xd8\x9d");
#endif
return EXPECT_RESULT();
}
int test_wc_Sha_Flags(void)
{
EXPECT_DECLS;
#if !defined(NO_SHA) && defined(WOLFSSL_HASH_FLAGS)
DIGEST_FLAGS_TEST(wc_Sha, Sha);
#endif
return EXPECT_RESULT();
}
|