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 /* sha512.h
wolfSSL 15:117db924cf7c 2 *
wolfSSL 15:117db924cf7c 3 * Copyright (C) 2006-2018 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/sha512.h
wolfSSL 15:117db924cf7c 24 */
wolfSSL 15:117db924cf7c 25
wolfSSL 15:117db924cf7c 26
wolfSSL 15:117db924cf7c 27 #ifndef WOLF_CRYPT_SHA512_H
wolfSSL 15:117db924cf7c 28 #define WOLF_CRYPT_SHA512_H
wolfSSL 15:117db924cf7c 29
wolfSSL 15:117db924cf7c 30 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 15:117db924cf7c 31
wolfSSL 15:117db924cf7c 32 #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
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 #ifdef WOLFSSL_SHA512
wolfSSL 15:117db924cf7c 42 #define wc_Sha512 Sha512
wolfSSL 15:117db924cf7c 43 #define WC_SHA512 SHA512
wolfSSL 15:117db924cf7c 44 #define WC_SHA512_BLOCK_SIZE SHA512_BLOCK_SIZE
wolfSSL 15:117db924cf7c 45 #define WC_SHA512_DIGEST_SIZE SHA512_DIGEST_SIZE
wolfSSL 15:117db924cf7c 46 #define WC_SHA512_PAD_SIZE SHA512_PAD_SIZE
wolfSSL 15:117db924cf7c 47 #endif /* WOLFSSL_SHA512 */
wolfSSL 15:117db924cf7c 48 #ifdef WOLFSSL_SHA384
wolfSSL 15:117db924cf7c 49 #define wc_Sha384 Sha384
wolfSSL 15:117db924cf7c 50 #define WC_SHA384 SHA384
wolfSSL 15:117db924cf7c 51 #define WC_SHA384_BLOCK_SIZE SHA384_BLOCK_SIZE
wolfSSL 15:117db924cf7c 52 #define WC_SHA384_DIGEST_SIZE SHA384_DIGEST_SIZE
wolfSSL 15:117db924cf7c 53 #define WC_SHA384_PAD_SIZE SHA384_PAD_SIZE
wolfSSL 15:117db924cf7c 54 #endif /* WOLFSSL_SHA384 */
wolfSSL 15:117db924cf7c 55
wolfSSL 15:117db924cf7c 56 #define CYASSL_SHA512
wolfSSL 15:117db924cf7c 57 #if defined(WOLFSSL_SHA384)
wolfSSL 15:117db924cf7c 58 #define CYASSL_SHA384
wolfSSL 15:117db924cf7c 59 #endif
wolfSSL 15:117db924cf7c 60 /* for fips @wc_fips */
wolfSSL 15:117db924cf7c 61 #include <cyassl/ctaocrypt/sha512.h>
wolfSSL 15:117db924cf7c 62 #endif
wolfSSL 15:117db924cf7c 63
wolfSSL 15:117db924cf7c 64 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 65 extern "C" {
wolfSSL 15:117db924cf7c 66 #endif
wolfSSL 15:117db924cf7c 67
wolfSSL 15:117db924cf7c 68 /* avoid redefinition of structs */
wolfSSL 15:117db924cf7c 69 #if !defined(HAVE_FIPS) || \
wolfSSL 15:117db924cf7c 70 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
wolfSSL 15:117db924cf7c 71
wolfSSL 15:117db924cf7c 72 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 15:117db924cf7c 73 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 15:117db924cf7c 74 #endif
wolfSSL 15:117db924cf7c 75
wolfSSL 15:117db924cf7c 76 #if defined(_MSC_VER)
wolfSSL 15:117db924cf7c 77 #define SHA512_NOINLINE __declspec(noinline)
wolfSSL 15:117db924cf7c 78 #elif defined(__GNUC__)
wolfSSL 15:117db924cf7c 79 #define SHA512_NOINLINE __attribute__((noinline))
wolfSSL 15:117db924cf7c 80 #else
wolfSSL 15:117db924cf7c 81 #define SHA512_NOINLINE
wolfSSL 15:117db924cf7c 82 #endif
wolfSSL 15:117db924cf7c 83
wolfSSL 15:117db924cf7c 84 #ifdef WOLFSSL_SHA512
wolfSSL 15:117db924cf7c 85
wolfSSL 15:117db924cf7c 86 #if !defined(NO_OLD_SHA_NAMES)
wolfSSL 15:117db924cf7c 87 #define SHA512 WC_SHA512
wolfSSL 15:117db924cf7c 88 #endif
wolfSSL 15:117db924cf7c 89
wolfSSL 15:117db924cf7c 90 #if !defined(NO_OLD_WC_NAMES)
wolfSSL 15:117db924cf7c 91 #define Sha512 wc_Sha512
wolfSSL 15:117db924cf7c 92 #define SHA512_BLOCK_SIZE WC_SHA512_BLOCK_SIZE
wolfSSL 15:117db924cf7c 93 #define SHA512_DIGEST_SIZE WC_SHA512_DIGEST_SIZE
wolfSSL 15:117db924cf7c 94 #define SHA512_PAD_SIZE WC_SHA512_PAD_SIZE
wolfSSL 15:117db924cf7c 95 #endif
wolfSSL 15:117db924cf7c 96
wolfSSL 15:117db924cf7c 97 #endif /* WOLFSSL_SHA512 */
wolfSSL 15:117db924cf7c 98
wolfSSL 15:117db924cf7c 99 /* in bytes */
wolfSSL 15:117db924cf7c 100 enum {
wolfSSL 15:117db924cf7c 101 #ifdef WOLFSSL_SHA512
wolfSSL 15:117db924cf7c 102 WC_SHA512 = WC_HASH_TYPE_SHA512,
wolfSSL 15:117db924cf7c 103 #endif
wolfSSL 15:117db924cf7c 104 WC_SHA512_BLOCK_SIZE = 128,
wolfSSL 15:117db924cf7c 105 WC_SHA512_DIGEST_SIZE = 64,
wolfSSL 15:117db924cf7c 106 WC_SHA512_PAD_SIZE = 112
wolfSSL 15:117db924cf7c 107 };
wolfSSL 15:117db924cf7c 108
wolfSSL 15:117db924cf7c 109
wolfSSL 15:117db924cf7c 110 #ifdef WOLFSSL_IMX6_CAAM
wolfSSL 15:117db924cf7c 111 #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
wolfSSL 15:117db924cf7c 112 #else
wolfSSL 15:117db924cf7c 113 /* wc_Sha512 digest */
wolfSSL 15:117db924cf7c 114 typedef struct wc_Sha512 {
wolfSSL 15:117db924cf7c 115 word64 digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
wolfSSL 15:117db924cf7c 116 word64 buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64)];
wolfSSL 15:117db924cf7c 117 word32 buffLen; /* in bytes */
wolfSSL 15:117db924cf7c 118 word64 loLen; /* length in bytes */
wolfSSL 15:117db924cf7c 119 word64 hiLen; /* length in bytes */
wolfSSL 15:117db924cf7c 120 void* heap;
wolfSSL 15:117db924cf7c 121 #ifdef USE_INTEL_SPEEDUP
wolfSSL 15:117db924cf7c 122 const byte* data;
wolfSSL 15:117db924cf7c 123 #endif
wolfSSL 15:117db924cf7c 124 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 15:117db924cf7c 125 WC_ASYNC_DEV asyncDev;
wolfSSL 15:117db924cf7c 126 #endif /* WOLFSSL_ASYNC_CRYPT */
wolfSSL 15:117db924cf7c 127 #ifdef WOLFSSL_SMALL_STACK_CACHE
wolfSSL 15:117db924cf7c 128 word64* W;
wolfSSL 15:117db924cf7c 129 #endif
wolfSSL 15:117db924cf7c 130 } wc_Sha512;
wolfSSL 15:117db924cf7c 131 #endif
wolfSSL 15:117db924cf7c 132
wolfSSL 15:117db924cf7c 133 #endif /* HAVE_FIPS */
wolfSSL 15:117db924cf7c 134
wolfSSL 15:117db924cf7c 135 #ifdef WOLFSSL_SHA512
wolfSSL 15:117db924cf7c 136
wolfSSL 15:117db924cf7c 137 WOLFSSL_API int wc_InitSha512(wc_Sha512*);
wolfSSL 15:117db924cf7c 138 WOLFSSL_API int wc_InitSha512_ex(wc_Sha512*, void*, int);
wolfSSL 15:117db924cf7c 139 WOLFSSL_API int wc_Sha512Update(wc_Sha512*, const byte*, word32);
wolfSSL 15:117db924cf7c 140 WOLFSSL_API int wc_Sha512FinalRaw(wc_Sha512*, byte*);
wolfSSL 15:117db924cf7c 141 WOLFSSL_API int wc_Sha512Final(wc_Sha512*, byte*);
wolfSSL 15:117db924cf7c 142 WOLFSSL_API void wc_Sha512Free(wc_Sha512*);
wolfSSL 15:117db924cf7c 143
wolfSSL 15:117db924cf7c 144 WOLFSSL_API int wc_Sha512GetHash(wc_Sha512*, byte*);
wolfSSL 15:117db924cf7c 145 WOLFSSL_API int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst);
wolfSSL 15:117db924cf7c 146
wolfSSL 15:117db924cf7c 147 #endif /* WOLFSSL_SHA512 */
wolfSSL 15:117db924cf7c 148
wolfSSL 15:117db924cf7c 149 #if defined(WOLFSSL_SHA384)
wolfSSL 15:117db924cf7c 150
wolfSSL 15:117db924cf7c 151 /* avoid redefinition of structs */
wolfSSL 15:117db924cf7c 152 #if !defined(HAVE_FIPS) || \
wolfSSL 15:117db924cf7c 153 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
wolfSSL 15:117db924cf7c 154
wolfSSL 15:117db924cf7c 155 #if !defined(NO_OLD_SHA_NAMES)
wolfSSL 15:117db924cf7c 156 #define SHA384 WC_SHA384
wolfSSL 15:117db924cf7c 157 #endif
wolfSSL 15:117db924cf7c 158
wolfSSL 15:117db924cf7c 159 #if !defined(NO_OLD_WC_NAMES)
wolfSSL 15:117db924cf7c 160 #define Sha384 wc_Sha384
wolfSSL 15:117db924cf7c 161 #define SHA384_BLOCK_SIZE WC_SHA384_BLOCK_SIZE
wolfSSL 15:117db924cf7c 162 #define SHA384_DIGEST_SIZE WC_SHA384_DIGEST_SIZE
wolfSSL 15:117db924cf7c 163 #define SHA384_PAD_SIZE WC_SHA384_PAD_SIZE
wolfSSL 15:117db924cf7c 164 #endif
wolfSSL 15:117db924cf7c 165
wolfSSL 15:117db924cf7c 166 /* in bytes */
wolfSSL 15:117db924cf7c 167 enum {
wolfSSL 15:117db924cf7c 168 WC_SHA384 = WC_HASH_TYPE_SHA384,
wolfSSL 15:117db924cf7c 169 WC_SHA384_BLOCK_SIZE = WC_SHA512_BLOCK_SIZE,
wolfSSL 15:117db924cf7c 170 WC_SHA384_DIGEST_SIZE = 48,
wolfSSL 15:117db924cf7c 171 WC_SHA384_PAD_SIZE = WC_SHA512_PAD_SIZE
wolfSSL 15:117db924cf7c 172 };
wolfSSL 15:117db924cf7c 173
wolfSSL 15:117db924cf7c 174
wolfSSL 15:117db924cf7c 175 typedef wc_Sha512 wc_Sha384;
wolfSSL 15:117db924cf7c 176 #endif /* HAVE_FIPS */
wolfSSL 15:117db924cf7c 177
wolfSSL 15:117db924cf7c 178 WOLFSSL_API int wc_InitSha384(wc_Sha384*);
wolfSSL 15:117db924cf7c 179 WOLFSSL_API int wc_InitSha384_ex(wc_Sha384*, void*, int);
wolfSSL 15:117db924cf7c 180 WOLFSSL_API int wc_Sha384Update(wc_Sha384*, const byte*, word32);
wolfSSL 15:117db924cf7c 181 WOLFSSL_API int wc_Sha384FinalRaw(wc_Sha384*, byte*);
wolfSSL 15:117db924cf7c 182 WOLFSSL_API int wc_Sha384Final(wc_Sha384*, byte*);
wolfSSL 15:117db924cf7c 183 WOLFSSL_API void wc_Sha384Free(wc_Sha384*);
wolfSSL 15:117db924cf7c 184
wolfSSL 15:117db924cf7c 185 WOLFSSL_API int wc_Sha384GetHash(wc_Sha384*, byte*);
wolfSSL 15:117db924cf7c 186 WOLFSSL_API int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst);
wolfSSL 15:117db924cf7c 187
wolfSSL 15:117db924cf7c 188 #endif /* WOLFSSL_SHA384 */
wolfSSL 15:117db924cf7c 189
wolfSSL 15:117db924cf7c 190 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 191 } /* extern "C" */
wolfSSL 15:117db924cf7c 192 #endif
wolfSSL 15:117db924cf7c 193
wolfSSL 15:117db924cf7c 194 #endif /* WOLFSSL_SHA512 || WOLFSSL_SHA384 */
wolfSSL 15:117db924cf7c 195 #endif /* WOLF_CRYPT_SHA512_H */
wolfSSL 15:117db924cf7c 196
wolfSSL 15:117db924cf7c 197