My Project
Loading...
Searching...
No Matches
sha3.h
1/* sha3.h
2 *
3 * Copyright (C) 2006-2020 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
23#ifndef WOLF_CRYPT_SHA3_H
24#define WOLF_CRYPT_SHA3_H
25
27
28#ifdef WOLFSSL_SHA3
29
30#ifdef HAVE_FIPS
31 /* for fips @wc_fips */
32 #include <wolfssl/wolfcrypt/fips.h>
33#endif
34
35#ifdef __cplusplus
36 extern "C" {
37#endif
38
39#ifdef WOLFSSL_ASYNC_CRYPT
40 #include <wolfssl/wolfcrypt/async.h>
41#endif
42
43/* in bytes */
44enum {
45 WC_SHA3_224 = WC_HASH_TYPE_SHA3_224,
46 WC_SHA3_224_DIGEST_SIZE = 28,
47 WC_SHA3_224_COUNT = 18,
48
49 WC_SHA3_256 = WC_HASH_TYPE_SHA3_256,
50 WC_SHA3_256_DIGEST_SIZE = 32,
51 WC_SHA3_256_COUNT = 17,
52
53 WC_SHA3_384 = WC_HASH_TYPE_SHA3_384,
54 WC_SHA3_384_DIGEST_SIZE = 48,
55 WC_SHA3_384_COUNT = 13,
56
57 WC_SHA3_512 = WC_HASH_TYPE_SHA3_512,
58 WC_SHA3_512_DIGEST_SIZE = 64,
59 WC_SHA3_512_COUNT = 9,
60
61#ifndef HAVE_SELFTEST
62 /* These values are used for HMAC, not SHA-3 directly.
63 * They come from from FIPS PUB 202. */
64 WC_SHA3_224_BLOCK_SIZE = 144,
65 WC_SHA3_256_BLOCK_SIZE = 136,
66 WC_SHA3_384_BLOCK_SIZE = 104,
67 WC_SHA3_512_BLOCK_SIZE = 72,
68#endif
69};
70
71#ifndef NO_OLD_WC_NAMES
72 #define SHA3_224 WC_SHA3_224
73 #define SHA3_224_DIGEST_SIZE WC_SHA3_224_DIGEST_SIZE
74 #define SHA3_256 WC_SHA3_256
75 #define SHA3_256_DIGEST_SIZE WC_SHA3_256_DIGEST_SIZE
76 #define SHA3_384 WC_SHA3_384
77 #define SHA3_384_DIGEST_SIZE WC_SHA3_384_DIGEST_SIZE
78 #define SHA3_512 WC_SHA3_512
79 #define SHA3_512_DIGEST_SIZE WC_SHA3_512_DIGEST_SIZE
80 #define Sha3 wc_Sha3
81#endif
82
83
84
85#ifdef WOLFSSL_XILINX_CRYPT
86 #include "wolfssl/wolfcrypt/port/xilinx/xil-sha3.h"
87#elif defined(WOLFSSL_AFALG_XILINX_SHA3)
88 #include <wolfssl/wolfcrypt/port/af_alg/afalg_hash.h>
89#else
90
91/* Sha3 digest */
92struct Sha3 {
93 /* State data that is processed for each block. */
94 word64 s[25];
95 /* Unprocessed message data. */
96 byte t[200];
97 /* Index into unprocessed data to place next message byte. */
98 byte i;
99
100 void* heap;
101
102#ifdef WOLFSSL_ASYNC_CRYPT
103 WC_ASYNC_DEV asyncDev;
104#endif /* WOLFSSL_ASYNC_CRYPT */
105#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
106 word32 flags; /* enum wc_HashFlags in hash.h */
107#endif
108};
109
110#ifndef WC_SHA3_TYPE_DEFINED
111 typedef struct Sha3 wc_Sha3;
112 #define WC_SHA3_TYPE_DEFINED
113#endif
114
115#endif
116
117typedef wc_Sha3 wc_Shake;
118
119
120WOLFSSL_API int wc_InitSha3_224(wc_Sha3*, void*, int);
121WOLFSSL_API int wc_Sha3_224_Update(wc_Sha3*, const byte*, word32);
122WOLFSSL_API int wc_Sha3_224_Final(wc_Sha3*, byte*);
123WOLFSSL_API void wc_Sha3_224_Free(wc_Sha3*);
124WOLFSSL_API int wc_Sha3_224_GetHash(wc_Sha3*, byte*);
125WOLFSSL_API int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst);
126
127WOLFSSL_API int wc_InitSha3_256(wc_Sha3*, void*, int);
128WOLFSSL_API int wc_Sha3_256_Update(wc_Sha3*, const byte*, word32);
129WOLFSSL_API int wc_Sha3_256_Final(wc_Sha3*, byte*);
130WOLFSSL_API void wc_Sha3_256_Free(wc_Sha3*);
131WOLFSSL_API int wc_Sha3_256_GetHash(wc_Sha3*, byte*);
132WOLFSSL_API int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst);
133
134WOLFSSL_API int wc_InitSha3_384(wc_Sha3*, void*, int);
135WOLFSSL_API int wc_Sha3_384_Update(wc_Sha3*, const byte*, word32);
136WOLFSSL_API int wc_Sha3_384_Final(wc_Sha3*, byte*);
137WOLFSSL_API void wc_Sha3_384_Free(wc_Sha3*);
138WOLFSSL_API int wc_Sha3_384_GetHash(wc_Sha3*, byte*);
139WOLFSSL_API int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst);
140
141WOLFSSL_API int wc_InitSha3_512(wc_Sha3*, void*, int);
142WOLFSSL_API int wc_Sha3_512_Update(wc_Sha3*, const byte*, word32);
143WOLFSSL_API int wc_Sha3_512_Final(wc_Sha3*, byte*);
144WOLFSSL_API void wc_Sha3_512_Free(wc_Sha3*);
145WOLFSSL_API int wc_Sha3_512_GetHash(wc_Sha3*, byte*);
146WOLFSSL_API int wc_Sha3_512_Copy(wc_Sha3* src, wc_Sha3* dst);
147
148WOLFSSL_API int wc_InitShake256(wc_Shake*, void*, int);
149WOLFSSL_API int wc_Shake256_Update(wc_Shake*, const byte*, word32);
150WOLFSSL_API int wc_Shake256_Final(wc_Shake*, byte*, word32);
151WOLFSSL_API void wc_Shake256_Free(wc_Shake*);
152WOLFSSL_API int wc_Shake256_Copy(wc_Shake* src, wc_Sha3* dst);
153
154#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
155 WOLFSSL_API int wc_Sha3_SetFlags(wc_Sha3* sha3, word32 flags);
156 WOLFSSL_API int wc_Sha3_GetFlags(wc_Sha3* sha3, word32* flags);
157#endif
158
159#ifdef __cplusplus
160 } /* extern "C" */
161#endif
162
163#endif /* WOLFSSL_SHA3 */
164#endif /* WOLF_CRYPT_SHA3_H */
165
Definition sha3.h:92
Definition afalg_hash.h:31