1 | /* sha256.h
|
---|
2 | *
|
---|
3 | * Copyright (C) 2006-2017 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 | /* code submitted by raphael.huck@efixo.com */
|
---|
24 |
|
---|
25 | #ifndef WOLF_CRYPT_SHA256_H
|
---|
26 | #define WOLF_CRYPT_SHA256_H
|
---|
27 |
|
---|
28 | #include <wolfssl/wolfcrypt/types.h>
|
---|
29 |
|
---|
30 | #ifndef NO_SHA256
|
---|
31 |
|
---|
32 | #ifdef HAVE_FIPS
|
---|
33 | #define wc_Sha256 Sha256
|
---|
34 | #define WC_SHA256 SHA256
|
---|
35 | #define WC_SHA256_BLOCK_SIZE SHA256_BLOCK_SIZE
|
---|
36 | #define WC_SHA256_DIGEST_SIZE SHA256_DIGEST_SIZE
|
---|
37 | #define WC_SHA256_PAD_SIZE SHA256_PAD_SIZE
|
---|
38 |
|
---|
39 | #ifdef WOLFSSL_SHA224
|
---|
40 | #define wc_Sha224 Sha224
|
---|
41 | #define WC_SHA224 SHA224
|
---|
42 | #define WC_SHA224_BLOCK_SIZE SHA224_BLOCK_SIZE
|
---|
43 | #define WC_SHA224_DIGEST_SIZE SHA224_DIGEST_SIZE
|
---|
44 | #define WC_SHA224_PAD_SIZE SHA224_PAD_SIZE
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | /* for fips @wc_fips */
|
---|
48 | #include <cyassl/ctaocrypt/sha256.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #ifdef FREESCALE_LTC_SHA
|
---|
52 | #include "fsl_ltc.h"
|
---|
53 | #endif
|
---|
54 |
|
---|
55 |
|
---|
56 | #ifdef __cplusplus
|
---|
57 | extern "C" {
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | #ifndef HAVE_FIPS /* avoid redefinition of structs */
|
---|
61 |
|
---|
62 | #ifdef WOLFSSL_MICROCHIP_PIC32MZ
|
---|
63 | #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
|
---|
64 | #endif
|
---|
65 | #ifdef WOLFSSL_ASYNC_CRYPT
|
---|
66 | #include <wolfssl/wolfcrypt/async.h>
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #ifndef NO_OLD_WC_NAMES
|
---|
70 | #define Sha256 wc_Sha256
|
---|
71 | #define SHA256 WC_SHA256
|
---|
72 | #define SHA256_BLOCK_SIZE WC_SHA256_BLOCK_SIZE
|
---|
73 | #define SHA256_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
|
---|
74 | #define SHA256_PAD_SIZE WC_SHA256_PAD_SIZE
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | /* in bytes */
|
---|
78 | enum {
|
---|
79 | WC_SHA256 = 2, /* hash type unique */
|
---|
80 | WC_SHA256_BLOCK_SIZE = 64,
|
---|
81 | WC_SHA256_DIGEST_SIZE = 32,
|
---|
82 | WC_SHA256_PAD_SIZE = 56
|
---|
83 | };
|
---|
84 |
|
---|
85 | #ifndef WOLFSSL_TI_HASH
|
---|
86 |
|
---|
87 | /* wc_Sha256 digest */
|
---|
88 | typedef struct wc_Sha256 {
|
---|
89 | #ifdef FREESCALE_LTC_SHA
|
---|
90 | ltc_hash_ctx_t ctx;
|
---|
91 | #else
|
---|
92 | /* alignment on digest and buffer speeds up ARMv8 crypto operations */
|
---|
93 | ALIGN16 word32 digest[WC_SHA256_DIGEST_SIZE / sizeof(word32)];
|
---|
94 | ALIGN16 word32 buffer[WC_SHA256_BLOCK_SIZE / sizeof(word32)];
|
---|
95 | word32 buffLen; /* in bytes */
|
---|
96 | word32 loLen; /* length in bytes */
|
---|
97 | word32 hiLen; /* length in bytes */
|
---|
98 | void* heap;
|
---|
99 | #ifdef WOLFSSL_PIC32MZ_HASH
|
---|
100 | hashUpdCache cache; /* cache for updates */
|
---|
101 | #endif
|
---|
102 | #if defined(STM32_HASH) && defined(WOLFSSL_STM32_CUBEMX)
|
---|
103 | HASH_HandleTypeDef hashHandle;
|
---|
104 | #endif
|
---|
105 | #ifdef WOLFSSL_ASYNC_CRYPT
|
---|
106 | WC_ASYNC_DEV asyncDev;
|
---|
107 | #endif /* WOLFSSL_ASYNC_CRYPT */
|
---|
108 | #endif /* FREESCALE_LTC_SHA */
|
---|
109 | } wc_Sha256;
|
---|
110 |
|
---|
111 | #else
|
---|
112 | #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | #endif /* HAVE_FIPS */
|
---|
116 |
|
---|
117 | WOLFSSL_API int wc_InitSha256(wc_Sha256*);
|
---|
118 | WOLFSSL_API int wc_InitSha256_ex(wc_Sha256*, void*, int);
|
---|
119 | WOLFSSL_API int wc_Sha256Update(wc_Sha256*, const byte*, word32);
|
---|
120 | WOLFSSL_API int wc_Sha256Final(wc_Sha256*, byte*);
|
---|
121 | WOLFSSL_API void wc_Sha256Free(wc_Sha256*);
|
---|
122 |
|
---|
123 | WOLFSSL_API int wc_Sha256GetHash(wc_Sha256*, byte*);
|
---|
124 | WOLFSSL_API int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst);
|
---|
125 |
|
---|
126 | #ifdef WOLFSSL_PIC32MZ_HASH
|
---|
127 | WOLFSSL_API void wc_Sha256SizeSet(wc_Sha256*, word32);
|
---|
128 | #endif
|
---|
129 |
|
---|
130 | #ifdef WOLFSSL_SHA224
|
---|
131 | #ifndef HAVE_FIPS /* avoid redefinition of structs */
|
---|
132 |
|
---|
133 | #ifndef NO_OLD_WC_NAMES
|
---|
134 | #define Sha224 wc_Sha224
|
---|
135 | #define SHA224 WC_SHA224
|
---|
136 | #define SHA224_BLOCK_SIZE WC_SHA224_BLOCK_SIZE
|
---|
137 | #define SHA224_DIGEST_SIZE WC_SHA224_DIGEST_SIZE
|
---|
138 | #define SHA224_PAD_SIZE WC_SHA224_PAD_SIZE
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | /* in bytes */
|
---|
142 | enum {
|
---|
143 | WC_SHA224 = 8, /* hash type unique */
|
---|
144 | WC_SHA224_BLOCK_SIZE = WC_SHA256_BLOCK_SIZE,
|
---|
145 | WC_SHA224_DIGEST_SIZE = 28,
|
---|
146 | WC_SHA224_PAD_SIZE = WC_SHA256_PAD_SIZE
|
---|
147 | };
|
---|
148 |
|
---|
149 | typedef wc_Sha256 wc_Sha224;
|
---|
150 | #endif /* HAVE_FIPS */
|
---|
151 |
|
---|
152 | WOLFSSL_API int wc_InitSha224(wc_Sha224*);
|
---|
153 | WOLFSSL_API int wc_InitSha224_ex(wc_Sha224*, void*, int);
|
---|
154 | WOLFSSL_API int wc_Sha224Update(wc_Sha224*, const byte*, word32);
|
---|
155 | WOLFSSL_API int wc_Sha224Final(wc_Sha224*, byte*);
|
---|
156 | WOLFSSL_API void wc_Sha224Free(wc_Sha224*);
|
---|
157 |
|
---|
158 | WOLFSSL_API int wc_Sha224GetHash(wc_Sha224*, byte*);
|
---|
159 | WOLFSSL_API int wc_Sha224Copy(wc_Sha224* src, wc_Sha224* dst);
|
---|
160 |
|
---|
161 | #endif /* WOLFSSL_SHA224 */
|
---|
162 |
|
---|
163 | #ifdef __cplusplus
|
---|
164 | } /* extern "C" */
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | #endif /* NO_SHA256 */
|
---|
168 | #endif /* WOLF_CRYPT_SHA256_H */
|
---|
169 |
|
---|