Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
wolfSSL
Date:
Tue May 02 08:44:47 2017 +0000
Revision:
7:481bce714567
wolfSSL3.10.2

Who changed what in which revision?

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