13b4e3dcbSSimon L. B. Nielsen /* crypto/sha/sha256.c */ 23b4e3dcbSSimon L. B. Nielsen /* ==================================================================== 33b4e3dcbSSimon L. B. Nielsen * Copyright (c) 2004 The OpenSSL Project. All rights reserved 43b4e3dcbSSimon L. B. Nielsen * according to the OpenSSL license [found in ../../LICENSE]. 53b4e3dcbSSimon L. B. Nielsen * ==================================================================== 63b4e3dcbSSimon L. B. Nielsen */ 73b4e3dcbSSimon L. B. Nielsen #include <openssl/opensslconf.h> 83b4e3dcbSSimon L. B. Nielsen #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA256) 93b4e3dcbSSimon L. B. Nielsen 103b4e3dcbSSimon L. B. Nielsen # include <stdlib.h> 113b4e3dcbSSimon L. B. Nielsen # include <string.h> 123b4e3dcbSSimon L. B. Nielsen 133b4e3dcbSSimon L. B. Nielsen # include <openssl/crypto.h> 143b4e3dcbSSimon L. B. Nielsen # include <openssl/sha.h> 153b4e3dcbSSimon L. B. Nielsen # include <openssl/opensslv.h> 163b4e3dcbSSimon L. B. Nielsen 175471f83eSSimon L. B. Nielsen const char SHA256_version[] = "SHA-256" OPENSSL_VERSION_PTEXT; 183b4e3dcbSSimon L. B. Nielsen 191f13597dSJung-uk Kim fips_md_init_ctx(SHA224, SHA256) 203b4e3dcbSSimon L. B. Nielsen { 211f13597dSJung-uk Kim memset(c, 0, sizeof(*c)); 22*6f9291ceSJung-uk Kim c->h[0] = 0xc1059ed8UL; 23*6f9291ceSJung-uk Kim c->h[1] = 0x367cd507UL; 24*6f9291ceSJung-uk Kim c->h[2] = 0x3070dd17UL; 25*6f9291ceSJung-uk Kim c->h[3] = 0xf70e5939UL; 26*6f9291ceSJung-uk Kim c->h[4] = 0xffc00b31UL; 27*6f9291ceSJung-uk Kim c->h[5] = 0x68581511UL; 28*6f9291ceSJung-uk Kim c->h[6] = 0x64f98fa7UL; 29*6f9291ceSJung-uk Kim c->h[7] = 0xbefa4fa4UL; 301f13597dSJung-uk Kim c->md_len = SHA224_DIGEST_LENGTH; 313b4e3dcbSSimon L. B. Nielsen return 1; 323b4e3dcbSSimon L. B. Nielsen } 333b4e3dcbSSimon L. B. Nielsen 341f13597dSJung-uk Kim fips_md_init(SHA256) 353b4e3dcbSSimon L. B. Nielsen { 361f13597dSJung-uk Kim memset(c, 0, sizeof(*c)); 37*6f9291ceSJung-uk Kim c->h[0] = 0x6a09e667UL; 38*6f9291ceSJung-uk Kim c->h[1] = 0xbb67ae85UL; 39*6f9291ceSJung-uk Kim c->h[2] = 0x3c6ef372UL; 40*6f9291ceSJung-uk Kim c->h[3] = 0xa54ff53aUL; 41*6f9291ceSJung-uk Kim c->h[4] = 0x510e527fUL; 42*6f9291ceSJung-uk Kim c->h[5] = 0x9b05688cUL; 43*6f9291ceSJung-uk Kim c->h[6] = 0x1f83d9abUL; 44*6f9291ceSJung-uk Kim c->h[7] = 0x5be0cd19UL; 451f13597dSJung-uk Kim c->md_len = SHA256_DIGEST_LENGTH; 463b4e3dcbSSimon L. B. Nielsen return 1; 473b4e3dcbSSimon L. B. Nielsen } 483b4e3dcbSSimon L. B. Nielsen 493b4e3dcbSSimon L. B. Nielsen unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md) 503b4e3dcbSSimon L. B. Nielsen { 513b4e3dcbSSimon L. B. Nielsen SHA256_CTX c; 523b4e3dcbSSimon L. B. Nielsen static unsigned char m[SHA224_DIGEST_LENGTH]; 533b4e3dcbSSimon L. B. Nielsen 54*6f9291ceSJung-uk Kim if (md == NULL) 55*6f9291ceSJung-uk Kim md = m; 563b4e3dcbSSimon L. B. Nielsen SHA224_Init(&c); 573b4e3dcbSSimon L. B. Nielsen SHA256_Update(&c, d, n); 583b4e3dcbSSimon L. B. Nielsen SHA256_Final(md, &c); 593b4e3dcbSSimon L. B. Nielsen OPENSSL_cleanse(&c, sizeof(c)); 603b4e3dcbSSimon L. B. Nielsen return (md); 613b4e3dcbSSimon L. B. Nielsen } 623b4e3dcbSSimon L. B. Nielsen 633b4e3dcbSSimon L. B. Nielsen unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md) 643b4e3dcbSSimon L. B. Nielsen { 653b4e3dcbSSimon L. B. Nielsen SHA256_CTX c; 663b4e3dcbSSimon L. B. Nielsen static unsigned char m[SHA256_DIGEST_LENGTH]; 673b4e3dcbSSimon L. B. Nielsen 68*6f9291ceSJung-uk Kim if (md == NULL) 69*6f9291ceSJung-uk Kim md = m; 703b4e3dcbSSimon L. B. Nielsen SHA256_Init(&c); 713b4e3dcbSSimon L. B. Nielsen SHA256_Update(&c, d, n); 723b4e3dcbSSimon L. B. Nielsen SHA256_Final(md, &c); 733b4e3dcbSSimon L. B. Nielsen OPENSSL_cleanse(&c, sizeof(c)); 743b4e3dcbSSimon L. B. Nielsen return (md); 753b4e3dcbSSimon L. B. Nielsen } 763b4e3dcbSSimon L. B. Nielsen 773b4e3dcbSSimon L. B. Nielsen int SHA224_Update(SHA256_CTX *c, const void *data, size_t len) 78*6f9291ceSJung-uk Kim { 79*6f9291ceSJung-uk Kim return SHA256_Update(c, data, len); 80*6f9291ceSJung-uk Kim } 81*6f9291ceSJung-uk Kim 823b4e3dcbSSimon L. B. Nielsen int SHA224_Final(unsigned char *md, SHA256_CTX *c) 83*6f9291ceSJung-uk Kim { 84*6f9291ceSJung-uk Kim return SHA256_Final(md, c); 85*6f9291ceSJung-uk Kim } 863b4e3dcbSSimon L. B. Nielsen 873b4e3dcbSSimon L. B. Nielsen # define DATA_ORDER_IS_BIG_ENDIAN 883b4e3dcbSSimon L. B. Nielsen 893b4e3dcbSSimon L. B. Nielsen # define HASH_LONG SHA_LONG 903b4e3dcbSSimon L. B. Nielsen # define HASH_CTX SHA256_CTX 913b4e3dcbSSimon L. B. Nielsen # define HASH_CBLOCK SHA_CBLOCK 923b4e3dcbSSimon L. B. Nielsen /* 933b4e3dcbSSimon L. B. Nielsen * Note that FIPS180-2 discusses "Truncation of the Hash Function Output." 943b4e3dcbSSimon L. B. Nielsen * default: case below covers for it. It's not clear however if it's 953b4e3dcbSSimon L. B. Nielsen * permitted to truncate to amount of bytes not divisible by 4. I bet not, 963b4e3dcbSSimon L. B. Nielsen * but if it is, then default: case shall be extended. For reference. 973b4e3dcbSSimon L. B. Nielsen * Idea behind separate cases for pre-defined lenghts is to let the 983b4e3dcbSSimon L. B. Nielsen * compiler decide if it's appropriate to unroll small loops. 993b4e3dcbSSimon L. B. Nielsen */ 1003b4e3dcbSSimon L. B. Nielsen # define HASH_MAKE_STRING(c,s) do { \ 1013b4e3dcbSSimon L. B. Nielsen unsigned long ll; \ 1021f13597dSJung-uk Kim unsigned int nn; \ 1033b4e3dcbSSimon L. B. Nielsen switch ((c)->md_len) \ 1043b4e3dcbSSimon L. B. Nielsen { case SHA224_DIGEST_LENGTH: \ 1051f13597dSJung-uk Kim for (nn=0;nn<SHA224_DIGEST_LENGTH/4;nn++) \ 10609286989SJung-uk Kim { ll=(c)->h[nn]; (void)HOST_l2c(ll,(s)); } \ 1073b4e3dcbSSimon L. B. Nielsen break; \ 1083b4e3dcbSSimon L. B. Nielsen case SHA256_DIGEST_LENGTH: \ 1091f13597dSJung-uk Kim for (nn=0;nn<SHA256_DIGEST_LENGTH/4;nn++) \ 11009286989SJung-uk Kim { ll=(c)->h[nn]; (void)HOST_l2c(ll,(s)); } \ 1113b4e3dcbSSimon L. B. Nielsen break; \ 1123b4e3dcbSSimon L. B. Nielsen default: \ 1133b4e3dcbSSimon L. B. Nielsen if ((c)->md_len > SHA256_DIGEST_LENGTH) \ 1143b4e3dcbSSimon L. B. Nielsen return 0; \ 1151f13597dSJung-uk Kim for (nn=0;nn<(c)->md_len/4;nn++) \ 11609286989SJung-uk Kim { ll=(c)->h[nn]; (void)HOST_l2c(ll,(s)); } \ 1173b4e3dcbSSimon L. B. Nielsen break; \ 1183b4e3dcbSSimon L. B. Nielsen } \ 1193b4e3dcbSSimon L. B. Nielsen } while (0) 1203b4e3dcbSSimon L. B. Nielsen 1213b4e3dcbSSimon L. B. Nielsen # define HASH_UPDATE SHA256_Update 1223b4e3dcbSSimon L. B. Nielsen # define HASH_TRANSFORM SHA256_Transform 1233b4e3dcbSSimon L. B. Nielsen # define HASH_FINAL SHA256_Final 1243b4e3dcbSSimon L. B. Nielsen # define HASH_BLOCK_DATA_ORDER sha256_block_data_order 125db522d3aSSimon L. B. Nielsen # ifndef SHA256_ASM 126db522d3aSSimon L. B. Nielsen static 127db522d3aSSimon L. B. Nielsen # endif 1283b4e3dcbSSimon L. B. Nielsen void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num); 1293b4e3dcbSSimon L. B. Nielsen 1303b4e3dcbSSimon L. B. Nielsen # include "md32_common.h" 1313b4e3dcbSSimon L. B. Nielsen 132db522d3aSSimon L. B. Nielsen # ifndef SHA256_ASM 1333b4e3dcbSSimon L. B. Nielsen static const SHA_LONG K256[64] = { 1343b4e3dcbSSimon L. B. Nielsen 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 1353b4e3dcbSSimon L. B. Nielsen 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 1363b4e3dcbSSimon L. B. Nielsen 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, 1373b4e3dcbSSimon L. B. Nielsen 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, 1383b4e3dcbSSimon L. B. Nielsen 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, 1393b4e3dcbSSimon L. B. Nielsen 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 1403b4e3dcbSSimon L. B. Nielsen 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 1413b4e3dcbSSimon L. B. Nielsen 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, 1423b4e3dcbSSimon L. B. Nielsen 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, 1433b4e3dcbSSimon L. B. Nielsen 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, 1443b4e3dcbSSimon L. B. Nielsen 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 1453b4e3dcbSSimon L. B. Nielsen 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 1463b4e3dcbSSimon L. B. Nielsen 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, 1473b4e3dcbSSimon L. B. Nielsen 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, 1483b4e3dcbSSimon L. B. Nielsen 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, 149*6f9291ceSJung-uk Kim 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL 150*6f9291ceSJung-uk Kim }; 1513b4e3dcbSSimon L. B. Nielsen 1523b4e3dcbSSimon L. B. Nielsen /* 1533b4e3dcbSSimon L. B. Nielsen * FIPS specification refers to right rotations, while our ROTATE macro 1543b4e3dcbSSimon L. B. Nielsen * is left one. This is why you might notice that rotation coefficients 1553b4e3dcbSSimon L. B. Nielsen * differ from those observed in FIPS document by 32-N... 1563b4e3dcbSSimon L. B. Nielsen */ 1573b4e3dcbSSimon L. B. Nielsen # define Sigma0(x) (ROTATE((x),30) ^ ROTATE((x),19) ^ ROTATE((x),10)) 1583b4e3dcbSSimon L. B. Nielsen # define Sigma1(x) (ROTATE((x),26) ^ ROTATE((x),21) ^ ROTATE((x),7)) 1593b4e3dcbSSimon L. B. Nielsen # define sigma0(x) (ROTATE((x),25) ^ ROTATE((x),14) ^ ((x)>>3)) 1603b4e3dcbSSimon L. B. Nielsen # define sigma1(x) (ROTATE((x),15) ^ ROTATE((x),13) ^ ((x)>>10)) 1613b4e3dcbSSimon L. B. Nielsen 1623b4e3dcbSSimon L. B. Nielsen # define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) 1633b4e3dcbSSimon L. B. Nielsen # define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 1643b4e3dcbSSimon L. B. Nielsen 1653b4e3dcbSSimon L. B. Nielsen # ifdef OPENSSL_SMALL_FOOTPRINT 1663b4e3dcbSSimon L. B. Nielsen 167*6f9291ceSJung-uk Kim static void sha256_block_data_order(SHA256_CTX *ctx, const void *in, 168*6f9291ceSJung-uk Kim size_t num) 1693b4e3dcbSSimon L. B. Nielsen { 1703b4e3dcbSSimon L. B. Nielsen unsigned MD32_REG_T a, b, c, d, e, f, g, h, s0, s1, T1, T2; 171db522d3aSSimon L. B. Nielsen SHA_LONG X[16], l; 1723b4e3dcbSSimon L. B. Nielsen int i; 1733b4e3dcbSSimon L. B. Nielsen const unsigned char *data = in; 1743b4e3dcbSSimon L. B. Nielsen 1753b4e3dcbSSimon L. B. Nielsen while (num--) { 1763b4e3dcbSSimon L. B. Nielsen 177*6f9291ceSJung-uk Kim a = ctx->h[0]; 178*6f9291ceSJung-uk Kim b = ctx->h[1]; 179*6f9291ceSJung-uk Kim c = ctx->h[2]; 180*6f9291ceSJung-uk Kim d = ctx->h[3]; 181*6f9291ceSJung-uk Kim e = ctx->h[4]; 182*6f9291ceSJung-uk Kim f = ctx->h[5]; 183*6f9291ceSJung-uk Kim g = ctx->h[6]; 184*6f9291ceSJung-uk Kim h = ctx->h[7]; 1853b4e3dcbSSimon L. B. Nielsen 186*6f9291ceSJung-uk Kim for (i = 0; i < 16; i++) { 187*6f9291ceSJung-uk Kim HOST_c2l(data, l); 188*6f9291ceSJung-uk Kim T1 = X[i] = l; 1893b4e3dcbSSimon L. B. Nielsen T1 += h + Sigma1(e) + Ch(e, f, g) + K256[i]; 1903b4e3dcbSSimon L. B. Nielsen T2 = Sigma0(a) + Maj(a, b, c); 191*6f9291ceSJung-uk Kim h = g; 192*6f9291ceSJung-uk Kim g = f; 193*6f9291ceSJung-uk Kim f = e; 194*6f9291ceSJung-uk Kim e = d + T1; 195*6f9291ceSJung-uk Kim d = c; 196*6f9291ceSJung-uk Kim c = b; 197*6f9291ceSJung-uk Kim b = a; 198*6f9291ceSJung-uk Kim a = T1 + T2; 1993b4e3dcbSSimon L. B. Nielsen } 2003b4e3dcbSSimon L. B. Nielsen 201*6f9291ceSJung-uk Kim for (; i < 64; i++) { 202*6f9291ceSJung-uk Kim s0 = X[(i + 1) & 0x0f]; 203*6f9291ceSJung-uk Kim s0 = sigma0(s0); 204*6f9291ceSJung-uk Kim s1 = X[(i + 14) & 0x0f]; 205*6f9291ceSJung-uk Kim s1 = sigma1(s1); 2063b4e3dcbSSimon L. B. Nielsen 2073b4e3dcbSSimon L. B. Nielsen T1 = X[i & 0xf] += s0 + s1 + X[(i + 9) & 0xf]; 2083b4e3dcbSSimon L. B. Nielsen T1 += h + Sigma1(e) + Ch(e, f, g) + K256[i]; 2093b4e3dcbSSimon L. B. Nielsen T2 = Sigma0(a) + Maj(a, b, c); 210*6f9291ceSJung-uk Kim h = g; 211*6f9291ceSJung-uk Kim g = f; 212*6f9291ceSJung-uk Kim f = e; 213*6f9291ceSJung-uk Kim e = d + T1; 214*6f9291ceSJung-uk Kim d = c; 215*6f9291ceSJung-uk Kim c = b; 216*6f9291ceSJung-uk Kim b = a; 217*6f9291ceSJung-uk Kim a = T1 + T2; 2183b4e3dcbSSimon L. B. Nielsen } 2193b4e3dcbSSimon L. B. Nielsen 220*6f9291ceSJung-uk Kim ctx->h[0] += a; 221*6f9291ceSJung-uk Kim ctx->h[1] += b; 222*6f9291ceSJung-uk Kim ctx->h[2] += c; 223*6f9291ceSJung-uk Kim ctx->h[3] += d; 224*6f9291ceSJung-uk Kim ctx->h[4] += e; 225*6f9291ceSJung-uk Kim ctx->h[5] += f; 226*6f9291ceSJung-uk Kim ctx->h[6] += g; 227*6f9291ceSJung-uk Kim ctx->h[7] += h; 2283b4e3dcbSSimon L. B. Nielsen 2293b4e3dcbSSimon L. B. Nielsen } 2303b4e3dcbSSimon L. B. Nielsen } 2313b4e3dcbSSimon L. B. Nielsen 2323b4e3dcbSSimon L. B. Nielsen # else 2333b4e3dcbSSimon L. B. Nielsen 2343b4e3dcbSSimon L. B. Nielsen # define ROUND_00_15(i,a,b,c,d,e,f,g,h) do { \ 2353b4e3dcbSSimon L. B. Nielsen T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i]; \ 2363b4e3dcbSSimon L. B. Nielsen h = Sigma0(a) + Maj(a,b,c); \ 2373b4e3dcbSSimon L. B. Nielsen d += T1; h += T1; } while (0) 2383b4e3dcbSSimon L. B. Nielsen 2393b4e3dcbSSimon L. B. Nielsen # define ROUND_16_63(i,a,b,c,d,e,f,g,h,X) do { \ 2403b4e3dcbSSimon L. B. Nielsen s0 = X[(i+1)&0x0f]; s0 = sigma0(s0); \ 2413b4e3dcbSSimon L. B. Nielsen s1 = X[(i+14)&0x0f]; s1 = sigma1(s1); \ 2423b4e3dcbSSimon L. B. Nielsen T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \ 2433b4e3dcbSSimon L. B. Nielsen ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0) 2443b4e3dcbSSimon L. B. Nielsen 245*6f9291ceSJung-uk Kim static void sha256_block_data_order(SHA256_CTX *ctx, const void *in, 246*6f9291ceSJung-uk Kim size_t num) 2473b4e3dcbSSimon L. B. Nielsen { 2483b4e3dcbSSimon L. B. Nielsen unsigned MD32_REG_T a, b, c, d, e, f, g, h, s0, s1, T1; 2493b4e3dcbSSimon L. B. Nielsen SHA_LONG X[16]; 2503b4e3dcbSSimon L. B. Nielsen int i; 2513b4e3dcbSSimon L. B. Nielsen const unsigned char *data = in; 252*6f9291ceSJung-uk Kim const union { 253*6f9291ceSJung-uk Kim long one; 254*6f9291ceSJung-uk Kim char little; 255*6f9291ceSJung-uk Kim } is_endian = { 256*6f9291ceSJung-uk Kim 1 257*6f9291ceSJung-uk Kim }; 2583b4e3dcbSSimon L. B. Nielsen 2593b4e3dcbSSimon L. B. Nielsen while (num--) { 2603b4e3dcbSSimon L. B. Nielsen 261*6f9291ceSJung-uk Kim a = ctx->h[0]; 262*6f9291ceSJung-uk Kim b = ctx->h[1]; 263*6f9291ceSJung-uk Kim c = ctx->h[2]; 264*6f9291ceSJung-uk Kim d = ctx->h[3]; 265*6f9291ceSJung-uk Kim e = ctx->h[4]; 266*6f9291ceSJung-uk Kim f = ctx->h[5]; 267*6f9291ceSJung-uk Kim g = ctx->h[6]; 268*6f9291ceSJung-uk Kim h = ctx->h[7]; 2693b4e3dcbSSimon L. B. Nielsen 270*6f9291ceSJung-uk Kim if (!is_endian.little && sizeof(SHA_LONG) == 4 271*6f9291ceSJung-uk Kim && ((size_t)in % 4) == 0) { 2723b4e3dcbSSimon L. B. Nielsen const SHA_LONG *W = (const SHA_LONG *)data; 2733b4e3dcbSSimon L. B. Nielsen 274*6f9291ceSJung-uk Kim T1 = X[0] = W[0]; 275*6f9291ceSJung-uk Kim ROUND_00_15(0, a, b, c, d, e, f, g, h); 276*6f9291ceSJung-uk Kim T1 = X[1] = W[1]; 277*6f9291ceSJung-uk Kim ROUND_00_15(1, h, a, b, c, d, e, f, g); 278*6f9291ceSJung-uk Kim T1 = X[2] = W[2]; 279*6f9291ceSJung-uk Kim ROUND_00_15(2, g, h, a, b, c, d, e, f); 280*6f9291ceSJung-uk Kim T1 = X[3] = W[3]; 281*6f9291ceSJung-uk Kim ROUND_00_15(3, f, g, h, a, b, c, d, e); 282*6f9291ceSJung-uk Kim T1 = X[4] = W[4]; 283*6f9291ceSJung-uk Kim ROUND_00_15(4, e, f, g, h, a, b, c, d); 284*6f9291ceSJung-uk Kim T1 = X[5] = W[5]; 285*6f9291ceSJung-uk Kim ROUND_00_15(5, d, e, f, g, h, a, b, c); 286*6f9291ceSJung-uk Kim T1 = X[6] = W[6]; 287*6f9291ceSJung-uk Kim ROUND_00_15(6, c, d, e, f, g, h, a, b); 288*6f9291ceSJung-uk Kim T1 = X[7] = W[7]; 289*6f9291ceSJung-uk Kim ROUND_00_15(7, b, c, d, e, f, g, h, a); 290*6f9291ceSJung-uk Kim T1 = X[8] = W[8]; 291*6f9291ceSJung-uk Kim ROUND_00_15(8, a, b, c, d, e, f, g, h); 292*6f9291ceSJung-uk Kim T1 = X[9] = W[9]; 293*6f9291ceSJung-uk Kim ROUND_00_15(9, h, a, b, c, d, e, f, g); 294*6f9291ceSJung-uk Kim T1 = X[10] = W[10]; 295*6f9291ceSJung-uk Kim ROUND_00_15(10, g, h, a, b, c, d, e, f); 296*6f9291ceSJung-uk Kim T1 = X[11] = W[11]; 297*6f9291ceSJung-uk Kim ROUND_00_15(11, f, g, h, a, b, c, d, e); 298*6f9291ceSJung-uk Kim T1 = X[12] = W[12]; 299*6f9291ceSJung-uk Kim ROUND_00_15(12, e, f, g, h, a, b, c, d); 300*6f9291ceSJung-uk Kim T1 = X[13] = W[13]; 301*6f9291ceSJung-uk Kim ROUND_00_15(13, d, e, f, g, h, a, b, c); 302*6f9291ceSJung-uk Kim T1 = X[14] = W[14]; 303*6f9291ceSJung-uk Kim ROUND_00_15(14, c, d, e, f, g, h, a, b); 304*6f9291ceSJung-uk Kim T1 = X[15] = W[15]; 305*6f9291ceSJung-uk Kim ROUND_00_15(15, b, c, d, e, f, g, h, a); 3063b4e3dcbSSimon L. B. Nielsen 3073b4e3dcbSSimon L. B. Nielsen data += SHA256_CBLOCK; 308*6f9291ceSJung-uk Kim } else { 3093b4e3dcbSSimon L. B. Nielsen SHA_LONG l; 3103b4e3dcbSSimon L. B. Nielsen 311*6f9291ceSJung-uk Kim HOST_c2l(data, l); 312*6f9291ceSJung-uk Kim T1 = X[0] = l; 313*6f9291ceSJung-uk Kim ROUND_00_15(0, a, b, c, d, e, f, g, h); 314*6f9291ceSJung-uk Kim HOST_c2l(data, l); 315*6f9291ceSJung-uk Kim T1 = X[1] = l; 316*6f9291ceSJung-uk Kim ROUND_00_15(1, h, a, b, c, d, e, f, g); 317*6f9291ceSJung-uk Kim HOST_c2l(data, l); 318*6f9291ceSJung-uk Kim T1 = X[2] = l; 319*6f9291ceSJung-uk Kim ROUND_00_15(2, g, h, a, b, c, d, e, f); 320*6f9291ceSJung-uk Kim HOST_c2l(data, l); 321*6f9291ceSJung-uk Kim T1 = X[3] = l; 322*6f9291ceSJung-uk Kim ROUND_00_15(3, f, g, h, a, b, c, d, e); 323*6f9291ceSJung-uk Kim HOST_c2l(data, l); 324*6f9291ceSJung-uk Kim T1 = X[4] = l; 325*6f9291ceSJung-uk Kim ROUND_00_15(4, e, f, g, h, a, b, c, d); 326*6f9291ceSJung-uk Kim HOST_c2l(data, l); 327*6f9291ceSJung-uk Kim T1 = X[5] = l; 328*6f9291ceSJung-uk Kim ROUND_00_15(5, d, e, f, g, h, a, b, c); 329*6f9291ceSJung-uk Kim HOST_c2l(data, l); 330*6f9291ceSJung-uk Kim T1 = X[6] = l; 331*6f9291ceSJung-uk Kim ROUND_00_15(6, c, d, e, f, g, h, a, b); 332*6f9291ceSJung-uk Kim HOST_c2l(data, l); 333*6f9291ceSJung-uk Kim T1 = X[7] = l; 334*6f9291ceSJung-uk Kim ROUND_00_15(7, b, c, d, e, f, g, h, a); 335*6f9291ceSJung-uk Kim HOST_c2l(data, l); 336*6f9291ceSJung-uk Kim T1 = X[8] = l; 337*6f9291ceSJung-uk Kim ROUND_00_15(8, a, b, c, d, e, f, g, h); 338*6f9291ceSJung-uk Kim HOST_c2l(data, l); 339*6f9291ceSJung-uk Kim T1 = X[9] = l; 340*6f9291ceSJung-uk Kim ROUND_00_15(9, h, a, b, c, d, e, f, g); 341*6f9291ceSJung-uk Kim HOST_c2l(data, l); 342*6f9291ceSJung-uk Kim T1 = X[10] = l; 343*6f9291ceSJung-uk Kim ROUND_00_15(10, g, h, a, b, c, d, e, f); 344*6f9291ceSJung-uk Kim HOST_c2l(data, l); 345*6f9291ceSJung-uk Kim T1 = X[11] = l; 346*6f9291ceSJung-uk Kim ROUND_00_15(11, f, g, h, a, b, c, d, e); 347*6f9291ceSJung-uk Kim HOST_c2l(data, l); 348*6f9291ceSJung-uk Kim T1 = X[12] = l; 349*6f9291ceSJung-uk Kim ROUND_00_15(12, e, f, g, h, a, b, c, d); 350*6f9291ceSJung-uk Kim HOST_c2l(data, l); 351*6f9291ceSJung-uk Kim T1 = X[13] = l; 352*6f9291ceSJung-uk Kim ROUND_00_15(13, d, e, f, g, h, a, b, c); 353*6f9291ceSJung-uk Kim HOST_c2l(data, l); 354*6f9291ceSJung-uk Kim T1 = X[14] = l; 355*6f9291ceSJung-uk Kim ROUND_00_15(14, c, d, e, f, g, h, a, b); 356*6f9291ceSJung-uk Kim HOST_c2l(data, l); 357*6f9291ceSJung-uk Kim T1 = X[15] = l; 358*6f9291ceSJung-uk Kim ROUND_00_15(15, b, c, d, e, f, g, h, a); 3593b4e3dcbSSimon L. B. Nielsen } 3603b4e3dcbSSimon L. B. Nielsen 361*6f9291ceSJung-uk Kim for (i = 16; i < 64; i += 8) { 3623b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 0, a, b, c, d, e, f, g, h, X); 3633b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 1, h, a, b, c, d, e, f, g, X); 3643b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 2, g, h, a, b, c, d, e, f, X); 3653b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 3, f, g, h, a, b, c, d, e, X); 3663b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 4, e, f, g, h, a, b, c, d, X); 3673b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 5, d, e, f, g, h, a, b, c, X); 3683b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 6, c, d, e, f, g, h, a, b, X); 3693b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i + 7, b, c, d, e, f, g, h, a, X); 3703b4e3dcbSSimon L. B. Nielsen } 3713b4e3dcbSSimon L. B. Nielsen 372*6f9291ceSJung-uk Kim ctx->h[0] += a; 373*6f9291ceSJung-uk Kim ctx->h[1] += b; 374*6f9291ceSJung-uk Kim ctx->h[2] += c; 375*6f9291ceSJung-uk Kim ctx->h[3] += d; 376*6f9291ceSJung-uk Kim ctx->h[4] += e; 377*6f9291ceSJung-uk Kim ctx->h[5] += f; 378*6f9291ceSJung-uk Kim ctx->h[6] += g; 379*6f9291ceSJung-uk Kim ctx->h[7] += h; 3803b4e3dcbSSimon L. B. Nielsen 3813b4e3dcbSSimon L. B. Nielsen } 3823b4e3dcbSSimon L. B. Nielsen } 3833b4e3dcbSSimon L. B. Nielsen 3843b4e3dcbSSimon L. B. Nielsen # endif 3853b4e3dcbSSimon L. B. Nielsen # endif /* SHA256_ASM */ 3863b4e3dcbSSimon L. B. Nielsen 3873b4e3dcbSSimon L. B. Nielsen #endif /* OPENSSL_NO_SHA256 */ 388