Browse code

core: replace redundant for-loop memset/ memcpy with standard (faster) libc versions

Henning Westerholt authored on 23/06/2011 22:04:01
Showing 1 changed files
... ...
@@ -1,29 +1,24 @@
1 1
 /* 
2
-
3
-$Id$
4
-
5
-MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
6
-
7
-Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
8
-rights reserved.
9
-
10
-License to copy and use this software is granted provided that it
11
-is identified as the "RSA Data Security, Inc. MD5 Message-Digest
12
-Algorithm" in all material mentioning or referencing this software
13
-or this function.
14
-
15
-License is also granted to make and use derivative works provided
16
-that such works are identified as "derived from the RSA Data
17
-Security, Inc. MD5 Message-Digest Algorithm" in all material
18
-mentioning or referencing the derived work.
19
-
20
-RSA Data Security, Inc. makes no representations concerning either
21
-the merchantability of this software or the suitability of this
22
-software for any particular purpose. It is provided "as is"
23
-without express or implied warranty of any kind.
24
-
25
-These notices must be retained in any copies of any part of this
26
-documentation and/or software.
2
+ * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
3
+ * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
4
+ * rights reserved.
5
+ * License to copy and use this software is granted provided that it
6
+ * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
7
+ * Algorithm" in all material mentioning or referencing this software
8
+ * or this function.
9
+ * 
10
+ * License is also granted to make and use derivative works provided
11
+ * that such works are identified as "derived from the RSA Data
12
+ * Security, Inc. MD5 Message-Digest Algorithm" in all material
13
+ * mentioning or referencing the derived work.
14
+ * 
15
+ * RSA Data Security, Inc. makes no representations concerning either
16
+ * the merchantability of this software or the suitability of this
17
+ * software for any particular purpose. It is provided "as is"
18
+ * without express or implied warranty of any kind.
19
+ * 
20
+ * These notices must be retained in any copies of any part of this
21
+ * documentation and/or software.
27 22
  */
28 23
 
29 24
 /*!
... ...
@@ -39,14 +34,9 @@ documentation and/or software.
39 34
 #include "md5.h"
40 35
 
41 36
 
42
-#define USE_MEM
43
-
44 37
 /* Constants for MD5Transform routine.
45 38
  */
46 39
 
47
-
48
-
49
-
50 40
 #define S11 7
51 41
 #define S12 12
52 42
 #define S13 17
... ...
@@ -69,8 +59,6 @@ static void Encode PROTO_LIST
69 59
   ((unsigned char *, UINT4 *, unsigned int));
70 60
 static void Decode PROTO_LIST
71 61
   ((UINT4 *, unsigned char *, unsigned int));
72
-static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
73
-static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
74 62
 
75 63
 static unsigned char PADDING[64] = {
76 64
   0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
... ...
@@ -153,7 +141,7 @@ unsigned int inputLen;                     /* length of input block */
153 141
   /* Transform as many times as possible.
154 142
 */
155 143
   if (inputLen >= partLen) {
156
- MD5_memcpy
144
+ memcpy
157 145
    ((POINTER)&context->buffer[index], (POINTER)input, partLen);
158 146
  MD5Transform (context->state, context->buffer);
159 147
 
... ...
@@ -166,7 +154,7 @@ unsigned int inputLen;                     /* length of input block */
166 154
  i = 0;
167 155
 
168 156
   /* Buffer remaining input */
169
-  MD5_memcpy
157
+  memcpy
170 158
  ((POINTER)&context->buffer[index], (POINTER)&input[i],
171 159
   inputLen-i);
172 160
 }
... ...
@@ -198,7 +186,7 @@ MD5_CTX *context;                                       /* context */
198 186
 
199 187
   /* Zeroize sensitive information.
200 188
 */
201
-  MD5_memset ((POINTER)context, 0, sizeof (*context));
189
+  memset ((POINTER)context, 0, sizeof (*context));
202 190
 }
203 191
 
204 192
 /* MD5 basic transformation. Transforms state based on block.
... ...
@@ -290,7 +278,7 @@ unsigned char block[64];
290 278
 
291 279
   /* Zeroize sensitive information.
292 280
 */
293
-  MD5_memset ((POINTER)x, 0, sizeof (x));
281
+  memset ((POINTER)x, 0, sizeof (x));
294 282
 }
295 283
 
296 284
 /* Encodes input (UINT4) into output (unsigned char). Assumes len is
... ...
@@ -325,40 +313,3 @@ unsigned int len;
325 313
  output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
326 314
    (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
327 315
 }
328
-
329
-/* Note: Replace "for loop" with standard memcpy if possible.
330
- */
331
-
332
-static void MD5_memcpy (output, input, len)
333
-POINTER output;
334
-POINTER input;
335
-unsigned int len;
336
-{
337
-
338
-#ifndef USE_MEM
339
-  unsigned int i;
340
-
341
-  for (i = 0; i < len; i++)
342
- output[i] = input[i];
343
-#else
344
-  memcpy( output, input, len );
345
-#endif
346
-}
347
-
348
-/* Note: Replace "for loop" with standard memset if possible.
349
- */
350
-static void MD5_memset (output, value, len)
351
-POINTER output;
352
-int value;
353
-unsigned int len;
354
-{
355
-
356
-#ifndef USE_MEM
357
-  unsigned int i;
358
-  for (i = 0; i < len; i++)
359
- ((char *)output)[i] = (char)value;
360
-#else
361
-  memset( output, value, len );
362
-#endif
363
-}
364
-