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