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

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

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

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