yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* sha3.h |
| 2 | * |
| 3 | * Copyright (C) 2006-2021 wolfSSL Inc. |
| 4 | * |
| 5 | * This file is part of wolfSSL. |
| 6 | * |
| 7 | * wolfSSL is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * wolfSSL is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | */ |
| 21 | |
| 22 | /* sha3.h for openssl */ |
| 23 | |
| 24 | |
| 25 | #ifndef WOLFSSL_SHA3_H_ |
| 26 | #define WOLFSSL_SHA3_H_ |
| 27 | |
| 28 | #include <wolfssl/wolfcrypt/settings.h> |
| 29 | #include <wolfssl/wolfcrypt/types.h> |
| 30 | |
| 31 | #ifdef WOLFSSL_PREFIX |
| 32 | #include "prefix_sha.h" |
| 33 | #endif |
| 34 | |
| 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
| 39 | |
| 40 | /* Using ALIGN16 because when AES-NI is enabled digest and buffer in Sha3 |
| 41 | * struct are 16 byte aligned. Any dereference to those elements after casting |
| 42 | * to Sha3 is expected to also be 16 byte aligned addresses. */ |
| 43 | struct WOLFSSL_SHA3_CTX { |
| 44 | /* big enough to hold wolfcrypt Sha3, but check on init */ |
| 45 | ALIGN16 void* holder[(424 + WC_ASYNC_DEV_SIZE) / sizeof(void*)]; |
| 46 | }; |
| 47 | |
| 48 | #ifndef WOLFSSL_NOSHA3_224 |
| 49 | typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_224_CTX; |
| 50 | |
| 51 | WOLFSSL_API int wolfSSL_SHA3_224_Init(WOLFSSL_SHA3_224_CTX*); |
| 52 | WOLFSSL_API int wolfSSL_SHA3_224_Update(WOLFSSL_SHA3_224_CTX*, const void*, |
| 53 | unsigned long); |
| 54 | WOLFSSL_API int wolfSSL_SHA3_224_Final(unsigned char*, WOLFSSL_SHA3_224_CTX*); |
| 55 | |
| 56 | enum { |
| 57 | SHA3_224_DIGEST_LENGTH = 28 |
| 58 | }; |
| 59 | |
| 60 | typedef WOLFSSL_SHA3_224_CTX SHA3_224_CTX; |
| 61 | |
| 62 | #define SHA3_224_Init wolfSSL_SHA3_224_Init |
| 63 | #define SHA3_224_Update wolfSSL_SHA3_224_Update |
| 64 | #define SHA3_224_Final wolfSSL_SHA3_224_Final |
| 65 | #if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) |
| 66 | #define SHA3_224 wolfSSL_SHA3_224 |
| 67 | #endif |
| 68 | #endif /* WOLFSSL_NOSHA3_224 */ |
| 69 | |
| 70 | |
| 71 | #ifndef WOLFSSL_NOSHA3_256 |
| 72 | typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_256_CTX; |
| 73 | |
| 74 | |
| 75 | WOLFSSL_API int wolfSSL_SHA3_256_Init(WOLFSSL_SHA3_256_CTX*); |
| 76 | WOLFSSL_API int wolfSSL_SHA3_256_Update(WOLFSSL_SHA3_256_CTX*, const void*, |
| 77 | unsigned long); |
| 78 | WOLFSSL_API int wolfSSL_SHA3_256_Final(unsigned char*, WOLFSSL_SHA3_256_CTX*); |
| 79 | |
| 80 | enum { |
| 81 | SHA3_256_DIGEST_LENGTH = 32 |
| 82 | }; |
| 83 | |
| 84 | |
| 85 | typedef WOLFSSL_SHA3_256_CTX SHA3_256_CTX; |
| 86 | |
| 87 | #define SHA3_256_Init wolfSSL_SHA3_256_Init |
| 88 | #define SHA3_256_Update wolfSSL_SHA3_256_Update |
| 89 | #define SHA3_256_Final wolfSSL_SHA3_256_Final |
| 90 | #if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) |
| 91 | #define SHA3_256 wolfSSL_SHA3_256 |
| 92 | #endif |
| 93 | #endif /* WOLFSSL_NOSHA3_256 */ |
| 94 | |
| 95 | |
| 96 | typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_384_CTX; |
| 97 | |
| 98 | WOLFSSL_API int wolfSSL_SHA3_384_Init(WOLFSSL_SHA3_384_CTX*); |
| 99 | WOLFSSL_API int wolfSSL_SHA3_384_Update(WOLFSSL_SHA3_384_CTX*, const void*, |
| 100 | unsigned long); |
| 101 | WOLFSSL_API int wolfSSL_SHA3_384_Final(unsigned char*, WOLFSSL_SHA3_384_CTX*); |
| 102 | |
| 103 | enum { |
| 104 | SHA3_384_DIGEST_LENGTH = 48 |
| 105 | }; |
| 106 | |
| 107 | typedef WOLFSSL_SHA3_384_CTX SHA3_384_CTX; |
| 108 | |
| 109 | #define SHA3_384_Init wolfSSL_SHA3_384_Init |
| 110 | #define SHA3_384_Update wolfSSL_SHA3_384_Update |
| 111 | #define SHA3_384_Final wolfSSL_SHA3_384_Final |
| 112 | #if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) |
| 113 | #define SHA3_384 wolfSSL_SHA3_384 |
| 114 | #endif |
| 115 | |
| 116 | |
| 117 | #ifndef WOLFSSL_NOSHA3_512 |
| 118 | |
| 119 | typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_512_CTX; |
| 120 | |
| 121 | WOLFSSL_API int wolfSSL_SHA3_512_Init(WOLFSSL_SHA3_512_CTX*); |
| 122 | WOLFSSL_API int wolfSSL_SHA3_512_Update(WOLFSSL_SHA3_512_CTX*, const void*, |
| 123 | unsigned long); |
| 124 | WOLFSSL_API int wolfSSL_SHA3_512_Final(unsigned char*, WOLFSSL_SHA3_512_CTX*); |
| 125 | |
| 126 | enum { |
| 127 | SHA3_512_DIGEST_LENGTH = 64 |
| 128 | }; |
| 129 | |
| 130 | |
| 131 | typedef WOLFSSL_SHA3_512_CTX SHA3_512_CTX; |
| 132 | |
| 133 | #define SHA3_512_Init wolfSSL_SHA3_512_Init |
| 134 | #define SHA3_512_Update wolfSSL_SHA3_512_Update |
| 135 | #define SHA3_512_Final wolfSSL_SHA3_512_Final |
| 136 | #if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) |
| 137 | #define SHA3_512 wolfSSL_SHA3_512 |
| 138 | #endif |
| 139 | #endif /* WOLFSSL_NOSHA3_512 */ |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | #ifdef __cplusplus |
| 145 | } /* extern "C" */ |
| 146 | #endif |
| 147 | |
| 148 | |
| 149 | #endif /* WOLFSSL_SHA3_H_ */ |
| 150 | |