summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/md5
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/md5')
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl304
-rw-r--r--src/lib/libcrypto/md5/md5.h99
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c440
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h195
-rw-r--r--src/lib/libcrypto/md5/md5_one.c77
5 files changed, 1115 insertions, 0 deletions
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl
new file mode 100644
index 0000000000..2c7fb7dd98
--- /dev/null
+++ b/src/lib/libcrypto/md5/asm/md5-586.pl
@@ -0,0 +1,304 @@
1#!/usr/bin/perl
2
3# Normal is the
4# md5_block_x86(MD5_CTX *c, ULONG *X);
5# version, non-normal is the
6# md5_block_x86(MD5_CTX *c, ULONG *X,int blocks);
7
8$normal=0;
9
10push(@INC,"perlasm","../../perlasm");
11require "x86asm.pl";
12
13&asm_init($ARGV[0],$0);
14
15$A="eax";
16$B="ebx";
17$C="ecx";
18$D="edx";
19$tmp1="edi";
20$tmp2="ebp";
21$X="esi";
22
23# What we need to load into $tmp for the next round
24%Ltmp1=("R0",&Np($C), "R1",&Np($C), "R2",&Np($C), "R3",&Np($D));
25@xo=(
26 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # R0
27 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, # R1
28 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, # R2
29 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3
30 );
31
32&md5_block("md5_block_x86");
33&asm_finish();
34
35sub Np
36 {
37 local($p)=@_;
38 local(%n)=($A,$D,$B,$A,$C,$B,$D,$C);
39 return($n{$p});
40 }
41
42sub R0
43 {
44 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
45
46 &mov($tmp1,$C) if $pos < 0;
47 &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one
48
49 # body proper
50
51 &comment("R0 $ki");
52 &xor($tmp1,$d); # F function - part 2
53
54 &and($tmp1,$b); # F function - part 3
55 &lea($a,&DWP($t,$a,$tmp2,1));
56
57 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
58 &xor($tmp1,$d); # F function - part 4
59
60 &add($a,$tmp1);
61 &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0
62 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1
63
64 &rotl($a,$s);
65 &add($a,$b);
66
67 }
68
69sub R1
70 {
71 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
72
73 &comment("R1 $ki");
74
75 &lea($a,&DWP($t,$a,$tmp2,1));
76
77 &xor($tmp1,$b); # G function - part 2
78 &and($tmp1,$d); # G function - part 3
79
80 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
81 &xor($tmp1,$c); # G function - part 4
82
83 &add($a,$tmp1);
84 &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1
85 &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1
86
87 &rotl($a,$s);
88
89 &add($a,$b);
90 }
91
92sub R2
93 {
94 local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
95 # This one is different, only 3 logical operations
96
97if (($n & 1) == 0)
98 {
99 &comment("R2 $ki");
100 # make sure to do 'D' first, not 'B', else we clash with
101 # the last add from the previous round.
102
103 &xor($tmp1,$d); # H function - part 2
104
105 &xor($tmp1,$b); # H function - part 3
106 &lea($a,&DWP($t,$a,$tmp2,1));
107
108 &add($a,$tmp1);
109 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
110
111 &rotl($a,$s);
112
113 &mov($tmp1,&Np($c));
114 }
115else
116 {
117 &comment("R2 $ki");
118 # make sure to do 'D' first, not 'B', else we clash with
119 # the last add from the previous round.
120
121 &lea($a,&DWP($t,$a,$tmp2,1));
122
123 &add($b,$c); # MOVED FORWARD
124 &xor($tmp1,$d); # H function - part 2
125
126 &xor($tmp1,$b); # H function - part 3
127 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
128
129 &add($a,$tmp1);
130 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1
131 &mov($tmp1,-1) if $pos == 1; # I function - part 1
132
133 &rotl($a,$s);
134
135 &add($a,$b);
136 }
137 }
138
139sub R3
140 {
141 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
142
143 &comment("R3 $ki");
144
145 # &not($tmp1)
146 &xor($tmp1,$d) if $pos < 0; # I function - part 2
147
148 &or($tmp1,$b); # I function - part 3
149 &lea($a,&DWP($t,$a,$tmp2,1));
150
151 &xor($tmp1,$c); # I function - part 4
152 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value
153 &mov($tmp2,&wparam(0)) if $pos == 2;
154
155 &add($a,$tmp1);
156 &mov($tmp1,-1) if $pos < 1; # H function - part 1
157 &add($K,64) if $pos >=1 && !$normal;
158
159 &rotl($a,$s);
160
161 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time
162 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0;
163 &add($a,$b);
164 }
165
166
167sub md5_block
168 {
169 local($name)=@_;
170
171 &function_begin_B($name,"",3);
172
173 # parameter 1 is the MD5_CTX structure.
174 # A 0
175 # B 4
176 # C 8
177 # D 12
178
179 &push("esi");
180 &push("edi");
181 &mov($tmp1, &wparam(0)); # edi
182 &mov($X, &wparam(1)); # esi
183 &mov($C, &wparam(2));
184 &push("ebp");
185 &push("ebx");
186 &add($C, $X); # offset we end at
187 &sub($C, 64);
188 &mov($A, &DWP( 0,$tmp1,"",0));
189 &push($C); # Put on the TOS
190 &mov($B, &DWP( 4,$tmp1,"",0));
191 &mov($C, &DWP( 8,$tmp1,"",0));
192 &mov($D, &DWP(12,$tmp1,"",0));
193
194 &set_label("start") unless $normal;
195 &comment("");
196 &comment("R0 section");
197
198 &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478);
199 &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756);
200 &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db);
201 &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee);
202 &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf);
203 &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a);
204 &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613);
205 &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501);
206 &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8);
207 &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af);
208 &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1);
209 &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be);
210 &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122);
211 &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193);
212 &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e);
213 &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821);
214
215 &comment("");
216 &comment("R1 section");
217 &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562);
218 &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340);
219 &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51);
220 &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa);
221 &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d);
222 &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453);
223 &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681);
224 &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8);
225 &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6);
226 &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6);
227 &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87);
228 &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed);
229 &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905);
230 &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8);
231 &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9);
232 &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a);
233
234 &comment("");
235 &comment("R2 section");
236 &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942);
237 &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681);
238 &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122);
239 &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c);
240 &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44);
241 &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9);
242 &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60);
243 &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70);
244 &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6);
245 &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa);
246 &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085);
247 &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05);
248 &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039);
249 &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5);
250 &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8);
251 &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665);
252
253 &comment("");
254 &comment("R3 section");
255 &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244);
256 &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97);
257 &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7);
258 &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039);
259 &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3);
260 &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92);
261 &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d);
262 &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1);
263 &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f);
264 &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0);
265 &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314);
266 &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1);
267 &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82);
268 &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235);
269 &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb);
270 &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391);
271
272 # &mov($tmp2,&wparam(0)); # done in the last R3
273 # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3
274
275 &add($A,$tmp1);
276 &mov($tmp1, &DWP( 4,$tmp2,"",0));
277
278 &add($B,$tmp1);
279 &mov($tmp1, &DWP( 8,$tmp2,"",0));
280
281 &add($C,$tmp1);
282 &mov($tmp1, &DWP(12,$tmp2,"",0));
283
284 &add($D,$tmp1);
285 &mov(&DWP( 0,$tmp2,"",0),$A);
286
287 &mov(&DWP( 4,$tmp2,"",0),$B);
288 &mov($tmp1,&swtmp(0)) unless $normal;
289
290 &mov(&DWP( 8,$tmp2,"",0),$C);
291 &mov(&DWP(12,$tmp2,"",0),$D);
292
293 &cmp($tmp1,$X) unless $normal; # check count
294 &jge(&label("start")) unless $normal;
295
296 &pop("eax"); # pop the temp variable off the stack
297 &pop("ebx");
298 &pop("ebp");
299 &pop("edi");
300 &pop("esi");
301 &ret();
302 &function_end_B($name);
303 }
304
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h
new file mode 100644
index 0000000000..357c6c625d
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5.h
@@ -0,0 +1,99 @@
1/* crypto/md5/md5.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MD5_H
60#define HEADER_MD5_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define MD5_CBLOCK 64
67#define MD5_LBLOCK 16
68#define MD5_BLOCK 16
69#define MD5_LAST_BLOCK 56
70#define MD5_LENGTH_BLOCK 8
71#define MD5_DIGEST_LENGTH 16
72
73typedef struct MD5state_st
74 {
75 unsigned long A,B,C,D;
76 unsigned long Nl,Nh;
77 unsigned long data[MD5_LBLOCK];
78 int num;
79 } MD5_CTX;
80
81#ifndef NOPROTO
82void MD5_Init(MD5_CTX *c);
83void MD5_Update(MD5_CTX *c, unsigned char *data, unsigned long len);
84void MD5_Final(unsigned char *md, MD5_CTX *c);
85unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md);
86void MD5_Transform(MD5_CTX *c, unsigned char *b);
87#else
88void MD5_Init();
89void MD5_Update();
90void MD5_Final();
91unsigned char *MD5();
92void MD5_Transform();
93#endif
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c
new file mode 100644
index 0000000000..43b3498d92
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5_dgst.c
@@ -0,0 +1,440 @@
1/* crypto/md5/md5_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "md5_locl.h"
61
62char *MD5_version="MD5 part of SSLeay 0.9.0b 29-Jun-1998";
63
64/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
65 */
66
67#define INIT_DATA_A (unsigned long)0x67452301L
68#define INIT_DATA_B (unsigned long)0xefcdab89L
69#define INIT_DATA_C (unsigned long)0x98badcfeL
70#define INIT_DATA_D (unsigned long)0x10325476L
71
72#ifndef NOPROTO
73# ifdef MD5_ASM
74 void md5_block_x86(MD5_CTX *c, unsigned long *p,int num);
75# define md5_block md5_block_x86
76# else
77 static void md5_block(MD5_CTX *c, unsigned long *p,int num);
78# endif
79#else
80# ifdef MD5_ASM
81 void md5_block_x86();
82# define md5_block md5_block_x86
83# else
84 static void md5_block();
85# endif
86#endif
87
88void MD5_Init(c)
89MD5_CTX *c;
90 {
91 c->A=INIT_DATA_A;
92 c->B=INIT_DATA_B;
93 c->C=INIT_DATA_C;
94 c->D=INIT_DATA_D;
95 c->Nl=0;
96 c->Nh=0;
97 c->num=0;
98 }
99
100void MD5_Update(c, data, len)
101MD5_CTX *c;
102register unsigned char *data;
103unsigned long len;
104 {
105 register ULONG *p;
106 int sw,sc;
107 ULONG l;
108
109 if (len == 0) return;
110
111 l=(c->Nl+(len<<3))&0xffffffffL;
112 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
113 * Wei Dai <weidai@eskimo.com> for pointing it out. */
114 if (l < c->Nl) /* overflow */
115 c->Nh++;
116 c->Nh+=(len>>29);
117 c->Nl=l;
118
119 if (c->num != 0)
120 {
121 p=c->data;
122 sw=c->num>>2;
123 sc=c->num&0x03;
124
125 if ((c->num+len) >= MD5_CBLOCK)
126 {
127 l= p[sw];
128 p_c2l(data,l,sc);
129 p[sw++]=l;
130 for (; sw<MD5_LBLOCK; sw++)
131 {
132 c2l(data,l);
133 p[sw]=l;
134 }
135 len-=(MD5_CBLOCK-c->num);
136
137 md5_block(c,p,64);
138 c->num=0;
139 /* drop through and do the rest */
140 }
141 else
142 {
143 int ew,ec;
144
145 c->num+=(int)len;
146 if ((sc+len) < 4) /* ugly, add char's to a word */
147 {
148 l= p[sw];
149 p_c2l_p(data,l,sc,len);
150 p[sw]=l;
151 }
152 else
153 {
154 ew=(c->num>>2);
155 ec=(c->num&0x03);
156 l= p[sw];
157 p_c2l(data,l,sc);
158 p[sw++]=l;
159 for (; sw < ew; sw++)
160 { c2l(data,l); p[sw]=l; }
161 if (ec)
162 {
163 c2l_p(data,l,ec);
164 p[sw]=l;
165 }
166 }
167 return;
168 }
169 }
170 /* we now can process the input data in blocks of MD5_CBLOCK
171 * chars and save the leftovers to c->data. */
172#ifdef L_ENDIAN
173 if ((((unsigned long)data)%sizeof(ULONG)) == 0)
174 {
175 sw=(int)len/MD5_CBLOCK;
176 if (sw > 0)
177 {
178 sw*=MD5_CBLOCK;
179 md5_block(c,(ULONG *)data,sw);
180 data+=sw;
181 len-=sw;
182 }
183 }
184#endif
185 p=c->data;
186 while (len >= MD5_CBLOCK)
187 {
188#if defined(L_ENDIAN) || defined(B_ENDIAN)
189 if (p != (unsigned long *)data)
190 memcpy(p,data,MD5_CBLOCK);
191 data+=MD5_CBLOCK;
192#ifdef B_ENDIAN
193 for (sw=(MD5_LBLOCK/4); sw; sw--)
194 {
195 Endian_Reverse32(p[0]);
196 Endian_Reverse32(p[1]);
197 Endian_Reverse32(p[2]);
198 Endian_Reverse32(p[3]);
199 p+=4;
200 }
201#endif
202#else
203 for (sw=(MD5_LBLOCK/4); sw; sw--)
204 {
205 c2l(data,l); *(p++)=l;
206 c2l(data,l); *(p++)=l;
207 c2l(data,l); *(p++)=l;
208 c2l(data,l); *(p++)=l;
209 }
210#endif
211 p=c->data;
212 md5_block(c,p,64);
213 len-=MD5_CBLOCK;
214 }
215 sc=(int)len;
216 c->num=sc;
217 if (sc)
218 {
219 sw=sc>>2; /* words to copy */
220#ifdef L_ENDIAN
221 p[sw]=0;
222 memcpy(p,data,sc);
223#else
224 sc&=0x03;
225 for ( ; sw; sw--)
226 { c2l(data,l); *(p++)=l; }
227 c2l_p(data,l,sc);
228 *p=l;
229#endif
230 }
231 }
232
233void MD5_Transform(c,b)
234MD5_CTX *c;
235unsigned char *b;
236 {
237 ULONG p[16];
238#if !defined(L_ENDIAN)
239 ULONG *q;
240 int i;
241#endif
242
243#if defined(B_ENDIAN) || defined(L_ENDIAN)
244 memcpy(p,b,64);
245#ifdef B_ENDIAN
246 q=p;
247 for (i=(MD5_LBLOCK/4); i; i--)
248 {
249 Endian_Reverse32(q[0]);
250 Endian_Reverse32(q[1]);
251 Endian_Reverse32(q[2]);
252 Endian_Reverse32(q[3]);
253 q+=4;
254 }
255#endif
256#else
257 q=p;
258 for (i=(MD5_LBLOCK/4); i; i--)
259 {
260 ULONG l;
261 c2l(b,l); *(q++)=l;
262 c2l(b,l); *(q++)=l;
263 c2l(b,l); *(q++)=l;
264 c2l(b,l); *(q++)=l;
265 }
266#endif
267 md5_block(c,p,64);
268 }
269
270#ifndef MD5_ASM
271
272static void md5_block(c, X, num)
273MD5_CTX *c;
274register ULONG *X;
275int num;
276 {
277 register ULONG A,B,C,D;
278
279 A=c->A;
280 B=c->B;
281 C=c->C;
282 D=c->D;
283 for (;;)
284 {
285 /* Round 0 */
286 R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
287 R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
288 R0(C,D,A,B,X[ 2],17,0x242070dbL);
289 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
290 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
291 R0(D,A,B,C,X[ 5],12,0x4787c62aL);
292 R0(C,D,A,B,X[ 6],17,0xa8304613L);
293 R0(B,C,D,A,X[ 7],22,0xfd469501L);
294 R0(A,B,C,D,X[ 8], 7,0x698098d8L);
295 R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
296 R0(C,D,A,B,X[10],17,0xffff5bb1L);
297 R0(B,C,D,A,X[11],22,0x895cd7beL);
298 R0(A,B,C,D,X[12], 7,0x6b901122L);
299 R0(D,A,B,C,X[13],12,0xfd987193L);
300 R0(C,D,A,B,X[14],17,0xa679438eL);
301 R0(B,C,D,A,X[15],22,0x49b40821L);
302 /* Round 1 */
303 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
304 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
305 R1(C,D,A,B,X[11],14,0x265e5a51L);
306 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
307 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
308 R1(D,A,B,C,X[10], 9,0x02441453L);
309 R1(C,D,A,B,X[15],14,0xd8a1e681L);
310 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
311 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
312 R1(D,A,B,C,X[14], 9,0xc33707d6L);
313 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
314 R1(B,C,D,A,X[ 8],20,0x455a14edL);
315 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
316 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
317 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
318 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
319 /* Round 2 */
320 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
321 R2(D,A,B,C,X[ 8],11,0x8771f681L);
322 R2(C,D,A,B,X[11],16,0x6d9d6122L);
323 R2(B,C,D,A,X[14],23,0xfde5380cL);
324 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
325 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
326 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
327 R2(B,C,D,A,X[10],23,0xbebfbc70L);
328 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
329 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
330 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
331 R2(B,C,D,A,X[ 6],23,0x04881d05L);
332 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
333 R2(D,A,B,C,X[12],11,0xe6db99e5L);
334 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
335 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
336 /* Round 3 */
337 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
338 R3(D,A,B,C,X[ 7],10,0x432aff97L);
339 R3(C,D,A,B,X[14],15,0xab9423a7L);
340 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
341 R3(A,B,C,D,X[12], 6,0x655b59c3L);
342 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
343 R3(C,D,A,B,X[10],15,0xffeff47dL);
344 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
345 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
346 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
347 R3(C,D,A,B,X[ 6],15,0xa3014314L);
348 R3(B,C,D,A,X[13],21,0x4e0811a1L);
349 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
350 R3(D,A,B,C,X[11],10,0xbd3af235L);
351 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
352 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
353
354 A+=c->A&0xffffffffL;
355 B+=c->B&0xffffffffL;
356 c->A=A;
357 c->B=B;
358 C+=c->C&0xffffffffL;
359 D+=c->D&0xffffffffL;
360 c->C=C;
361 c->D=D;
362 X+=16;
363 num-=64;
364 if (num <= 0) break;
365 }
366 }
367#endif
368
369void MD5_Final(md, c)
370unsigned char *md;
371MD5_CTX *c;
372 {
373 register int i,j;
374 register ULONG l;
375 register ULONG *p;
376 static unsigned char end[4]={0x80,0x00,0x00,0x00};
377 unsigned char *cp=end;
378
379 /* c->num should definitly have room for at least one more byte. */
380 p=c->data;
381 j=c->num;
382 i=j>>2;
383
384 /* purify often complains about the following line as an
385 * Uninitialized Memory Read. While this can be true, the
386 * following p_c2l macro will reset l when that case is true.
387 * This is because j&0x03 contains the number of 'valid' bytes
388 * already in p[i]. If and only if j&0x03 == 0, the UMR will
389 * occur but this is also the only time p_c2l will do
390 * l= *(cp++) instead of l|= *(cp++)
391 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
392 * 'potential bug' */
393#ifdef PURIFY
394 if ((j&0x03) == 0) p[i]=0;
395#endif
396 l=p[i];
397 p_c2l(cp,l,j&0x03);
398 p[i]=l;
399 i++;
400 /* i is the next 'undefined word' */
401 if (c->num >= MD5_LAST_BLOCK)
402 {
403 for (; i<MD5_LBLOCK; i++)
404 p[i]=0;
405 md5_block(c,p,64);
406 i=0;
407 }
408 for (; i<(MD5_LBLOCK-2); i++)
409 p[i]=0;
410 p[MD5_LBLOCK-2]=c->Nl;
411 p[MD5_LBLOCK-1]=c->Nh;
412 md5_block(c,p,64);
413 cp=md;
414 l=c->A; l2c(l,cp);
415 l=c->B; l2c(l,cp);
416 l=c->C; l2c(l,cp);
417 l=c->D; l2c(l,cp);
418
419 /* clear stuff, md5_block may be leaving some stuff on the stack
420 * but I'm not worried :-) */
421 c->num=0;
422/* memset((char *)&c,0,sizeof(c));*/
423 }
424
425#ifdef undef
426int printit(l)
427unsigned long *l;
428 {
429 int i,ii;
430
431 for (i=0; i<2; i++)
432 {
433 for (ii=0; ii<8; ii++)
434 {
435 fprintf(stderr,"%08lx ",l[i*8+ii]);
436 }
437 fprintf(stderr,"\n");
438 }
439 }
440#endif
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
new file mode 100644
index 0000000000..dbbe1b71ca
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5_locl.h
@@ -0,0 +1,195 @@
1/* crypto/md5/md5_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* On sparc, this actually slows things down :-( */
60#if defined(sun)
61#undef B_ENDIAN
62#endif
63
64#include <stdlib.h>
65#include <string.h>
66#include "md5.h"
67
68#define ULONG unsigned long
69#define UCHAR unsigned char
70#define UINT unsigned int
71
72#if defined(NOCONST)
73#define const
74#endif
75
76#undef c2l
77#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
78 l|=(((unsigned long)(*((c)++)))<< 8), \
79 l|=(((unsigned long)(*((c)++)))<<16), \
80 l|=(((unsigned long)(*((c)++)))<<24))
81
82#undef p_c2l
83#define p_c2l(c,l,n) { \
84 switch (n) { \
85 case 0: l =((unsigned long)(*((c)++))); \
86 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
87 case 2: l|=((unsigned long)(*((c)++)))<<16; \
88 case 3: l|=((unsigned long)(*((c)++)))<<24; \
89 } \
90 }
91
92/* NOTE the pointer is not incremented at the end of this */
93#undef c2l_p
94#define c2l_p(c,l,n) { \
95 l=0; \
96 (c)+=n; \
97 switch (n) { \
98 case 3: l =((unsigned long)(*(--(c))))<<16; \
99 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
100 case 1: l|=((unsigned long)(*(--(c)))) ; \
101 } \
102 }
103
104#undef p_c2l_p
105#define p_c2l_p(c,l,sc,len) { \
106 switch (sc) \
107 { \
108 case 0: l =((unsigned long)(*((c)++))); \
109 if (--len == 0) break; \
110 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
111 if (--len == 0) break; \
112 case 2: l|=((unsigned long)(*((c)++)))<<16; \
113 } \
114 }
115
116#undef l2c
117#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
118 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
119 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
120 *((c)++)=(unsigned char)(((l)>>24)&0xff))
121
122/* NOTE - c is not incremented as per l2c */
123#undef l2cn
124#define l2cn(l1,l2,c,n) { \
125 c+=n; \
126 switch (n) { \
127 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
128 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
129 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
130 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
131 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
132 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
133 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
134 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
135 } \
136 }
137
138/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
139#if defined(WIN32)
140/* 5 instructions with rotate instruction, else 9 */
141#define Endian_Reverse32(a) \
142 { \
143 unsigned long l=(a); \
144 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
145 }
146#else
147/* 6 instructions with rotate instruction, else 8 */
148#define Endian_Reverse32(a) \
149 { \
150 unsigned long l=(a); \
151 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
152 (a)=ROTATE(l,16L); \
153 }
154#endif
155/*
156#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
157#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
158*/
159
160/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
161 * simplified to the code below. Wei attributes these optimisations
162 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
163 */
164#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
165#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
166#define H(b,c,d) ((b) ^ (c) ^ (d))
167#define I(b,c,d) (((~(d)) | (b)) ^ (c))
168
169#undef ROTATE
170#if defined(WIN32)
171#define ROTATE(a,n) _lrotl(a,n)
172#else
173#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
174#endif
175
176
177#define R0(a,b,c,d,k,s,t) { \
178 a+=((k)+(t)+F((b),(c),(d))); \
179 a=ROTATE(a,s); \
180 a+=b; };\
181
182#define R1(a,b,c,d,k,s,t) { \
183 a+=((k)+(t)+G((b),(c),(d))); \
184 a=ROTATE(a,s); \
185 a+=b; };
186
187#define R2(a,b,c,d,k,s,t) { \
188 a+=((k)+(t)+H((b),(c),(d))); \
189 a=ROTATE(a,s); \
190 a+=b; };
191
192#define R3(a,b,c,d,k,s,t) { \
193 a+=((k)+(t)+I((b),(c),(d))); \
194 a=ROTATE(a,s); \
195 a+=b; };
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c
new file mode 100644
index 0000000000..ab6bb435f9
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5_one.c
@@ -0,0 +1,77 @@
1/* crypto/md5/md5_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "md5_locl.h"
61
62unsigned char *MD5(d, n, md)
63unsigned char *d;
64unsigned long n;
65unsigned char *md;
66 {
67 MD5_CTX c;
68 static unsigned char m[MD5_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 MD5_Init(&c);
72 MD5_Update(&c,d,n);
73 MD5_Final(md,&c);
74 memset(&c,0,sizeof(c)); /* security consideration */
75 return(md);
76 }
77