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)); 223b4e3dcbSSimon L. B. Nielsen c->h[0]=0xc1059ed8UL; c->h[1]=0x367cd507UL; 233b4e3dcbSSimon L. B. Nielsen c->h[2]=0x3070dd17UL; c->h[3]=0xf70e5939UL; 243b4e3dcbSSimon L. B. Nielsen c->h[4]=0xffc00b31UL; c->h[5]=0x68581511UL; 253b4e3dcbSSimon L. B. Nielsen c->h[6]=0x64f98fa7UL; c->h[7]=0xbefa4fa4UL; 261f13597dSJung-uk Kim c->md_len=SHA224_DIGEST_LENGTH; 273b4e3dcbSSimon L. B. Nielsen return 1; 283b4e3dcbSSimon L. B. Nielsen } 293b4e3dcbSSimon L. B. Nielsen 301f13597dSJung-uk Kim fips_md_init(SHA256) 313b4e3dcbSSimon L. B. Nielsen { 321f13597dSJung-uk Kim memset (c,0,sizeof(*c)); 333b4e3dcbSSimon L. B. Nielsen c->h[0]=0x6a09e667UL; c->h[1]=0xbb67ae85UL; 343b4e3dcbSSimon L. B. Nielsen c->h[2]=0x3c6ef372UL; c->h[3]=0xa54ff53aUL; 353b4e3dcbSSimon L. B. Nielsen c->h[4]=0x510e527fUL; c->h[5]=0x9b05688cUL; 363b4e3dcbSSimon L. B. Nielsen c->h[6]=0x1f83d9abUL; c->h[7]=0x5be0cd19UL; 371f13597dSJung-uk Kim c->md_len=SHA256_DIGEST_LENGTH; 383b4e3dcbSSimon L. B. Nielsen return 1; 393b4e3dcbSSimon L. B. Nielsen } 403b4e3dcbSSimon L. B. Nielsen 413b4e3dcbSSimon L. B. Nielsen unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md) 423b4e3dcbSSimon L. B. Nielsen { 433b4e3dcbSSimon L. B. Nielsen SHA256_CTX c; 443b4e3dcbSSimon L. B. Nielsen static unsigned char m[SHA224_DIGEST_LENGTH]; 453b4e3dcbSSimon L. B. Nielsen 463b4e3dcbSSimon L. B. Nielsen if (md == NULL) md=m; 473b4e3dcbSSimon L. B. Nielsen SHA224_Init(&c); 483b4e3dcbSSimon L. B. Nielsen SHA256_Update(&c,d,n); 493b4e3dcbSSimon L. B. Nielsen SHA256_Final(md,&c); 503b4e3dcbSSimon L. B. Nielsen OPENSSL_cleanse(&c,sizeof(c)); 513b4e3dcbSSimon L. B. Nielsen return(md); 523b4e3dcbSSimon L. B. Nielsen } 533b4e3dcbSSimon L. B. Nielsen 543b4e3dcbSSimon L. B. Nielsen unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md) 553b4e3dcbSSimon L. B. Nielsen { 563b4e3dcbSSimon L. B. Nielsen SHA256_CTX c; 573b4e3dcbSSimon L. B. Nielsen static unsigned char m[SHA256_DIGEST_LENGTH]; 583b4e3dcbSSimon L. B. Nielsen 593b4e3dcbSSimon L. B. Nielsen if (md == NULL) md=m; 603b4e3dcbSSimon L. B. Nielsen SHA256_Init(&c); 613b4e3dcbSSimon L. B. Nielsen SHA256_Update(&c,d,n); 623b4e3dcbSSimon L. B. Nielsen SHA256_Final(md,&c); 633b4e3dcbSSimon L. B. Nielsen OPENSSL_cleanse(&c,sizeof(c)); 643b4e3dcbSSimon L. B. Nielsen return(md); 653b4e3dcbSSimon L. B. Nielsen } 663b4e3dcbSSimon L. B. Nielsen 673b4e3dcbSSimon L. B. Nielsen int SHA224_Update(SHA256_CTX *c, const void *data, size_t len) 683b4e3dcbSSimon L. B. Nielsen { return SHA256_Update (c,data,len); } 693b4e3dcbSSimon L. B. Nielsen int SHA224_Final (unsigned char *md, SHA256_CTX *c) 703b4e3dcbSSimon L. B. Nielsen { return SHA256_Final (md,c); } 713b4e3dcbSSimon L. B. Nielsen 723b4e3dcbSSimon L. B. Nielsen #define DATA_ORDER_IS_BIG_ENDIAN 733b4e3dcbSSimon L. B. Nielsen 743b4e3dcbSSimon L. B. Nielsen #define HASH_LONG SHA_LONG 753b4e3dcbSSimon L. B. Nielsen #define HASH_CTX SHA256_CTX 763b4e3dcbSSimon L. B. Nielsen #define HASH_CBLOCK SHA_CBLOCK 773b4e3dcbSSimon L. B. Nielsen /* 783b4e3dcbSSimon L. B. Nielsen * Note that FIPS180-2 discusses "Truncation of the Hash Function Output." 793b4e3dcbSSimon L. B. Nielsen * default: case below covers for it. It's not clear however if it's 803b4e3dcbSSimon L. B. Nielsen * permitted to truncate to amount of bytes not divisible by 4. I bet not, 813b4e3dcbSSimon L. B. Nielsen * but if it is, then default: case shall be extended. For reference. 823b4e3dcbSSimon L. B. Nielsen * Idea behind separate cases for pre-defined lenghts is to let the 833b4e3dcbSSimon L. B. Nielsen * compiler decide if it's appropriate to unroll small loops. 843b4e3dcbSSimon L. B. Nielsen */ 853b4e3dcbSSimon L. B. Nielsen #define HASH_MAKE_STRING(c,s) do { \ 863b4e3dcbSSimon L. B. Nielsen unsigned long ll; \ 871f13597dSJung-uk Kim unsigned int nn; \ 883b4e3dcbSSimon L. B. Nielsen switch ((c)->md_len) \ 893b4e3dcbSSimon L. B. Nielsen { case SHA224_DIGEST_LENGTH: \ 901f13597dSJung-uk Kim for (nn=0;nn<SHA224_DIGEST_LENGTH/4;nn++) \ 91*09286989SJung-uk Kim { ll=(c)->h[nn]; (void)HOST_l2c(ll,(s)); } \ 923b4e3dcbSSimon L. B. Nielsen break; \ 933b4e3dcbSSimon L. B. Nielsen case SHA256_DIGEST_LENGTH: \ 941f13597dSJung-uk Kim for (nn=0;nn<SHA256_DIGEST_LENGTH/4;nn++) \ 95*09286989SJung-uk Kim { ll=(c)->h[nn]; (void)HOST_l2c(ll,(s)); } \ 963b4e3dcbSSimon L. B. Nielsen break; \ 973b4e3dcbSSimon L. B. Nielsen default: \ 983b4e3dcbSSimon L. B. Nielsen if ((c)->md_len > SHA256_DIGEST_LENGTH) \ 993b4e3dcbSSimon L. B. Nielsen return 0; \ 1001f13597dSJung-uk Kim for (nn=0;nn<(c)->md_len/4;nn++) \ 101*09286989SJung-uk Kim { ll=(c)->h[nn]; (void)HOST_l2c(ll,(s)); } \ 1023b4e3dcbSSimon L. B. Nielsen break; \ 1033b4e3dcbSSimon L. B. Nielsen } \ 1043b4e3dcbSSimon L. B. Nielsen } while (0) 1053b4e3dcbSSimon L. B. Nielsen 1063b4e3dcbSSimon L. B. Nielsen #define HASH_UPDATE SHA256_Update 1073b4e3dcbSSimon L. B. Nielsen #define HASH_TRANSFORM SHA256_Transform 1083b4e3dcbSSimon L. B. Nielsen #define HASH_FINAL SHA256_Final 1093b4e3dcbSSimon L. B. Nielsen #define HASH_BLOCK_DATA_ORDER sha256_block_data_order 110db522d3aSSimon L. B. Nielsen #ifndef SHA256_ASM 111db522d3aSSimon L. B. Nielsen static 112db522d3aSSimon L. B. Nielsen #endif 1133b4e3dcbSSimon L. B. Nielsen void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num); 1143b4e3dcbSSimon L. B. Nielsen 1153b4e3dcbSSimon L. B. Nielsen #include "md32_common.h" 1163b4e3dcbSSimon L. B. Nielsen 117db522d3aSSimon L. B. Nielsen #ifndef SHA256_ASM 1183b4e3dcbSSimon L. B. Nielsen static const SHA_LONG K256[64] = { 1193b4e3dcbSSimon L. B. Nielsen 0x428a2f98UL,0x71374491UL,0xb5c0fbcfUL,0xe9b5dba5UL, 1203b4e3dcbSSimon L. B. Nielsen 0x3956c25bUL,0x59f111f1UL,0x923f82a4UL,0xab1c5ed5UL, 1213b4e3dcbSSimon L. B. Nielsen 0xd807aa98UL,0x12835b01UL,0x243185beUL,0x550c7dc3UL, 1223b4e3dcbSSimon L. B. Nielsen 0x72be5d74UL,0x80deb1feUL,0x9bdc06a7UL,0xc19bf174UL, 1233b4e3dcbSSimon L. B. Nielsen 0xe49b69c1UL,0xefbe4786UL,0x0fc19dc6UL,0x240ca1ccUL, 1243b4e3dcbSSimon L. B. Nielsen 0x2de92c6fUL,0x4a7484aaUL,0x5cb0a9dcUL,0x76f988daUL, 1253b4e3dcbSSimon L. B. Nielsen 0x983e5152UL,0xa831c66dUL,0xb00327c8UL,0xbf597fc7UL, 1263b4e3dcbSSimon L. B. Nielsen 0xc6e00bf3UL,0xd5a79147UL,0x06ca6351UL,0x14292967UL, 1273b4e3dcbSSimon L. B. Nielsen 0x27b70a85UL,0x2e1b2138UL,0x4d2c6dfcUL,0x53380d13UL, 1283b4e3dcbSSimon L. B. Nielsen 0x650a7354UL,0x766a0abbUL,0x81c2c92eUL,0x92722c85UL, 1293b4e3dcbSSimon L. B. Nielsen 0xa2bfe8a1UL,0xa81a664bUL,0xc24b8b70UL,0xc76c51a3UL, 1303b4e3dcbSSimon L. B. Nielsen 0xd192e819UL,0xd6990624UL,0xf40e3585UL,0x106aa070UL, 1313b4e3dcbSSimon L. B. Nielsen 0x19a4c116UL,0x1e376c08UL,0x2748774cUL,0x34b0bcb5UL, 1323b4e3dcbSSimon L. B. Nielsen 0x391c0cb3UL,0x4ed8aa4aUL,0x5b9cca4fUL,0x682e6ff3UL, 1333b4e3dcbSSimon L. B. Nielsen 0x748f82eeUL,0x78a5636fUL,0x84c87814UL,0x8cc70208UL, 1343b4e3dcbSSimon L. B. Nielsen 0x90befffaUL,0xa4506cebUL,0xbef9a3f7UL,0xc67178f2UL }; 1353b4e3dcbSSimon L. B. Nielsen 1363b4e3dcbSSimon L. B. Nielsen /* 1373b4e3dcbSSimon L. B. Nielsen * FIPS specification refers to right rotations, while our ROTATE macro 1383b4e3dcbSSimon L. B. Nielsen * is left one. This is why you might notice that rotation coefficients 1393b4e3dcbSSimon L. B. Nielsen * differ from those observed in FIPS document by 32-N... 1403b4e3dcbSSimon L. B. Nielsen */ 1413b4e3dcbSSimon L. B. Nielsen #define Sigma0(x) (ROTATE((x),30) ^ ROTATE((x),19) ^ ROTATE((x),10)) 1423b4e3dcbSSimon L. B. Nielsen #define Sigma1(x) (ROTATE((x),26) ^ ROTATE((x),21) ^ ROTATE((x),7)) 1433b4e3dcbSSimon L. B. Nielsen #define sigma0(x) (ROTATE((x),25) ^ ROTATE((x),14) ^ ((x)>>3)) 1443b4e3dcbSSimon L. B. Nielsen #define sigma1(x) (ROTATE((x),15) ^ ROTATE((x),13) ^ ((x)>>10)) 1453b4e3dcbSSimon L. B. Nielsen 1463b4e3dcbSSimon L. B. Nielsen #define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) 1473b4e3dcbSSimon L. B. Nielsen #define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 1483b4e3dcbSSimon L. B. Nielsen 1493b4e3dcbSSimon L. B. Nielsen #ifdef OPENSSL_SMALL_FOOTPRINT 1503b4e3dcbSSimon L. B. Nielsen 151db522d3aSSimon L. B. Nielsen static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num) 1523b4e3dcbSSimon L. B. Nielsen { 1533b4e3dcbSSimon L. B. Nielsen unsigned MD32_REG_T a,b,c,d,e,f,g,h,s0,s1,T1,T2; 154db522d3aSSimon L. B. Nielsen SHA_LONG X[16],l; 1553b4e3dcbSSimon L. B. Nielsen int i; 1563b4e3dcbSSimon L. B. Nielsen const unsigned char *data=in; 1573b4e3dcbSSimon L. B. Nielsen 1583b4e3dcbSSimon L. B. Nielsen while (num--) { 1593b4e3dcbSSimon L. B. Nielsen 1603b4e3dcbSSimon L. B. Nielsen a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3]; 1613b4e3dcbSSimon L. B. Nielsen e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7]; 1623b4e3dcbSSimon L. B. Nielsen 1633b4e3dcbSSimon L. B. Nielsen for (i=0;i<16;i++) 1643b4e3dcbSSimon L. B. Nielsen { 1653b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[i] = l; 1663b4e3dcbSSimon L. B. Nielsen T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i]; 1673b4e3dcbSSimon L. B. Nielsen T2 = Sigma0(a) + Maj(a,b,c); 1683b4e3dcbSSimon L. B. Nielsen h = g; g = f; f = e; e = d + T1; 1693b4e3dcbSSimon L. B. Nielsen d = c; c = b; b = a; a = T1 + T2; 1703b4e3dcbSSimon L. B. Nielsen } 1713b4e3dcbSSimon L. B. Nielsen 1723b4e3dcbSSimon L. B. Nielsen for (;i<64;i++) 1733b4e3dcbSSimon L. B. Nielsen { 1743b4e3dcbSSimon L. B. Nielsen s0 = X[(i+1)&0x0f]; s0 = sigma0(s0); 1753b4e3dcbSSimon L. B. Nielsen s1 = X[(i+14)&0x0f]; s1 = sigma1(s1); 1763b4e3dcbSSimon L. B. Nielsen 1773b4e3dcbSSimon L. B. Nielsen T1 = X[i&0xf] += s0 + s1 + X[(i+9)&0xf]; 1783b4e3dcbSSimon L. B. Nielsen T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i]; 1793b4e3dcbSSimon L. B. Nielsen T2 = Sigma0(a) + Maj(a,b,c); 1803b4e3dcbSSimon L. B. Nielsen h = g; g = f; f = e; e = d + T1; 1813b4e3dcbSSimon L. B. Nielsen d = c; c = b; b = a; a = T1 + T2; 1823b4e3dcbSSimon L. B. Nielsen } 1833b4e3dcbSSimon L. B. Nielsen 1843b4e3dcbSSimon L. B. Nielsen ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d; 1853b4e3dcbSSimon L. B. Nielsen ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h; 1863b4e3dcbSSimon L. B. Nielsen 1873b4e3dcbSSimon L. B. Nielsen } 1883b4e3dcbSSimon L. B. Nielsen } 1893b4e3dcbSSimon L. B. Nielsen 1903b4e3dcbSSimon L. B. Nielsen #else 1913b4e3dcbSSimon L. B. Nielsen 1923b4e3dcbSSimon L. B. Nielsen #define ROUND_00_15(i,a,b,c,d,e,f,g,h) do { \ 1933b4e3dcbSSimon L. B. Nielsen T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i]; \ 1943b4e3dcbSSimon L. B. Nielsen h = Sigma0(a) + Maj(a,b,c); \ 1953b4e3dcbSSimon L. B. Nielsen d += T1; h += T1; } while (0) 1963b4e3dcbSSimon L. B. Nielsen 1973b4e3dcbSSimon L. B. Nielsen #define ROUND_16_63(i,a,b,c,d,e,f,g,h,X) do { \ 1983b4e3dcbSSimon L. B. Nielsen s0 = X[(i+1)&0x0f]; s0 = sigma0(s0); \ 1993b4e3dcbSSimon L. B. Nielsen s1 = X[(i+14)&0x0f]; s1 = sigma1(s1); \ 2003b4e3dcbSSimon L. B. Nielsen T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \ 2013b4e3dcbSSimon L. B. Nielsen ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0) 2023b4e3dcbSSimon L. B. Nielsen 203db522d3aSSimon L. B. Nielsen static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num) 2043b4e3dcbSSimon L. B. Nielsen { 2053b4e3dcbSSimon L. B. Nielsen unsigned MD32_REG_T a,b,c,d,e,f,g,h,s0,s1,T1; 2063b4e3dcbSSimon L. B. Nielsen SHA_LONG X[16]; 2073b4e3dcbSSimon L. B. Nielsen int i; 2083b4e3dcbSSimon L. B. Nielsen const unsigned char *data=in; 209db522d3aSSimon L. B. Nielsen const union { long one; char little; } is_endian = {1}; 2103b4e3dcbSSimon L. B. Nielsen 2113b4e3dcbSSimon L. B. Nielsen while (num--) { 2123b4e3dcbSSimon L. B. Nielsen 2133b4e3dcbSSimon L. B. Nielsen a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3]; 2143b4e3dcbSSimon L. B. Nielsen e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7]; 2153b4e3dcbSSimon L. B. Nielsen 216db522d3aSSimon L. B. Nielsen if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)in%4)==0) 2173b4e3dcbSSimon L. B. Nielsen { 2183b4e3dcbSSimon L. B. Nielsen const SHA_LONG *W=(const SHA_LONG *)data; 2193b4e3dcbSSimon L. B. Nielsen 2203b4e3dcbSSimon L. B. Nielsen T1 = X[0] = W[0]; ROUND_00_15(0,a,b,c,d,e,f,g,h); 2213b4e3dcbSSimon L. B. Nielsen T1 = X[1] = W[1]; ROUND_00_15(1,h,a,b,c,d,e,f,g); 2223b4e3dcbSSimon L. B. Nielsen T1 = X[2] = W[2]; ROUND_00_15(2,g,h,a,b,c,d,e,f); 2233b4e3dcbSSimon L. B. Nielsen T1 = X[3] = W[3]; ROUND_00_15(3,f,g,h,a,b,c,d,e); 2243b4e3dcbSSimon L. B. Nielsen T1 = X[4] = W[4]; ROUND_00_15(4,e,f,g,h,a,b,c,d); 2253b4e3dcbSSimon L. B. Nielsen T1 = X[5] = W[5]; ROUND_00_15(5,d,e,f,g,h,a,b,c); 2263b4e3dcbSSimon L. B. Nielsen T1 = X[6] = W[6]; ROUND_00_15(6,c,d,e,f,g,h,a,b); 2273b4e3dcbSSimon L. B. Nielsen T1 = X[7] = W[7]; ROUND_00_15(7,b,c,d,e,f,g,h,a); 2283b4e3dcbSSimon L. B. Nielsen T1 = X[8] = W[8]; ROUND_00_15(8,a,b,c,d,e,f,g,h); 2293b4e3dcbSSimon L. B. Nielsen T1 = X[9] = W[9]; ROUND_00_15(9,h,a,b,c,d,e,f,g); 2303b4e3dcbSSimon L. B. Nielsen T1 = X[10] = W[10]; ROUND_00_15(10,g,h,a,b,c,d,e,f); 2313b4e3dcbSSimon L. B. Nielsen T1 = X[11] = W[11]; ROUND_00_15(11,f,g,h,a,b,c,d,e); 2323b4e3dcbSSimon L. B. Nielsen T1 = X[12] = W[12]; ROUND_00_15(12,e,f,g,h,a,b,c,d); 2333b4e3dcbSSimon L. B. Nielsen T1 = X[13] = W[13]; ROUND_00_15(13,d,e,f,g,h,a,b,c); 2343b4e3dcbSSimon L. B. Nielsen T1 = X[14] = W[14]; ROUND_00_15(14,c,d,e,f,g,h,a,b); 2353b4e3dcbSSimon L. B. Nielsen T1 = X[15] = W[15]; ROUND_00_15(15,b,c,d,e,f,g,h,a); 2363b4e3dcbSSimon L. B. Nielsen 2373b4e3dcbSSimon L. B. Nielsen data += SHA256_CBLOCK; 2383b4e3dcbSSimon L. B. Nielsen } 2393b4e3dcbSSimon L. B. Nielsen else 2403b4e3dcbSSimon L. B. Nielsen { 2413b4e3dcbSSimon L. B. Nielsen SHA_LONG l; 2423b4e3dcbSSimon L. B. Nielsen 2433b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[0] = l; ROUND_00_15(0,a,b,c,d,e,f,g,h); 2443b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[1] = l; ROUND_00_15(1,h,a,b,c,d,e,f,g); 2453b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[2] = l; ROUND_00_15(2,g,h,a,b,c,d,e,f); 2463b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[3] = l; ROUND_00_15(3,f,g,h,a,b,c,d,e); 2473b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[4] = l; ROUND_00_15(4,e,f,g,h,a,b,c,d); 2483b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[5] = l; ROUND_00_15(5,d,e,f,g,h,a,b,c); 2493b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[6] = l; ROUND_00_15(6,c,d,e,f,g,h,a,b); 2503b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[7] = l; ROUND_00_15(7,b,c,d,e,f,g,h,a); 2513b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[8] = l; ROUND_00_15(8,a,b,c,d,e,f,g,h); 2523b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[9] = l; ROUND_00_15(9,h,a,b,c,d,e,f,g); 2533b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[10] = l; ROUND_00_15(10,g,h,a,b,c,d,e,f); 2543b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[11] = l; ROUND_00_15(11,f,g,h,a,b,c,d,e); 2553b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[12] = l; ROUND_00_15(12,e,f,g,h,a,b,c,d); 2563b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[13] = l; ROUND_00_15(13,d,e,f,g,h,a,b,c); 2573b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[14] = l; ROUND_00_15(14,c,d,e,f,g,h,a,b); 2583b4e3dcbSSimon L. B. Nielsen HOST_c2l(data,l); T1 = X[15] = l; ROUND_00_15(15,b,c,d,e,f,g,h,a); 2593b4e3dcbSSimon L. B. Nielsen } 2603b4e3dcbSSimon L. B. Nielsen 2613b4e3dcbSSimon L. B. Nielsen for (i=16;i<64;i+=8) 2623b4e3dcbSSimon L. B. Nielsen { 2633b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+0,a,b,c,d,e,f,g,h,X); 2643b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+1,h,a,b,c,d,e,f,g,X); 2653b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+2,g,h,a,b,c,d,e,f,X); 2663b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+3,f,g,h,a,b,c,d,e,X); 2673b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+4,e,f,g,h,a,b,c,d,X); 2683b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+5,d,e,f,g,h,a,b,c,X); 2693b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+6,c,d,e,f,g,h,a,b,X); 2703b4e3dcbSSimon L. B. Nielsen ROUND_16_63(i+7,b,c,d,e,f,g,h,a,X); 2713b4e3dcbSSimon L. B. Nielsen } 2723b4e3dcbSSimon L. B. Nielsen 2733b4e3dcbSSimon L. B. Nielsen ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d; 2743b4e3dcbSSimon L. B. Nielsen ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h; 2753b4e3dcbSSimon L. B. Nielsen 2763b4e3dcbSSimon L. B. Nielsen } 2773b4e3dcbSSimon L. B. Nielsen } 2783b4e3dcbSSimon L. B. Nielsen 2793b4e3dcbSSimon L. B. Nielsen #endif 2803b4e3dcbSSimon L. B. Nielsen #endif /* SHA256_ASM */ 2813b4e3dcbSSimon L. B. Nielsen 2823b4e3dcbSSimon L. B. Nielsen #endif /* OPENSSL_NO_SHA256 */ 283