1/* 2 * rfc1321 requires that I include this. The code is new. The constants 3 * all come from the rfc (hence the copyright). We trade a table for the 4 * macros in rfc. The total size is a lot less. -- presotto 5 * 6 * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 7 * rights reserved. 8 * 9 * License to copy and use this software is granted provided that it 10 * is identified as the "RSA Data Security, Inc. MD5 Message-Digest 11 * Algorithm" in all material mentioning or referencing this software 12 * or this function. 13 * 14 * License is also granted to make and use derivative works provided 15 * that such works are identified as "derived from the RSA Data 16 * Security, Inc. MD5 Message-Digest Algorithm" in all material 17 * mentioning or referencing the derived work. 18 * 19 * RSA Data Security, Inc. makes no representations concerning either 20 * the merchantability of this software or the suitability of this 21 * software forany particular purpose. It is provided "as is" 22 * without express or implied warranty of any kind. 23 * These notices must be retained in any copies of any part of this 24 * documentation and/or software. 25 */ 26#define S11 7 27#define S12 12 28#define S13 17 29#define S14 22 30 31#define S21 5 32#define S22 9 33#define S23 14 34#define S24 20 35 36#define S31 4 37#define S32 11 38#define S33 16 39#define S34 23 40 41#define S41 6 42#define S42 10 43#define S43 15 44#define S44 21 45 46/* 47 * SI is data 48 * a += FN(B,C,D); 49 * a += x[sh] + t[sh]; 50 * a = (a << S11) | (a >> (32 - S11)); 51 * a += b; 52 */ 53 54#define BODY1(off,V,FN,SH,A,B,C,D)\ 55 FN(B,C,D)\ 56 LEAL V(A)(DI*1),A;\ 57 ADDL (off)(BP),A;\ 58 ROLL $SH,A;\ 59 ADDL B,A;\ 60 61#define BODY(off,V,FN,SH,A,B,C,D)\ 62 FN(B,C,D)\ 63 LEAL V(A)(DI*1),A;\ 64 ADDL (off)(BP),A;\ 65 ROLL $SH,A;\ 66 ADDL B,A;\ 67 68/* 69 * fn1 = ((c ^ d) & b) ^ d 70 */ 71#define FN1(B,C,D)\ 72 MOVL C,DI;\ 73 XORL D,DI;\ 74 ANDL B,DI;\ 75 XORL D,DI;\ 76 77/* 78 * fn2 = ((b ^ c) & d) ^ c; 79 */ 80#define FN2(B,C,D)\ 81 MOVL B,DI;\ 82 XORL C,DI;\ 83 ANDL D,DI;\ 84 XORL C,DI;\ 85 86/* 87 * fn3 = b ^ c ^ d; 88 */ 89#define FN3(B,C,D)\ 90 MOVL B,DI;\ 91 XORL C,DI;\ 92 XORL D,DI;\ 93 94/* 95 * fn4 = c ^ (b | ~d); 96 */ 97#define FN4(B,C,D)\ 98 MOVL D,DI;\ 99 XORL $-1,DI;\ 100 ORL B,DI;\ 101 XORL C,DI;\ 102 103#define DATA 0 104#define LEN 4 105#define STATE 8 106 107#define EDATA (-4) 108 109 TEXT _md5block+0(SB),$4 110 111 MOVL data+DATA(FP),AX 112 ADDL len+LEN(FP),AX 113 MOVL AX,edata+EDATA(SP) 114 115 MOVL data+DATA(FP),BP 116 117mainloop: 118 MOVL state+STATE(FP),SI 119 MOVL (SI),AX 120 MOVL 4(SI),BX 121 MOVL 8(SI),CX 122 MOVL 12(SI),DX 123 124 BODY1( 0*4,0xd76aa478,FN1,S11,AX,BX,CX,DX) 125 BODY1( 1*4,0xe8c7b756,FN1,S12,DX,AX,BX,CX) 126 BODY1( 2*4,0x242070db,FN1,S13,CX,DX,AX,BX) 127 BODY1( 3*4,0xc1bdceee,FN1,S14,BX,CX,DX,AX) 128 129 BODY1( 4*4,0xf57c0faf,FN1,S11,AX,BX,CX,DX) 130 BODY1( 5*4,0x4787c62a,FN1,S12,DX,AX,BX,CX) 131 BODY1( 6*4,0xa8304613,FN1,S13,CX,DX,AX,BX) 132 BODY1( 7*4,0xfd469501,FN1,S14,BX,CX,DX,AX) 133 134 BODY1( 8*4,0x698098d8,FN1,S11,AX,BX,CX,DX) 135 BODY1( 9*4,0x8b44f7af,FN1,S12,DX,AX,BX,CX) 136 BODY1(10*4,0xffff5bb1,FN1,S13,CX,DX,AX,BX) 137 BODY1(11*4,0x895cd7be,FN1,S14,BX,CX,DX,AX) 138 139 BODY1(12*4,0x6b901122,FN1,S11,AX,BX,CX,DX) 140 BODY1(13*4,0xfd987193,FN1,S12,DX,AX,BX,CX) 141 BODY1(14*4,0xa679438e,FN1,S13,CX,DX,AX,BX) 142 BODY1(15*4,0x49b40821,FN1,S14,BX,CX,DX,AX) 143 144 145 BODY( 1*4,0xf61e2562,FN2,S21,AX,BX,CX,DX) 146 BODY( 6*4,0xc040b340,FN2,S22,DX,AX,BX,CX) 147 BODY(11*4,0x265e5a51,FN2,S23,CX,DX,AX,BX) 148 BODY( 0*4,0xe9b6c7aa,FN2,S24,BX,CX,DX,AX) 149 150 BODY( 5*4,0xd62f105d,FN2,S21,AX,BX,CX,DX) 151 BODY(10*4,0x02441453,FN2,S22,DX,AX,BX,CX) 152 BODY(15*4,0xd8a1e681,FN2,S23,CX,DX,AX,BX) 153 BODY( 4*4,0xe7d3fbc8,FN2,S24,BX,CX,DX,AX) 154 155 BODY( 9*4,0x21e1cde6,FN2,S21,AX,BX,CX,DX) 156 BODY(14*4,0xc33707d6,FN2,S22,DX,AX,BX,CX) 157 BODY( 3*4,0xf4d50d87,FN2,S23,CX,DX,AX,BX) 158 BODY( 8*4,0x455a14ed,FN2,S24,BX,CX,DX,AX) 159 160 BODY(13*4,0xa9e3e905,FN2,S21,AX,BX,CX,DX) 161 BODY( 2*4,0xfcefa3f8,FN2,S22,DX,AX,BX,CX) 162 BODY( 7*4,0x676f02d9,FN2,S23,CX,DX,AX,BX) 163 BODY(12*4,0x8d2a4c8a,FN2,S24,BX,CX,DX,AX) 164 165 166 BODY( 5*4,0xfffa3942,FN3,S31,AX,BX,CX,DX) 167 BODY( 8*4,0x8771f681,FN3,S32,DX,AX,BX,CX) 168 BODY(11*4,0x6d9d6122,FN3,S33,CX,DX,AX,BX) 169 BODY(14*4,0xfde5380c,FN3,S34,BX,CX,DX,AX) 170 171 BODY( 1*4,0xa4beea44,FN3,S31,AX,BX,CX,DX) 172 BODY( 4*4,0x4bdecfa9,FN3,S32,DX,AX,BX,CX) 173 BODY( 7*4,0xf6bb4b60,FN3,S33,CX,DX,AX,BX) 174 BODY(10*4,0xbebfbc70,FN3,S34,BX,CX,DX,AX) 175 176 BODY(13*4,0x289b7ec6,FN3,S31,AX,BX,CX,DX) 177 BODY( 0*4,0xeaa127fa,FN3,S32,DX,AX,BX,CX) 178 BODY( 3*4,0xd4ef3085,FN3,S33,CX,DX,AX,BX) 179 BODY( 6*4,0x04881d05,FN3,S34,BX,CX,DX,AX) 180 181 BODY( 9*4,0xd9d4d039,FN3,S31,AX,BX,CX,DX) 182 BODY(12*4,0xe6db99e5,FN3,S32,DX,AX,BX,CX) 183 BODY(15*4,0x1fa27cf8,FN3,S33,CX,DX,AX,BX) 184 BODY( 2*4,0xc4ac5665,FN3,S34,BX,CX,DX,AX) 185 186 187 BODY( 0*4,0xf4292244,FN4,S41,AX,BX,CX,DX) 188 BODY( 7*4,0x432aff97,FN4,S42,DX,AX,BX,CX) 189 BODY(14*4,0xab9423a7,FN4,S43,CX,DX,AX,BX) 190 BODY( 5*4,0xfc93a039,FN4,S44,BX,CX,DX,AX) 191 192 BODY(12*4,0x655b59c3,FN4,S41,AX,BX,CX,DX) 193 BODY( 3*4,0x8f0ccc92,FN4,S42,DX,AX,BX,CX) 194 BODY(10*4,0xffeff47d,FN4,S43,CX,DX,AX,BX) 195 BODY( 1*4,0x85845dd1,FN4,S44,BX,CX,DX,AX) 196 197 BODY( 8*4,0x6fa87e4f,FN4,S41,AX,BX,CX,DX) 198 BODY(15*4,0xfe2ce6e0,FN4,S42,DX,AX,BX,CX) 199 BODY( 6*4,0xa3014314,FN4,S43,CX,DX,AX,BX) 200 BODY(13*4,0x4e0811a1,FN4,S44,BX,CX,DX,AX) 201 202 BODY( 4*4,0xf7537e82,FN4,S41,AX,BX,CX,DX) 203 BODY(11*4,0xbd3af235,FN4,S42,DX,AX,BX,CX) 204 BODY( 2*4,0x2ad7d2bb,FN4,S43,CX,DX,AX,BX) 205 BODY( 9*4,0xeb86d391,FN4,S44,BX,CX,DX,AX) 206 207 ADDL $(16*4),BP 208 MOVL state+STATE(FP),DI 209 ADDL AX,0(DI) 210 ADDL BX,4(DI) 211 ADDL CX,8(DI) 212 ADDL DX,12(DI) 213 214 MOVL edata+EDATA(SP),DI 215 CMPL BP,DI 216 JCS mainloop 217 218 RET 219 220 END 221