source: azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/sha256.h@ 464

Last change on this file since 464 was 464, checked in by coas-nagasima, 3 years ago

WolfSSLとAzure IoT SDKを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 7.7 KB
Line 
1/* sha256.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 \file wolfssl/wolfcrypt/sha256.h
24*/
25
26
27
28#ifndef WOLF_CRYPT_SHA256_H
29#define WOLF_CRYPT_SHA256_H
30
31#include <wolfssl/wolfcrypt/types.h>
32
33#ifndef NO_SHA256
34
35#if defined(HAVE_FIPS) && \
36 defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
37 #include <wolfssl/wolfcrypt/fips.h>
38#endif /* HAVE_FIPS_VERSION >= 2 */
39
40#if defined(HAVE_FIPS) && \
41 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
42 #define wc_Sha256 Sha256
43 #define WC_SHA256 SHA256
44 #define WC_SHA256_BLOCK_SIZE SHA256_BLOCK_SIZE
45 #define WC_SHA256_DIGEST_SIZE SHA256_DIGEST_SIZE
46 #define WC_SHA256_PAD_SIZE SHA256_PAD_SIZE
47
48 #ifdef WOLFSSL_SHA224
49 #define wc_Sha224 Sha224
50 #define WC_SHA224 SHA224
51 #define WC_SHA224_BLOCK_SIZE SHA224_BLOCK_SIZE
52 #define WC_SHA224_DIGEST_SIZE SHA224_DIGEST_SIZE
53 #define WC_SHA224_PAD_SIZE SHA224_PAD_SIZE
54 #endif
55
56 /* for fips @wc_fips */
57 #include <cyassl/ctaocrypt/sha256.h>
58#endif
59
60#ifdef FREESCALE_LTC_SHA
61 #include "fsl_ltc.h"
62#endif
63
64
65#ifdef __cplusplus
66 extern "C" {
67#endif
68
69/* avoid redefinition of structs */
70#if !defined(HAVE_FIPS) || \
71 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
72
73#ifdef WOLFSSL_MICROCHIP_PIC32MZ
74 #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
75#endif
76#ifdef STM32_HASH
77 #include <wolfssl/wolfcrypt/port/st/stm32.h>
78#endif
79#ifdef WOLFSSL_ASYNC_CRYPT
80 #include <wolfssl/wolfcrypt/async.h>
81#endif
82#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_DEVCRYPTO_HASH)
83 #include <wolfssl/wolfcrypt/port/devcrypto/wc_devcrypto.h>
84#endif
85#if defined(WOLFSSL_ESP32WROOM32_CRYPT)
86 #include "wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h"
87#endif
88#if defined(WOLFSSL_CRYPTOCELL)
89 #include <wolfssl/wolfcrypt/port/arm/cryptoCell.h>
90#endif
91#if defined(WOLFSSL_SILABS_SE_ACCEL)
92 #include <wolfssl/wolfcrypt/port/silabs/silabs_hash.h>
93#endif
94
95#if defined(_MSC_VER)
96 #define SHA256_NOINLINE __declspec(noinline)
97#elif defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
98 #define SHA256_NOINLINE __attribute__((noinline))
99#else
100 #define SHA256_NOINLINE
101#endif
102
103#if !defined(NO_OLD_SHA_NAMES)
104 #define SHA256 WC_SHA256
105#endif
106
107#ifndef NO_OLD_WC_NAMES
108 #define Sha256 wc_Sha256
109 #define SHA256_BLOCK_SIZE WC_SHA256_BLOCK_SIZE
110 #define SHA256_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
111 #define SHA256_PAD_SIZE WC_SHA256_PAD_SIZE
112#endif
113
114/* in bytes */
115enum {
116 WC_SHA256 = WC_HASH_TYPE_SHA256,
117 WC_SHA256_BLOCK_SIZE = 64,
118 WC_SHA256_DIGEST_SIZE = 32,
119 WC_SHA256_PAD_SIZE = 56
120};
121
122
123#ifdef WOLFSSL_TI_HASH
124 #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
125#elif defined(WOLFSSL_IMX6_CAAM)
126 #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
127#elif defined(WOLFSSL_AFALG_HASH)
128 #include "wolfssl/wolfcrypt/port/af_alg/afalg_hash.h"
129#elif defined(WOLFSSL_RENESAS_TSIP_CRYPT) && \
130 !defined(NO_WOLFSSL_RENESAS_TSIP_CRYPT_HASH)
131 #include "wolfssl/wolfcrypt/port/Renesas/renesas-tsip-crypt.h"
132#elif defined(WOLFSSL_PSOC6_CRYPTO)
133 #include "wolfssl/wolfcrypt/port/cypress/psoc6_crypto.h"
134#elif defined(WOLFSSL_IMXRT_DCP)
135 #include <wolfssl/wolfcrypt/port/nxp/dcp_port.h>
136#else
137
138/* wc_Sha256 digest */
139struct wc_Sha256 {
140#ifdef FREESCALE_LTC_SHA
141 ltc_hash_ctx_t ctx;
142#elif defined(STM32_HASH_SHA2)
143 STM32_HASH_Context stmCtx;
144#elif defined(WOLFSSL_SILABS_SE_ACCEL)
145 wc_silabs_sha_t silabsCtx;
146#else
147 /* alignment on digest and buffer speeds up ARMv8 crypto operations */
148 ALIGN16 word32 digest[WC_SHA256_DIGEST_SIZE / sizeof(word32)];
149 ALIGN16 word32 buffer[WC_SHA256_BLOCK_SIZE / sizeof(word32)];
150 word32 buffLen; /* in bytes */
151 word32 loLen; /* length in bytes */
152 word32 hiLen; /* length in bytes */
153 void* heap;
154#endif
155#ifdef WOLFSSL_PIC32MZ_HASH
156 hashUpdCache cache; /* cache for updates */
157#endif
158#ifdef WOLFSSL_ASYNC_CRYPT
159 WC_ASYNC_DEV asyncDev;
160#endif /* WOLFSSL_ASYNC_CRYPT */
161#ifdef WOLFSSL_SMALL_STACK_CACHE
162 word32* W;
163#endif /* !FREESCALE_LTC_SHA && !STM32_HASH_SHA2 */
164#ifdef WOLFSSL_DEVCRYPTO_HASH
165 WC_CRYPTODEV ctx;
166 byte* msg;
167 word32 used;
168 word32 len;
169#endif
170#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
171 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
172 WC_ESP32SHA ctx;
173#endif
174#ifdef WOLFSSL_CRYPTOCELL
175 CRYS_HASHUserContext_t ctx;
176#endif
177#ifdef WOLF_CRYPTO_CB
178 int devId;
179 void* devCtx; /* generic crypto callback context */
180#endif
181#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
182 word32 flags; /* enum wc_HashFlags in hash.h */
183#endif
184};
185
186#ifndef WC_SHA256_TYPE_DEFINED
187 typedef struct wc_Sha256 wc_Sha256;
188 #define WC_SHA256_TYPE_DEFINED
189#endif
190
191#endif
192
193#endif /* HAVE_FIPS */
194
195WOLFSSL_API int wc_InitSha256(wc_Sha256*);
196WOLFSSL_API int wc_InitSha256_ex(wc_Sha256*, void*, int);
197WOLFSSL_API int wc_Sha256Update(wc_Sha256*, const byte*, word32);
198WOLFSSL_API int wc_Sha256FinalRaw(wc_Sha256*, byte*);
199WOLFSSL_API int wc_Sha256Final(wc_Sha256*, byte*);
200WOLFSSL_API void wc_Sha256Free(wc_Sha256*);
201
202WOLFSSL_API int wc_Sha256GetHash(wc_Sha256*, byte*);
203WOLFSSL_API int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst);
204
205#ifdef WOLFSSL_PIC32MZ_HASH
206WOLFSSL_API void wc_Sha256SizeSet(wc_Sha256*, word32);
207#endif
208
209#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
210 WOLFSSL_API int wc_Sha256SetFlags(wc_Sha256* sha256, word32 flags);
211 WOLFSSL_API int wc_Sha256GetFlags(wc_Sha256* sha256, word32* flags);
212#endif
213
214#ifdef WOLFSSL_SHA224
215/* avoid redefinition of structs */
216#if !defined(HAVE_FIPS) || \
217 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
218
219#ifndef NO_OLD_WC_NAMES
220 #define Sha224 wc_Sha224
221 #define SHA224 WC_SHA224
222 #define SHA224_BLOCK_SIZE WC_SHA224_BLOCK_SIZE
223 #define SHA224_DIGEST_SIZE WC_SHA224_DIGEST_SIZE
224 #define SHA224_PAD_SIZE WC_SHA224_PAD_SIZE
225#endif
226
227/* in bytes */
228enum {
229 WC_SHA224 = WC_HASH_TYPE_SHA224,
230 WC_SHA224_BLOCK_SIZE = WC_SHA256_BLOCK_SIZE,
231 WC_SHA224_DIGEST_SIZE = 28,
232 WC_SHA224_PAD_SIZE = WC_SHA256_PAD_SIZE
233};
234
235
236#ifndef WC_SHA224_TYPE_DEFINED
237 typedef struct wc_Sha256 wc_Sha224;
238 #define WC_SHA224_TYPE_DEFINED
239#endif
240#endif /* HAVE_FIPS */
241
242WOLFSSL_API int wc_InitSha224(wc_Sha224*);
243WOLFSSL_API int wc_InitSha224_ex(wc_Sha224*, void*, int);
244WOLFSSL_API int wc_Sha224Update(wc_Sha224*, const byte*, word32);
245WOLFSSL_API int wc_Sha224Final(wc_Sha224*, byte*);
246WOLFSSL_API void wc_Sha224Free(wc_Sha224*);
247
248WOLFSSL_API int wc_Sha224GetHash(wc_Sha224*, byte*);
249WOLFSSL_API int wc_Sha224Copy(wc_Sha224* src, wc_Sha224* dst);
250
251#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
252 WOLFSSL_API int wc_Sha224SetFlags(wc_Sha224* sha224, word32 flags);
253 WOLFSSL_API int wc_Sha224GetFlags(wc_Sha224* sha224, word32* flags);
254#endif
255
256#endif /* WOLFSSL_SHA224 */
257
258#ifdef __cplusplus
259 } /* extern "C" */
260#endif
261
262#endif /* NO_SHA256 */
263#endif /* WOLF_CRYPT_SHA256_H */
264
Note: See TracBrowser for help on using the repository browser.