Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
wolfSSL
Date:
Sat Aug 18 22:20:43 2018 +0000
Revision:
15:117db924cf7c
wolfSSL 3.15.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 15:117db924cf7c 1 /* sha.h
wolfSSL 15:117db924cf7c 2 *
wolfSSL 15:117db924cf7c 3 * Copyright (C) 2006-2017 wolfSSL Inc.
wolfSSL 15:117db924cf7c 4 *
wolfSSL 15:117db924cf7c 5 * This file is part of wolfSSL.
wolfSSL 15:117db924cf7c 6 *
wolfSSL 15:117db924cf7c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 15:117db924cf7c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 15:117db924cf7c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 15:117db924cf7c 10 * (at your option) any later version.
wolfSSL 15:117db924cf7c 11 *
wolfSSL 15:117db924cf7c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 15:117db924cf7c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 15:117db924cf7c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 15:117db924cf7c 15 * GNU General Public License for more details.
wolfSSL 15:117db924cf7c 16 *
wolfSSL 15:117db924cf7c 17 * You should have received a copy of the GNU General Public License
wolfSSL 15:117db924cf7c 18 * along with this program; if not, write to the Free Software
wolfSSL 15:117db924cf7c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 15:117db924cf7c 20 */
wolfSSL 15:117db924cf7c 21
wolfSSL 15:117db924cf7c 22 /*!
wolfSSL 15:117db924cf7c 23 \file wolfssl/wolfcrypt/sha.h
wolfSSL 15:117db924cf7c 24 */
wolfSSL 15:117db924cf7c 25
wolfSSL 15:117db924cf7c 26
wolfSSL 15:117db924cf7c 27 #ifndef WOLF_CRYPT_SHA_H
wolfSSL 15:117db924cf7c 28 #define WOLF_CRYPT_SHA_H
wolfSSL 15:117db924cf7c 29
wolfSSL 15:117db924cf7c 30 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 15:117db924cf7c 31
wolfSSL 15:117db924cf7c 32 #ifndef NO_SHA
wolfSSL 15:117db924cf7c 33
wolfSSL 15:117db924cf7c 34 #if defined(HAVE_FIPS) && \
wolfSSL 15:117db924cf7c 35 defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
wolfSSL 15:117db924cf7c 36 #include <wolfssl/wolfcrypt/fips.h>
wolfSSL 15:117db924cf7c 37 #endif /* HAVE_FIPS_VERSION >= 2 */
wolfSSL 15:117db924cf7c 38
wolfSSL 15:117db924cf7c 39 #if defined(HAVE_FIPS) && \
wolfSSL 15:117db924cf7c 40 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
wolfSSL 15:117db924cf7c 41 #define wc_Sha Sha
wolfSSL 15:117db924cf7c 42 #define WC_SHA SHA
wolfSSL 15:117db924cf7c 43 #define WC_SHA_BLOCK_SIZE SHA_BLOCK_SIZE
wolfSSL 15:117db924cf7c 44 #define WC_SHA_DIGEST_SIZE SHA_DIGEST_SIZE
wolfSSL 15:117db924cf7c 45 #define WC_SHA_PAD_SIZE SHA_PAD_SIZE
wolfSSL 15:117db924cf7c 46
wolfSSL 15:117db924cf7c 47 /* for fips @wc_fips */
wolfSSL 15:117db924cf7c 48 #include <cyassl/ctaocrypt/sha.h>
wolfSSL 15:117db924cf7c 49 #endif
wolfSSL 15:117db924cf7c 50
wolfSSL 15:117db924cf7c 51 #ifdef FREESCALE_LTC_SHA
wolfSSL 15:117db924cf7c 52 #include "fsl_ltc.h"
wolfSSL 15:117db924cf7c 53 #endif
wolfSSL 15:117db924cf7c 54
wolfSSL 15:117db924cf7c 55 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 56 extern "C" {
wolfSSL 15:117db924cf7c 57 #endif
wolfSSL 15:117db924cf7c 58
wolfSSL 15:117db924cf7c 59 /* avoid redefinition of structs */
wolfSSL 15:117db924cf7c 60 #if !defined(HAVE_FIPS) || \
wolfSSL 15:117db924cf7c 61 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
wolfSSL 15:117db924cf7c 62
wolfSSL 15:117db924cf7c 63 #ifdef WOLFSSL_MICROCHIP_PIC32MZ
wolfSSL 15:117db924cf7c 64 #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
wolfSSL 15:117db924cf7c 65 #endif
wolfSSL 15:117db924cf7c 66 #ifdef STM32_HASH
wolfSSL 15:117db924cf7c 67 #include <wolfssl/wolfcrypt/port/st/stm32.h>
wolfSSL 15:117db924cf7c 68 #endif
wolfSSL 15:117db924cf7c 69 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 15:117db924cf7c 70 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 15:117db924cf7c 71 #endif
wolfSSL 15:117db924cf7c 72
wolfSSL 15:117db924cf7c 73 #if !defined(NO_OLD_SHA_NAMES)
wolfSSL 15:117db924cf7c 74 #define SHA WC_SHA
wolfSSL 15:117db924cf7c 75 #endif
wolfSSL 15:117db924cf7c 76
wolfSSL 15:117db924cf7c 77 #ifndef NO_OLD_WC_NAMES
wolfSSL 15:117db924cf7c 78 #define Sha wc_Sha
wolfSSL 15:117db924cf7c 79 #define SHA_BLOCK_SIZE WC_SHA_BLOCK_SIZE
wolfSSL 15:117db924cf7c 80 #define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
wolfSSL 15:117db924cf7c 81 #define SHA_PAD_SIZE WC_SHA_PAD_SIZE
wolfSSL 15:117db924cf7c 82 #endif
wolfSSL 15:117db924cf7c 83
wolfSSL 15:117db924cf7c 84 /* in bytes */
wolfSSL 15:117db924cf7c 85 enum {
wolfSSL 15:117db924cf7c 86 WC_SHA = WC_HASH_TYPE_SHA,
wolfSSL 15:117db924cf7c 87 WC_SHA_BLOCK_SIZE = 64,
wolfSSL 15:117db924cf7c 88 WC_SHA_DIGEST_SIZE = 20,
wolfSSL 15:117db924cf7c 89 WC_SHA_PAD_SIZE = 56
wolfSSL 15:117db924cf7c 90 };
wolfSSL 15:117db924cf7c 91
wolfSSL 15:117db924cf7c 92
wolfSSL 15:117db924cf7c 93 #if defined(WOLFSSL_TI_HASH)
wolfSSL 15:117db924cf7c 94 #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
wolfSSL 15:117db924cf7c 95
wolfSSL 15:117db924cf7c 96 #elif defined(WOLFSSL_IMX6_CAAM)
wolfSSL 15:117db924cf7c 97 #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
wolfSSL 15:117db924cf7c 98
wolfSSL 15:117db924cf7c 99 #else
wolfSSL 15:117db924cf7c 100 /* Sha digest */
wolfSSL 15:117db924cf7c 101 typedef struct wc_Sha {
wolfSSL 15:117db924cf7c 102 #ifdef FREESCALE_LTC_SHA
wolfSSL 15:117db924cf7c 103 ltc_hash_ctx_t ctx;
wolfSSL 15:117db924cf7c 104 #elif defined(STM32_HASH)
wolfSSL 15:117db924cf7c 105 STM32_HASH_Context stmCtx;
wolfSSL 15:117db924cf7c 106 #else
wolfSSL 15:117db924cf7c 107 word32 buffLen; /* in bytes */
wolfSSL 15:117db924cf7c 108 word32 loLen; /* length in bytes */
wolfSSL 15:117db924cf7c 109 word32 hiLen; /* length in bytes */
wolfSSL 15:117db924cf7c 110 word32 buffer[WC_SHA_BLOCK_SIZE / sizeof(word32)];
wolfSSL 15:117db924cf7c 111 #ifdef WOLFSSL_PIC32MZ_HASH
wolfSSL 15:117db924cf7c 112 word32 digest[PIC32_DIGEST_SIZE / sizeof(word32)];
wolfSSL 15:117db924cf7c 113 #else
wolfSSL 15:117db924cf7c 114 word32 digest[WC_SHA_DIGEST_SIZE / sizeof(word32)];
wolfSSL 15:117db924cf7c 115 #endif
wolfSSL 15:117db924cf7c 116 void* heap;
wolfSSL 15:117db924cf7c 117 #ifdef WOLFSSL_PIC32MZ_HASH
wolfSSL 15:117db924cf7c 118 hashUpdCache cache; /* cache for updates */
wolfSSL 15:117db924cf7c 119 #endif
wolfSSL 15:117db924cf7c 120 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 15:117db924cf7c 121 WC_ASYNC_DEV asyncDev;
wolfSSL 15:117db924cf7c 122 #endif /* WOLFSSL_ASYNC_CRYPT */
wolfSSL 15:117db924cf7c 123 #endif
wolfSSL 15:117db924cf7c 124 } wc_Sha;
wolfSSL 15:117db924cf7c 125
wolfSSL 15:117db924cf7c 126 #endif /* WOLFSSL_TI_HASH */
wolfSSL 15:117db924cf7c 127
wolfSSL 15:117db924cf7c 128
wolfSSL 15:117db924cf7c 129 #endif /* HAVE_FIPS */
wolfSSL 15:117db924cf7c 130
wolfSSL 15:117db924cf7c 131 WOLFSSL_API int wc_InitSha(wc_Sha*);
wolfSSL 15:117db924cf7c 132 WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId);
wolfSSL 15:117db924cf7c 133 WOLFSSL_API int wc_ShaUpdate(wc_Sha*, const byte*, word32);
wolfSSL 15:117db924cf7c 134 WOLFSSL_API int wc_ShaFinalRaw(wc_Sha*, byte*);
wolfSSL 15:117db924cf7c 135 WOLFSSL_API int wc_ShaFinal(wc_Sha*, byte*);
wolfSSL 15:117db924cf7c 136 WOLFSSL_API void wc_ShaFree(wc_Sha*);
wolfSSL 15:117db924cf7c 137
wolfSSL 15:117db924cf7c 138 WOLFSSL_API int wc_ShaGetHash(wc_Sha*, byte*);
wolfSSL 15:117db924cf7c 139 WOLFSSL_API int wc_ShaCopy(wc_Sha*, wc_Sha*);
wolfSSL 15:117db924cf7c 140
wolfSSL 15:117db924cf7c 141 #ifdef WOLFSSL_PIC32MZ_HASH
wolfSSL 15:117db924cf7c 142 WOLFSSL_API void wc_ShaSizeSet(wc_Sha* sha, word32 len);
wolfSSL 15:117db924cf7c 143 #endif
wolfSSL 15:117db924cf7c 144
wolfSSL 15:117db924cf7c 145 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 146 } /* extern "C" */
wolfSSL 15:117db924cf7c 147 #endif
wolfSSL 15:117db924cf7c 148
wolfSSL 15:117db924cf7c 149 #endif /* NO_SHA */
wolfSSL 15:117db924cf7c 150 #endif /* WOLF_CRYPT_SHA_H */
wolfSSL 15:117db924cf7c 151
wolfSSL 15:117db924cf7c 152