1 | /* sha.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 | \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 |
|
---|
73 | #if !defined(NO_OLD_SHA_NAMES)
|
---|
74 | #define SHA WC_SHA
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | #ifndef NO_OLD_WC_NAMES
|
---|
78 | #define Sha wc_Sha
|
---|
79 | #define SHA_BLOCK_SIZE WC_SHA_BLOCK_SIZE
|
---|
80 | #define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
|
---|
81 | #define SHA_PAD_SIZE WC_SHA_PAD_SIZE
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | /* in bytes */
|
---|
85 | enum {
|
---|
86 | WC_SHA = WC_HASH_TYPE_SHA,
|
---|
87 | WC_SHA_BLOCK_SIZE = 64,
|
---|
88 | WC_SHA_DIGEST_SIZE = 20,
|
---|
89 | WC_SHA_PAD_SIZE = 56
|
---|
90 | };
|
---|
91 |
|
---|
92 |
|
---|
93 | #if defined(WOLFSSL_TI_HASH)
|
---|
94 | #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
---|
95 |
|
---|
96 | #elif defined(WOLFSSL_IMX6_CAAM)
|
---|
97 | #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
|
---|
98 |
|
---|
99 | #else
|
---|
100 | /* Sha digest */
|
---|
101 | typedef struct wc_Sha {
|
---|
102 | #ifdef FREESCALE_LTC_SHA
|
---|
103 | ltc_hash_ctx_t ctx;
|
---|
104 | #elif defined(STM32_HASH)
|
---|
105 | STM32_HASH_Context stmCtx;
|
---|
106 | #else
|
---|
107 | word32 buffLen; /* in bytes */
|
---|
108 | word32 loLen; /* length in bytes */
|
---|
109 | word32 hiLen; /* length in bytes */
|
---|
110 | word32 buffer[WC_SHA_BLOCK_SIZE / sizeof(word32)];
|
---|
111 | #ifdef WOLFSSL_PIC32MZ_HASH
|
---|
112 | word32 digest[PIC32_DIGEST_SIZE / sizeof(word32)];
|
---|
113 | #else
|
---|
114 | word32 digest[WC_SHA_DIGEST_SIZE / sizeof(word32)];
|
---|
115 | #endif
|
---|
116 | void* heap;
|
---|
117 | #ifdef WOLFSSL_PIC32MZ_HASH
|
---|
118 | hashUpdCache cache; /* cache for updates */
|
---|
119 | #endif
|
---|
120 | #ifdef WOLFSSL_ASYNC_CRYPT
|
---|
121 | WC_ASYNC_DEV asyncDev;
|
---|
122 | #endif /* WOLFSSL_ASYNC_CRYPT */
|
---|
123 | #endif
|
---|
124 | } wc_Sha;
|
---|
125 |
|
---|
126 | #endif /* WOLFSSL_TI_HASH */
|
---|
127 |
|
---|
128 |
|
---|
129 | #endif /* HAVE_FIPS */
|
---|
130 |
|
---|
131 | WOLFSSL_API int wc_InitSha(wc_Sha*);
|
---|
132 | WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId);
|
---|
133 | WOLFSSL_API int wc_ShaUpdate(wc_Sha*, const byte*, word32);
|
---|
134 | WOLFSSL_API int wc_ShaFinalRaw(wc_Sha*, byte*);
|
---|
135 | WOLFSSL_API int wc_ShaFinal(wc_Sha*, byte*);
|
---|
136 | WOLFSSL_API void wc_ShaFree(wc_Sha*);
|
---|
137 |
|
---|
138 | WOLFSSL_API int wc_ShaGetHash(wc_Sha*, byte*);
|
---|
139 | WOLFSSL_API int wc_ShaCopy(wc_Sha*, wc_Sha*);
|
---|
140 |
|
---|
141 | #ifdef WOLFSSL_PIC32MZ_HASH
|
---|
142 | WOLFSSL_API void wc_ShaSizeSet(wc_Sha* sha, word32 len);
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | #ifdef __cplusplus
|
---|
146 | } /* extern "C" */
|
---|
147 | #endif
|
---|
148 |
|
---|
149 | #endif /* NO_SHA */
|
---|
150 | #endif /* WOLF_CRYPT_SHA_H */
|
---|
151 |
|
---|