Fork of CyaSSL for my specific settings

Dependents:   CyaSSL_Example

Fork of CyaSSL by wolf SSL

Committer:
d0773d
Date:
Tue Mar 03 22:52:52 2015 +0000
Revision:
4:28ac50e1d49c
Parent:
0:1239e9b70ca2
CyaSSL example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:1239e9b70ca2 1 /* sha256.c
wolfSSL 0:1239e9b70ca2 2 *
wolfSSL 0:1239e9b70ca2 3 * Copyright (C) 2006-2014 wolfSSL Inc.
wolfSSL 0:1239e9b70ca2 4 *
wolfSSL 0:1239e9b70ca2 5 * This file is part of CyaSSL.
wolfSSL 0:1239e9b70ca2 6 *
wolfSSL 0:1239e9b70ca2 7 * CyaSSL is free software; you can redistribute it and/or modify
wolfSSL 0:1239e9b70ca2 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:1239e9b70ca2 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:1239e9b70ca2 10 * (at your option) any later version.
wolfSSL 0:1239e9b70ca2 11 *
wolfSSL 0:1239e9b70ca2 12 * CyaSSL is distributed in the hope that it will be useful,
wolfSSL 0:1239e9b70ca2 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:1239e9b70ca2 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:1239e9b70ca2 15 * GNU General Public License for more details.
wolfSSL 0:1239e9b70ca2 16 *
wolfSSL 0:1239e9b70ca2 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:1239e9b70ca2 18 * along with this program; if not, write to the Free Software
wolfSSL 0:1239e9b70ca2 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:1239e9b70ca2 20 */
wolfSSL 0:1239e9b70ca2 21
wolfSSL 0:1239e9b70ca2 22
wolfSSL 0:1239e9b70ca2 23 /* code submitted by raphael.huck@efixo.com */
wolfSSL 0:1239e9b70ca2 24
wolfSSL 0:1239e9b70ca2 25 #ifdef HAVE_CONFIG_H
wolfSSL 0:1239e9b70ca2 26 #include <config.h>
wolfSSL 0:1239e9b70ca2 27 #endif
wolfSSL 0:1239e9b70ca2 28
wolfSSL 0:1239e9b70ca2 29 #include <cyassl/ctaocrypt/settings.h>
wolfSSL 0:1239e9b70ca2 30
wolfSSL 0:1239e9b70ca2 31 #if !defined(NO_SHA256)
wolfSSL 0:1239e9b70ca2 32
wolfSSL 0:1239e9b70ca2 33 #ifdef CYASSL_PIC32MZ_HASH
wolfSSL 0:1239e9b70ca2 34 #define InitSha256 InitSha256_sw
wolfSSL 0:1239e9b70ca2 35 #define Sha256Update Sha256Update_sw
wolfSSL 0:1239e9b70ca2 36 #define Sha256Final Sha256Final_sw
wolfSSL 0:1239e9b70ca2 37 #endif
wolfSSL 0:1239e9b70ca2 38
wolfSSL 0:1239e9b70ca2 39 #ifdef HAVE_FIPS
wolfSSL 0:1239e9b70ca2 40 /* set NO_WRAPPERS before headers, use direct internal f()s not wrappers */
wolfSSL 0:1239e9b70ca2 41 #define FIPS_NO_WRAPPERS
wolfSSL 0:1239e9b70ca2 42 #endif
wolfSSL 0:1239e9b70ca2 43
wolfSSL 0:1239e9b70ca2 44 #include <cyassl/ctaocrypt/sha256.h>
wolfSSL 0:1239e9b70ca2 45 #include <cyassl/ctaocrypt/error-crypt.h>
wolfSSL 0:1239e9b70ca2 46 #ifdef NO_INLINE
wolfSSL 0:1239e9b70ca2 47 #include <cyassl/ctaocrypt/misc.h>
wolfSSL 0:1239e9b70ca2 48 #else
wolfSSL 0:1239e9b70ca2 49 #include <ctaocrypt/src/misc.c>
wolfSSL 0:1239e9b70ca2 50 #endif
wolfSSL 0:1239e9b70ca2 51
wolfSSL 0:1239e9b70ca2 52 #ifdef FREESCALE_MMCAU
wolfSSL 0:1239e9b70ca2 53 #include "cau_api.h"
wolfSSL 0:1239e9b70ca2 54 #endif
wolfSSL 0:1239e9b70ca2 55
wolfSSL 0:1239e9b70ca2 56 #ifndef min
wolfSSL 0:1239e9b70ca2 57
wolfSSL 0:1239e9b70ca2 58 static INLINE word32 min(word32 a, word32 b)
wolfSSL 0:1239e9b70ca2 59 {
wolfSSL 0:1239e9b70ca2 60 return a > b ? b : a;
wolfSSL 0:1239e9b70ca2 61 }
wolfSSL 0:1239e9b70ca2 62
wolfSSL 0:1239e9b70ca2 63 #endif /* min */
wolfSSL 0:1239e9b70ca2 64
wolfSSL 0:1239e9b70ca2 65
wolfSSL 0:1239e9b70ca2 66 int InitSha256(Sha256* sha256)
wolfSSL 0:1239e9b70ca2 67 {
wolfSSL 0:1239e9b70ca2 68 #ifdef FREESCALE_MMCAU
wolfSSL 0:1239e9b70ca2 69 cau_sha256_initialize_output(sha256->digest);
wolfSSL 0:1239e9b70ca2 70 #else
wolfSSL 0:1239e9b70ca2 71 sha256->digest[0] = 0x6A09E667L;
wolfSSL 0:1239e9b70ca2 72 sha256->digest[1] = 0xBB67AE85L;
wolfSSL 0:1239e9b70ca2 73 sha256->digest[2] = 0x3C6EF372L;
wolfSSL 0:1239e9b70ca2 74 sha256->digest[3] = 0xA54FF53AL;
wolfSSL 0:1239e9b70ca2 75 sha256->digest[4] = 0x510E527FL;
wolfSSL 0:1239e9b70ca2 76 sha256->digest[5] = 0x9B05688CL;
wolfSSL 0:1239e9b70ca2 77 sha256->digest[6] = 0x1F83D9ABL;
wolfSSL 0:1239e9b70ca2 78 sha256->digest[7] = 0x5BE0CD19L;
wolfSSL 0:1239e9b70ca2 79 #endif
wolfSSL 0:1239e9b70ca2 80
wolfSSL 0:1239e9b70ca2 81 sha256->buffLen = 0;
wolfSSL 0:1239e9b70ca2 82 sha256->loLen = 0;
wolfSSL 0:1239e9b70ca2 83 sha256->hiLen = 0;
wolfSSL 0:1239e9b70ca2 84
wolfSSL 0:1239e9b70ca2 85 return 0;
wolfSSL 0:1239e9b70ca2 86 }
wolfSSL 0:1239e9b70ca2 87
wolfSSL 0:1239e9b70ca2 88 #ifdef FREESCALE_MMCAU
wolfSSL 0:1239e9b70ca2 89 #define XTRANSFORM(S,B) Transform((S), (B))
wolfSSL 0:1239e9b70ca2 90
wolfSSL 0:1239e9b70ca2 91 static int Transform(Sha256* sha256, byte* buf)
wolfSSL 0:1239e9b70ca2 92 {
wolfSSL 0:1239e9b70ca2 93 cau_sha256_hash_n(buf, 1, sha256->digest);
wolfSSL 0:1239e9b70ca2 94
wolfSSL 0:1239e9b70ca2 95 return 0;
wolfSSL 0:1239e9b70ca2 96 }
wolfSSL 0:1239e9b70ca2 97
wolfSSL 0:1239e9b70ca2 98 #else
wolfSSL 0:1239e9b70ca2 99 #define XTRANSFORM(S,B) Transform((S))
wolfSSL 0:1239e9b70ca2 100
wolfSSL 0:1239e9b70ca2 101 static const word32 K[64] = {
wolfSSL 0:1239e9b70ca2 102 0x428A2F98L, 0x71374491L, 0xB5C0FBCFL, 0xE9B5DBA5L, 0x3956C25BL,
wolfSSL 0:1239e9b70ca2 103 0x59F111F1L, 0x923F82A4L, 0xAB1C5ED5L, 0xD807AA98L, 0x12835B01L,
wolfSSL 0:1239e9b70ca2 104 0x243185BEL, 0x550C7DC3L, 0x72BE5D74L, 0x80DEB1FEL, 0x9BDC06A7L,
wolfSSL 0:1239e9b70ca2 105 0xC19BF174L, 0xE49B69C1L, 0xEFBE4786L, 0x0FC19DC6L, 0x240CA1CCL,
wolfSSL 0:1239e9b70ca2 106 0x2DE92C6FL, 0x4A7484AAL, 0x5CB0A9DCL, 0x76F988DAL, 0x983E5152L,
wolfSSL 0:1239e9b70ca2 107 0xA831C66DL, 0xB00327C8L, 0xBF597FC7L, 0xC6E00BF3L, 0xD5A79147L,
wolfSSL 0:1239e9b70ca2 108 0x06CA6351L, 0x14292967L, 0x27B70A85L, 0x2E1B2138L, 0x4D2C6DFCL,
wolfSSL 0:1239e9b70ca2 109 0x53380D13L, 0x650A7354L, 0x766A0ABBL, 0x81C2C92EL, 0x92722C85L,
wolfSSL 0:1239e9b70ca2 110 0xA2BFE8A1L, 0xA81A664BL, 0xC24B8B70L, 0xC76C51A3L, 0xD192E819L,
wolfSSL 0:1239e9b70ca2 111 0xD6990624L, 0xF40E3585L, 0x106AA070L, 0x19A4C116L, 0x1E376C08L,
wolfSSL 0:1239e9b70ca2 112 0x2748774CL, 0x34B0BCB5L, 0x391C0CB3L, 0x4ED8AA4AL, 0x5B9CCA4FL,
wolfSSL 0:1239e9b70ca2 113 0x682E6FF3L, 0x748F82EEL, 0x78A5636FL, 0x84C87814L, 0x8CC70208L,
wolfSSL 0:1239e9b70ca2 114 0x90BEFFFAL, 0xA4506CEBL, 0xBEF9A3F7L, 0xC67178F2L
wolfSSL 0:1239e9b70ca2 115 };
wolfSSL 0:1239e9b70ca2 116
wolfSSL 0:1239e9b70ca2 117 #define Ch(x,y,z) (z ^ (x & (y ^ z)))
wolfSSL 0:1239e9b70ca2 118 #define Maj(x,y,z) (((x | y) & z) | (x & y))
wolfSSL 0:1239e9b70ca2 119 #define S(x, n) rotrFixed(x, n)
wolfSSL 0:1239e9b70ca2 120 #define R(x, n) (((x)&0xFFFFFFFFU)>>(n))
wolfSSL 0:1239e9b70ca2 121 #define Sigma0(x) (S(x, 2) ^ S(x, 13) ^ S(x, 22))
wolfSSL 0:1239e9b70ca2 122 #define Sigma1(x) (S(x, 6) ^ S(x, 11) ^ S(x, 25))
wolfSSL 0:1239e9b70ca2 123 #define Gamma0(x) (S(x, 7) ^ S(x, 18) ^ R(x, 3))
wolfSSL 0:1239e9b70ca2 124 #define Gamma1(x) (S(x, 17) ^ S(x, 19) ^ R(x, 10))
wolfSSL 0:1239e9b70ca2 125
wolfSSL 0:1239e9b70ca2 126 #define RND(a,b,c,d,e,f,g,h,i) \
wolfSSL 0:1239e9b70ca2 127 t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
wolfSSL 0:1239e9b70ca2 128 t1 = Sigma0(a) + Maj(a, b, c); \
wolfSSL 0:1239e9b70ca2 129 d += t0; \
wolfSSL 0:1239e9b70ca2 130 h = t0 + t1;
wolfSSL 0:1239e9b70ca2 131
wolfSSL 0:1239e9b70ca2 132
wolfSSL 0:1239e9b70ca2 133 static int Transform(Sha256* sha256)
wolfSSL 0:1239e9b70ca2 134 {
wolfSSL 0:1239e9b70ca2 135 word32 S[8], t0, t1;
wolfSSL 0:1239e9b70ca2 136 int i;
wolfSSL 0:1239e9b70ca2 137
wolfSSL 0:1239e9b70ca2 138 #ifdef CYASSL_SMALL_STACK
wolfSSL 0:1239e9b70ca2 139 word32* W;
wolfSSL 0:1239e9b70ca2 140
wolfSSL 0:1239e9b70ca2 141 W = (word32*) XMALLOC(sizeof(word32) * 64, NULL, DYNAMIC_TYPE_TMP_BUFFER);
wolfSSL 0:1239e9b70ca2 142 if (W == NULL)
wolfSSL 0:1239e9b70ca2 143 return MEMORY_E;
wolfSSL 0:1239e9b70ca2 144 #else
wolfSSL 0:1239e9b70ca2 145 word32 W[64];
wolfSSL 0:1239e9b70ca2 146 #endif
wolfSSL 0:1239e9b70ca2 147
wolfSSL 0:1239e9b70ca2 148 /* Copy context->state[] to working vars */
wolfSSL 0:1239e9b70ca2 149 for (i = 0; i < 8; i++)
wolfSSL 0:1239e9b70ca2 150 S[i] = sha256->digest[i];
wolfSSL 0:1239e9b70ca2 151
wolfSSL 0:1239e9b70ca2 152 for (i = 0; i < 16; i++)
wolfSSL 0:1239e9b70ca2 153 W[i] = sha256->buffer[i];
wolfSSL 0:1239e9b70ca2 154
wolfSSL 0:1239e9b70ca2 155 for (i = 16; i < 64; i++)
wolfSSL 0:1239e9b70ca2 156 W[i] = Gamma1(W[i-2]) + W[i-7] + Gamma0(W[i-15]) + W[i-16];
wolfSSL 0:1239e9b70ca2 157
wolfSSL 0:1239e9b70ca2 158 for (i = 0; i < 64; i += 8) {
wolfSSL 0:1239e9b70ca2 159 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i+0);
wolfSSL 0:1239e9b70ca2 160 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],i+1);
wolfSSL 0:1239e9b70ca2 161 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],i+2);
wolfSSL 0:1239e9b70ca2 162 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],i+3);
wolfSSL 0:1239e9b70ca2 163 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],i+4);
wolfSSL 0:1239e9b70ca2 164 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],i+5);
wolfSSL 0:1239e9b70ca2 165 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],i+6);
wolfSSL 0:1239e9b70ca2 166 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],i+7);
wolfSSL 0:1239e9b70ca2 167 }
wolfSSL 0:1239e9b70ca2 168
wolfSSL 0:1239e9b70ca2 169 /* Add the working vars back into digest state[] */
wolfSSL 0:1239e9b70ca2 170 for (i = 0; i < 8; i++) {
wolfSSL 0:1239e9b70ca2 171 sha256->digest[i] += S[i];
wolfSSL 0:1239e9b70ca2 172 }
wolfSSL 0:1239e9b70ca2 173
wolfSSL 0:1239e9b70ca2 174 #ifdef CYASSL_SMALL_STACK
wolfSSL 0:1239e9b70ca2 175 XFREE(W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
wolfSSL 0:1239e9b70ca2 176 #endif
wolfSSL 0:1239e9b70ca2 177
wolfSSL 0:1239e9b70ca2 178 return 0;
wolfSSL 0:1239e9b70ca2 179 }
wolfSSL 0:1239e9b70ca2 180
wolfSSL 0:1239e9b70ca2 181 #endif /* FREESCALE_MMCAU */
wolfSSL 0:1239e9b70ca2 182
wolfSSL 0:1239e9b70ca2 183
wolfSSL 0:1239e9b70ca2 184 static INLINE void AddLength(Sha256* sha256, word32 len)
wolfSSL 0:1239e9b70ca2 185 {
wolfSSL 0:1239e9b70ca2 186 word32 tmp = sha256->loLen;
wolfSSL 0:1239e9b70ca2 187 if ( (sha256->loLen += len) < tmp)
wolfSSL 0:1239e9b70ca2 188 sha256->hiLen++; /* carry low to high */
wolfSSL 0:1239e9b70ca2 189 }
wolfSSL 0:1239e9b70ca2 190
wolfSSL 0:1239e9b70ca2 191
wolfSSL 0:1239e9b70ca2 192 int Sha256Update(Sha256* sha256, const byte* data, word32 len)
wolfSSL 0:1239e9b70ca2 193 {
wolfSSL 0:1239e9b70ca2 194 /* do block size increments */
wolfSSL 0:1239e9b70ca2 195 byte* local = (byte*)sha256->buffer;
wolfSSL 0:1239e9b70ca2 196
wolfSSL 0:1239e9b70ca2 197 while (len) {
wolfSSL 0:1239e9b70ca2 198 word32 add = min(len, SHA256_BLOCK_SIZE - sha256->buffLen);
wolfSSL 0:1239e9b70ca2 199 XMEMCPY(&local[sha256->buffLen], data, add);
wolfSSL 0:1239e9b70ca2 200
wolfSSL 0:1239e9b70ca2 201 sha256->buffLen += add;
wolfSSL 0:1239e9b70ca2 202 data += add;
wolfSSL 0:1239e9b70ca2 203 len -= add;
wolfSSL 0:1239e9b70ca2 204
wolfSSL 0:1239e9b70ca2 205 if (sha256->buffLen == SHA256_BLOCK_SIZE) {
wolfSSL 0:1239e9b70ca2 206 int ret;
wolfSSL 0:1239e9b70ca2 207
wolfSSL 0:1239e9b70ca2 208 #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU)
wolfSSL 0:1239e9b70ca2 209 ByteReverseWords(sha256->buffer, sha256->buffer,
wolfSSL 0:1239e9b70ca2 210 SHA256_BLOCK_SIZE);
wolfSSL 0:1239e9b70ca2 211 #endif
wolfSSL 0:1239e9b70ca2 212
wolfSSL 0:1239e9b70ca2 213 ret = XTRANSFORM(sha256, local);
wolfSSL 0:1239e9b70ca2 214 if (ret != 0)
wolfSSL 0:1239e9b70ca2 215 return ret;
wolfSSL 0:1239e9b70ca2 216
wolfSSL 0:1239e9b70ca2 217 AddLength(sha256, SHA256_BLOCK_SIZE);
wolfSSL 0:1239e9b70ca2 218 sha256->buffLen = 0;
wolfSSL 0:1239e9b70ca2 219 }
wolfSSL 0:1239e9b70ca2 220 }
wolfSSL 0:1239e9b70ca2 221
wolfSSL 0:1239e9b70ca2 222 return 0;
wolfSSL 0:1239e9b70ca2 223 }
wolfSSL 0:1239e9b70ca2 224
wolfSSL 0:1239e9b70ca2 225
wolfSSL 0:1239e9b70ca2 226 int Sha256Final(Sha256* sha256, byte* hash)
wolfSSL 0:1239e9b70ca2 227 {
wolfSSL 0:1239e9b70ca2 228 byte* local = (byte*)sha256->buffer;
wolfSSL 0:1239e9b70ca2 229 int ret;
wolfSSL 0:1239e9b70ca2 230
wolfSSL 0:1239e9b70ca2 231 AddLength(sha256, sha256->buffLen); /* before adding pads */
wolfSSL 0:1239e9b70ca2 232
wolfSSL 0:1239e9b70ca2 233 local[sha256->buffLen++] = 0x80; /* add 1 */
wolfSSL 0:1239e9b70ca2 234
wolfSSL 0:1239e9b70ca2 235 /* pad with zeros */
wolfSSL 0:1239e9b70ca2 236 if (sha256->buffLen > SHA256_PAD_SIZE) {
wolfSSL 0:1239e9b70ca2 237 XMEMSET(&local[sha256->buffLen], 0, SHA256_BLOCK_SIZE - sha256->buffLen);
wolfSSL 0:1239e9b70ca2 238 sha256->buffLen += SHA256_BLOCK_SIZE - sha256->buffLen;
wolfSSL 0:1239e9b70ca2 239
wolfSSL 0:1239e9b70ca2 240 #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU)
wolfSSL 0:1239e9b70ca2 241 ByteReverseWords(sha256->buffer, sha256->buffer, SHA256_BLOCK_SIZE);
wolfSSL 0:1239e9b70ca2 242 #endif
wolfSSL 0:1239e9b70ca2 243
wolfSSL 0:1239e9b70ca2 244 ret = XTRANSFORM(sha256, local);
wolfSSL 0:1239e9b70ca2 245 if (ret != 0)
wolfSSL 0:1239e9b70ca2 246 return ret;
wolfSSL 0:1239e9b70ca2 247
wolfSSL 0:1239e9b70ca2 248 sha256->buffLen = 0;
wolfSSL 0:1239e9b70ca2 249 }
wolfSSL 0:1239e9b70ca2 250 XMEMSET(&local[sha256->buffLen], 0, SHA256_PAD_SIZE - sha256->buffLen);
wolfSSL 0:1239e9b70ca2 251
wolfSSL 0:1239e9b70ca2 252 /* put lengths in bits */
wolfSSL 0:1239e9b70ca2 253 sha256->hiLen = (sha256->loLen >> (8*sizeof(sha256->loLen) - 3)) +
wolfSSL 0:1239e9b70ca2 254 (sha256->hiLen << 3);
wolfSSL 0:1239e9b70ca2 255 sha256->loLen = sha256->loLen << 3;
wolfSSL 0:1239e9b70ca2 256
wolfSSL 0:1239e9b70ca2 257 /* store lengths */
wolfSSL 0:1239e9b70ca2 258 #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU)
wolfSSL 0:1239e9b70ca2 259 ByteReverseWords(sha256->buffer, sha256->buffer, SHA256_BLOCK_SIZE);
wolfSSL 0:1239e9b70ca2 260 #endif
wolfSSL 0:1239e9b70ca2 261 /* ! length ordering dependent on digest endian type ! */
wolfSSL 0:1239e9b70ca2 262 XMEMCPY(&local[SHA256_PAD_SIZE], &sha256->hiLen, sizeof(word32));
wolfSSL 0:1239e9b70ca2 263 XMEMCPY(&local[SHA256_PAD_SIZE + sizeof(word32)], &sha256->loLen,
wolfSSL 0:1239e9b70ca2 264 sizeof(word32));
wolfSSL 0:1239e9b70ca2 265
wolfSSL 0:1239e9b70ca2 266 #ifdef FREESCALE_MMCAU
wolfSSL 0:1239e9b70ca2 267 /* Kinetis requires only these bytes reversed */
wolfSSL 0:1239e9b70ca2 268 ByteReverseWords(&sha256->buffer[SHA256_PAD_SIZE/sizeof(word32)],
wolfSSL 0:1239e9b70ca2 269 &sha256->buffer[SHA256_PAD_SIZE/sizeof(word32)],
wolfSSL 0:1239e9b70ca2 270 2 * sizeof(word32));
wolfSSL 0:1239e9b70ca2 271 #endif
wolfSSL 0:1239e9b70ca2 272
wolfSSL 0:1239e9b70ca2 273 ret = XTRANSFORM(sha256, local);
wolfSSL 0:1239e9b70ca2 274 if (ret != 0)
wolfSSL 0:1239e9b70ca2 275 return ret;
wolfSSL 0:1239e9b70ca2 276
wolfSSL 0:1239e9b70ca2 277 #ifdef LITTLE_ENDIAN_ORDER
wolfSSL 0:1239e9b70ca2 278 ByteReverseWords(sha256->digest, sha256->digest, SHA256_DIGEST_SIZE);
wolfSSL 0:1239e9b70ca2 279 #endif
wolfSSL 0:1239e9b70ca2 280 XMEMCPY(hash, sha256->digest, SHA256_DIGEST_SIZE);
wolfSSL 0:1239e9b70ca2 281
wolfSSL 0:1239e9b70ca2 282 return InitSha256(sha256); /* reset state */
wolfSSL 0:1239e9b70ca2 283 }
wolfSSL 0:1239e9b70ca2 284
wolfSSL 0:1239e9b70ca2 285
wolfSSL 0:1239e9b70ca2 286 #endif /* NO_SHA256 */
wolfSSL 0:1239e9b70ca2 287
wolfSSL 0:1239e9b70ca2 288