source: azure_iot_hub_f767zi/trunk/wolfssl-4.4.0/wolfssl/wolfcrypt/sha512.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: 6.5 KB
Line 
1/* sha512.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/sha512.h
24*/
25
26
27#ifndef WOLF_CRYPT_SHA512_H
28#define WOLF_CRYPT_SHA512_H
29
30#include <wolfssl/wolfcrypt/types.h>
31
32#if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
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 #ifdef WOLFSSL_SHA512
42 #define wc_Sha512 Sha512
43 #define WC_SHA512 SHA512
44 #define WC_SHA512_BLOCK_SIZE SHA512_BLOCK_SIZE
45 #define WC_SHA512_DIGEST_SIZE SHA512_DIGEST_SIZE
46 #define WC_SHA512_PAD_SIZE SHA512_PAD_SIZE
47 #endif /* WOLFSSL_SHA512 */
48 #ifdef WOLFSSL_SHA384
49 #define wc_Sha384 Sha384
50 #define WC_SHA384 SHA384
51 #define WC_SHA384_BLOCK_SIZE SHA384_BLOCK_SIZE
52 #define WC_SHA384_DIGEST_SIZE SHA384_DIGEST_SIZE
53 #define WC_SHA384_PAD_SIZE SHA384_PAD_SIZE
54 #endif /* WOLFSSL_SHA384 */
55
56 #define CYASSL_SHA512
57 #if defined(WOLFSSL_SHA384)
58 #define CYASSL_SHA384
59 #endif
60 /* for fips @wc_fips */
61 #include <cyassl/ctaocrypt/sha512.h>
62#endif
63
64#ifdef __cplusplus
65 extern "C" {
66#endif
67
68/* avoid redefinition of structs */
69#if !defined(HAVE_FIPS) || \
70 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
71
72#ifdef WOLFSSL_ASYNC_CRYPT
73 #include <wolfssl/wolfcrypt/async.h>
74#endif
75#ifdef WOLFSSL_ESP32WROOM32_CRYPT
76 #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
77#endif
78#if defined(_MSC_VER)
79 #define SHA512_NOINLINE __declspec(noinline)
80#elif defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
81 #define SHA512_NOINLINE __attribute__((noinline))
82#else
83 #define SHA512_NOINLINE
84#endif
85
86#ifdef WOLFSSL_SHA512
87
88#if !defined(NO_OLD_SHA_NAMES)
89 #define SHA512 WC_SHA512
90#endif
91
92#if !defined(NO_OLD_WC_NAMES)
93 #define Sha512 wc_Sha512
94 #define SHA512_BLOCK_SIZE WC_SHA512_BLOCK_SIZE
95 #define SHA512_DIGEST_SIZE WC_SHA512_DIGEST_SIZE
96 #define SHA512_PAD_SIZE WC_SHA512_PAD_SIZE
97#endif
98
99#endif /* WOLFSSL_SHA512 */
100
101/* in bytes */
102enum {
103#ifdef WOLFSSL_SHA512
104 WC_SHA512 = WC_HASH_TYPE_SHA512,
105#endif
106 WC_SHA512_BLOCK_SIZE = 128,
107 WC_SHA512_DIGEST_SIZE = 64,
108 WC_SHA512_PAD_SIZE = 112
109};
110
111
112#ifdef WOLFSSL_IMX6_CAAM
113 #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
114#else
115/* wc_Sha512 digest */
116struct wc_Sha512 {
117 word64 digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
118 word64 buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64)];
119 word32 buffLen; /* in bytes */
120 word64 loLen; /* length in bytes */
121 word64 hiLen; /* length in bytes */
122 void* heap;
123#ifdef USE_INTEL_SPEEDUP
124 const byte* data;
125#endif
126#ifdef WOLFSSL_ASYNC_CRYPT
127 WC_ASYNC_DEV asyncDev;
128#endif /* WOLFSSL_ASYNC_CRYPT */
129#ifdef WOLFSSL_SMALL_STACK_CACHE
130 word64* W;
131#endif
132#if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \
133 !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
134 WC_ESP32SHA ctx;
135#endif
136#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
137 word32 flags; /* enum wc_HashFlags in hash.h */
138#endif
139};
140
141#ifndef WC_SHA512_TYPE_DEFINED
142 typedef struct wc_Sha512 wc_Sha512;
143 #define WC_SHA512_TYPE_DEFINED
144#endif
145#endif
146
147#endif /* HAVE_FIPS */
148
149#ifdef WOLFSSL_ARMASM
150WOLFSSL_LOCAL void Transform_Sha512_Len(wc_Sha512* sha512, const byte* data,
151 word32 len);
152#endif
153
154#ifdef WOLFSSL_SHA512
155
156WOLFSSL_API int wc_InitSha512(wc_Sha512*);
157WOLFSSL_API int wc_InitSha512_ex(wc_Sha512*, void*, int);
158WOLFSSL_API int wc_Sha512Update(wc_Sha512*, const byte*, word32);
159WOLFSSL_API int wc_Sha512FinalRaw(wc_Sha512*, byte*);
160WOLFSSL_API int wc_Sha512Final(wc_Sha512*, byte*);
161WOLFSSL_API void wc_Sha512Free(wc_Sha512*);
162
163WOLFSSL_API int wc_Sha512GetHash(wc_Sha512*, byte*);
164WOLFSSL_API int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst);
165
166#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
167 WOLFSSL_API int wc_Sha512SetFlags(wc_Sha512* sha512, word32 flags);
168 WOLFSSL_API int wc_Sha512GetFlags(wc_Sha512* sha512, word32* flags);
169#endif
170
171#endif /* WOLFSSL_SHA512 */
172
173#if defined(WOLFSSL_SHA384)
174
175/* avoid redefinition of structs */
176#if !defined(HAVE_FIPS) || \
177 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
178
179#if !defined(NO_OLD_SHA_NAMES)
180 #define SHA384 WC_SHA384
181#endif
182
183#if !defined(NO_OLD_WC_NAMES)
184 #define Sha384 wc_Sha384
185 #define SHA384_BLOCK_SIZE WC_SHA384_BLOCK_SIZE
186 #define SHA384_DIGEST_SIZE WC_SHA384_DIGEST_SIZE
187 #define SHA384_PAD_SIZE WC_SHA384_PAD_SIZE
188#endif
189
190/* in bytes */
191enum {
192 WC_SHA384 = WC_HASH_TYPE_SHA384,
193 WC_SHA384_BLOCK_SIZE = WC_SHA512_BLOCK_SIZE,
194 WC_SHA384_DIGEST_SIZE = 48,
195 WC_SHA384_PAD_SIZE = WC_SHA512_PAD_SIZE
196};
197
198
199#ifndef WC_SHA384_TYPE_DEFINED
200 typedef struct wc_Sha512 wc_Sha384;
201 #define WC_SHA384_TYPE_DEFINED
202#endif
203#endif /* HAVE_FIPS */
204
205WOLFSSL_API int wc_InitSha384(wc_Sha384*);
206WOLFSSL_API int wc_InitSha384_ex(wc_Sha384*, void*, int);
207WOLFSSL_API int wc_Sha384Update(wc_Sha384*, const byte*, word32);
208WOLFSSL_API int wc_Sha384FinalRaw(wc_Sha384*, byte*);
209WOLFSSL_API int wc_Sha384Final(wc_Sha384*, byte*);
210WOLFSSL_API void wc_Sha384Free(wc_Sha384*);
211
212WOLFSSL_API int wc_Sha384GetHash(wc_Sha384*, byte*);
213WOLFSSL_API int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst);
214
215#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
216 WOLFSSL_API int wc_Sha384SetFlags(wc_Sha384* sha384, word32 flags);
217 WOLFSSL_API int wc_Sha384GetFlags(wc_Sha384* sha384, word32* flags);
218#endif
219
220#endif /* WOLFSSL_SHA384 */
221
222#ifdef __cplusplus
223 } /* extern "C" */
224#endif
225
226#endif /* WOLFSSL_SHA512 || WOLFSSL_SHA384 */
227#endif /* WOLF_CRYPT_SHA512_H */
228
Note: See TracBrowser for help on using the repository browser.