155714Skris/* crypto/sha/sha_locl.h */
255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
355714Skris * All rights reserved.
455714Skris *
555714Skris * This package is an SSL implementation written
655714Skris * by Eric Young (eay@cryptsoft.com).
755714Skris * The implementation was written so as to conform with Netscapes SSL.
855714Skris *
955714Skris * This library is free for commercial and non-commercial use as long as
1055714Skris * the following conditions are aheared to.  The following conditions
1155714Skris * apply to all code found in this distribution, be it the RC4, RSA,
1255714Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1355714Skris * included with this distribution is covered by the same copyright terms
1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1555714Skris *
1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in
1755714Skris * the code are not to be removed.
1855714Skris * If this package is used in a product, Eric Young should be given attribution
1955714Skris * as the author of the parts of the library used.
2055714Skris * This can be in the form of a textual message at program startup or
2155714Skris * in documentation (online or textual) provided with the package.
2255714Skris *
2355714Skris * Redistribution and use in source and binary forms, with or without
2455714Skris * modification, are permitted provided that the following conditions
2555714Skris * are met:
2655714Skris * 1. Redistributions of source code must retain the copyright
2755714Skris *    notice, this list of conditions and the following disclaimer.
2855714Skris * 2. Redistributions in binary form must reproduce the above copyright
2955714Skris *    notice, this list of conditions and the following disclaimer in the
3055714Skris *    documentation and/or other materials provided with the distribution.
3155714Skris * 3. All advertising materials mentioning features or use of this software
3255714Skris *    must display the following acknowledgement:
3355714Skris *    "This product includes cryptographic software written by
3455714Skris *     Eric Young (eay@cryptsoft.com)"
3555714Skris *    The word 'cryptographic' can be left out if the rouines from the library
3655714Skris *    being used are not cryptographic related :-).
3755714Skris * 4. If you include any Windows specific code (or a derivative thereof) from
3855714Skris *    the apps directory (application code) you must include an acknowledgement:
3955714Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4055714Skris *
4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4455714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5155714Skris * SUCH DAMAGE.
5255714Skris *
5355714Skris * The licence and distribution terms for any publically available version or
5455714Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
5555714Skris * copied and put under another distribution licence
5655714Skris * [including the GNU Public Licence.]
5755714Skris */
5855714Skris
5955714Skris#include <stdlib.h>
6055714Skris#include <string.h>
6155714Skris
6255714Skris#include <openssl/opensslconf.h>
6359191Skris#include <openssl/sha.h>
6455714Skris
6559191Skris#define DATA_ORDER_IS_BIG_ENDIAN
6655714Skris
6759191Skris#define HASH_LONG               SHA_LONG
6859191Skris#define HASH_CTX                SHA_CTX
6959191Skris#define HASH_CBLOCK             SHA_CBLOCK
7059191Skris#define HASH_MAKE_STRING(c,s)   do {	\
7159191Skris	unsigned long ll;		\
72246772Sjkim	ll=(c)->h0; (void)HOST_l2c(ll,(s));	\
73246772Sjkim	ll=(c)->h1; (void)HOST_l2c(ll,(s));	\
74246772Sjkim	ll=(c)->h2; (void)HOST_l2c(ll,(s));	\
75246772Sjkim	ll=(c)->h3; (void)HOST_l2c(ll,(s));	\
76246772Sjkim	ll=(c)->h4; (void)HOST_l2c(ll,(s));	\
7759191Skris	} while (0)
7855714Skris
7959191Skris#if defined(SHA_0)
8055714Skris
8159191Skris# define HASH_UPDATE             	SHA_Update
8259191Skris# define HASH_TRANSFORM          	SHA_Transform
8359191Skris# define HASH_FINAL              	SHA_Final
8459191Skris# define HASH_INIT			SHA_Init
8559191Skris# define HASH_BLOCK_DATA_ORDER   	sha_block_data_order
8659191Skris# define Xupdate(a,ix,ia,ib,ic,id)	(ix=(a)=(ia^ib^ic^id))
8755714Skris
88194206Ssimonstatic void sha_block_data_order (SHA_CTX *c, const void *p,size_t num);
8955714Skris
9059191Skris#elif defined(SHA_1)
9155714Skris
9259191Skris# define HASH_UPDATE             	SHA1_Update
9359191Skris# define HASH_TRANSFORM          	SHA1_Transform
9459191Skris# define HASH_FINAL              	SHA1_Final
9559191Skris# define HASH_INIT			SHA1_Init
9659191Skris# define HASH_BLOCK_DATA_ORDER   	sha1_block_data_order
9759191Skris# if defined(__MWERKS__) && defined(__MC68K__)
9859191Skris   /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */
9959191Skris#  define Xupdate(a,ix,ia,ib,ic,id)	do { (a)=(ia^ib^ic^id);		\
10059191Skris					     ix=(a)=ROTATE((a),1);	\
10159191Skris					} while (0)
10259191Skris# else
10359191Skris#  define Xupdate(a,ix,ia,ib,ic,id)	( (a)=(ia^ib^ic^id),	\
10459191Skris					  ix=(a)=ROTATE((a),1)	\
10559191Skris					)
10659191Skris# endif
10755714Skris
108194206Ssimon#ifndef SHA1_ASM
109194206Ssimonstatic
110194206Ssimon#endif
111194206Ssimonvoid sha1_block_data_order (SHA_CTX *c, const void *p,size_t num);
11255714Skris
11359191Skris#else
11459191Skris# error "Either SHA_0 or SHA_1 must be defined."
11559191Skris#endif
11655714Skris
11759191Skris#include "md32_common.h"
11855714Skris
11959191Skris#define INIT_DATA_h0 0x67452301UL
12059191Skris#define INIT_DATA_h1 0xefcdab89UL
12159191Skris#define INIT_DATA_h2 0x98badcfeUL
12259191Skris#define INIT_DATA_h3 0x10325476UL
12359191Skris#define INIT_DATA_h4 0xc3d2e1f0UL
12455714Skris
125238405Sjkim#ifdef SHA_0
126238405Sjkimfips_md_init(SHA)
127194206Ssimon#else
128238405Sjkimfips_md_init_ctx(SHA1, SHA)
129194206Ssimon#endif
13059191Skris	{
131238405Sjkim	memset (c,0,sizeof(*c));
13259191Skris	c->h0=INIT_DATA_h0;
13359191Skris	c->h1=INIT_DATA_h1;
13459191Skris	c->h2=INIT_DATA_h2;
13559191Skris	c->h3=INIT_DATA_h3;
13659191Skris	c->h4=INIT_DATA_h4;
137109998Smarkm	return 1;
13855714Skris	}
13955714Skris
14059191Skris#define K_00_19	0x5a827999UL
14159191Skris#define K_20_39 0x6ed9eba1UL
14259191Skris#define K_40_59 0x8f1bbcdcUL
14359191Skris#define K_60_79 0xca62c1d6UL
14459191Skris
14555714Skris/* As  pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
14655714Skris * simplified to the code in F_00_19.  Wei attributes these optimisations
14755714Skris * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
14855714Skris * #define F(x,y,z) (((x) & (y))  |  ((~(x)) & (z)))
14955714Skris * I've just become aware of another tweak to be made, again from Wei Dai,
15055714Skris * in F_40_59, (x&a)|(y&a) -> (x|y)&a
15155714Skris */
15255714Skris#define	F_00_19(b,c,d)	((((c) ^ (d)) & (b)) ^ (d))
15355714Skris#define	F_20_39(b,c,d)	((b) ^ (c) ^ (d))
15455714Skris#define F_40_59(b,c,d)	(((b) & (c)) | (((b)|(c)) & (d)))
15555714Skris#define	F_60_79(b,c,d)	F_20_39(b,c,d)
15655714Skris
157160814Ssimon#ifndef OPENSSL_SMALL_FOOTPRINT
158160814Ssimon
15959191Skris#define BODY_00_15(i,a,b,c,d,e,f,xi) \
16059191Skris	(f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
16155714Skris	(b)=ROTATE((b),30);
16255714Skris
16359191Skris#define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
16459191Skris	Xupdate(f,xi,xa,xb,xc,xd); \
16555714Skris	(f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
16655714Skris	(b)=ROTATE((b),30);
16755714Skris
16859191Skris#define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
16959191Skris	Xupdate(f,xi,xa,xb,xc,xd); \
17055714Skris	(f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
17155714Skris	(b)=ROTATE((b),30);
17255714Skris
17359191Skris#define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \
17459191Skris	Xupdate(f,xa,xa,xb,xc,xd); \
17555714Skris	(f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
17655714Skris	(b)=ROTATE((b),30);
17755714Skris
17859191Skris#define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \
17959191Skris	Xupdate(f,xa,xa,xb,xc,xd); \
18055714Skris	(f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
18155714Skris	(b)=ROTATE((b),30);
18255714Skris
18359191Skris#define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \
18459191Skris	Xupdate(f,xa,xa,xb,xc,xd); \
18559191Skris	(f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
18655714Skris	(b)=ROTATE((b),30);
18755714Skris
18859191Skris#ifdef X
18959191Skris#undef X
19059191Skris#endif
19159191Skris#ifndef MD32_XARRAY
19259191Skris  /*
19359191Skris   * Originally X was an array. As it's automatic it's natural
19459191Skris   * to expect RISC compiler to accomodate at least part of it in
19559191Skris   * the register bank, isn't it? Unfortunately not all compilers
19659191Skris   * "find" this expectation reasonable:-( On order to make such
19759191Skris   * compilers generate better code I replace X[] with a bunch of
19859191Skris   * X0, X1, etc. See the function body below...
19959191Skris   *					<appro@fy.chalmers.se>
20059191Skris   */
20159191Skris# define X(i)	XX##i
20259191Skris#else
20359191Skris  /*
20459191Skris   * However! Some compilers (most notably HP C) get overwhelmed by
20559191Skris   * that many local variables so that we have to have the way to
20659191Skris   * fall down to the original behavior.
20759191Skris   */
20859191Skris# define X(i)	XX[i]
20959191Skris#endif
21059191Skris
211194206Ssimon#if !defined(SHA_1) || !defined(SHA1_ASM)
212194206Ssimonstatic void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
21359191Skris	{
214194206Ssimon	const unsigned char *data=p;
215194206Ssimon	register unsigned MD32_REG_T A,B,C,D,E,T,l;
21659191Skris#ifndef MD32_XARRAY
217109998Smarkm	unsigned MD32_REG_T	XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
218109998Smarkm				XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
21959191Skris#else
22059191Skris	SHA_LONG	XX[16];
22159191Skris#endif
22259191Skris
22359191Skris	A=c->h0;
22459191Skris	B=c->h1;
22559191Skris	C=c->h2;
22659191Skris	D=c->h3;
22759191Skris	E=c->h4;
22859191Skris
22959191Skris	for (;;)
230194206Ssimon			{
231194206Ssimon	const union { long one; char little; } is_endian = {1};
232194206Ssimon
233194206Ssimon	if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)p%4)==0)
23459191Skris		{
235194206Ssimon		const SHA_LONG *W=(const SHA_LONG *)data;
23659191Skris
237194206Ssimon		X( 0) = W[0];				X( 1) = W[ 1];
238194206Ssimon		BODY_00_15( 0,A,B,C,D,E,T,X( 0));	X( 2) = W[ 2];
239194206Ssimon		BODY_00_15( 1,T,A,B,C,D,E,X( 1));	X( 3) = W[ 3];
240194206Ssimon		BODY_00_15( 2,E,T,A,B,C,D,X( 2));	X( 4) = W[ 4];
241194206Ssimon		BODY_00_15( 3,D,E,T,A,B,C,X( 3));	X( 5) = W[ 5];
242194206Ssimon		BODY_00_15( 4,C,D,E,T,A,B,X( 4));	X( 6) = W[ 6];
243194206Ssimon		BODY_00_15( 5,B,C,D,E,T,A,X( 5));	X( 7) = W[ 7];
244194206Ssimon		BODY_00_15( 6,A,B,C,D,E,T,X( 6));	X( 8) = W[ 8];
245194206Ssimon		BODY_00_15( 7,T,A,B,C,D,E,X( 7));	X( 9) = W[ 9];
246194206Ssimon		BODY_00_15( 8,E,T,A,B,C,D,X( 8));	X(10) = W[10];
247194206Ssimon		BODY_00_15( 9,D,E,T,A,B,C,X( 9));	X(11) = W[11];
248194206Ssimon		BODY_00_15(10,C,D,E,T,A,B,X(10));	X(12) = W[12];
249194206Ssimon		BODY_00_15(11,B,C,D,E,T,A,X(11));	X(13) = W[13];
250194206Ssimon		BODY_00_15(12,A,B,C,D,E,T,X(12));	X(14) = W[14];
251194206Ssimon		BODY_00_15(13,T,A,B,C,D,E,X(13));	X(15) = W[15];
252194206Ssimon		BODY_00_15(14,E,T,A,B,C,D,X(14));
253194206Ssimon		BODY_00_15(15,D,E,T,A,B,C,X(15));
25459191Skris
255194206Ssimon		data += SHA_CBLOCK;
25659191Skris		}
257194206Ssimon	else
25859191Skris		{
259246772Sjkim		(void)HOST_c2l(data,l); X( 0)=l;	(void)HOST_c2l(data,l); X( 1)=l;
260246772Sjkim		BODY_00_15( 0,A,B,C,D,E,T,X( 0));	(void)HOST_c2l(data,l); X( 2)=l;
261246772Sjkim		BODY_00_15( 1,T,A,B,C,D,E,X( 1));	(void)HOST_c2l(data,l); X( 3)=l;
262246772Sjkim		BODY_00_15( 2,E,T,A,B,C,D,X( 2));	(void)HOST_c2l(data,l); X( 4)=l;
263246772Sjkim		BODY_00_15( 3,D,E,T,A,B,C,X( 3));	(void)HOST_c2l(data,l); X( 5)=l;
264246772Sjkim		BODY_00_15( 4,C,D,E,T,A,B,X( 4));	(void)HOST_c2l(data,l); X( 6)=l;
265246772Sjkim		BODY_00_15( 5,B,C,D,E,T,A,X( 5));	(void)HOST_c2l(data,l); X( 7)=l;
266246772Sjkim		BODY_00_15( 6,A,B,C,D,E,T,X( 6));	(void)HOST_c2l(data,l); X( 8)=l;
267246772Sjkim		BODY_00_15( 7,T,A,B,C,D,E,X( 7));	(void)HOST_c2l(data,l); X( 9)=l;
268246772Sjkim		BODY_00_15( 8,E,T,A,B,C,D,X( 8));	(void)HOST_c2l(data,l); X(10)=l;
269246772Sjkim		BODY_00_15( 9,D,E,T,A,B,C,X( 9));	(void)HOST_c2l(data,l); X(11)=l;
270246772Sjkim		BODY_00_15(10,C,D,E,T,A,B,X(10));	(void)HOST_c2l(data,l); X(12)=l;
271246772Sjkim		BODY_00_15(11,B,C,D,E,T,A,X(11));	(void)HOST_c2l(data,l); X(13)=l;
272246772Sjkim		BODY_00_15(12,A,B,C,D,E,T,X(12));	(void)HOST_c2l(data,l); X(14)=l;
273246772Sjkim		BODY_00_15(13,T,A,B,C,D,E,X(13));	(void)HOST_c2l(data,l); X(15)=l;
274194206Ssimon		BODY_00_15(14,E,T,A,B,C,D,X(14));
275194206Ssimon		BODY_00_15(15,D,E,T,A,B,C,X(15));
276194206Ssimon		}
27759191Skris
27859191Skris	BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13));
27959191Skris	BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14));
28059191Skris	BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15));
28159191Skris	BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0));
28259191Skris
28359191Skris	BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1));
28459191Skris	BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2));
28559191Skris	BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3));
28659191Skris	BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4));
28759191Skris	BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5));
28859191Skris	BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6));
28959191Skris	BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7));
29059191Skris	BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8));
29159191Skris	BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9));
29259191Skris	BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10));
29359191Skris	BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
29459191Skris	BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
29559191Skris
29659191Skris	BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
29759191Skris	BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
29859191Skris	BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
29959191Skris	BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
30059191Skris	BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
30159191Skris	BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
30259191Skris	BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
30359191Skris	BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
30459191Skris
30559191Skris	BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
30659191Skris	BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
30759191Skris	BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
30859191Skris	BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
30959191Skris	BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
31059191Skris	BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
31159191Skris	BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
31259191Skris	BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
31359191Skris	BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
31459191Skris	BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
31559191Skris	BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
31659191Skris	BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
31759191Skris	BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
31859191Skris	BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
31959191Skris	BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
32059191Skris	BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
32159191Skris	BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
32259191Skris	BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
32359191Skris	BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
32459191Skris	BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
32559191Skris
32659191Skris	BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
32759191Skris	BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
32859191Skris	BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
32959191Skris	BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
33059191Skris	BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
33159191Skris	BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
33259191Skris	BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
33359191Skris	BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
33459191Skris	BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
33559191Skris	BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
33659191Skris	BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
33759191Skris	BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
33859191Skris	BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
33959191Skris	BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
34059191Skris	BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
34159191Skris	BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
34259191Skris	BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
34359191Skris	BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
34459191Skris	BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
34559191Skris	BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
34659191Skris
34759191Skris	c->h0=(c->h0+E)&0xffffffffL;
34859191Skris	c->h1=(c->h1+T)&0xffffffffL;
34959191Skris	c->h2=(c->h2+A)&0xffffffffL;
35059191Skris	c->h3=(c->h3+B)&0xffffffffL;
35159191Skris	c->h4=(c->h4+C)&0xffffffffL;
35259191Skris
353160814Ssimon	if (--num == 0) break;
35459191Skris
35559191Skris	A=c->h0;
35659191Skris	B=c->h1;
35759191Skris	C=c->h2;
35859191Skris	D=c->h3;
35959191Skris	E=c->h4;
36059191Skris
361194206Ssimon			}
36259191Skris	}
36359191Skris#endif
364160814Ssimon
365160814Ssimon#else	/* OPENSSL_SMALL_FOOTPRINT */
366160814Ssimon
367160814Ssimon#define BODY_00_15(xi)		 do {	\
368160814Ssimon	T=E+K_00_19+F_00_19(B,C,D);	\
369160814Ssimon	E=D, D=C, C=ROTATE(B,30), B=A;	\
370160814Ssimon	A=ROTATE(A,5)+T+xi;	    } while(0)
371160814Ssimon
372160814Ssimon#define BODY_16_19(xa,xb,xc,xd)	 do {	\
373160814Ssimon	Xupdate(T,xa,xa,xb,xc,xd);	\
374160814Ssimon	T+=E+K_00_19+F_00_19(B,C,D);	\
375160814Ssimon	E=D, D=C, C=ROTATE(B,30), B=A;	\
376160814Ssimon	A=ROTATE(A,5)+T;	    } while(0)
377160814Ssimon
378160814Ssimon#define BODY_20_39(xa,xb,xc,xd)	 do {	\
379160814Ssimon	Xupdate(T,xa,xa,xb,xc,xd);	\
380160814Ssimon	T+=E+K_20_39+F_20_39(B,C,D);	\
381160814Ssimon	E=D, D=C, C=ROTATE(B,30), B=A;	\
382160814Ssimon	A=ROTATE(A,5)+T;	    } while(0)
383160814Ssimon
384160814Ssimon#define BODY_40_59(xa,xb,xc,xd)	 do {	\
385160814Ssimon	Xupdate(T,xa,xa,xb,xc,xd);	\
386160814Ssimon	T+=E+K_40_59+F_40_59(B,C,D);	\
387160814Ssimon	E=D, D=C, C=ROTATE(B,30), B=A;	\
388160814Ssimon	A=ROTATE(A,5)+T;	    } while(0)
389160814Ssimon
390160814Ssimon#define BODY_60_79(xa,xb,xc,xd)	 do {	\
391160814Ssimon	Xupdate(T,xa,xa,xb,xc,xd);	\
392160814Ssimon	T=E+K_60_79+F_60_79(B,C,D);	\
393160814Ssimon	E=D, D=C, C=ROTATE(B,30), B=A;	\
394160814Ssimon	A=ROTATE(A,5)+T+xa;	    } while(0)
395160814Ssimon
396194206Ssimon#if !defined(SHA_1) || !defined(SHA1_ASM)
397194206Ssimonstatic void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
398160814Ssimon	{
399160814Ssimon	const unsigned char *data=p;
400160814Ssimon	register unsigned MD32_REG_T A,B,C,D,E,T,l;
401160814Ssimon	int i;
402160814Ssimon	SHA_LONG	X[16];
403160814Ssimon
404160814Ssimon	A=c->h0;
405160814Ssimon	B=c->h1;
406160814Ssimon	C=c->h2;
407160814Ssimon	D=c->h3;
408160814Ssimon	E=c->h4;
409160814Ssimon
410160814Ssimon	for (;;)
411160814Ssimon		{
412160814Ssimon	for (i=0;i<16;i++)
413160814Ssimon	{ HOST_c2l(data,l); X[i]=l; BODY_00_15(X[i]); }
414160814Ssimon	for (i=0;i<4;i++)
415160814Ssimon	{ BODY_16_19(X[i],       X[i+2],      X[i+8],     X[(i+13)&15]); }
416160814Ssimon	for (;i<24;i++)
417160814Ssimon	{ BODY_20_39(X[i&15],    X[(i+2)&15], X[(i+8)&15],X[(i+13)&15]); }
418160814Ssimon	for (i=0;i<20;i++)
419160814Ssimon	{ BODY_40_59(X[(i+8)&15],X[(i+10)&15],X[i&15],    X[(i+5)&15]);  }
420160814Ssimon	for (i=4;i<24;i++)
421160814Ssimon	{ BODY_60_79(X[(i+8)&15],X[(i+10)&15],X[i&15],    X[(i+5)&15]);  }
422160814Ssimon
423160814Ssimon	c->h0=(c->h0+A)&0xffffffffL;
424160814Ssimon	c->h1=(c->h1+B)&0xffffffffL;
425160814Ssimon	c->h2=(c->h2+C)&0xffffffffL;
426160814Ssimon	c->h3=(c->h3+D)&0xffffffffL;
427160814Ssimon	c->h4=(c->h4+E)&0xffffffffL;
428160814Ssimon
429160814Ssimon	if (--num == 0) break;
430160814Ssimon
431160814Ssimon	A=c->h0;
432160814Ssimon	B=c->h1;
433160814Ssimon	C=c->h2;
434160814Ssimon	D=c->h3;
435160814Ssimon	E=c->h4;
436160814Ssimon
437160814Ssimon		}
438160814Ssimon	}
439160814Ssimon#endif
440160814Ssimon
441160814Ssimon#endif
442