source: azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/sha.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: 5.1 KB
Line 
1/* sha.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/sha.h
24*/
25
26
27#ifndef WOLF_CRYPT_SHA_H
28#define WOLF_CRYPT_SHA_H
29
30#include <wolfssl/wolfcrypt/types.h>
31
32#ifndef NO_SHA
33
34#if defined(HAVE_FIPS) && \
35 defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
36 #include <wolfssl/wolfcrypt/fips.h>
37#endif /* HAVE_FIPS_VERSION >= 2 */
38
39#if defined(HAVE_FIPS) && \
40 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
41#define wc_Sha Sha
42#define WC_SHA SHA
43#define WC_SHA_BLOCK_SIZE SHA_BLOCK_SIZE
44#define WC_SHA_DIGEST_SIZE SHA_DIGEST_SIZE
45#define WC_SHA_PAD_SIZE SHA_PAD_SIZE
46
47/* for fips @wc_fips */
48#include <cyassl/ctaocrypt/sha.h>
49#endif
50
51#ifdef FREESCALE_LTC_SHA
52 #include "fsl_ltc.h"
53#endif
54
55#ifdef __cplusplus
56 extern "C" {
57#endif
58
59/* avoid redefinition of structs */
60#if !defined(HAVE_FIPS) || \
61 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
62
63#ifdef WOLFSSL_MICROCHIP_PIC32MZ
64 #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
65#endif
66#ifdef STM32_HASH
67 #include <wolfssl/wolfcrypt/port/st/stm32.h>
68#endif
69#ifdef WOLFSSL_ASYNC_CRYPT
70 #include <wolfssl/wolfcrypt/async.h>
71#endif
72#ifdef WOLFSSL_ESP32WROOM32_CRYPT
73 #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
74#endif
75#ifdef WOLFSSL_IMXRT_DCP
76 #include <wolfssl/wolfcrypt/port/nxp/dcp_port.h>
77#endif
78#if defined(WOLFSSL_SILABS_SE_ACCEL)
79 #include <wolfssl/wolfcrypt/port/silabs/silabs_hash.h>
80#endif
81
82#if !defined(NO_OLD_SHA_NAMES)
83 #define SHA WC_SHA
84#endif
85
86#ifndef NO_OLD_WC_NAMES
87 #define Sha wc_Sha
88 #define SHA_BLOCK_SIZE WC_SHA_BLOCK_SIZE
89 #define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
90 #define SHA_PAD_SIZE WC_SHA_PAD_SIZE
91#endif
92
93/* in bytes */
94enum {
95 WC_SHA = WC_HASH_TYPE_SHA,
96 WC_SHA_BLOCK_SIZE = 64,
97 WC_SHA_DIGEST_SIZE = 20,
98 WC_SHA_PAD_SIZE = 56
99};
100
101
102#if defined(WOLFSSL_TI_HASH)
103 #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
104
105#elif defined(WOLFSSL_IMX6_CAAM)
106 #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
107#elif defined(WOLFSSL_RENESAS_TSIP_CRYPT) && \
108 !defined(NO_WOLFSSL_RENESAS_TSIP_CRYPT_HASH)
109 #include "wolfssl/wolfcrypt/port/Renesas/renesas-tsip-crypt.h"
110#elif defined(WOLFSSL_PSOC6_CRYPTO)
111 #include "wolfssl/wolfcrypt/port/cypress/psoc6_crypto.h"
112#else
113
114/* Sha digest */
115struct wc_Sha {
116#ifdef FREESCALE_LTC_SHA
117 ltc_hash_ctx_t ctx;
118#elif defined(STM32_HASH)
119 STM32_HASH_Context stmCtx;
120#elif defined(WOLFSSL_SILABS_SE_ACCEL)
121 wc_silabs_sha_t silabsCtx;
122#else
123 word32 buffLen; /* in bytes */
124 word32 loLen; /* length in bytes */
125 word32 hiLen; /* length in bytes */
126 word32 buffer[WC_SHA_BLOCK_SIZE / sizeof(word32)];
127 #ifdef WOLFSSL_PIC32MZ_HASH
128 word32 digest[PIC32_DIGEST_SIZE / sizeof(word32)];
129 #else
130 word32 digest[WC_SHA_DIGEST_SIZE / sizeof(word32)];
131 #endif
132 void* heap;
133 #ifdef WOLFSSL_PIC32MZ_HASH
134 hashUpdCache cache; /* cache for updates */
135 #endif
136 #ifdef WOLFSSL_ASYNC_CRYPT
137 WC_ASYNC_DEV asyncDev;
138 #endif /* WOLFSSL_ASYNC_CRYPT */
139 #ifdef WOLF_CRYPTO_CB
140 int devId;
141 void* devCtx; /* generic crypto callback context */
142 #endif
143#endif
144#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
145 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
146 WC_ESP32SHA ctx;
147#endif
148#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
149 word32 flags; /* enum wc_HashFlags in hash.h */
150#endif
151};
152
153#ifndef WC_SHA_TYPE_DEFINED
154 typedef struct wc_Sha wc_Sha;
155 #define WC_SHA_TYPE_DEFINED
156#endif
157
158#endif /* WOLFSSL_TI_HASH */
159
160
161#endif /* HAVE_FIPS */
162
163WOLFSSL_API int wc_InitSha(wc_Sha*);
164WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId);
165WOLFSSL_API int wc_ShaUpdate(wc_Sha*, const byte*, word32);
166WOLFSSL_API int wc_ShaFinalRaw(wc_Sha*, byte*);
167WOLFSSL_API int wc_ShaFinal(wc_Sha*, byte*);
168WOLFSSL_API void wc_ShaFree(wc_Sha*);
169
170WOLFSSL_API int wc_ShaGetHash(wc_Sha*, byte*);
171WOLFSSL_API int wc_ShaCopy(wc_Sha*, wc_Sha*);
172
173#ifdef WOLFSSL_PIC32MZ_HASH
174WOLFSSL_API void wc_ShaSizeSet(wc_Sha* sha, word32 len);
175#endif
176
177#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
178 WOLFSSL_API int wc_ShaSetFlags(wc_Sha* sha, word32 flags);
179 WOLFSSL_API int wc_ShaGetFlags(wc_Sha* sha, word32* flags);
180#endif
181
182#ifdef __cplusplus
183 } /* extern "C" */
184#endif
185
186#endif /* NO_SHA */
187#endif /* WOLF_CRYPT_SHA_H */
188
Note: See TracBrowser for help on using the repository browser.