source: azure_iot_hub_f767zi/trunk/wolfssl-4.4.0/wolfssl/wolfcrypt/sha.h@ 457

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

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 4.8 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
76#if !defined(NO_OLD_SHA_NAMES)
77 #define SHA WC_SHA
78#endif
79
80#ifndef NO_OLD_WC_NAMES
81 #define Sha wc_Sha
82 #define SHA_BLOCK_SIZE WC_SHA_BLOCK_SIZE
83 #define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
84 #define SHA_PAD_SIZE WC_SHA_PAD_SIZE
85#endif
86
87/* in bytes */
88enum {
89 WC_SHA = WC_HASH_TYPE_SHA,
90 WC_SHA_BLOCK_SIZE = 64,
91 WC_SHA_DIGEST_SIZE = 20,
92 WC_SHA_PAD_SIZE = 56
93};
94
95
96#if defined(WOLFSSL_TI_HASH)
97 #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
98
99#elif defined(WOLFSSL_IMX6_CAAM)
100 #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
101#elif defined(WOLFSSL_RENESAS_TSIP_CRYPT) && \
102 !defined(NO_WOLFSSL_RENESAS_TSIP_CRYPT_HASH)
103 #include "wolfssl/wolfcrypt/port/Renesas/renesas-tsip-crypt.h"
104#else
105
106/* Sha digest */
107struct wc_Sha {
108#ifdef FREESCALE_LTC_SHA
109 ltc_hash_ctx_t ctx;
110#elif defined(STM32_HASH)
111 STM32_HASH_Context stmCtx;
112#else
113 word32 buffLen; /* in bytes */
114 word32 loLen; /* length in bytes */
115 word32 hiLen; /* length in bytes */
116 word32 buffer[WC_SHA_BLOCK_SIZE / sizeof(word32)];
117 #ifdef WOLFSSL_PIC32MZ_HASH
118 word32 digest[PIC32_DIGEST_SIZE / sizeof(word32)];
119 #else
120 word32 digest[WC_SHA_DIGEST_SIZE / sizeof(word32)];
121 #endif
122 void* heap;
123 #ifdef WOLFSSL_PIC32MZ_HASH
124 hashUpdCache cache; /* cache for updates */
125 #endif
126 #ifdef WOLFSSL_ASYNC_CRYPT
127 WC_ASYNC_DEV asyncDev;
128 #endif /* WOLFSSL_ASYNC_CRYPT */
129 #ifdef WOLF_CRYPTO_CB
130 int devId;
131 void* devCtx; /* generic crypto callback context */
132 #endif
133#endif
134#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
135 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
136 WC_ESP32SHA ctx;
137#endif
138#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
139 word32 flags; /* enum wc_HashFlags in hash.h */
140#endif
141};
142
143#ifndef WC_SHA_TYPE_DEFINED
144 typedef struct wc_Sha wc_Sha;
145 #define WC_SHA_TYPE_DEFINED
146#endif
147
148#endif /* WOLFSSL_TI_HASH */
149
150
151#endif /* HAVE_FIPS */
152
153WOLFSSL_API int wc_InitSha(wc_Sha*);
154WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId);
155WOLFSSL_API int wc_ShaUpdate(wc_Sha*, const byte*, word32);
156WOLFSSL_API int wc_ShaFinalRaw(wc_Sha*, byte*);
157WOLFSSL_API int wc_ShaFinal(wc_Sha*, byte*);
158WOLFSSL_API void wc_ShaFree(wc_Sha*);
159
160WOLFSSL_API int wc_ShaGetHash(wc_Sha*, byte*);
161WOLFSSL_API int wc_ShaCopy(wc_Sha*, wc_Sha*);
162
163#ifdef WOLFSSL_PIC32MZ_HASH
164WOLFSSL_API void wc_ShaSizeSet(wc_Sha* sha, word32 len);
165#endif
166
167#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
168 WOLFSSL_API int wc_ShaSetFlags(wc_Sha* sha, word32 flags);
169 WOLFSSL_API int wc_ShaGetFlags(wc_Sha* sha, word32* flags);
170#endif
171
172#ifdef __cplusplus
173 } /* extern "C" */
174#endif
175
176#endif /* NO_SHA */
177#endif /* WOLF_CRYPT_SHA_H */
178
Note: See TracBrowser for help on using the repository browser.