Xuyi Wang / wolfcrypt

Dependents:   OS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sha.h Source File

sha.h

00001 /* sha.h
00002  *
00003  * Copyright (C) 2006-2017 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 /*!
00023     \file wolfssl/wolfcrypt/sha.h
00024 */
00025 
00026 
00027 #ifndef WOLF_CRYPT_SHA_H
00028 #define WOLF_CRYPT_SHA_H
00029 
00030 #include <wolfcrypt/types.h>
00031 
00032 #ifndef NO_SHA
00033 
00034 #if defined(HAVE_FIPS) && \
00035     defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
00036     #include <wolfcrypt/fips.h>
00037 #endif /* HAVE_FIPS_VERSION >= 2 */
00038 
00039 #if defined(HAVE_FIPS) && \
00040     (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
00041 #define wc_Sha             Sha
00042 #define WC_SHA             SHA
00043 #define WC_SHA_BLOCK_SIZE  SHA_BLOCK_SIZE
00044 #define WC_SHA_DIGEST_SIZE SHA_DIGEST_SIZE
00045 #define WC_SHA_PAD_SIZE    SHA_PAD_SIZE
00046 
00047 /* for fips @wc_fips */
00048 #include <cyassl/ctaocrypt/sha.h>
00049 #endif
00050 
00051 #ifdef FREESCALE_LTC_SHA
00052     #include "fsl_ltc.h"
00053 #endif
00054 
00055 #ifdef __cplusplus
00056     extern "C" {
00057 #endif
00058 
00059 /* avoid redefinition of structs */
00060 #if !defined(HAVE_FIPS) || \
00061     (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
00062 
00063 #ifdef WOLFSSL_MICROCHIP_PIC32MZ
00064     #include <wolfcrypt/port/pic32/pic32mz-crypt.h>
00065 #endif
00066 #ifdef STM32_HASH
00067     #include <wolfcrypt/port/st/stm32.h>
00068 #endif
00069 #ifdef WOLFSSL_ASYNC_CRYPT
00070     #include <wolfcrypt/async.h>
00071 #endif
00072 
00073 #if !defined(NO_OLD_SHA_NAMES)
00074     #define SHA             WC_SHA
00075 #endif
00076 
00077 #ifndef NO_OLD_WC_NAMES
00078     #define Sha             wc_Sha
00079     #define SHA_BLOCK_SIZE  WC_SHA_BLOCK_SIZE
00080     #define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
00081     #define SHA_PAD_SIZE    WC_SHA_PAD_SIZE
00082 #endif
00083 
00084 /* in bytes */
00085 enum {
00086     WC_SHA              =  WC_HASH_TYPE_SHA,
00087     WC_SHA_BLOCK_SIZE   = 64,
00088     WC_SHA_DIGEST_SIZE  = 20,
00089     WC_SHA_PAD_SIZE     = 56
00090 };
00091 
00092 
00093 #if defined(WOLFSSL_TI_HASH)
00094     #include "wolfcrypt/port/ti/ti-hash.h"
00095 
00096 #elif defined(WOLFSSL_IMX6_CAAM)
00097     #include "wolfcrypt/port/caam/wolfcaam_sha.h"
00098 
00099 #else
00100 /* Sha digest */
00101 typedef struct wc_Sha {
00102 #ifdef FREESCALE_LTC_SHA
00103         ltc_hash_ctx_t ctx;
00104 #elif defined(STM32_HASH)
00105         STM32_HASH_Context stmCtx;
00106 #else
00107         word32  buffLen;   /* in bytes          */
00108         word32  loLen;     /* length in bytes   */
00109         word32  hiLen;     /* length in bytes   */
00110         word32  buffer[WC_SHA_BLOCK_SIZE  / sizeof(word32)];
00111     #ifdef WOLFSSL_PIC32MZ_HASH
00112         word32  digest[PIC32_DIGEST_SIZE / sizeof(word32)];
00113     #else
00114         word32  digest[WC_SHA_DIGEST_SIZE / sizeof(word32)];
00115     #endif
00116         void*   heap;
00117     #ifdef WOLFSSL_PIC32MZ_HASH
00118         hashUpdCache cache; /* cache for updates */
00119     #endif
00120     #ifdef WOLFSSL_ASYNC_CRYPT
00121         WC_ASYNC_DEV asyncDev;
00122     #endif /* WOLFSSL_ASYNC_CRYPT */
00123 #endif
00124 } wc_Sha;
00125 
00126 #endif /* WOLFSSL_TI_HASH */
00127 
00128 
00129 #endif /* HAVE_FIPS */
00130 
00131 WOLFSSL_API int wc_InitSha(wc_Sha*);
00132 WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId);
00133 WOLFSSL_API int wc_ShaUpdate(wc_Sha*, const byte*, word32);
00134 WOLFSSL_API int wc_ShaFinalRaw(wc_Sha*, byte*);
00135 WOLFSSL_API int wc_ShaFinal(wc_Sha*, byte*);
00136 WOLFSSL_API void wc_ShaFree(wc_Sha*);
00137 
00138 WOLFSSL_API int wc_ShaGetHash(wc_Sha*, byte*);
00139 WOLFSSL_API int wc_ShaCopy(wc_Sha*, wc_Sha*);
00140 
00141 #ifdef WOLFSSL_PIC32MZ_HASH
00142 WOLFSSL_API void wc_ShaSizeSet(wc_Sha* sha, word32 len);
00143 #endif
00144 
00145 #ifdef __cplusplus
00146     } /* extern "C" */
00147 #endif
00148 
00149 #endif /* NO_SHA */
00150 #endif /* WOLF_CRYPT_SHA_H */
00151 
00152