md5_dgst.c revision 65c4736d9c0ebc6d9b1d991593b55566909da9cd
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer/* crypto/md5/md5_dgst.c */
1443158c1101e58bf2fa0b9c785a40265b898a3bTinderbox User/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews * All rights reserved.
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * This package is an SSL implementation written
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * by Eric Young (eay@cryptsoft.com).
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * The implementation was written so as to conform with Netscapes SSL.
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer *
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews * This library is free for commercial and non-commercial use as long as
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews * the following conditions are aheared to. The following conditions
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews * apply to all code found in this distribution, be it the RC4, RSA,
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews * included with this distribution is covered by the same copyright terms
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews *
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * Copyright remains Eric Young's, and as such any Copyright notices in
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * the code are not to be removed.
36e97eb661df71069df2d75f5fd3b5bb0dcf1efeMark Andrews * If this package is used in a product, Eric Young should be given attribution
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * as the author of the parts of the library used.
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * This can be in the form of a textual message at program startup or
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * in documentation (online or textual) provided with the package.
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer *
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * Redistribution and use in source and binary forms, with or without
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * modification, are permitted provided that the following conditions
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer * are met:
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * 1. Redistributions of source code must retain the copyright
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * notice, this list of conditions and the following disclaimer.
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * 2. Redistributions in binary form must reproduce the above copyright
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * notice, this list of conditions and the following disclaimer in the
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * documentation and/or other materials provided with the distribution.
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * 3. All advertising materials mentioning features or use of this software
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * must display the following acknowledgement:
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * "This product includes cryptographic software written by
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * Eric Young (eay@cryptsoft.com)"
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * The word 'cryptographic' can be left out if the rouines from the library
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * being used are not cryptographic related :-).
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * 4. If you include any Windows specific code (or a derivative thereof) from
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * the apps directory (application code) you must include an acknowledgement:
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer *
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * SUCH DAMAGE.
667c498942c0e605c1aab98bca6b90aac4cbbd71Mark Andrews *
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * The licence and distribution terms for any publically available version or
36e97eb661df71069df2d75f5fd3b5bb0dcf1efeMark Andrews * derivative of this code cannot be changed. i.e. this code cannot simply be
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * copied and put under another distribution licence
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * [including the GNU Public Licence.]
36e97eb661df71069df2d75f5fd3b5bb0dcf1efeMark Andrews */
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#include <stdio.h>
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#include "md5_locl.h"
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#include <openssl/opensslv.h>
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrewschar *MD5_version="MD5" OPENSSL_VERSION_PTEXT;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews */
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt#define INIT_DATA_A (unsigned long)0x67452301L
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence#define INIT_DATA_B (unsigned long)0xefcdab89L
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence#define INIT_DATA_C (unsigned long)0x98badcfeL
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence#define INIT_DATA_D (unsigned long)0x10325476L
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrencevoid MD5_Init(MD5_CTX *c)
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence {
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence c->A=INIT_DATA_A;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence c->B=INIT_DATA_B;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence c->C=INIT_DATA_C;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence c->D=INIT_DATA_D;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence c->Nl=0;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence c->Nh=0;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence c->num=0;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence }
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence#ifndef md5_block_host_order
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrencevoid md5_block_host_order (MD5_CTX *c, const void *data, int num)
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence {
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence const MD5_LONG *X=data;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence register unsigned long A,B,C,D;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence /*
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * In case you wonder why A-D are declared as long and not
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * as MD5_LONG. Doing so results in slight performance
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * boost on LP64 architectures. The catch is we don't
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * really care if 32 MSBs of a 64-bit register get polluted
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * with eventual overflows as we *save* only 32 LSBs in
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * *either* case. Now declaring 'em long excuses the compiler
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * from keeping 32 MSBs zeroed resulting in 13% performance
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * Well, to be honest it should say that this *prevents*
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * performance degradation.
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence *
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence * <appro@fy.chalmers.se>
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence */
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence A=c->A;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence B=c->B;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence C=c->C;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence D=c->D;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence for (;num--;X+=HASH_LBLOCK)
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence {
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence /* Round 0 */
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(C,D,A,B,X[ 2],17,0x242070dbL);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(D,A,B,C,X[ 5],12,0x4787c62aL);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(C,D,A,B,X[ 6],17,0xa8304613L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(B,C,D,A,X[ 7],22,0xfd469501L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(A,B,C,D,X[ 8], 7,0x698098d8L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(C,D,A,B,X[10],17,0xffff5bb1L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(B,C,D,A,X[11],22,0x895cd7beL);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(A,B,C,D,X[12], 7,0x6b901122L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(D,A,B,C,X[13],12,0xfd987193L);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(C,D,A,B,X[14],17,0xa679438eL);
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence R0(B,C,D,A,X[15],22,0x49b40821L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer /* Round 1 */
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(D,A,B,C,X[ 6], 9,0xc040b340L);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(C,D,A,B,X[11],14,0x265e5a51L);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(D,A,B,C,X[10], 9,0x02441453L);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(C,D,A,B,X[15],14,0xd8a1e681L);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(D,A,B,C,X[14], 9,0xc33707d6L);
ecffc3aae3e72c5c65b1911ec3f4e1d180dc4bbcMark Andrews R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt R1(B,C,D,A,X[ 8],20,0x455a14edL);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt R1(A,B,C,D,X[13], 5,0xa9e3e905L);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt R1(C,D,A,B,X[ 7],14,0x676f02d9L);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
422009fe5b15e31e7f5d09212bd1480121a1464eEvan Hunt /* Round 2 */
422009fe5b15e31e7f5d09212bd1480121a1464eEvan Hunt R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
422009fe5b15e31e7f5d09212bd1480121a1464eEvan Hunt R2(D,A,B,C,X[ 8],11,0x8771f681L);
422009fe5b15e31e7f5d09212bd1480121a1464eEvan Hunt R2(C,D,A,B,X[11],16,0x6d9d6122L);
422009fe5b15e31e7f5d09212bd1480121a1464eEvan Hunt R2(B,C,D,A,X[14],23,0xfde5380cL);
422009fe5b15e31e7f5d09212bd1480121a1464eEvan Hunt R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
422009fe5b15e31e7f5d09212bd1480121a1464eEvan Hunt R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
07555e64d9102eae058efd58f872b4a3b9ddff61Mark Andrews R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
578f588228f5e04ccf648b6ae596f396ad6a22c9Mark Andrews R2(B,C,D,A,X[10],23,0xbebfbc70L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(A,B,C,D,X[13], 4,0x289b7ec6L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(D,A,B,C,X[ 0],11,0xeaa127faL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(B,C,D,A,X[ 6],23,0x04881d05L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(D,A,B,C,X[12],11,0xe6db99e5L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(C,D,A,B,X[15],16,0x1fa27cf8L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer /* Round 3 */
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(A,B,C,D,X[ 0], 6,0xf4292244L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(D,A,B,C,X[ 7],10,0x432aff97L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(C,D,A,B,X[14],15,0xab9423a7L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(B,C,D,A,X[ 5],21,0xfc93a039L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(A,B,C,D,X[12], 6,0x655b59c3L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(C,D,A,B,X[10],15,0xffeff47dL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(B,C,D,A,X[ 1],21,0x85845dd1L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
a687db7ce86c97d884b7ee1a68f59fcddf4d1c2aAutomatic Updater R3(C,D,A,B,X[ 6],15,0xa3014314L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(B,C,D,A,X[13],21,0x4e0811a1L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(D,A,B,C,X[11],10,0xbd3af235L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(B,C,D,A,X[ 9],21,0xeb86d391L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer A = c->A += A;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer B = c->B += B;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer C = c->C += C;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer D = c->D += D;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence }
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence }
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence#endif
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer#ifndef md5_block_data_order
36e97eb661df71069df2d75f5fd3b5bb0dcf1efeMark Andrewsvoid md5_block_data_order (MD5_CTX *c, const void *data_, int num)
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer {
36e97eb661df71069df2d75f5fd3b5bb0dcf1efeMark Andrews const unsigned char *data=data_;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer register unsigned long A,B,C,D,l;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer /*
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * In case you wonder why A-D are declared as long and not
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * as MD5_LONG. Doing so results in slight performance
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * boost on LP64 architectures. The catch is we don't
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * really care if 32 MSBs of a 64-bit register get polluted
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * with eventual overflows as we *save* only 32 LSBs in
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * *either* case. Now declaring 'em long excuses the compiler
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * from keeping 32 MSBs zeroed resulting in 13% performance
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * Well, to be honest it should say that this *prevents*
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * performance degradation.
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer *
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * <appro@fy.chalmers.se>
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer */
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer MD5_LONG X[MD5_LBLOCK];
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews /*
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * In case you wonder why don't I use c->data for this.
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * RISCs usually have a handful of registers and if X is
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer * declared as automatic array good optimizing compiler
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * shall accomodate at least part of it in register bank
c213258356638f9af1e1c68425df527b856567a2Francis Dupont * instead of memory.
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews *
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * <appro@fy.chalmers.se>
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews */
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer
6fa7a247a1037be08d7a8e0b4c4fd3785b2f268cAndreas Gustafsson A=c->A;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer B=c->B;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer C=c->C;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer D=c->D;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer for (;num--;)
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence {
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence HOST_c2l(data,l); X[ 0]=l; HOST_c2l(data,l); X[ 1]=l;
487e6abc16c1b2958d371b0d4e808953646b520aDavid Lawrence /* Round 0 */
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R0(A,B,C,D,X[ 0], 7,0xd76aa478L); HOST_c2l(data,l); X[ 2]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(D,A,B,C,X[ 1],12,0xe8c7b756L); HOST_c2l(data,l); X[ 3]=l;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R0(C,D,A,B,X[ 2],17,0x242070dbL); HOST_c2l(data,l); X[ 4]=l;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); HOST_c2l(data,l); X[ 5]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); HOST_c2l(data,l); X[ 6]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(D,A,B,C,X[ 5],12,0x4787c62aL); HOST_c2l(data,l); X[ 7]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(C,D,A,B,X[ 6],17,0xa8304613L); HOST_c2l(data,l); X[ 8]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(B,C,D,A,X[ 7],22,0xfd469501L); HOST_c2l(data,l); X[ 9]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(A,B,C,D,X[ 8], 7,0x698098d8L); HOST_c2l(data,l); X[10]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(D,A,B,C,X[ 9],12,0x8b44f7afL); HOST_c2l(data,l); X[11]=l;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R0(C,D,A,B,X[10],17,0xffff5bb1L); HOST_c2l(data,l); X[12]=l;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R0(B,C,D,A,X[11],22,0x895cd7beL); HOST_c2l(data,l); X[13]=l;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R0(A,B,C,D,X[12], 7,0x6b901122L); HOST_c2l(data,l); X[14]=l;
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R0(D,A,B,C,X[13],12,0xfd987193L); HOST_c2l(data,l); X[15]=l;
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R0(C,D,A,B,X[14],17,0xa679438eL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R0(B,C,D,A,X[15],22,0x49b40821L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer /* Round 1 */
a687db7ce86c97d884b7ee1a68f59fcddf4d1c2aAutomatic Updater R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(D,A,B,C,X[ 6], 9,0xc040b340L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(C,D,A,B,X[11],14,0x265e5a51L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(D,A,B,C,X[10], 9,0x02441453L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(C,D,A,B,X[15],14,0xd8a1e681L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(D,A,B,C,X[14], 9,0xc33707d6L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(B,C,D,A,X[ 8],20,0x455a14edL);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(A,B,C,D,X[13], 5,0xa9e3e905L);
6ceca14e5ea7972a9ba8bc1dca0de1f63f669cfdDanny Mayer R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(C,D,A,B,X[ 7],14,0x676f02d9L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer /* Round 2 */
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(D,A,B,C,X[ 8],11,0x8771f681L);
90039392500d15bf056ab4505d048fcba0d485dfMark Andrews R2(C,D,A,B,X[11],16,0x6d9d6122L);
b39213ce599dc433c6f99144c97ca3d562f40344Mark Andrews R2(B,C,D,A,X[14],23,0xfde5380cL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(B,C,D,A,X[10],23,0xbebfbc70L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(A,B,C,D,X[13], 4,0x289b7ec6L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(D,A,B,C,X[ 0],11,0xeaa127faL);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(B,C,D,A,X[ 6],23,0x04881d05L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(D,A,B,C,X[12],11,0xe6db99e5L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(C,D,A,B,X[15],16,0x1fa27cf8L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews /* Round 3 */
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(A,B,C,D,X[ 0], 6,0xf4292244L);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(D,A,B,C,X[ 7],10,0x432aff97L);
d3243476c280d3a98cadbfd6343437fa2b29356bDanny Mayer R3(C,D,A,B,X[14],15,0xab9423a7L);
22d44896ad30af27f7b483a806d1452daf5451c2Mark Andrews R3(B,C,D,A,X[ 5],21,0xfc93a039L);
22d44896ad30af27f7b483a806d1452daf5451c2Mark Andrews R3(A,B,C,D,X[12], 6,0x655b59c3L);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(C,D,A,B,X[10],15,0xffeff47dL);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(B,C,D,A,X[ 1],21,0x85845dd1L);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(C,D,A,B,X[ 6],15,0xa3014314L);
22d44896ad30af27f7b483a806d1452daf5451c2Mark Andrews R3(B,C,D,A,X[13],21,0x4e0811a1L);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt R3(D,A,B,C,X[11],10,0xbd3af235L);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt R3(B,C,D,A,X[ 9],21,0xeb86d391L);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews A = c->A += A;
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt B = c->B += B;
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt C = c->C += C;
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt D = c->D += D;
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt }
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt }
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt#endif
6a90baa0d5ac5ad6bf5a5e29b6e8b26a931e844eEvan Hunt
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews#ifdef undef
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrewsint printit(unsigned long *l)
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews {
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews int i,ii;
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews for (i=0; i<2; i++)
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews {
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews for (ii=0; ii<8; ii++)
503e5aa8d2400e47c9617db10b57f2d4f3495fd2Mark Andrews {
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews fprintf(stderr,"%08lx ",l[i*8+ii]);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews }
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews fprintf(stderr,"\n");
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews }
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews }
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#endif
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews