wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue May 30 01:44:10 2017 +0000
Revision:
11:cee25a834751
wolfSSL 3.11.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 11:cee25a834751 1 /* sha256.h
wolfSSL 11:cee25a834751 2 *
wolfSSL 11:cee25a834751 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 11:cee25a834751 4 *
wolfSSL 11:cee25a834751 5 * This file is part of wolfSSL.
wolfSSL 11:cee25a834751 6 *
wolfSSL 11:cee25a834751 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 11:cee25a834751 8 * it under the terms of the GNU General Public License as published by
wolfSSL 11:cee25a834751 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 11:cee25a834751 10 * (at your option) any later version.
wolfSSL 11:cee25a834751 11 *
wolfSSL 11:cee25a834751 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 11:cee25a834751 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 11:cee25a834751 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 11:cee25a834751 15 * GNU General Public License for more details.
wolfSSL 11:cee25a834751 16 *
wolfSSL 11:cee25a834751 17 * You should have received a copy of the GNU General Public License
wolfSSL 11:cee25a834751 18 * along with this program; if not, write to the Free Software
wolfSSL 11:cee25a834751 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 11:cee25a834751 20 */
wolfSSL 11:cee25a834751 21
wolfSSL 11:cee25a834751 22
wolfSSL 11:cee25a834751 23 /* code submitted by raphael.huck@efixo.com */
wolfSSL 11:cee25a834751 24
wolfSSL 11:cee25a834751 25 #ifndef WOLF_CRYPT_SHA256_H
wolfSSL 11:cee25a834751 26 #define WOLF_CRYPT_SHA256_H
wolfSSL 11:cee25a834751 27
wolfSSL 11:cee25a834751 28 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 11:cee25a834751 29
wolfSSL 11:cee25a834751 30 #ifndef NO_SHA256
wolfSSL 11:cee25a834751 31
wolfSSL 11:cee25a834751 32 #ifdef HAVE_FIPS
wolfSSL 11:cee25a834751 33 /* for fips @wc_fips */
wolfSSL 11:cee25a834751 34 #include <cyassl/ctaocrypt/sha256.h>
wolfSSL 11:cee25a834751 35 #endif
wolfSSL 11:cee25a834751 36
wolfSSL 11:cee25a834751 37 #ifdef FREESCALE_LTC_SHA
wolfSSL 11:cee25a834751 38 #include "fsl_ltc.h"
wolfSSL 11:cee25a834751 39 #endif
wolfSSL 11:cee25a834751 40
wolfSSL 11:cee25a834751 41
wolfSSL 11:cee25a834751 42 #ifdef __cplusplus
wolfSSL 11:cee25a834751 43 extern "C" {
wolfSSL 11:cee25a834751 44 #endif
wolfSSL 11:cee25a834751 45
wolfSSL 11:cee25a834751 46 #ifndef HAVE_FIPS /* avoid redefinition of structs */
wolfSSL 11:cee25a834751 47
wolfSSL 11:cee25a834751 48 #ifdef WOLFSSL_PIC32MZ_HASH
wolfSSL 11:cee25a834751 49 #include "port/pic32/pic32mz-crypt.h"
wolfSSL 11:cee25a834751 50 #endif
wolfSSL 11:cee25a834751 51 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 11:cee25a834751 52 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 11:cee25a834751 53 #endif
wolfSSL 11:cee25a834751 54
wolfSSL 11:cee25a834751 55 /* in bytes */
wolfSSL 11:cee25a834751 56 enum {
wolfSSL 11:cee25a834751 57 SHA256 = 2, /* hash type unique */
wolfSSL 11:cee25a834751 58 SHA256_BLOCK_SIZE = 64,
wolfSSL 11:cee25a834751 59 SHA256_DIGEST_SIZE = 32,
wolfSSL 11:cee25a834751 60 SHA256_PAD_SIZE = 56
wolfSSL 11:cee25a834751 61 };
wolfSSL 11:cee25a834751 62
wolfSSL 11:cee25a834751 63 #ifndef WOLFSSL_TI_HASH
wolfSSL 11:cee25a834751 64
wolfSSL 11:cee25a834751 65 /* Sha256 digest */
wolfSSL 11:cee25a834751 66 typedef struct Sha256 {
wolfSSL 11:cee25a834751 67 #ifdef FREESCALE_LTC_SHA
wolfSSL 11:cee25a834751 68 ltc_hash_ctx_t ctx;
wolfSSL 11:cee25a834751 69 #else
wolfSSL 11:cee25a834751 70 /* alignment on digest and buffer speeds up ARMv8 crypto operations */
wolfSSL 11:cee25a834751 71 ALIGN16 word32 digest[SHA256_DIGEST_SIZE / sizeof(word32)];
wolfSSL 11:cee25a834751 72 ALIGN16 word32 buffer[SHA256_BLOCK_SIZE / sizeof(word32)];
wolfSSL 11:cee25a834751 73 word32 buffLen; /* in bytes */
wolfSSL 11:cee25a834751 74 word32 loLen; /* length in bytes */
wolfSSL 11:cee25a834751 75 word32 hiLen; /* length in bytes */
wolfSSL 11:cee25a834751 76 void* heap;
wolfSSL 11:cee25a834751 77 #ifdef WOLFSSL_PIC32MZ_HASH
wolfSSL 11:cee25a834751 78 pic32mz_desc desc; /* Crypt Engine descriptor */
wolfSSL 11:cee25a834751 79 #endif
wolfSSL 11:cee25a834751 80 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 11:cee25a834751 81 WC_ASYNC_DEV asyncDev;
wolfSSL 11:cee25a834751 82 #endif /* WOLFSSL_ASYNC_CRYPT */
wolfSSL 11:cee25a834751 83 #endif /* FREESCALE_LTC_SHA */
wolfSSL 11:cee25a834751 84 } Sha256;
wolfSSL 11:cee25a834751 85
wolfSSL 11:cee25a834751 86 #else /* WOLFSSL_TI_HASH */
wolfSSL 11:cee25a834751 87 #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
wolfSSL 11:cee25a834751 88 #endif
wolfSSL 11:cee25a834751 89
wolfSSL 11:cee25a834751 90 #endif /* HAVE_FIPS */
wolfSSL 11:cee25a834751 91
wolfSSL 11:cee25a834751 92 WOLFSSL_API int wc_InitSha256(Sha256*);
wolfSSL 11:cee25a834751 93 WOLFSSL_API int wc_InitSha256_ex(Sha256*, void*, int);
wolfSSL 11:cee25a834751 94 WOLFSSL_API int wc_Sha256Update(Sha256*, const byte*, word32);
wolfSSL 11:cee25a834751 95 WOLFSSL_API int wc_Sha256Final(Sha256*, byte*);
wolfSSL 11:cee25a834751 96 WOLFSSL_API void wc_Sha256Free(Sha256*);
wolfSSL 11:cee25a834751 97
wolfSSL 11:cee25a834751 98 WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*);
wolfSSL 11:cee25a834751 99 WOLFSSL_API int wc_Sha256Copy(Sha256* src, Sha256* dst);
wolfSSL 11:cee25a834751 100
wolfSSL 11:cee25a834751 101 #ifdef WOLFSSL_SHA224
wolfSSL 11:cee25a834751 102
wolfSSL 11:cee25a834751 103 #ifndef HAVE_FIPS /* avoid redefinition of structs */
wolfSSL 11:cee25a834751 104 /* in bytes */
wolfSSL 11:cee25a834751 105 enum {
wolfSSL 11:cee25a834751 106 SHA224 = 8, /* hash type unique */
wolfSSL 11:cee25a834751 107 SHA224_BLOCK_SIZE = SHA256_BLOCK_SIZE,
wolfSSL 11:cee25a834751 108 SHA224_DIGEST_SIZE = 28,
wolfSSL 11:cee25a834751 109 SHA224_PAD_SIZE = SHA256_PAD_SIZE
wolfSSL 11:cee25a834751 110 };
wolfSSL 11:cee25a834751 111
wolfSSL 11:cee25a834751 112 typedef Sha256 Sha224;
wolfSSL 11:cee25a834751 113 #endif /* HAVE_FIPS */
wolfSSL 11:cee25a834751 114
wolfSSL 11:cee25a834751 115 WOLFSSL_API int wc_InitSha224(Sha224*);
wolfSSL 11:cee25a834751 116 WOLFSSL_API int wc_InitSha224_ex(Sha224*, void*, int);
wolfSSL 11:cee25a834751 117 WOLFSSL_API int wc_Sha224Update(Sha224*, const byte*, word32);
wolfSSL 11:cee25a834751 118 WOLFSSL_API int wc_Sha224Final(Sha224*, byte*);
wolfSSL 11:cee25a834751 119 WOLFSSL_API void wc_Sha224Free(Sha224*);
wolfSSL 11:cee25a834751 120
wolfSSL 11:cee25a834751 121 WOLFSSL_API int wc_Sha224GetHash(Sha224*, byte*);
wolfSSL 11:cee25a834751 122 WOLFSSL_API int wc_Sha224Copy(Sha224* src, Sha224* dst);
wolfSSL 11:cee25a834751 123
wolfSSL 11:cee25a834751 124 #endif /* WOLFSSL_SHA224 */
wolfSSL 11:cee25a834751 125
wolfSSL 11:cee25a834751 126 #ifdef __cplusplus
wolfSSL 11:cee25a834751 127 } /* extern "C" */
wolfSSL 11:cee25a834751 128 #endif
wolfSSL 11:cee25a834751 129
wolfSSL 11:cee25a834751 130 #endif /* NO_SHA256 */
wolfSSL 11:cee25a834751 131 #endif /* WOLF_CRYPT_SHA256_H */
wolfSSL 11:cee25a834751 132
wolfSSL 11:cee25a834751 133