1 /*
2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6 #pragma ident "%Z%%M% %I% %E% SMI"
7
8 /*
9 * MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
10 */
11
12 /*
13 * Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
14 *
15 * License to copy and use this software is granted provided that it
16 * is identified as the "RSA Data Security, Inc. MD4 Message-Digest
17 * Algorithm" in all material mentioning or referencing this software
18 * or this function.
19 *
20 * License is also granted to make and use derivative works provided
21 * that such works are identified as "derived from the RSA Data
22 * Security, Inc. MD4 Message-Digest Algorithm" in all material
23 * mentioning or referencing the derived work.
24 *
25 * RSA Data Security, Inc. makes no representations concerning either
26 * the merchantability of this software or the suitability of this
27 * software for any particular purpose. It is provided "as is"
28 * without express or implied warranty of any kind.
29 *
30 * These notices must be retained in any copies of any part of this
31 * documentation and/or software.
32 */
33
34 #include <sys/types.h>
35 #ifdef _KERNEL
36 #include <sys/sunddi.h>
37 #else
38 #include <strings.h>
39 #endif /* _KERNEL */
40
41 #include <sys/md4.h>
42
43 /*
44 * Constants for MD4Transform routine.
45 */
46 #define S11 3
47 #define S12 7
48 #define S13 11
49 #define S14 19
50 #define S21 3
51 #define S22 5
52 #define S23 9
53 #define S24 13
54 #define S31 3
55 #define S32 9
56 #define S33 11
57 #define S34 15
58
59 static void MD4Transform(uint32_t [4], unsigned char [64]);
60 static void Encode(unsigned char *, uint32_t *, unsigned int);
245 HH(b, c, d, a, x[13], S34); /* 44 */
246 HH(a, b, c, d, x[ 3], S31); /* 45 */
247 HH(d, a, b, c, x[11], S32); /* 46 */
248 HH(c, d, a, b, x[ 7], S33); /* 47 */
249 HH(b, c, d, a, x[15], S34); /* 48 */
250
251 state[0] += a;
252 state[1] += b;
253 state[2] += c;
254 state[3] += d;
255
256 /* zeroize sensitive information */
257 bzero(x, sizeof (*x));
258 }
259
260 /*
261 * Encodes input (uint32_t) into output (unsigned char). Assumes len is
262 * a multiple of 4.
263 */
264 static void
265 Encode(output, input, len)
266 unsigned char *output;
267 uint32_t *input;
268 unsigned int len;
269 {
270 unsigned int i, j;
271
272 for (i = 0, j = 0; j < len; i++, j += 4) {
273 output[j] = (unsigned char)(input[i] & 0xff);
274 output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
275 output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
276 output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
277 }
278 }
279
280 /*
281 * Decodes input (unsigned char) into output (uint32_t). Assumes len is
282 * a multiple of 4.
283 */
284 static void
285 Decode(output, input, len)
286 uint32_t *output;
287 unsigned char *input;
288 unsigned int len;
289 {
290 unsigned int i, j;
291
292 for (i = 0, j = 0; j < len; i++, j += 4)
293 output[i] = ((uint32_t)input[j]) |
294 (((uint32_t)input[j+1]) << 8) |
295 (((uint32_t)input[j+2]) << 16) |
296 (((uint32_t)input[j+3]) << 24);
297 }
|
1 /*
2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6 /*
7 * MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
8 */
9
10 /*
11 * Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
12 *
13 * License to copy and use this software is granted provided that it
14 * is identified as the "RSA Data Security, Inc. MD4 Message-Digest
15 * Algorithm" in all material mentioning or referencing this software
16 * or this function.
17 *
18 * License is also granted to make and use derivative works provided
19 * that such works are identified as "derived from the RSA Data
20 * Security, Inc. MD4 Message-Digest Algorithm" in all material
21 * mentioning or referencing the derived work.
22 *
23 * RSA Data Security, Inc. makes no representations concerning either
24 * the merchantability of this software or the suitability of this
25 * software for any particular purpose. It is provided "as is"
26 * without express or implied warranty of any kind.
27 *
28 * These notices must be retained in any copies of any part of this
29 * documentation and/or software.
30 */
31
32 #include <sys/types.h>
33 #ifdef _KERNEL
34 #include <sys/sunddi.h>
35 #else
36 #include <strings.h>
37 #endif /* _KERNEL */
38
39 #if defined(__i386) || defined(__amd64)
40 #define UNALIGNED_POINTERS_PERMITTED
41 #endif
42
43 #include <sys/md4.h>
44
45 /*
46 * Constants for MD4Transform routine.
47 */
48 #define S11 3
49 #define S12 7
50 #define S13 11
51 #define S14 19
52 #define S21 3
53 #define S22 5
54 #define S23 9
55 #define S24 13
56 #define S31 3
57 #define S32 9
58 #define S33 11
59 #define S34 15
60
61 static void MD4Transform(uint32_t [4], unsigned char [64]);
62 static void Encode(unsigned char *, uint32_t *, unsigned int);
247 HH(b, c, d, a, x[13], S34); /* 44 */
248 HH(a, b, c, d, x[ 3], S31); /* 45 */
249 HH(d, a, b, c, x[11], S32); /* 46 */
250 HH(c, d, a, b, x[ 7], S33); /* 47 */
251 HH(b, c, d, a, x[15], S34); /* 48 */
252
253 state[0] += a;
254 state[1] += b;
255 state[2] += c;
256 state[3] += d;
257
258 /* zeroize sensitive information */
259 bzero(x, sizeof (*x));
260 }
261
262 /*
263 * Encodes input (uint32_t) into output (unsigned char). Assumes len is
264 * a multiple of 4.
265 */
266 static void
267 Encode(unsigned char *output, uint32_t *input, unsigned int len)
268 {
269 unsigned int i, j;
270
271 for (i = 0, j = 0; j < len; i++, j += 4) {
272 #if defined(_LITTLE_ENDIAN) && defined(UNALIGNED_POINTERS_PERMITTED)
273 *(uint32_t *)&output[j] = input[i];
274 #else
275 /* endian-independent code */
276 output[j] = (unsigned char)(input[i] & 0xff);
277 output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
278 output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
279 output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
280 #endif /* _LITTLE_ENDIAN && UNALIGNED_POINTERS_PERMITTED */
281 }
282 }
283
284 /*
285 * Decodes input (unsigned char) into output (uint32_t). Assumes len is
286 * a multiple of 4.
287 */
288 static void
289 Decode(uint32_t *output, unsigned char *input, unsigned int len)
290 {
291 unsigned int i, j;
292
293 for (i = 0, j = 0; j < len; i++, j += 4) {
294 #if defined(_LITTLE_ENDIAN) && defined(UNALIGNED_POINTERS_PERMITTED)
295 output[i] = *(uint32_t *)&input[j];
296 #else
297 /* endian-independent code */
298 output[i] = ((uint32_t)input[j]) |
299 (((uint32_t)input[j+1]) << 8) |
300 (((uint32_t)input[j+2]) << 16) |
301 (((uint32_t)input[j+3]) << 24);
302 #endif /* _LITTLE_ENDIAN && UNALIGNED_POINTERS_PERMITTED */
303 }
304
305 }
|