summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/md5
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2012-07-13 17:49:55 +0000
committercvs2svn <admin@example.com>2012-07-13 17:49:55 +0000
commit6fdb436ab2cd5b35066babb3a03be7ad0daf1ae2 (patch)
treea760cf389e7ea59961bb306a1f50bf5443205176 /src/lib/libcrypto/md5
parent9204e59073bcf27e1487ec4ac46e981902ddd904 (diff)
downloadopenbsd-OPENBSD_5_2_BASE.tar.gz
openbsd-OPENBSD_5_2_BASE.tar.bz2
openbsd-OPENBSD_5_2_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_5_2_BASE'.OPENBSD_5_2_BASE
Diffstat (limited to 'src/lib/libcrypto/md5')
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl307
-rw-r--r--src/lib/libcrypto/md5/asm/md5-ia64.S992
-rwxr-xr-xsrc/lib/libcrypto/md5/asm/md5-x86_64.pl369
-rw-r--r--src/lib/libcrypto/md5/md5.h117
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c184
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h130
-rw-r--r--src/lib/libcrypto/md5/md5_one.c97
7 files changed, 0 insertions, 2196 deletions
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl
deleted file mode 100644
index 6cb66bb499..0000000000
--- a/src/lib/libcrypto/md5/asm/md5-586.pl
+++ /dev/null
@@ -1,307 +0,0 @@
1#!/usr/local/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
10$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
11push(@INC,"${dir}","${dir}../../perlasm");
12require "x86asm.pl";
13
14&asm_init($ARGV[0],$0);
15
16$A="eax";
17$B="ebx";
18$C="ecx";
19$D="edx";
20$tmp1="edi";
21$tmp2="ebp";
22$X="esi";
23
24# What we need to load into $tmp for the next round
25%Ltmp1=("R0",&Np($C), "R1",&Np($C), "R2",&Np($C), "R3",&Np($D));
26@xo=(
27 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # R0
28 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, # R1
29 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, # R2
30 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3
31 );
32
33&md5_block("md5_block_asm_data_order");
34&asm_finish();
35
36sub Np
37 {
38 local($p)=@_;
39 local(%n)=($A,$D,$B,$A,$C,$B,$D,$C);
40 return($n{$p});
41 }
42
43sub R0
44 {
45 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
46
47 &mov($tmp1,$C) if $pos < 0;
48 &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one
49
50 # body proper
51
52 &comment("R0 $ki");
53 &xor($tmp1,$d); # F function - part 2
54
55 &and($tmp1,$b); # F function - part 3
56 &lea($a,&DWP($t,$a,$tmp2,1));
57
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
66 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
67
68 &add($a,$b);
69 }
70
71sub R1
72 {
73 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
74
75 &comment("R1 $ki");
76
77 &lea($a,&DWP($t,$a,$tmp2,1));
78
79 &xor($tmp1,$b); # G function - part 2
80 &and($tmp1,$d); # G function - part 3
81
82 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
83 &xor($tmp1,$c); # G function - part 4
84
85 &add($a,$tmp1);
86 &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1
87 &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1
88
89 &rotl($a,$s);
90
91 &add($a,$b);
92 }
93
94sub R2
95 {
96 local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
97 # This one is different, only 3 logical operations
98
99if (($n & 1) == 0)
100 {
101 &comment("R2 $ki");
102 # make sure to do 'D' first, not 'B', else we clash with
103 # the last add from the previous round.
104
105 &xor($tmp1,$d); # H function - part 2
106
107 &xor($tmp1,$b); # H function - part 3
108 &lea($a,&DWP($t,$a,$tmp2,1));
109
110 &add($a,$tmp1);
111
112 &rotl($a,$s);
113
114 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
115 &mov($tmp1,&Np($c));
116 }
117else
118 {
119 &comment("R2 $ki");
120 # make sure to do 'D' first, not 'B', else we clash with
121 # the last add from the previous round.
122
123 &lea($a,&DWP($t,$a,$tmp2,1));
124
125 &add($b,$c); # MOVED FORWARD
126 &xor($tmp1,$d); # H function - part 2
127
128 &xor($tmp1,$b); # H function - part 3
129 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
130
131 &add($a,$tmp1);
132 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1
133 &mov($tmp1,-1) if $pos == 1; # I function - part 1
134
135 &rotl($a,$s);
136
137 &add($a,$b);
138 }
139 }
140
141sub R3
142 {
143 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
144
145 &comment("R3 $ki");
146
147 # &not($tmp1)
148 &xor($tmp1,$d) if $pos < 0; # I function - part 2
149
150 &or($tmp1,$b); # I function - part 3
151 &lea($a,&DWP($t,$a,$tmp2,1));
152
153 &xor($tmp1,$c); # I function - part 4
154 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value
155 &mov($tmp2,&wparam(0)) if $pos == 2;
156
157 &add($a,$tmp1);
158 &mov($tmp1,-1) if $pos < 1; # H function - part 1
159 &add($K,64) if $pos >=1 && !$normal;
160
161 &rotl($a,$s);
162
163 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time
164 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0;
165 &add($a,$b);
166 }
167
168
169sub md5_block
170 {
171 local($name)=@_;
172
173 &function_begin_B($name,"",3);
174
175 # parameter 1 is the MD5_CTX structure.
176 # A 0
177 # B 4
178 # C 8
179 # D 12
180
181 &push("esi");
182 &push("edi");
183 &mov($tmp1, &wparam(0)); # edi
184 &mov($X, &wparam(1)); # esi
185 &mov($C, &wparam(2));
186 &push("ebp");
187 &shl($C, 6);
188 &push("ebx");
189 &add($C, $X); # offset we end at
190 &sub($C, 64);
191 &mov($A, &DWP( 0,$tmp1,"",0));
192 &push($C); # Put on the TOS
193 &mov($B, &DWP( 4,$tmp1,"",0));
194 &mov($C, &DWP( 8,$tmp1,"",0));
195 &mov($D, &DWP(12,$tmp1,"",0));
196
197 &set_label("start") unless $normal;
198 &comment("");
199 &comment("R0 section");
200
201 &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478);
202 &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756);
203 &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db);
204 &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee);
205 &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf);
206 &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a);
207 &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613);
208 &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501);
209 &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8);
210 &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af);
211 &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1);
212 &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be);
213 &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122);
214 &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193);
215 &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e);
216 &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821);
217
218 &comment("");
219 &comment("R1 section");
220 &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562);
221 &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340);
222 &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51);
223 &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa);
224 &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d);
225 &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453);
226 &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681);
227 &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8);
228 &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6);
229 &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6);
230 &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87);
231 &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed);
232 &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905);
233 &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8);
234 &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9);
235 &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a);
236
237 &comment("");
238 &comment("R2 section");
239 &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942);
240 &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681);
241 &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122);
242 &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c);
243 &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44);
244 &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9);
245 &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60);
246 &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70);
247 &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6);
248 &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa);
249 &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085);
250 &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05);
251 &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039);
252 &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5);
253 &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8);
254 &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665);
255
256 &comment("");
257 &comment("R3 section");
258 &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244);
259 &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97);
260 &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7);
261 &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039);
262 &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3);
263 &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92);
264 &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d);
265 &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1);
266 &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f);
267 &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0);
268 &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314);
269 &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1);
270 &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82);
271 &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235);
272 &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb);
273 &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391);
274
275 # &mov($tmp2,&wparam(0)); # done in the last R3
276 # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3
277
278 &add($A,$tmp1);
279 &mov($tmp1, &DWP( 4,$tmp2,"",0));
280
281 &add($B,$tmp1);
282 &mov($tmp1, &DWP( 8,$tmp2,"",0));
283
284 &add($C,$tmp1);
285 &mov($tmp1, &DWP(12,$tmp2,"",0));
286
287 &add($D,$tmp1);
288 &mov(&DWP( 0,$tmp2,"",0),$A);
289
290 &mov(&DWP( 4,$tmp2,"",0),$B);
291 &mov($tmp1,&swtmp(0)) unless $normal;
292
293 &mov(&DWP( 8,$tmp2,"",0),$C);
294 &mov(&DWP(12,$tmp2,"",0),$D);
295
296 &cmp($tmp1,$X) unless $normal; # check count
297 &jae(&label("start")) unless $normal;
298
299 &pop("eax"); # pop the temp variable off the stack
300 &pop("ebx");
301 &pop("ebp");
302 &pop("edi");
303 &pop("esi");
304 &ret();
305 &function_end_B($name);
306 }
307
diff --git a/src/lib/libcrypto/md5/asm/md5-ia64.S b/src/lib/libcrypto/md5/asm/md5-ia64.S
deleted file mode 100644
index e7de08d46a..0000000000
--- a/src/lib/libcrypto/md5/asm/md5-ia64.S
+++ /dev/null
@@ -1,992 +0,0 @@
1/* Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
2
3Permission is hereby granted, free of charge, to any person obtaining
4a copy of this software and associated documentation files (the
5"Software"), to deal in the Software without restriction, including
6without limitation the rights to use, copy, modify, merge, publish,
7distribute, sublicense, and/or sell copies of the Software, and to
8permit persons to whom the Software is furnished to do so, subject to
9the following conditions:
10
11The above copyright notice and this permission notice shall be
12included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
21
22// Common registers are assigned as follows:
23//
24// COMMON
25//
26// t0 Const Tbl Ptr TPtr
27// t1 Round Constant TRound
28// t4 Block residual LenResid
29// t5 Residual Data DTmp
30//
31// {in,out}0 Block 0 Cycle RotateM0
32// {in,out}1 Block Value 12 M12
33// {in,out}2 Block Value 8 M8
34// {in,out}3 Block Value 4 M4
35// {in,out}4 Block Value 0 M0
36// {in,out}5 Block 1 Cycle RotateM1
37// {in,out}6 Block Value 13 M13
38// {in,out}7 Block Value 9 M9
39// {in,out}8 Block Value 5 M5
40// {in,out}9 Block Value 1 M1
41// {in,out}10 Block 2 Cycle RotateM2
42// {in,out}11 Block Value 14 M14
43// {in,out}12 Block Value 10 M10
44// {in,out}13 Block Value 6 M6
45// {in,out}14 Block Value 2 M2
46// {in,out}15 Block 3 Cycle RotateM3
47// {in,out}16 Block Value 15 M15
48// {in,out}17 Block Value 11 M11
49// {in,out}18 Block Value 7 M7
50// {in,out}19 Block Value 3 M3
51// {in,out}20 Scratch Z
52// {in,out}21 Scratch Y
53// {in,out}22 Scratch X
54// {in,out}23 Scratch W
55// {in,out}24 Digest A A
56// {in,out}25 Digest B B
57// {in,out}26 Digest C C
58// {in,out}27 Digest D D
59// {in,out}28 Active Data Ptr DPtr
60// in28 Dummy Value -
61// out28 Dummy Value -
62// bt0 Coroutine Link QUICK_RTN
63//
64/// These predicates are used for computing the padding block(s) and
65/// are shared between the driver and digest co-routines
66//
67// pt0 Extra Pad Block pExtra
68// pt1 Load next word pLoad
69// pt2 Skip next word pSkip
70// pt3 Search for Pad pNoPad
71// pt4 Pad Word 0 pPad0
72// pt5 Pad Word 1 pPad1
73// pt6 Pad Word 2 pPad2
74// pt7 Pad Word 3 pPad3
75
76#define DTmp r19
77#define LenResid r18
78#define QUICK_RTN b6
79#define TPtr r14
80#define TRound r15
81#define pExtra p6
82#define pLoad p7
83#define pNoPad p9
84#define pPad0 p10
85#define pPad1 p11
86#define pPad2 p12
87#define pPad3 p13
88#define pSkip p8
89
90#define A_ out24
91#define B_ out25
92#define C_ out26
93#define D_ out27
94#define DPtr_ out28
95#define M0_ out4
96#define M1_ out9
97#define M10_ out12
98#define M11_ out17
99#define M12_ out1
100#define M13_ out6
101#define M14_ out11
102#define M15_ out16
103#define M2_ out14
104#define M3_ out19
105#define M4_ out3
106#define M5_ out8
107#define M6_ out13
108#define M7_ out18
109#define M8_ out2
110#define M9_ out7
111#define RotateM0_ out0
112#define RotateM1_ out5
113#define RotateM2_ out10
114#define RotateM3_ out15
115#define W_ out23
116#define X_ out22
117#define Y_ out21
118#define Z_ out20
119
120#define A in24
121#define B in25
122#define C in26
123#define D in27
124#define DPtr in28
125#define M0 in4
126#define M1 in9
127#define M10 in12
128#define M11 in17
129#define M12 in1
130#define M13 in6
131#define M14 in11
132#define M15 in16
133#define M2 in14
134#define M3 in19
135#define M4 in3
136#define M5 in8
137#define M6 in13
138#define M7 in18
139#define M8 in2
140#define M9 in7
141#define RotateM0 in0
142#define RotateM1 in5
143#define RotateM2 in10
144#define RotateM3 in15
145#define W in23
146#define X in22
147#define Y in21
148#define Z in20
149
150/* register stack configuration for md5_block_asm_data_order(): */
151#define MD5_NINP 3
152#define MD5_NLOC 0
153#define MD5_NOUT 29
154#define MD5_NROT 0
155
156/* register stack configuration for helpers: */
157#define _NINPUTS MD5_NOUT
158#define _NLOCALS 0
159#define _NOUTPUT 0
160#define _NROTATE 24 /* this must be <= _NINPUTS */
161
162#if defined(_HPUX_SOURCE) && !defined(_LP64)
163#define ADDP addp4
164#else
165#define ADDP add
166#endif
167
168#if defined(_HPUX_SOURCE) || defined(B_ENDIAN)
169#define HOST_IS_BIG_ENDIAN
170#endif
171
172// Macros for getting the left and right portions of little-endian words
173
174#define GETLW(dst, src, align) dep.z dst = src, 32 - 8 * align, 8 * align
175#define GETRW(dst, src, align) extr.u dst = src, 8 * align, 32 - 8 * align
176
177// MD5 driver
178//
179// Reads an input block, then calls the digest block
180// subroutine and adds the results to the accumulated
181// digest. It allocates 32 outs which the subroutine
182// uses as it's inputs and rotating
183// registers. Initializes the round constant pointer and
184// takes care of saving/restoring ar.lc
185//
186/// INPUT
187//
188// in0 Context Ptr CtxPtr0
189// in1 Input Data Ptr DPtrIn
190// in2 Integral Blocks BlockCount
191// rp Return Address -
192//
193/// CODE
194//
195// v2 Input Align InAlign
196// t0 Shared w/digest -
197// t1 Shared w/digest -
198// t2 Shared w/digest -
199// t3 Shared w/digest -
200// t4 Shared w/digest -
201// t5 Shared w/digest -
202// t6 PFS Save PFSSave
203// t7 ar.lc Save LCSave
204// t8 Saved PR PRSave
205// t9 2nd CtxPtr CtxPtr1
206// t10 Table Base CTable
207// t11 Table[0] CTable0
208// t13 Accumulator A AccumA
209// t14 Accumulator B AccumB
210// t15 Accumulator C AccumC
211// t16 Accumulator D AccumD
212// pt0 Shared w/digest -
213// pt1 Shared w/digest -
214// pt2 Shared w/digest -
215// pt3 Shared w/digest -
216// pt4 Shared w/digest -
217// pt5 Shared w/digest -
218// pt6 Shared w/digest -
219// pt7 Shared w/digest -
220// pt8 Not Aligned pOff
221// pt8 Blocks Left pAgain
222
223#define AccumA r27
224#define AccumB r28
225#define AccumC r29
226#define AccumD r30
227#define CTable r24
228#define CTable0 r25
229#define CtxPtr0 in0
230#define CtxPtr1 r23
231#define DPtrIn in1
232#define BlockCount in2
233#define InAlign r10
234#define LCSave r21
235#define PFSSave r20
236#define PRSave r22
237#define pAgain p63
238#define pOff p63
239
240 .text
241
242/* md5_block_asm_data_order(MD5_CTX *c, const void *data, size_t num)
243
244 where:
245 c: a pointer to a structure of this type:
246
247 typedef struct MD5state_st
248 {
249 MD5_LONG A,B,C,D;
250 MD5_LONG Nl,Nh;
251 MD5_LONG data[MD5_LBLOCK];
252 unsigned int num;
253 }
254 MD5_CTX;
255
256 data: a pointer to the input data (may be misaligned)
257 num: the number of 16-byte blocks to hash (i.e., the length
258 of DATA is 16*NUM.
259
260 */
261
262 .type md5_block_asm_data_order, @function
263 .global md5_block_asm_data_order
264 .align 32
265 .proc md5_block_asm_data_order
266md5_block_asm_data_order:
267.md5_block:
268 .prologue
269{ .mmi
270 .save ar.pfs, PFSSave
271 alloc PFSSave = ar.pfs, MD5_NINP, MD5_NLOC, MD5_NOUT, MD5_NROT
272 ADDP CtxPtr1 = 8, CtxPtr0
273 mov CTable = ip
274}
275{ .mmi
276 ADDP DPtrIn = 0, DPtrIn
277 ADDP CtxPtr0 = 0, CtxPtr0
278 .save ar.lc, LCSave
279 mov LCSave = ar.lc
280}
281;;
282{ .mmi
283 add CTable = .md5_tbl_data_order#-.md5_block#, CTable
284 and InAlign = 0x3, DPtrIn
285}
286
287{ .mmi
288 ld4 AccumA = [CtxPtr0], 4
289 ld4 AccumC = [CtxPtr1], 4
290 .save pr, PRSave
291 mov PRSave = pr
292 .body
293}
294;;
295{ .mmi
296 ld4 AccumB = [CtxPtr0]
297 ld4 AccumD = [CtxPtr1]
298 dep DPtr_ = 0, DPtrIn, 0, 2
299} ;;
300#ifdef HOST_IS_BIG_ENDIAN
301 rum psr.be;; // switch to little-endian
302#endif
303{ .mmb
304 ld4 CTable0 = [CTable], 4
305 cmp.ne pOff, p0 = 0, InAlign
306(pOff) br.cond.spnt.many .md5_unaligned
307} ;;
308
309// The FF load/compute loop rotates values three times, so that
310// loading into M12 here produces the M0 value, M13 -> M1, etc.
311
312.md5_block_loop0:
313{ .mmi
314 ld4 M12_ = [DPtr_], 4
315 mov TPtr = CTable
316 mov TRound = CTable0
317} ;;
318{ .mmi
319 ld4 M13_ = [DPtr_], 4
320 mov A_ = AccumA
321 mov B_ = AccumB
322} ;;
323{ .mmi
324 ld4 M14_ = [DPtr_], 4
325 mov C_ = AccumC
326 mov D_ = AccumD
327} ;;
328{ .mmb
329 ld4 M15_ = [DPtr_], 4
330 add BlockCount = -1, BlockCount
331 br.call.sptk.many QUICK_RTN = md5_digest_block0
332} ;;
333
334// Now, we add the new digest values and do some clean-up
335// before checking if there's another full block to process
336
337{ .mmi
338 add AccumA = AccumA, A_
339 add AccumB = AccumB, B_
340 cmp.ne pAgain, p0 = 0, BlockCount
341}
342{ .mib
343 add AccumC = AccumC, C_
344 add AccumD = AccumD, D_
345(pAgain) br.cond.dptk.many .md5_block_loop0
346} ;;
347
348.md5_exit:
349#ifdef HOST_IS_BIG_ENDIAN
350 sum psr.be;; // switch back to big-endian mode
351#endif
352{ .mmi
353 st4 [CtxPtr0] = AccumB, -4
354 st4 [CtxPtr1] = AccumD, -4
355 mov pr = PRSave, 0x1ffff ;;
356}
357{ .mmi
358 st4 [CtxPtr0] = AccumA
359 st4 [CtxPtr1] = AccumC
360 mov ar.lc = LCSave
361} ;;
362{ .mib
363 mov ar.pfs = PFSSave
364 br.ret.sptk.few rp
365} ;;
366
367#define MD5UNALIGNED(offset) \
368.md5_process##offset: \
369{ .mib ; \
370 nop 0x0 ; \
371 GETRW(DTmp, DTmp, offset) ; \
372} ;; \
373.md5_block_loop##offset: \
374{ .mmi ; \
375 ld4 Y_ = [DPtr_], 4 ; \
376 mov TPtr = CTable ; \
377 mov TRound = CTable0 ; \
378} ;; \
379{ .mmi ; \
380 ld4 M13_ = [DPtr_], 4 ; \
381 mov A_ = AccumA ; \
382 mov B_ = AccumB ; \
383} ;; \
384{ .mii ; \
385 ld4 M14_ = [DPtr_], 4 ; \
386 GETLW(W_, Y_, offset) ; \
387 mov C_ = AccumC ; \
388} \
389{ .mmi ; \
390 mov D_ = AccumD ;; \
391 or M12_ = W_, DTmp ; \
392 GETRW(DTmp, Y_, offset) ; \
393} \
394{ .mib ; \
395 ld4 M15_ = [DPtr_], 4 ; \
396 add BlockCount = -1, BlockCount ; \
397 br.call.sptk.many QUICK_RTN = md5_digest_block##offset; \
398} ;; \
399{ .mmi ; \
400 add AccumA = AccumA, A_ ; \
401 add AccumB = AccumB, B_ ; \
402 cmp.ne pAgain, p0 = 0, BlockCount ; \
403} \
404{ .mib ; \
405 add AccumC = AccumC, C_ ; \
406 add AccumD = AccumD, D_ ; \
407(pAgain) br.cond.dptk.many .md5_block_loop##offset ; \
408} ;; \
409{ .mib ; \
410 nop 0x0 ; \
411 nop 0x0 ; \
412 br.cond.sptk.many .md5_exit ; \
413} ;;
414
415 .align 32
416.md5_unaligned:
417//
418// Because variable shifts are expensive, we special case each of
419// the four alignements. In practice, this won't hurt too much
420// since only one working set of code will be loaded.
421//
422{ .mib
423 ld4 DTmp = [DPtr_], 4
424 cmp.eq pOff, p0 = 1, InAlign
425(pOff) br.cond.dpnt.many .md5_process1
426} ;;
427{ .mib
428 cmp.eq pOff, p0 = 2, InAlign
429 nop 0x0
430(pOff) br.cond.dpnt.many .md5_process2
431} ;;
432 MD5UNALIGNED(3)
433 MD5UNALIGNED(1)
434 MD5UNALIGNED(2)
435
436 .endp md5_block_asm_data_order
437
438
439// MD5 Perform the F function and load
440//
441// Passed the first 4 words (M0 - M3) and initial (A, B, C, D) values,
442// computes the FF() round of functions, then branches to the common
443// digest code to finish up with GG(), HH, and II().
444//
445// INPUT
446//
447// rp Return Address -
448//
449// CODE
450//
451// v0 PFS bit bucket PFS
452// v1 Loop Trip Count LTrip
453// pt0 Load next word pMore
454
455/* For F round: */
456#define LTrip r9
457#define PFS r8
458#define pMore p6
459
460/* For GHI rounds: */
461#define T r9
462#define U r10
463#define V r11
464
465#define COMPUTE(a, b, s, M, R) \
466{ \
467 .mii ; \
468 ld4 TRound = [TPtr], 4 ; \
469 dep.z Y = Z, 32, 32 ;; \
470 shrp Z = Z, Y, 64 - s ; \
471} ;; \
472{ \
473 .mmi ; \
474 add a = Z, b ; \
475 mov R = M ; \
476 nop 0x0 ; \
477} ;;
478
479#define LOOP(a, b, s, M, R, label) \
480{ .mii ; \
481 ld4 TRound = [TPtr], 4 ; \
482 dep.z Y = Z, 32, 32 ;; \
483 shrp Z = Z, Y, 64 - s ; \
484} ;; \
485{ .mib ; \
486 add a = Z, b ; \
487 mov R = M ; \
488 br.ctop.sptk.many label ; \
489} ;;
490
491// G(B, C, D) = (B & D) | (C & ~D)
492
493#define G(a, b, c, d, M) \
494{ .mmi ; \
495 add Z = M, TRound ; \
496 and Y = b, d ; \
497 andcm X = c, d ; \
498} ;; \
499{ .mii ; \
500 add Z = Z, a ; \
501 or Y = Y, X ;; \
502 add Z = Z, Y ; \
503} ;;
504
505// H(B, C, D) = B ^ C ^ D
506
507#define H(a, b, c, d, M) \
508{ .mmi ; \
509 add Z = M, TRound ; \
510 xor Y = b, c ; \
511 nop 0x0 ; \
512} ;; \
513{ .mii ; \
514 add Z = Z, a ; \
515 xor Y = Y, d ;; \
516 add Z = Z, Y ; \
517} ;;
518
519// I(B, C, D) = C ^ (B | ~D)
520//
521// However, since we have an andcm operator, we use the fact that
522//
523// Y ^ Z == ~Y ^ ~Z
524//
525// to rewrite the expression as
526//
527// I(B, C, D) = ~C ^ (~B & D)
528
529#define I(a, b, c, d, M) \
530{ .mmi ; \
531 add Z = M, TRound ; \
532 andcm Y = d, b ; \
533 andcm X = -1, c ; \
534} ;; \
535{ .mii ; \
536 add Z = Z, a ; \
537 xor Y = Y, X ;; \
538 add Z = Z, Y ; \
539} ;;
540
541#define GG4(label) \
542 G(A, B, C, D, M0) \
543 COMPUTE(A, B, 5, M0, RotateM0) \
544 G(D, A, B, C, M1) \
545 COMPUTE(D, A, 9, M1, RotateM1) \
546 G(C, D, A, B, M2) \
547 COMPUTE(C, D, 14, M2, RotateM2) \
548 G(B, C, D, A, M3) \
549 LOOP(B, C, 20, M3, RotateM3, label)
550
551#define HH4(label) \
552 H(A, B, C, D, M0) \
553 COMPUTE(A, B, 4, M0, RotateM0) \
554 H(D, A, B, C, M1) \
555 COMPUTE(D, A, 11, M1, RotateM1) \
556 H(C, D, A, B, M2) \
557 COMPUTE(C, D, 16, M2, RotateM2) \
558 H(B, C, D, A, M3) \
559 LOOP(B, C, 23, M3, RotateM3, label)
560
561#define II4(label) \
562 I(A, B, C, D, M0) \
563 COMPUTE(A, B, 6, M0, RotateM0) \
564 I(D, A, B, C, M1) \
565 COMPUTE(D, A, 10, M1, RotateM1) \
566 I(C, D, A, B, M2) \
567 COMPUTE(C, D, 15, M2, RotateM2) \
568 I(B, C, D, A, M3) \
569 LOOP(B, C, 21, M3, RotateM3, label)
570
571#define FFLOAD(a, b, c, d, M, N, s) \
572{ .mii ; \
573(pMore) ld4 N = [DPtr], 4 ; \
574 add Z = M, TRound ; \
575 and Y = c, b ; \
576} \
577{ .mmi ; \
578 andcm X = d, b ;; \
579 add Z = Z, a ; \
580 or Y = Y, X ; \
581} ;; \
582{ .mii ; \
583 ld4 TRound = [TPtr], 4 ; \
584 add Z = Z, Y ;; \
585 dep.z Y = Z, 32, 32 ; \
586} ;; \
587{ .mii ; \
588 nop 0x0 ; \
589 shrp Z = Z, Y, 64 - s ;; \
590 add a = Z, b ; \
591} ;;
592
593#define FFLOOP(a, b, c, d, M, N, s, dest) \
594{ .mii ; \
595(pMore) ld4 N = [DPtr], 4 ; \
596 add Z = M, TRound ; \
597 and Y = c, b ; \
598} \
599{ .mmi ; \
600 andcm X = d, b ;; \
601 add Z = Z, a ; \
602 or Y = Y, X ; \
603} ;; \
604{ .mii ; \
605 ld4 TRound = [TPtr], 4 ; \
606 add Z = Z, Y ;; \
607 dep.z Y = Z, 32, 32 ; \
608} ;; \
609{ .mii ; \
610 nop 0x0 ; \
611 shrp Z = Z, Y, 64 - s ;; \
612 add a = Z, b ; \
613} \
614{ .mib ; \
615 cmp.ne pMore, p0 = 0, LTrip ; \
616 add LTrip = -1, LTrip ; \
617 br.ctop.dptk.many dest ; \
618} ;;
619
620 .type md5_digest_block0, @function
621 .align 32
622
623 .proc md5_digest_block0
624 .prologue
625md5_digest_block0:
626 .altrp QUICK_RTN
627 .body
628{ .mmi
629 alloc PFS = ar.pfs, _NINPUTS, _NLOCALS, _NOUTPUT, _NROTATE
630 mov LTrip = 2
631 mov ar.lc = 3
632} ;;
633{ .mii
634 cmp.eq pMore, p0 = r0, r0
635 mov ar.ec = 0
636 nop 0x0
637} ;;
638
639.md5_FF_round0:
640 FFLOAD(A, B, C, D, M12, RotateM0, 7)
641 FFLOAD(D, A, B, C, M13, RotateM1, 12)
642 FFLOAD(C, D, A, B, M14, RotateM2, 17)
643 FFLOOP(B, C, D, A, M15, RotateM3, 22, .md5_FF_round0)
644 //
645 // !!! Fall through to md5_digest_GHI
646 //
647 .endp md5_digest_block0
648
649 .type md5_digest_GHI, @function
650 .align 32
651
652 .proc md5_digest_GHI
653 .prologue
654 .regstk _NINPUTS, _NLOCALS, _NOUTPUT, _NROTATE
655md5_digest_GHI:
656 .altrp QUICK_RTN
657 .body
658//
659// The following sequence shuffles the block counstants round for the
660// next round:
661//
662// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
663// 1 6 11 0 5 10 14 4 9 14 3 8 13 2 7 12
664//
665{ .mmi
666 mov Z = M0
667 mov Y = M15
668 mov ar.lc = 3
669}
670{ .mmi
671 mov X = M2
672 mov W = M9
673 mov V = M4
674} ;;
675
676{ .mmi
677 mov M0 = M1
678 mov M15 = M12
679 mov ar.ec = 1
680}
681{ .mmi
682 mov M2 = M11
683 mov M9 = M14
684 mov M4 = M5
685} ;;
686
687{ .mmi
688 mov M1 = M6
689 mov M12 = M13
690 mov U = M3
691}
692{ .mmi
693 mov M11 = M8
694 mov M14 = M7
695 mov M5 = M10
696} ;;
697
698{ .mmi
699 mov M6 = Y
700 mov M13 = X
701 mov M3 = Z
702}
703{ .mmi
704 mov M8 = W
705 mov M7 = V
706 mov M10 = U
707} ;;
708
709.md5_GG_round:
710 GG4(.md5_GG_round)
711
712// The following sequence shuffles the block constants round for the
713// next round:
714//
715// 1 6 11 0 5 10 14 4 9 14 3 8 13 2 7 12
716// 5 8 11 14 1 4 7 10 13 0 3 6 9 12 15 2
717
718{ .mmi
719 mov Z = M0
720 mov Y = M1
721 mov ar.lc = 3
722}
723{ .mmi
724 mov X = M3
725 mov W = M5
726 mov V = M6
727} ;;
728
729{ .mmi
730 mov M0 = M4
731 mov M1 = M11
732 mov ar.ec = 1
733}
734{ .mmi
735 mov M3 = M9
736 mov U = M8
737 mov T = M13
738} ;;
739
740{ .mmi
741 mov M4 = Z
742 mov M11 = Y
743 mov M5 = M7
744}
745{ .mmi
746 mov M6 = M14
747 mov M8 = M12
748 mov M13 = M15
749} ;;
750
751{ .mmi
752 mov M7 = W
753 mov M14 = V
754 nop 0x0
755}
756{ .mmi
757 mov M9 = X
758 mov M12 = U
759 mov M15 = T
760} ;;
761
762.md5_HH_round:
763 HH4(.md5_HH_round)
764
765// The following sequence shuffles the block constants round for the
766// next round:
767//
768// 5 8 11 14 1 4 7 10 13 0 3 6 9 12 15 2
769// 0 7 14 5 12 3 10 1 8 15 6 13 4 11 2 9
770
771{ .mmi
772 mov Z = M0
773 mov Y = M15
774 mov ar.lc = 3
775}
776{ .mmi
777 mov X = M10
778 mov W = M1
779 mov V = M4
780} ;;
781
782{ .mmi
783 mov M0 = M9
784 mov M15 = M12
785 mov ar.ec = 1
786}
787{ .mmi
788 mov M10 = M11
789 mov M1 = M6
790 mov M4 = M13
791} ;;
792
793{ .mmi
794 mov M9 = M14
795 mov M12 = M5
796 mov U = M3
797}
798{ .mmi
799 mov M11 = M8
800 mov M6 = M7
801 mov M13 = M2
802} ;;
803
804{ .mmi
805 mov M14 = Y
806 mov M5 = X
807 mov M3 = Z
808}
809{ .mmi
810 mov M8 = W
811 mov M7 = V
812 mov M2 = U
813} ;;
814
815.md5_II_round:
816 II4(.md5_II_round)
817
818{ .mib
819 nop 0x0
820 nop 0x0
821 br.ret.sptk.many QUICK_RTN
822} ;;
823
824 .endp md5_digest_GHI
825
826#define FFLOADU(a, b, c, d, M, P, N, s, offset) \
827{ .mii ; \
828(pMore) ld4 N = [DPtr], 4 ; \
829 add Z = M, TRound ; \
830 and Y = c, b ; \
831} \
832{ .mmi ; \
833 andcm X = d, b ;; \
834 add Z = Z, a ; \
835 or Y = Y, X ; \
836} ;; \
837{ .mii ; \
838 ld4 TRound = [TPtr], 4 ; \
839 GETLW(W, P, offset) ; \
840 add Z = Z, Y ; \
841} ;; \
842{ .mii ; \
843 or W = W, DTmp ; \
844 dep.z Y = Z, 32, 32 ;; \
845 shrp Z = Z, Y, 64 - s ; \
846} ;; \
847{ .mii ; \
848 add a = Z, b ; \
849 GETRW(DTmp, P, offset) ; \
850 mov P = W ; \
851} ;;
852
853#define FFLOOPU(a, b, c, d, M, P, N, s, offset) \
854{ .mii ; \
855(pMore) ld4 N = [DPtr], 4 ; \
856 add Z = M, TRound ; \
857 and Y = c, b ; \
858} \
859{ .mmi ; \
860 andcm X = d, b ;; \
861 add Z = Z, a ; \
862 or Y = Y, X ; \
863} ;; \
864{ .mii ; \
865 ld4 TRound = [TPtr], 4 ; \
866(pMore) GETLW(W, P, offset) ; \
867 add Z = Z, Y ; \
868} ;; \
869{ .mii ; \
870(pMore) or W = W, DTmp ; \
871 dep.z Y = Z, 32, 32 ;; \
872 shrp Z = Z, Y, 64 - s ; \
873} ;; \
874{ .mii ; \
875 add a = Z, b ; \
876(pMore) GETRW(DTmp, P, offset) ; \
877(pMore) mov P = W ; \
878} \
879{ .mib ; \
880 cmp.ne pMore, p0 = 0, LTrip ; \
881 add LTrip = -1, LTrip ; \
882 br.ctop.sptk.many .md5_FF_round##offset ; \
883} ;;
884
885#define MD5FBLOCK(offset) \
886 .type md5_digest_block##offset, @function ; \
887 \
888 .align 32 ; \
889 .proc md5_digest_block##offset ; \
890 .prologue ; \
891 .altrp QUICK_RTN ; \
892 .body ; \
893md5_digest_block##offset: \
894{ .mmi ; \
895 alloc PFS = ar.pfs, _NINPUTS, _NLOCALS, _NOUTPUT, _NROTATE ; \
896 mov LTrip = 2 ; \
897 mov ar.lc = 3 ; \
898} ;; \
899{ .mii ; \
900 cmp.eq pMore, p0 = r0, r0 ; \
901 mov ar.ec = 0 ; \
902 nop 0x0 ; \
903} ;; \
904 \
905 .pred.rel "mutex", pLoad, pSkip ; \
906.md5_FF_round##offset: \
907 FFLOADU(A, B, C, D, M12, M13, RotateM0, 7, offset) \
908 FFLOADU(D, A, B, C, M13, M14, RotateM1, 12, offset) \
909 FFLOADU(C, D, A, B, M14, M15, RotateM2, 17, offset) \
910 FFLOOPU(B, C, D, A, M15, RotateM0, RotateM3, 22, offset) \
911 \
912{ .mib ; \
913 nop 0x0 ; \
914 nop 0x0 ; \
915 br.cond.sptk.many md5_digest_GHI ; \
916} ;; \
917 .endp md5_digest_block##offset
918
919MD5FBLOCK(1)
920MD5FBLOCK(2)
921MD5FBLOCK(3)
922
923 .align 64
924 .type md5_constants, @object
925md5_constants:
926.md5_tbl_data_order: // To ensure little-endian data
927 // order, code as bytes.
928 data1 0x78, 0xa4, 0x6a, 0xd7 // 0
929 data1 0x56, 0xb7, 0xc7, 0xe8 // 1
930 data1 0xdb, 0x70, 0x20, 0x24 // 2
931 data1 0xee, 0xce, 0xbd, 0xc1 // 3
932 data1 0xaf, 0x0f, 0x7c, 0xf5 // 4
933 data1 0x2a, 0xc6, 0x87, 0x47 // 5
934 data1 0x13, 0x46, 0x30, 0xa8 // 6
935 data1 0x01, 0x95, 0x46, 0xfd // 7
936 data1 0xd8, 0x98, 0x80, 0x69 // 8
937 data1 0xaf, 0xf7, 0x44, 0x8b // 9
938 data1 0xb1, 0x5b, 0xff, 0xff // 10
939 data1 0xbe, 0xd7, 0x5c, 0x89 // 11
940 data1 0x22, 0x11, 0x90, 0x6b // 12
941 data1 0x93, 0x71, 0x98, 0xfd // 13
942 data1 0x8e, 0x43, 0x79, 0xa6 // 14
943 data1 0x21, 0x08, 0xb4, 0x49 // 15
944 data1 0x62, 0x25, 0x1e, 0xf6 // 16
945 data1 0x40, 0xb3, 0x40, 0xc0 // 17
946 data1 0x51, 0x5a, 0x5e, 0x26 // 18
947 data1 0xaa, 0xc7, 0xb6, 0xe9 // 19
948 data1 0x5d, 0x10, 0x2f, 0xd6 // 20
949 data1 0x53, 0x14, 0x44, 0x02 // 21
950 data1 0x81, 0xe6, 0xa1, 0xd8 // 22
951 data1 0xc8, 0xfb, 0xd3, 0xe7 // 23
952 data1 0xe6, 0xcd, 0xe1, 0x21 // 24
953 data1 0xd6, 0x07, 0x37, 0xc3 // 25
954 data1 0x87, 0x0d, 0xd5, 0xf4 // 26
955 data1 0xed, 0x14, 0x5a, 0x45 // 27
956 data1 0x05, 0xe9, 0xe3, 0xa9 // 28
957 data1 0xf8, 0xa3, 0xef, 0xfc // 29
958 data1 0xd9, 0x02, 0x6f, 0x67 // 30
959 data1 0x8a, 0x4c, 0x2a, 0x8d // 31
960 data1 0x42, 0x39, 0xfa, 0xff // 32
961 data1 0x81, 0xf6, 0x71, 0x87 // 33
962 data1 0x22, 0x61, 0x9d, 0x6d // 34
963 data1 0x0c, 0x38, 0xe5, 0xfd // 35
964 data1 0x44, 0xea, 0xbe, 0xa4 // 36
965 data1 0xa9, 0xcf, 0xde, 0x4b // 37
966 data1 0x60, 0x4b, 0xbb, 0xf6 // 38
967 data1 0x70, 0xbc, 0xbf, 0xbe // 39
968 data1 0xc6, 0x7e, 0x9b, 0x28 // 40
969 data1 0xfa, 0x27, 0xa1, 0xea // 41
970 data1 0x85, 0x30, 0xef, 0xd4 // 42
971 data1 0x05, 0x1d, 0x88, 0x04 // 43
972 data1 0x39, 0xd0, 0xd4, 0xd9 // 44
973 data1 0xe5, 0x99, 0xdb, 0xe6 // 45
974 data1 0xf8, 0x7c, 0xa2, 0x1f // 46
975 data1 0x65, 0x56, 0xac, 0xc4 // 47
976 data1 0x44, 0x22, 0x29, 0xf4 // 48
977 data1 0x97, 0xff, 0x2a, 0x43 // 49
978 data1 0xa7, 0x23, 0x94, 0xab // 50
979 data1 0x39, 0xa0, 0x93, 0xfc // 51
980 data1 0xc3, 0x59, 0x5b, 0x65 // 52
981 data1 0x92, 0xcc, 0x0c, 0x8f // 53
982 data1 0x7d, 0xf4, 0xef, 0xff // 54
983 data1 0xd1, 0x5d, 0x84, 0x85 // 55
984 data1 0x4f, 0x7e, 0xa8, 0x6f // 56
985 data1 0xe0, 0xe6, 0x2c, 0xfe // 57
986 data1 0x14, 0x43, 0x01, 0xa3 // 58
987 data1 0xa1, 0x11, 0x08, 0x4e // 59
988 data1 0x82, 0x7e, 0x53, 0xf7 // 60
989 data1 0x35, 0xf2, 0x3a, 0xbd // 61
990 data1 0xbb, 0xd2, 0xd7, 0x2a // 62
991 data1 0x91, 0xd3, 0x86, 0xeb // 63
992.size md5_constants#,64*4
diff --git a/src/lib/libcrypto/md5/asm/md5-x86_64.pl b/src/lib/libcrypto/md5/asm/md5-x86_64.pl
deleted file mode 100755
index 867885435e..0000000000
--- a/src/lib/libcrypto/md5/asm/md5-x86_64.pl
+++ /dev/null
@@ -1,369 +0,0 @@
1#!/usr/bin/perl -w
2#
3# MD5 optimized for AMD64.
4#
5# Author: Marc Bevand <bevand_m (at) epita.fr>
6# Licence: I hereby disclaim the copyright on this code and place it
7# in the public domain.
8#
9
10use strict;
11
12my $code;
13
14# round1_step() does:
15# dst = x + ((dst + F(x,y,z) + X[k] + T_i) <<< s)
16# %r10d = X[k_next]
17# %r11d = z' (copy of z for the next step)
18# Each round1_step() takes about 5.3 clocks (9 instructions, 1.7 IPC)
19sub round1_step
20{
21 my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
22 $code .= " mov 0*4(%rsi), %r10d /* (NEXT STEP) X[0] */\n" if ($pos == -1);
23 $code .= " mov %edx, %r11d /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
24 $code .= <<EOF;
25 xor $y, %r11d /* y ^ ... */
26 lea $T_i($dst,%r10d),$dst /* Const + dst + ... */
27 and $x, %r11d /* x & ... */
28 xor $z, %r11d /* z ^ ... */
29 mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */
30 add %r11d, $dst /* dst += ... */
31 rol \$$s, $dst /* dst <<< s */
32 mov $y, %r11d /* (NEXT STEP) z' = $y */
33 add $x, $dst /* dst += x */
34EOF
35}
36
37# round2_step() does:
38# dst = x + ((dst + G(x,y,z) + X[k] + T_i) <<< s)
39# %r10d = X[k_next]
40# %r11d = z' (copy of z for the next step)
41# %r12d = z' (copy of z for the next step)
42# Each round2_step() takes about 5.4 clocks (11 instructions, 2.0 IPC)
43sub round2_step
44{
45 my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
46 $code .= " mov 1*4(%rsi), %r10d /* (NEXT STEP) X[1] */\n" if ($pos == -1);
47 $code .= " mov %edx, %r11d /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
48 $code .= " mov %edx, %r12d /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
49 $code .= <<EOF;
50 not %r11d /* not z */
51 lea $T_i($dst,%r10d),$dst /* Const + dst + ... */
52 and $x, %r12d /* x & z */
53 and $y, %r11d /* y & (not z) */
54 mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */
55 or %r11d, %r12d /* (y & (not z)) | (x & z) */
56 mov $y, %r11d /* (NEXT STEP) z' = $y */
57 add %r12d, $dst /* dst += ... */
58 mov $y, %r12d /* (NEXT STEP) z' = $y */
59 rol \$$s, $dst /* dst <<< s */
60 add $x, $dst /* dst += x */
61EOF
62}
63
64# round3_step() does:
65# dst = x + ((dst + H(x,y,z) + X[k] + T_i) <<< s)
66# %r10d = X[k_next]
67# %r11d = y' (copy of y for the next step)
68# Each round3_step() takes about 4.2 clocks (8 instructions, 1.9 IPC)
69sub round3_step
70{
71 my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
72 $code .= " mov 5*4(%rsi), %r10d /* (NEXT STEP) X[5] */\n" if ($pos == -1);
73 $code .= " mov %ecx, %r11d /* (NEXT STEP) y' = %ecx */\n" if ($pos == -1);
74 $code .= <<EOF;
75 lea $T_i($dst,%r10d),$dst /* Const + dst + ... */
76 mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */
77 xor $z, %r11d /* z ^ ... */
78 xor $x, %r11d /* x ^ ... */
79 add %r11d, $dst /* dst += ... */
80 rol \$$s, $dst /* dst <<< s */
81 mov $x, %r11d /* (NEXT STEP) y' = $x */
82 add $x, $dst /* dst += x */
83EOF
84}
85
86# round4_step() does:
87# dst = x + ((dst + I(x,y,z) + X[k] + T_i) <<< s)
88# %r10d = X[k_next]
89# %r11d = not z' (copy of not z for the next step)
90# Each round4_step() takes about 5.2 clocks (9 instructions, 1.7 IPC)
91sub round4_step
92{
93 my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
94 $code .= " mov 0*4(%rsi), %r10d /* (NEXT STEP) X[0] */\n" if ($pos == -1);
95 $code .= " mov \$0xffffffff, %r11d\n" if ($pos == -1);
96 $code .= " xor %edx, %r11d /* (NEXT STEP) not z' = not %edx*/\n"
97 if ($pos == -1);
98 $code .= <<EOF;
99 lea $T_i($dst,%r10d),$dst /* Const + dst + ... */
100 or $x, %r11d /* x | ... */
101 xor $y, %r11d /* y ^ ... */
102 add %r11d, $dst /* dst += ... */
103 mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */
104 mov \$0xffffffff, %r11d
105 rol \$$s, $dst /* dst <<< s */
106 xor $y, %r11d /* (NEXT STEP) not z' = not $y */
107 add $x, $dst /* dst += x */
108EOF
109}
110
111my $flavour = shift;
112my $output = shift;
113if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
114
115my $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
116
117$0 =~ m/(.*[\/\\])[^\/\\]+$/; my $dir=$1; my $xlate;
118( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
119( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
120die "can't locate x86_64-xlate.pl";
121
122no warnings qw(uninitialized);
123open STDOUT,"| $^X $xlate $flavour $output";
124
125$code .= <<EOF;
126.text
127.align 16
128
129.globl md5_block_asm_data_order
130.type md5_block_asm_data_order,\@function,3
131md5_block_asm_data_order:
132 push %rbp
133 push %rbx
134 push %r12
135 push %r14
136 push %r15
137.Lprologue:
138
139 # rdi = arg #1 (ctx, MD5_CTX pointer)
140 # rsi = arg #2 (ptr, data pointer)
141 # rdx = arg #3 (nbr, number of 16-word blocks to process)
142 mov %rdi, %rbp # rbp = ctx
143 shl \$6, %rdx # rdx = nbr in bytes
144 lea (%rsi,%rdx), %rdi # rdi = end
145 mov 0*4(%rbp), %eax # eax = ctx->A
146 mov 1*4(%rbp), %ebx # ebx = ctx->B
147 mov 2*4(%rbp), %ecx # ecx = ctx->C
148 mov 3*4(%rbp), %edx # edx = ctx->D
149 # end is 'rdi'
150 # ptr is 'rsi'
151 # A is 'eax'
152 # B is 'ebx'
153 # C is 'ecx'
154 # D is 'edx'
155
156 cmp %rdi, %rsi # cmp end with ptr
157 je .Lend # jmp if ptr == end
158
159 # BEGIN of loop over 16-word blocks
160.Lloop: # save old values of A, B, C, D
161 mov %eax, %r8d
162 mov %ebx, %r9d
163 mov %ecx, %r14d
164 mov %edx, %r15d
165EOF
166round1_step(-1,'%eax','%ebx','%ecx','%edx', '1','0xd76aa478', '7');
167round1_step( 0,'%edx','%eax','%ebx','%ecx', '2','0xe8c7b756','12');
168round1_step( 0,'%ecx','%edx','%eax','%ebx', '3','0x242070db','17');
169round1_step( 0,'%ebx','%ecx','%edx','%eax', '4','0xc1bdceee','22');
170round1_step( 0,'%eax','%ebx','%ecx','%edx', '5','0xf57c0faf', '7');
171round1_step( 0,'%edx','%eax','%ebx','%ecx', '6','0x4787c62a','12');
172round1_step( 0,'%ecx','%edx','%eax','%ebx', '7','0xa8304613','17');
173round1_step( 0,'%ebx','%ecx','%edx','%eax', '8','0xfd469501','22');
174round1_step( 0,'%eax','%ebx','%ecx','%edx', '9','0x698098d8', '7');
175round1_step( 0,'%edx','%eax','%ebx','%ecx','10','0x8b44f7af','12');
176round1_step( 0,'%ecx','%edx','%eax','%ebx','11','0xffff5bb1','17');
177round1_step( 0,'%ebx','%ecx','%edx','%eax','12','0x895cd7be','22');
178round1_step( 0,'%eax','%ebx','%ecx','%edx','13','0x6b901122', '7');
179round1_step( 0,'%edx','%eax','%ebx','%ecx','14','0xfd987193','12');
180round1_step( 0,'%ecx','%edx','%eax','%ebx','15','0xa679438e','17');
181round1_step( 1,'%ebx','%ecx','%edx','%eax', '0','0x49b40821','22');
182
183round2_step(-1,'%eax','%ebx','%ecx','%edx', '6','0xf61e2562', '5');
184round2_step( 0,'%edx','%eax','%ebx','%ecx','11','0xc040b340', '9');
185round2_step( 0,'%ecx','%edx','%eax','%ebx', '0','0x265e5a51','14');
186round2_step( 0,'%ebx','%ecx','%edx','%eax', '5','0xe9b6c7aa','20');
187round2_step( 0,'%eax','%ebx','%ecx','%edx','10','0xd62f105d', '5');
188round2_step( 0,'%edx','%eax','%ebx','%ecx','15', '0x2441453', '9');
189round2_step( 0,'%ecx','%edx','%eax','%ebx', '4','0xd8a1e681','14');
190round2_step( 0,'%ebx','%ecx','%edx','%eax', '9','0xe7d3fbc8','20');
191round2_step( 0,'%eax','%ebx','%ecx','%edx','14','0x21e1cde6', '5');
192round2_step( 0,'%edx','%eax','%ebx','%ecx', '3','0xc33707d6', '9');
193round2_step( 0,'%ecx','%edx','%eax','%ebx', '8','0xf4d50d87','14');
194round2_step( 0,'%ebx','%ecx','%edx','%eax','13','0x455a14ed','20');
195round2_step( 0,'%eax','%ebx','%ecx','%edx', '2','0xa9e3e905', '5');
196round2_step( 0,'%edx','%eax','%ebx','%ecx', '7','0xfcefa3f8', '9');
197round2_step( 0,'%ecx','%edx','%eax','%ebx','12','0x676f02d9','14');
198round2_step( 1,'%ebx','%ecx','%edx','%eax', '0','0x8d2a4c8a','20');
199
200round3_step(-1,'%eax','%ebx','%ecx','%edx', '8','0xfffa3942', '4');
201round3_step( 0,'%edx','%eax','%ebx','%ecx','11','0x8771f681','11');
202round3_step( 0,'%ecx','%edx','%eax','%ebx','14','0x6d9d6122','16');
203round3_step( 0,'%ebx','%ecx','%edx','%eax', '1','0xfde5380c','23');
204round3_step( 0,'%eax','%ebx','%ecx','%edx', '4','0xa4beea44', '4');
205round3_step( 0,'%edx','%eax','%ebx','%ecx', '7','0x4bdecfa9','11');
206round3_step( 0,'%ecx','%edx','%eax','%ebx','10','0xf6bb4b60','16');
207round3_step( 0,'%ebx','%ecx','%edx','%eax','13','0xbebfbc70','23');
208round3_step( 0,'%eax','%ebx','%ecx','%edx', '0','0x289b7ec6', '4');
209round3_step( 0,'%edx','%eax','%ebx','%ecx', '3','0xeaa127fa','11');
210round3_step( 0,'%ecx','%edx','%eax','%ebx', '6','0xd4ef3085','16');
211round3_step( 0,'%ebx','%ecx','%edx','%eax', '9', '0x4881d05','23');
212round3_step( 0,'%eax','%ebx','%ecx','%edx','12','0xd9d4d039', '4');
213round3_step( 0,'%edx','%eax','%ebx','%ecx','15','0xe6db99e5','11');
214round3_step( 0,'%ecx','%edx','%eax','%ebx', '2','0x1fa27cf8','16');
215round3_step( 1,'%ebx','%ecx','%edx','%eax', '0','0xc4ac5665','23');
216
217round4_step(-1,'%eax','%ebx','%ecx','%edx', '7','0xf4292244', '6');
218round4_step( 0,'%edx','%eax','%ebx','%ecx','14','0x432aff97','10');
219round4_step( 0,'%ecx','%edx','%eax','%ebx', '5','0xab9423a7','15');
220round4_step( 0,'%ebx','%ecx','%edx','%eax','12','0xfc93a039','21');
221round4_step( 0,'%eax','%ebx','%ecx','%edx', '3','0x655b59c3', '6');
222round4_step( 0,'%edx','%eax','%ebx','%ecx','10','0x8f0ccc92','10');
223round4_step( 0,'%ecx','%edx','%eax','%ebx', '1','0xffeff47d','15');
224round4_step( 0,'%ebx','%ecx','%edx','%eax', '8','0x85845dd1','21');
225round4_step( 0,'%eax','%ebx','%ecx','%edx','15','0x6fa87e4f', '6');
226round4_step( 0,'%edx','%eax','%ebx','%ecx', '6','0xfe2ce6e0','10');
227round4_step( 0,'%ecx','%edx','%eax','%ebx','13','0xa3014314','15');
228round4_step( 0,'%ebx','%ecx','%edx','%eax', '4','0x4e0811a1','21');
229round4_step( 0,'%eax','%ebx','%ecx','%edx','11','0xf7537e82', '6');
230round4_step( 0,'%edx','%eax','%ebx','%ecx', '2','0xbd3af235','10');
231round4_step( 0,'%ecx','%edx','%eax','%ebx', '9','0x2ad7d2bb','15');
232round4_step( 1,'%ebx','%ecx','%edx','%eax', '0','0xeb86d391','21');
233$code .= <<EOF;
234 # add old values of A, B, C, D
235 add %r8d, %eax
236 add %r9d, %ebx
237 add %r14d, %ecx
238 add %r15d, %edx
239
240 # loop control
241 add \$64, %rsi # ptr += 64
242 cmp %rdi, %rsi # cmp end with ptr
243 jb .Lloop # jmp if ptr < end
244 # END of loop over 16-word blocks
245
246.Lend:
247 mov %eax, 0*4(%rbp) # ctx->A = A
248 mov %ebx, 1*4(%rbp) # ctx->B = B
249 mov %ecx, 2*4(%rbp) # ctx->C = C
250 mov %edx, 3*4(%rbp) # ctx->D = D
251
252 mov (%rsp),%r15
253 mov 8(%rsp),%r14
254 mov 16(%rsp),%r12
255 mov 24(%rsp),%rbx
256 mov 32(%rsp),%rbp
257 add \$40,%rsp
258.Lepilogue:
259 ret
260.size md5_block_asm_data_order,.-md5_block_asm_data_order
261EOF
262
263# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
264# CONTEXT *context,DISPATCHER_CONTEXT *disp)
265if ($win64) {
266my $rec="%rcx";
267my $frame="%rdx";
268my $context="%r8";
269my $disp="%r9";
270
271$code.=<<___;
272.extern __imp_RtlVirtualUnwind
273.type se_handler,\@abi-omnipotent
274.align 16
275se_handler:
276 push %rsi
277 push %rdi
278 push %rbx
279 push %rbp
280 push %r12
281 push %r13
282 push %r14
283 push %r15
284 pushfq
285 sub \$64,%rsp
286
287 mov 120($context),%rax # pull context->Rax
288 mov 248($context),%rbx # pull context->Rip
289
290 lea .Lprologue(%rip),%r10
291 cmp %r10,%rbx # context->Rip<.Lprologue
292 jb .Lin_prologue
293
294 mov 152($context),%rax # pull context->Rsp
295
296 lea .Lepilogue(%rip),%r10
297 cmp %r10,%rbx # context->Rip>=.Lepilogue
298 jae .Lin_prologue
299
300 lea 40(%rax),%rax
301
302 mov -8(%rax),%rbp
303 mov -16(%rax),%rbx
304 mov -24(%rax),%r12
305 mov -32(%rax),%r14
306 mov -40(%rax),%r15
307 mov %rbx,144($context) # restore context->Rbx
308 mov %rbp,160($context) # restore context->Rbp
309 mov %r12,216($context) # restore context->R12
310 mov %r14,232($context) # restore context->R14
311 mov %r15,240($context) # restore context->R15
312
313.Lin_prologue:
314 mov 8(%rax),%rdi
315 mov 16(%rax),%rsi
316 mov %rax,152($context) # restore context->Rsp
317 mov %rsi,168($context) # restore context->Rsi
318 mov %rdi,176($context) # restore context->Rdi
319
320 mov 40($disp),%rdi # disp->ContextRecord
321 mov $context,%rsi # context
322 mov \$154,%ecx # sizeof(CONTEXT)
323 .long 0xa548f3fc # cld; rep movsq
324
325 mov $disp,%rsi
326 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
327 mov 8(%rsi),%rdx # arg2, disp->ImageBase
328 mov 0(%rsi),%r8 # arg3, disp->ControlPc
329 mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
330 mov 40(%rsi),%r10 # disp->ContextRecord
331 lea 56(%rsi),%r11 # &disp->HandlerData
332 lea 24(%rsi),%r12 # &disp->EstablisherFrame
333 mov %r10,32(%rsp) # arg5
334 mov %r11,40(%rsp) # arg6
335 mov %r12,48(%rsp) # arg7
336 mov %rcx,56(%rsp) # arg8, (NULL)
337 call *__imp_RtlVirtualUnwind(%rip)
338
339 mov \$1,%eax # ExceptionContinueSearch
340 add \$64,%rsp
341 popfq
342 pop %r15
343 pop %r14
344 pop %r13
345 pop %r12
346 pop %rbp
347 pop %rbx
348 pop %rdi
349 pop %rsi
350 ret
351.size se_handler,.-se_handler
352
353.section .pdata
354.align 4
355 .rva .LSEH_begin_md5_block_asm_data_order
356 .rva .LSEH_end_md5_block_asm_data_order
357 .rva .LSEH_info_md5_block_asm_data_order
358
359.section .xdata
360.align 8
361.LSEH_info_md5_block_asm_data_order:
362 .byte 9,0,0,0
363 .rva se_handler
364___
365}
366
367print $code;
368
369close STDOUT;
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h
deleted file mode 100644
index 4cbf84386b..0000000000
--- a/src/lib/libcrypto/md5/md5.h
+++ /dev/null
@@ -1,117 +0,0 @@
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#include <openssl/e_os2.h>
63#include <stddef.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69#ifdef OPENSSL_NO_MD5
70#error MD5 is disabled.
71#endif
72
73/*
74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
76 * ! MD5_LONG_LOG2 has to be defined along. !
77 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 */
79
80#if defined(__LP32__)
81#define MD5_LONG unsigned long
82#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
83#define MD5_LONG unsigned long
84#define MD5_LONG_LOG2 3
85/*
86 * _CRAY note. I could declare short, but I have no idea what impact
87 * does it have on performance on none-T3E machines. I could declare
88 * int, but at least on C90 sizeof(int) can be chosen at compile time.
89 * So I've chosen long...
90 * <appro@fy.chalmers.se>
91 */
92#else
93#define MD5_LONG unsigned int
94#endif
95
96#define MD5_CBLOCK 64
97#define MD5_LBLOCK (MD5_CBLOCK/4)
98#define MD5_DIGEST_LENGTH 16
99
100typedef struct MD5state_st
101 {
102 MD5_LONG A,B,C,D;
103 MD5_LONG Nl,Nh;
104 MD5_LONG data[MD5_LBLOCK];
105 unsigned int num;
106 } MD5_CTX;
107
108int MD5_Init(MD5_CTX *c);
109int MD5_Update(MD5_CTX *c, const void *data, size_t len);
110int MD5_Final(unsigned char *md, MD5_CTX *c);
111unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
112void MD5_Transform(MD5_CTX *c, const unsigned char *b);
113#ifdef __cplusplus
114}
115#endif
116
117#endif
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c
deleted file mode 100644
index beace632e3..0000000000
--- a/src/lib/libcrypto/md5/md5_dgst.c
+++ /dev/null
@@ -1,184 +0,0 @@
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#include <openssl/opensslv.h>
62
63const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT;
64
65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
66 */
67
68#define INIT_DATA_A (unsigned long)0x67452301L
69#define INIT_DATA_B (unsigned long)0xefcdab89L
70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L
72
73int MD5_Init(MD5_CTX *c)
74 {
75 memset (c,0,sizeof(*c));
76 c->A=INIT_DATA_A;
77 c->B=INIT_DATA_B;
78 c->C=INIT_DATA_C;
79 c->D=INIT_DATA_D;
80 return 1;
81 }
82
83#ifndef md5_block_data_order
84#ifdef X
85#undef X
86#endif
87void md5_block_data_order (MD5_CTX *c, const void *data_, size_t num)
88 {
89 const unsigned char *data=data_;
90 register unsigned MD32_REG_T A,B,C,D,l;
91#ifndef MD32_XARRAY
92 /* See comment in crypto/sha/sha_locl.h for details. */
93 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
94 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
95# define X(i) XX##i
96#else
97 MD5_LONG XX[MD5_LBLOCK];
98# define X(i) XX[i]
99#endif
100
101 A=c->A;
102 B=c->B;
103 C=c->C;
104 D=c->D;
105
106 for (;num--;)
107 {
108 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
109 /* Round 0 */
110 R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l;
111 R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l;
112 R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l;
113 R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l;
114 R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l;
115 R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l;
116 R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l;
117 R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l;
118 R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l;
119 R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l;
120 R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l;
121 R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l;
122 R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l;
123 R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l;
124 R0(C,D,A,B,X(14),17,0xa679438eL);
125 R0(B,C,D,A,X(15),22,0x49b40821L);
126 /* Round 1 */
127 R1(A,B,C,D,X( 1), 5,0xf61e2562L);
128 R1(D,A,B,C,X( 6), 9,0xc040b340L);
129 R1(C,D,A,B,X(11),14,0x265e5a51L);
130 R1(B,C,D,A,X( 0),20,0xe9b6c7aaL);
131 R1(A,B,C,D,X( 5), 5,0xd62f105dL);
132 R1(D,A,B,C,X(10), 9,0x02441453L);
133 R1(C,D,A,B,X(15),14,0xd8a1e681L);
134 R1(B,C,D,A,X( 4),20,0xe7d3fbc8L);
135 R1(A,B,C,D,X( 9), 5,0x21e1cde6L);
136 R1(D,A,B,C,X(14), 9,0xc33707d6L);
137 R1(C,D,A,B,X( 3),14,0xf4d50d87L);
138 R1(B,C,D,A,X( 8),20,0x455a14edL);
139 R1(A,B,C,D,X(13), 5,0xa9e3e905L);
140 R1(D,A,B,C,X( 2), 9,0xfcefa3f8L);
141 R1(C,D,A,B,X( 7),14,0x676f02d9L);
142 R1(B,C,D,A,X(12),20,0x8d2a4c8aL);
143 /* Round 2 */
144 R2(A,B,C,D,X( 5), 4,0xfffa3942L);
145 R2(D,A,B,C,X( 8),11,0x8771f681L);
146 R2(C,D,A,B,X(11),16,0x6d9d6122L);
147 R2(B,C,D,A,X(14),23,0xfde5380cL);
148 R2(A,B,C,D,X( 1), 4,0xa4beea44L);
149 R2(D,A,B,C,X( 4),11,0x4bdecfa9L);
150 R2(C,D,A,B,X( 7),16,0xf6bb4b60L);
151 R2(B,C,D,A,X(10),23,0xbebfbc70L);
152 R2(A,B,C,D,X(13), 4,0x289b7ec6L);
153 R2(D,A,B,C,X( 0),11,0xeaa127faL);
154 R2(C,D,A,B,X( 3),16,0xd4ef3085L);
155 R2(B,C,D,A,X( 6),23,0x04881d05L);
156 R2(A,B,C,D,X( 9), 4,0xd9d4d039L);
157 R2(D,A,B,C,X(12),11,0xe6db99e5L);
158 R2(C,D,A,B,X(15),16,0x1fa27cf8L);
159 R2(B,C,D,A,X( 2),23,0xc4ac5665L);
160 /* Round 3 */
161 R3(A,B,C,D,X( 0), 6,0xf4292244L);
162 R3(D,A,B,C,X( 7),10,0x432aff97L);
163 R3(C,D,A,B,X(14),15,0xab9423a7L);
164 R3(B,C,D,A,X( 5),21,0xfc93a039L);
165 R3(A,B,C,D,X(12), 6,0x655b59c3L);
166 R3(D,A,B,C,X( 3),10,0x8f0ccc92L);
167 R3(C,D,A,B,X(10),15,0xffeff47dL);
168 R3(B,C,D,A,X( 1),21,0x85845dd1L);
169 R3(A,B,C,D,X( 8), 6,0x6fa87e4fL);
170 R3(D,A,B,C,X(15),10,0xfe2ce6e0L);
171 R3(C,D,A,B,X( 6),15,0xa3014314L);
172 R3(B,C,D,A,X(13),21,0x4e0811a1L);
173 R3(A,B,C,D,X( 4), 6,0xf7537e82L);
174 R3(D,A,B,C,X(11),10,0xbd3af235L);
175 R3(C,D,A,B,X( 2),15,0x2ad7d2bbL);
176 R3(B,C,D,A,X( 9),21,0xeb86d391L);
177
178 A = c->A += A;
179 B = c->B += B;
180 C = c->C += C;
181 D = c->D += D;
182 }
183 }
184#endif
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
deleted file mode 100644
index 968d577995..0000000000
--- a/src/lib/libcrypto/md5/md5_locl.h
+++ /dev/null
@@ -1,130 +0,0 @@
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#include <stdlib.h>
60#include <string.h>
61#include <openssl/e_os2.h>
62#include <openssl/md5.h>
63
64#ifndef MD5_LONG_LOG2
65#define MD5_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68#ifdef MD5_ASM
69# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) || \
70 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
71# define md5_block_data_order md5_block_asm_data_order
72# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
73# define md5_block_data_order md5_block_asm_data_order
74# endif
75#endif
76
77void md5_block_data_order (MD5_CTX *c, const void *p,size_t num);
78
79#define DATA_ORDER_IS_LITTLE_ENDIAN
80
81#define HASH_LONG MD5_LONG
82#define HASH_CTX MD5_CTX
83#define HASH_CBLOCK MD5_CBLOCK
84#define HASH_UPDATE MD5_Update
85#define HASH_TRANSFORM MD5_Transform
86#define HASH_FINAL MD5_Final
87#define HASH_MAKE_STRING(c,s) do { \
88 unsigned long ll; \
89 ll=(c)->A; HOST_l2c(ll,(s)); \
90 ll=(c)->B; HOST_l2c(ll,(s)); \
91 ll=(c)->C; HOST_l2c(ll,(s)); \
92 ll=(c)->D; HOST_l2c(ll,(s)); \
93 } while (0)
94#define HASH_BLOCK_DATA_ORDER md5_block_data_order
95
96#include "md32_common.h"
97
98/*
99#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
100#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
101*/
102
103/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
104 * simplified to the code below. Wei attributes these optimizations
105 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
106 */
107#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
108#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
109#define H(b,c,d) ((b) ^ (c) ^ (d))
110#define I(b,c,d) (((~(d)) | (b)) ^ (c))
111
112#define R0(a,b,c,d,k,s,t) { \
113 a+=((k)+(t)+F((b),(c),(d))); \
114 a=ROTATE(a,s); \
115 a+=b; };\
116
117#define R1(a,b,c,d,k,s,t) { \
118 a+=((k)+(t)+G((b),(c),(d))); \
119 a=ROTATE(a,s); \
120 a+=b; };
121
122#define R2(a,b,c,d,k,s,t) { \
123 a+=((k)+(t)+H((b),(c),(d))); \
124 a=ROTATE(a,s); \
125 a+=b; };
126
127#define R3(a,b,c,d,k,s,t) { \
128 a+=((k)+(t)+I((b),(c),(d))); \
129 a=ROTATE(a,s); \
130 a+=b; };
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c
deleted file mode 100644
index 43fee89379..0000000000
--- a/src/lib/libcrypto/md5/md5_one.c
+++ /dev/null
@@ -1,97 +0,0 @@
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 <string.h>
61#include <openssl/md5.h>
62#include <openssl/crypto.h>
63
64#ifdef CHARSET_EBCDIC
65#include <openssl/ebcdic.h>
66#endif
67
68unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
69 {
70 MD5_CTX c;
71 static unsigned char m[MD5_DIGEST_LENGTH];
72
73 if (md == NULL) md=m;
74 if (!MD5_Init(&c))
75 return NULL;
76#ifndef CHARSET_EBCDIC
77 MD5_Update(&c,d,n);
78#else
79 {
80 char temp[1024];
81 unsigned long chunk;
82
83 while (n > 0)
84 {
85 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
86 ebcdic2ascii(temp, d, chunk);
87 MD5_Update(&c,temp,chunk);
88 n -= chunk;
89 d += chunk;
90 }
91 }
92#endif
93 MD5_Final(md,&c);
94 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
95 return(md);
96 }
97