ansify function definitionsdiff -r1.2 -r1.3 src/common/lib/libc/gen/bswap64.c
(cegger)
--- src/common/lib/libc/gen/bswap64.c 2008/02/16 17:37:13 1.2
+++ src/common/lib/libc/gen/bswap64.c 2009/03/16 05:59:21 1.3
@@ -1,45 +1,44 @@ | @@ -1,45 +1,44 @@ | |||
1 | /* $NetBSD: bswap64.c,v 1.2 2008/02/16 17:37:13 apb Exp $ */ | 1 | /* $NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Written by Manuel Bouyer <bouyer@NetBSD.org>. | 4 | * Written by Manuel Bouyer <bouyer@NetBSD.org>. | |
5 | * Public domain. | 5 | * Public domain. | |
6 | */ | 6 | */ | |
7 | 7 | |||
8 | #include <sys/cdefs.h> | 8 | #include <sys/cdefs.h> | |
9 | #if defined(LIBC_SCCS) && !defined(lint) | 9 | #if defined(LIBC_SCCS) && !defined(lint) | |
10 | __RCSID("$NetBSD: bswap64.c,v 1.2 2008/02/16 17:37:13 apb Exp $"); | 10 | __RCSID("$NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $"); | |
11 | #endif /* LIBC_SCCS and not lint */ | 11 | #endif /* LIBC_SCCS and not lint */ | |
12 | 12 | |||
13 | #include <sys/types.h> | 13 | #include <sys/types.h> | |
14 | #include <machine/bswap.h> | 14 | #include <machine/bswap.h> | |
15 | 15 | |||
16 | #undef bswap64 | 16 | #undef bswap64 | |
17 | 17 | |||
18 | uint64_t | 18 | uint64_t | |
19 | bswap64(x) | 19 | bswap64(uint64_t x) | |
20 | uint64_t x; | |||
21 | { | 20 | { | |
22 | #ifdef _LP64 | 21 | #ifdef _LP64 | |
23 | /* | 22 | /* | |
24 | * Assume we have wide enough registers to do it without touching | 23 | * Assume we have wide enough registers to do it without touching | |
25 | * memory. | 24 | * memory. | |
26 | */ | 25 | */ | |
27 | return ( (x << 56) & 0xff00000000000000UL ) | | 26 | return ( (x << 56) & 0xff00000000000000UL ) | | |
28 | ( (x << 40) & 0x00ff000000000000UL ) | | 27 | ( (x << 40) & 0x00ff000000000000UL ) | | |
29 | ( (x << 24) & 0x0000ff0000000000UL ) | | 28 | ( (x << 24) & 0x0000ff0000000000UL ) | | |
30 | ( (x << 8) & 0x000000ff00000000UL ) | | 29 | ( (x << 8) & 0x000000ff00000000UL ) | | |
31 | ( (x >> 8) & 0x00000000ff000000UL ) | | 30 | ( (x >> 8) & 0x00000000ff000000UL ) | | |
32 | ( (x >> 24) & 0x0000000000ff0000UL ) | | 31 | ( (x >> 24) & 0x0000000000ff0000UL ) | | |
33 | ( (x >> 40) & 0x000000000000ff00UL ) | | 32 | ( (x >> 40) & 0x000000000000ff00UL ) | | |
34 | ( (x >> 56) & 0x00000000000000ffUL ); | 33 | ( (x >> 56) & 0x00000000000000ffUL ); | |
35 | #else | 34 | #else | |
36 | /* | 35 | /* | |
37 | * Split the operation in two 32bit steps. | 36 | * Split the operation in two 32bit steps. | |
38 | */ | 37 | */ | |
39 | uint32_t tl, th; | 38 | uint32_t tl, th; | |
40 | 39 | |||
41 | th = bswap32((uint32_t)(x & 0x00000000ffffffffULL)); | 40 | th = bswap32((uint32_t)(x & 0x00000000ffffffffULL)); | |
42 | tl = bswap32((uint32_t)((x >> 32) & 0x00000000ffffffffULL)); | 41 | tl = bswap32((uint32_t)((x >> 32) & 0x00000000ffffffffULL)); | |
43 | return ((uint64_t)th << 32) | tl; | 42 | return ((uint64_t)th << 32) | tl; | |
44 | #endif | 43 | #endif | |
45 | } | 44 | } |
--- src/common/lib/libc/hash/sha1/sha1.c 2008/02/16 17:37:13 1.3
+++ src/common/lib/libc/hash/sha1/sha1.c 2009/03/16 05:59:21 1.4
@@ -1,295 +1,287 @@ | @@ -1,295 +1,287 @@ | |||
1 | /* $NetBSD: sha1.c,v 1.3 2008/02/16 17:37:13 apb Exp $ */ | 1 | /* $NetBSD: sha1.c,v 1.4 2009/03/16 05:59:21 cegger Exp $ */ | |
2 | /* $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */ | 2 | /* $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * SHA-1 in C | 5 | * SHA-1 in C | |
6 | * By Steve Reid <steve@edmweb.com> | 6 | * By Steve Reid <steve@edmweb.com> | |
7 | * 100% Public Domain | 7 | * 100% Public Domain | |
8 | * | 8 | * | |
9 | * Test Vectors (from FIPS PUB 180-1) | 9 | * Test Vectors (from FIPS PUB 180-1) | |
10 | * "abc" | 10 | * "abc" | |
11 | * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D | 11 | * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D | |
12 | * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" | 12 | * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" | |
13 | * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 | 13 | * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 | |
14 | * A million repetitions of "a" | 14 | * A million repetitions of "a" | |
15 | * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F | 15 | * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F | |
16 | */ | 16 | */ | |
17 | 17 | |||
18 | #define SHA1HANDSOFF /* Copies data before messing with it. */ | 18 | #define SHA1HANDSOFF /* Copies data before messing with it. */ | |
19 | 19 | |||
20 | #include <sys/cdefs.h> | 20 | #include <sys/cdefs.h> | |
21 | 21 | |||
22 | #if defined(_KERNEL) || defined(_STANDALONE) | 22 | #if defined(_KERNEL) || defined(_STANDALONE) | |
23 | __KERNEL_RCSID(0, "$NetBSD: sha1.c,v 1.3 2008/02/16 17:37:13 apb Exp $"); | 23 | __KERNEL_RCSID(0, "$NetBSD: sha1.c,v 1.4 2009/03/16 05:59:21 cegger Exp $"); | |
24 | 24 | |||
25 | #include <lib/libkern/libkern.h> | 25 | #include <lib/libkern/libkern.h> | |
26 | 26 | |||
27 | #else | 27 | #else | |
28 | 28 | |||
29 | #if defined(LIBC_SCCS) && !defined(lint) | 29 | #if defined(LIBC_SCCS) && !defined(lint) | |
30 | __RCSID("$NetBSD: sha1.c,v 1.3 2008/02/16 17:37:13 apb Exp $"); | 30 | __RCSID("$NetBSD: sha1.c,v 1.4 2009/03/16 05:59:21 cegger Exp $"); | |
31 | #endif /* LIBC_SCCS and not lint */ | 31 | #endif /* LIBC_SCCS and not lint */ | |
32 | 32 | |||
33 | #include "namespace.h" | 33 | #include "namespace.h" | |
34 | #include <assert.h> | 34 | #include <assert.h> | |
35 | #include <string.h> | 35 | #include <string.h> | |
36 | 36 | |||
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include <sys/types.h> | 39 | #include <sys/types.h> | |
40 | #include <sys/sha1.h> | 40 | #include <sys/sha1.h> | |
41 | 41 | |||
42 | 42 | |||
43 | #if HAVE_NBTOOL_CONFIG_H | 43 | #if HAVE_NBTOOL_CONFIG_H | |
44 | #include "nbtool_config.h" | 44 | #include "nbtool_config.h" | |
45 | #endif | 45 | #endif | |
46 | 46 | |||
47 | #if !HAVE_SHA1_H | 47 | #if !HAVE_SHA1_H | |
48 | 48 | |||
49 | #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) | 49 | #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) | |
50 | 50 | |||
51 | /* | 51 | /* | |
52 | * blk0() and blk() perform the initial expand. | 52 | * blk0() and blk() perform the initial expand. | |
53 | * I got the idea of expanding during the round function from SSLeay | 53 | * I got the idea of expanding during the round function from SSLeay | |
54 | */ | 54 | */ | |
55 | #if BYTE_ORDER == LITTLE_ENDIAN | 55 | #if BYTE_ORDER == LITTLE_ENDIAN | |
56 | # define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ | 56 | # define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ | |
57 | |(rol(block->l[i],8)&0x00FF00FF)) | 57 | |(rol(block->l[i],8)&0x00FF00FF)) | |
58 | #else | 58 | #else | |
59 | # define blk0(i) block->l[i] | 59 | # define blk0(i) block->l[i] | |
60 | #endif | 60 | #endif | |
61 | #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ | 61 | #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ | |
62 | ^block->l[(i+2)&15]^block->l[i&15],1)) | 62 | ^block->l[(i+2)&15]^block->l[i&15],1)) | |
63 | 63 | |||
64 | /* | 64 | /* | |
65 | * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1 | 65 | * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1 | |
66 | */ | 66 | */ | |
67 | #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); | 67 | #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); | |
68 | #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); | 68 | #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); | |
69 | #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); | 69 | #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); | |
70 | #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); | 70 | #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); | |
71 | #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); | 71 | #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); | |
72 | 72 | |||
73 | 73 | |||
74 | #if !defined(_KERNEL) && defined(__weak_alias) | 74 | #if !defined(_KERNEL) && defined(__weak_alias) | |
75 | __weak_alias(SHA1Transform,_SHA1Transform) | 75 | __weak_alias(SHA1Transform,_SHA1Transform) | |
76 | __weak_alias(SHA1Init,_SHA1Init) | 76 | __weak_alias(SHA1Init,_SHA1Init) | |
77 | __weak_alias(SHA1Update,_SHA1Update) | 77 | __weak_alias(SHA1Update,_SHA1Update) | |
78 | __weak_alias(SHA1Final,_SHA1Final) | 78 | __weak_alias(SHA1Final,_SHA1Final) | |
79 | #endif | 79 | #endif | |
80 | 80 | |||
81 | typedef union { | 81 | typedef union { | |
82 | u_char c[64]; | 82 | u_char c[64]; | |
83 | u_int l[16]; | 83 | u_int l[16]; | |
84 | } CHAR64LONG16; | 84 | } CHAR64LONG16; | |
85 | 85 | |||
86 | /* old sparc64 gcc could not compile this */ | 86 | /* old sparc64 gcc could not compile this */ | |
87 | #undef SPARC64_GCC_WORKAROUND | 87 | #undef SPARC64_GCC_WORKAROUND | |
88 | #if defined(__sparc64__) && defined(__GNUC__) && __GNUC__ < 3 | 88 | #if defined(__sparc64__) && defined(__GNUC__) && __GNUC__ < 3 | |
89 | #define SPARC64_GCC_WORKAROUND | 89 | #define SPARC64_GCC_WORKAROUND | |
90 | #endif | 90 | #endif | |
91 | 91 | |||
92 | #ifdef SPARC64_GCC_WORKAROUND | 92 | #ifdef SPARC64_GCC_WORKAROUND | |
93 | void do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | 93 | void do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | |
94 | void do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | 94 | void do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | |
95 | void do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | 95 | void do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | |
96 | void do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | 96 | void do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *); | |
97 | 97 | |||
98 | #define nR0(v,w,x,y,z,i) R0(*v,*w,*x,*y,*z,i) | 98 | #define nR0(v,w,x,y,z,i) R0(*v,*w,*x,*y,*z,i) | |
99 | #define nR1(v,w,x,y,z,i) R1(*v,*w,*x,*y,*z,i) | 99 | #define nR1(v,w,x,y,z,i) R1(*v,*w,*x,*y,*z,i) | |
100 | #define nR2(v,w,x,y,z,i) R2(*v,*w,*x,*y,*z,i) | 100 | #define nR2(v,w,x,y,z,i) R2(*v,*w,*x,*y,*z,i) | |
101 | #define nR3(v,w,x,y,z,i) R3(*v,*w,*x,*y,*z,i) | 101 | #define nR3(v,w,x,y,z,i) R3(*v,*w,*x,*y,*z,i) | |
102 | #define nR4(v,w,x,y,z,i) R4(*v,*w,*x,*y,*z,i) | 102 | #define nR4(v,w,x,y,z,i) R4(*v,*w,*x,*y,*z,i) | |
103 | 103 | |||
104 | void | 104 | void | |
105 | do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | 105 | do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | |
106 | { | 106 | { | |
107 | nR0(a,b,c,d,e, 0); nR0(e,a,b,c,d, 1); nR0(d,e,a,b,c, 2); nR0(c,d,e,a,b, 3); | 107 | nR0(a,b,c,d,e, 0); nR0(e,a,b,c,d, 1); nR0(d,e,a,b,c, 2); nR0(c,d,e,a,b, 3); | |
108 | nR0(b,c,d,e,a, 4); nR0(a,b,c,d,e, 5); nR0(e,a,b,c,d, 6); nR0(d,e,a,b,c, 7); | 108 | nR0(b,c,d,e,a, 4); nR0(a,b,c,d,e, 5); nR0(e,a,b,c,d, 6); nR0(d,e,a,b,c, 7); | |
109 | nR0(c,d,e,a,b, 8); nR0(b,c,d,e,a, 9); nR0(a,b,c,d,e,10); nR0(e,a,b,c,d,11); | 109 | nR0(c,d,e,a,b, 8); nR0(b,c,d,e,a, 9); nR0(a,b,c,d,e,10); nR0(e,a,b,c,d,11); | |
110 | nR0(d,e,a,b,c,12); nR0(c,d,e,a,b,13); nR0(b,c,d,e,a,14); nR0(a,b,c,d,e,15); | 110 | nR0(d,e,a,b,c,12); nR0(c,d,e,a,b,13); nR0(b,c,d,e,a,14); nR0(a,b,c,d,e,15); | |
111 | nR1(e,a,b,c,d,16); nR1(d,e,a,b,c,17); nR1(c,d,e,a,b,18); nR1(b,c,d,e,a,19); | 111 | nR1(e,a,b,c,d,16); nR1(d,e,a,b,c,17); nR1(c,d,e,a,b,18); nR1(b,c,d,e,a,19); | |
112 | } | 112 | } | |
113 | 113 | |||
114 | void | 114 | void | |
115 | do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | 115 | do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | |
116 | { | 116 | { | |
117 | nR2(a,b,c,d,e,20); nR2(e,a,b,c,d,21); nR2(d,e,a,b,c,22); nR2(c,d,e,a,b,23); | 117 | nR2(a,b,c,d,e,20); nR2(e,a,b,c,d,21); nR2(d,e,a,b,c,22); nR2(c,d,e,a,b,23); | |
118 | nR2(b,c,d,e,a,24); nR2(a,b,c,d,e,25); nR2(e,a,b,c,d,26); nR2(d,e,a,b,c,27); | 118 | nR2(b,c,d,e,a,24); nR2(a,b,c,d,e,25); nR2(e,a,b,c,d,26); nR2(d,e,a,b,c,27); | |
119 | nR2(c,d,e,a,b,28); nR2(b,c,d,e,a,29); nR2(a,b,c,d,e,30); nR2(e,a,b,c,d,31); | 119 | nR2(c,d,e,a,b,28); nR2(b,c,d,e,a,29); nR2(a,b,c,d,e,30); nR2(e,a,b,c,d,31); | |
120 | nR2(d,e,a,b,c,32); nR2(c,d,e,a,b,33); nR2(b,c,d,e,a,34); nR2(a,b,c,d,e,35); | 120 | nR2(d,e,a,b,c,32); nR2(c,d,e,a,b,33); nR2(b,c,d,e,a,34); nR2(a,b,c,d,e,35); | |
121 | nR2(e,a,b,c,d,36); nR2(d,e,a,b,c,37); nR2(c,d,e,a,b,38); nR2(b,c,d,e,a,39); | 121 | nR2(e,a,b,c,d,36); nR2(d,e,a,b,c,37); nR2(c,d,e,a,b,38); nR2(b,c,d,e,a,39); | |
122 | } | 122 | } | |
123 | 123 | |||
124 | void | 124 | void | |
125 | do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | 125 | do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | |
126 | { | 126 | { | |
127 | nR3(a,b,c,d,e,40); nR3(e,a,b,c,d,41); nR3(d,e,a,b,c,42); nR3(c,d,e,a,b,43); | 127 | nR3(a,b,c,d,e,40); nR3(e,a,b,c,d,41); nR3(d,e,a,b,c,42); nR3(c,d,e,a,b,43); | |
128 | nR3(b,c,d,e,a,44); nR3(a,b,c,d,e,45); nR3(e,a,b,c,d,46); nR3(d,e,a,b,c,47); | 128 | nR3(b,c,d,e,a,44); nR3(a,b,c,d,e,45); nR3(e,a,b,c,d,46); nR3(d,e,a,b,c,47); | |
129 | nR3(c,d,e,a,b,48); nR3(b,c,d,e,a,49); nR3(a,b,c,d,e,50); nR3(e,a,b,c,d,51); | 129 | nR3(c,d,e,a,b,48); nR3(b,c,d,e,a,49); nR3(a,b,c,d,e,50); nR3(e,a,b,c,d,51); | |
130 | nR3(d,e,a,b,c,52); nR3(c,d,e,a,b,53); nR3(b,c,d,e,a,54); nR3(a,b,c,d,e,55); | 130 | nR3(d,e,a,b,c,52); nR3(c,d,e,a,b,53); nR3(b,c,d,e,a,54); nR3(a,b,c,d,e,55); | |
131 | nR3(e,a,b,c,d,56); nR3(d,e,a,b,c,57); nR3(c,d,e,a,b,58); nR3(b,c,d,e,a,59); | 131 | nR3(e,a,b,c,d,56); nR3(d,e,a,b,c,57); nR3(c,d,e,a,b,58); nR3(b,c,d,e,a,59); | |
132 | } | 132 | } | |
133 | 133 | |||
134 | void | 134 | void | |
135 | do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | 135 | do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block) | |
136 | { | 136 | { | |
137 | nR4(a,b,c,d,e,60); nR4(e,a,b,c,d,61); nR4(d,e,a,b,c,62); nR4(c,d,e,a,b,63); | 137 | nR4(a,b,c,d,e,60); nR4(e,a,b,c,d,61); nR4(d,e,a,b,c,62); nR4(c,d,e,a,b,63); | |
138 | nR4(b,c,d,e,a,64); nR4(a,b,c,d,e,65); nR4(e,a,b,c,d,66); nR4(d,e,a,b,c,67); | 138 | nR4(b,c,d,e,a,64); nR4(a,b,c,d,e,65); nR4(e,a,b,c,d,66); nR4(d,e,a,b,c,67); | |
139 | nR4(c,d,e,a,b,68); nR4(b,c,d,e,a,69); nR4(a,b,c,d,e,70); nR4(e,a,b,c,d,71); | 139 | nR4(c,d,e,a,b,68); nR4(b,c,d,e,a,69); nR4(a,b,c,d,e,70); nR4(e,a,b,c,d,71); | |
140 | nR4(d,e,a,b,c,72); nR4(c,d,e,a,b,73); nR4(b,c,d,e,a,74); nR4(a,b,c,d,e,75); | 140 | nR4(d,e,a,b,c,72); nR4(c,d,e,a,b,73); nR4(b,c,d,e,a,74); nR4(a,b,c,d,e,75); | |
141 | nR4(e,a,b,c,d,76); nR4(d,e,a,b,c,77); nR4(c,d,e,a,b,78); nR4(b,c,d,e,a,79); | 141 | nR4(e,a,b,c,d,76); nR4(d,e,a,b,c,77); nR4(c,d,e,a,b,78); nR4(b,c,d,e,a,79); | |
142 | } | 142 | } | |
143 | #endif | 143 | #endif | |
144 | 144 | |||
145 | /* | 145 | /* | |
146 | * Hash a single 512-bit block. This is the core of the algorithm. | 146 | * Hash a single 512-bit block. This is the core of the algorithm. | |
147 | */ | 147 | */ | |
148 | void SHA1Transform(state, buffer) | 148 | void SHA1Transform(uint32_t state[5], const u_char buffer[64]) | |
149 | uint32_t state[5]; | |||
150 | const u_char buffer[64]; | |||
151 | { | 149 | { | |
152 | uint32_t a, b, c, d, e; | 150 | uint32_t a, b, c, d, e; | |
153 | CHAR64LONG16 *block; | 151 | CHAR64LONG16 *block; | |
154 | 152 | |||
155 | #ifdef SHA1HANDSOFF | 153 | #ifdef SHA1HANDSOFF | |
156 | CHAR64LONG16 workspace; | 154 | CHAR64LONG16 workspace; | |
157 | #endif | 155 | #endif | |
158 | 156 | |||
159 | _DIAGASSERT(buffer != 0); | 157 | _DIAGASSERT(buffer != 0); | |
160 | _DIAGASSERT(state != 0); | 158 | _DIAGASSERT(state != 0); | |
161 | 159 | |||
162 | #ifdef SHA1HANDSOFF | 160 | #ifdef SHA1HANDSOFF | |
163 | block = &workspace; | 161 | block = &workspace; | |
164 | (void)memcpy(block, buffer, 64); | 162 | (void)memcpy(block, buffer, 64); | |
165 | #else | 163 | #else | |
166 | block = (CHAR64LONG16 *)(void *)buffer; | 164 | block = (CHAR64LONG16 *)(void *)buffer; | |
167 | #endif | 165 | #endif | |
168 | 166 | |||
169 | /* Copy context->state[] to working vars */ | 167 | /* Copy context->state[] to working vars */ | |
170 | a = state[0]; | 168 | a = state[0]; | |
171 | b = state[1]; | 169 | b = state[1]; | |
172 | c = state[2]; | 170 | c = state[2]; | |
173 | d = state[3]; | 171 | d = state[3]; | |
174 | e = state[4]; | 172 | e = state[4]; | |
175 | 173 | |||
176 | #ifdef SPARC64_GCC_WORKAROUND | 174 | #ifdef SPARC64_GCC_WORKAROUND | |
177 | do_R01(&a, &b, &c, &d, &e, block); | 175 | do_R01(&a, &b, &c, &d, &e, block); | |
178 | do_R2(&a, &b, &c, &d, &e, block); | 176 | do_R2(&a, &b, &c, &d, &e, block); | |
179 | do_R3(&a, &b, &c, &d, &e, block); | 177 | do_R3(&a, &b, &c, &d, &e, block); | |
180 | do_R4(&a, &b, &c, &d, &e, block); | 178 | do_R4(&a, &b, &c, &d, &e, block); | |
181 | #else | 179 | #else | |
182 | /* 4 rounds of 20 operations each. Loop unrolled. */ | 180 | /* 4 rounds of 20 operations each. Loop unrolled. */ | |
183 | R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); | 181 | R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); | |
184 | R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); | 182 | R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); | |
185 | R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); | 183 | R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); | |
186 | R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); | 184 | R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); | |
187 | R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); | 185 | R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); | |
188 | R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); | 186 | R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); | |
189 | R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); | 187 | R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); | |
190 | R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); | 188 | R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); | |
191 | R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); | 189 | R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); | |
192 | R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); | 190 | R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); | |
193 | R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); | 191 | R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); | |
194 | R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); | 192 | R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); | |
195 | R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); | 193 | R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); | |
196 | R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); | 194 | R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); | |
197 | R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); | 195 | R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); | |
198 | R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); | 196 | R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); | |
199 | R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); | 197 | R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); | |
200 | R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); | 198 | R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); | |
201 | R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); | 199 | R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); | |
202 | R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); | 200 | R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); | |
203 | #endif | 201 | #endif | |
204 | 202 | |||
205 | /* Add the working vars back into context.state[] */ | 203 | /* Add the working vars back into context.state[] */ | |
206 | state[0] += a; | 204 | state[0] += a; | |
207 | state[1] += b; | 205 | state[1] += b; | |
208 | state[2] += c; | 206 | state[2] += c; | |
209 | state[3] += d; | 207 | state[3] += d; | |
210 | state[4] += e; | 208 | state[4] += e; | |
211 | 209 | |||
212 | /* Wipe variables */ | 210 | /* Wipe variables */ | |
213 | a = b = c = d = e = 0; | 211 | a = b = c = d = e = 0; | |
214 | } | 212 | } | |
215 | 213 | |||
216 | 214 | |||
217 | /* | 215 | /* | |
218 | * SHA1Init - Initialize new context | 216 | * SHA1Init - Initialize new context | |
219 | */ | 217 | */ | |
220 | void SHA1Init(context) | 218 | void SHA1Init(SHA1_CTX *context) | |
221 | SHA1_CTX *context; | |||
222 | { | 219 | { | |
223 | 220 | |||
224 | _DIAGASSERT(context != 0); | 221 | _DIAGASSERT(context != 0); | |
225 | 222 | |||
226 | /* SHA1 initialization constants */ | 223 | /* SHA1 initialization constants */ | |
227 | context->state[0] = 0x67452301; | 224 | context->state[0] = 0x67452301; | |
228 | context->state[1] = 0xEFCDAB89; | 225 | context->state[1] = 0xEFCDAB89; | |
229 | context->state[2] = 0x98BADCFE; | 226 | context->state[2] = 0x98BADCFE; | |
230 | context->state[3] = 0x10325476; | 227 | context->state[3] = 0x10325476; | |
231 | context->state[4] = 0xC3D2E1F0; | 228 | context->state[4] = 0xC3D2E1F0; | |
232 | context->count[0] = context->count[1] = 0; | 229 | context->count[0] = context->count[1] = 0; | |
233 | } | 230 | } | |
234 | 231 | |||
235 | 232 | |||
236 | /* | 233 | /* | |
237 | * Run your data through this. | 234 | * Run your data through this. | |
238 | */ | 235 | */ | |
239 | void SHA1Update(context, data, len) | 236 | void SHA1Update(SHA1_CTX *context, const u_char *data, u_int len) | |
240 | SHA1_CTX *context; | |||
241 | const u_char *data; | |||
242 | u_int len; | |||
243 | { | 237 | { | |
244 | u_int i, j; | 238 | u_int i, j; | |
245 | 239 | |||
246 | _DIAGASSERT(context != 0); | 240 | _DIAGASSERT(context != 0); | |
247 | _DIAGASSERT(data != 0); | 241 | _DIAGASSERT(data != 0); | |
248 | 242 | |||
249 | j = context->count[0]; | 243 | j = context->count[0]; | |
250 | if ((context->count[0] += len << 3) < j) | 244 | if ((context->count[0] += len << 3) < j) | |
251 | context->count[1] += (len>>29)+1; | 245 | context->count[1] += (len>>29)+1; | |
252 | j = (j >> 3) & 63; | 246 | j = (j >> 3) & 63; | |
253 | if ((j + len) > 63) { | 247 | if ((j + len) > 63) { | |
254 | (void)memcpy(&context->buffer[j], data, (i = 64-j)); | 248 | (void)memcpy(&context->buffer[j], data, (i = 64-j)); | |
255 | SHA1Transform(context->state, context->buffer); | 249 | SHA1Transform(context->state, context->buffer); | |
256 | for ( ; i + 63 < len; i += 64) | 250 | for ( ; i + 63 < len; i += 64) | |
257 | SHA1Transform(context->state, &data[i]); | 251 | SHA1Transform(context->state, &data[i]); | |
258 | j = 0; | 252 | j = 0; | |
259 | } else { | 253 | } else { | |
260 | i = 0; | 254 | i = 0; | |
261 | } | 255 | } | |
262 | (void)memcpy(&context->buffer[j], &data[i], len - i); | 256 | (void)memcpy(&context->buffer[j], &data[i], len - i); | |
263 | } | 257 | } | |
264 | 258 | |||
265 | 259 | |||
266 | /* | 260 | /* | |
267 | * Add padding and return the message digest. | 261 | * Add padding and return the message digest. | |
268 | */ | 262 | */ | |
269 | void SHA1Final(digest, context) | 263 | void SHA1Final(u_char digest[20], SHA1_CTX *context) | |
270 | u_char digest[20]; | |||
271 | SHA1_CTX* context; | |||
272 | { | 264 | { | |
273 | u_int i; | 265 | u_int i; | |
274 | u_char finalcount[8]; | 266 | u_char finalcount[8]; | |
275 | 267 | |||
276 | _DIAGASSERT(digest != 0); | 268 | _DIAGASSERT(digest != 0); | |
277 | _DIAGASSERT(context != 0); | 269 | _DIAGASSERT(context != 0); | |
278 | 270 | |||
279 | for (i = 0; i < 8; i++) { | 271 | for (i = 0; i < 8; i++) { | |
280 | finalcount[i] = (u_char)((context->count[(i >= 4 ? 0 : 1)] | 272 | finalcount[i] = (u_char)((context->count[(i >= 4 ? 0 : 1)] | |
281 | >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ | 273 | >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ | |
282 | } | 274 | } | |
283 | SHA1Update(context, (const u_char *)"\200", 1); | 275 | SHA1Update(context, (const u_char *)"\200", 1); | |
284 | while ((context->count[0] & 504) != 448) | 276 | while ((context->count[0] & 504) != 448) | |
285 | SHA1Update(context, (const u_char *)"\0", 1); | 277 | SHA1Update(context, (const u_char *)"\0", 1); | |
286 | SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ | 278 | SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ | |
287 | 279 | |||
288 | if (digest) { | 280 | if (digest) { | |
289 | for (i = 0; i < 20; i++) | 281 | for (i = 0; i < 20; i++) | |
290 | digest[i] = (u_char) | 282 | digest[i] = (u_char) | |
291 | ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); | 283 | ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); | |
292 | } | 284 | } | |
293 | } | 285 | } | |
294 | 286 | |||
295 | #endif /* HAVE_SHA1_H */ | 287 | #endif /* HAVE_SHA1_H */ |
--- src/common/lib/libc/md/md4c.c 2008/02/16 17:37:13 1.3
+++ src/common/lib/libc/md/md4c.c 2009/03/16 05:59:21 1.4
@@ -1,335 +1,324 @@ | @@ -1,335 +1,324 @@ | |||
1 | /* $NetBSD: md4c.c,v 1.3 2008/02/16 17:37:13 apb Exp $ */ | 1 | /* $NetBSD: md4c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * This file is derived from the RSA Data Security, Inc. MD4 Message-Digest | 4 | * This file is derived from the RSA Data Security, Inc. MD4 Message-Digest | |
5 | * Algorithm and has been modified by Jason R. Thorpe <thorpej@NetBSD.org> | 5 | * Algorithm and has been modified by Jason R. Thorpe <thorpej@NetBSD.org> | |
6 | * for portability and formatting. | 6 | * for portability and formatting. | |
7 | */ | 7 | */ | |
8 | 8 | |||
9 | /* | 9 | /* | |
10 | * Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. | 10 | * Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. | |
11 | * | 11 | * | |
12 | * License to copy and use this software is granted provided that it | 12 | * License to copy and use this software is granted provided that it | |
13 | * is identified as the "RSA Data Security, Inc. MD4 Message-Digest | 13 | * is identified as the "RSA Data Security, Inc. MD4 Message-Digest | |
14 | * Algorithm" in all material mentioning or referencing this software | 14 | * Algorithm" in all material mentioning or referencing this software | |
15 | * or this function. | 15 | * or this function. | |
16 | * | 16 | * | |
17 | * License is also granted to make and use derivative works provided | 17 | * License is also granted to make and use derivative works provided | |
18 | * that such works are identified as "derived from the RSA Data | 18 | * that such works are identified as "derived from the RSA Data | |
19 | * Security, Inc. MD4 Message-Digest Algorithm" in all material | 19 | * Security, Inc. MD4 Message-Digest Algorithm" in all material | |
20 | * mentioning or referencing the derived work. | 20 | * mentioning or referencing the derived work. | |
21 | * | 21 | * | |
22 | * RSA Data Security, Inc. makes no representations concerning either | 22 | * RSA Data Security, Inc. makes no representations concerning either | |
23 | * the merchantability of this software or the suitability of this | 23 | * the merchantability of this software or the suitability of this | |
24 | * software for any particular purpose. It is provided "as is" | 24 | * software for any particular purpose. It is provided "as is" | |
25 | * without express or implied warranty of any kind. | 25 | * without express or implied warranty of any kind. | |
26 | * | 26 | * | |
27 | * These notices must be retained in any copies of any part of this | 27 | * These notices must be retained in any copies of any part of this | |
28 | * documentation and/or software. | 28 | * documentation and/or software. | |
29 | */ | 29 | */ | |
30 | 30 | |||
31 | #if !defined(_KERNEL) && !defined(_STANDALONE) | 31 | #if !defined(_KERNEL) && !defined(_STANDALONE) | |
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) | |
34 | __RCSID("$NetBSD: md4c.c,v 1.3 2008/02/16 17:37:13 apb Exp $"); | 34 | __RCSID("$NetBSD: md4c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $"); | |
35 | #endif /* LIBC_SCCS and not lint */ | 35 | #endif /* LIBC_SCCS and not lint */ | |
36 | 36 | |||
37 | #include "namespace.h" | 37 | #include "namespace.h" | |
38 | 38 | |||
39 | #include <sys/types.h> | 39 | #include <sys/types.h> | |
40 | 40 | |||
41 | #include <assert.h> | 41 | #include <assert.h> | |
42 | #include <md4.h> | 42 | #include <md4.h> | |
43 | #include <string.h> | 43 | #include <string.h> | |
44 | 44 | |||
45 | #if HAVE_NBTOOL_CONFIG_H | 45 | #if HAVE_NBTOOL_CONFIG_H | |
46 | #include "nbtool_config.h" | 46 | #include "nbtool_config.h" | |
47 | #endif | 47 | #endif | |
48 | 48 | |||
49 | #else | 49 | #else | |
50 | 50 | |||
51 | #include <sys/param.h> | 51 | #include <sys/param.h> | |
52 | #include <sys/md4.h> | 52 | #include <sys/md4.h> | |
53 | #include <lib/libkern/libkern.h> | 53 | #include <lib/libkern/libkern.h> | |
54 | 54 | |||
55 | #endif /* !_KERNEL && !_STANDALONE */ | 55 | #endif /* !_KERNEL && !_STANDALONE */ | |
56 | 56 | |||
57 | #if !HAVE_MD4_H | 57 | #if !HAVE_MD4_H | |
58 | 58 | |||
59 | typedef unsigned char *POINTER; | 59 | typedef unsigned char *POINTER; | |
60 | typedef uint16_t UINT2; | 60 | typedef uint16_t UINT2; | |
61 | typedef uint32_t UINT4; | 61 | typedef uint32_t UINT4; | |
62 | 62 | |||
63 | /* | 63 | /* | |
64 | * Constants for MD4Transform routine. | 64 | * Constants for MD4Transform routine. | |
65 | */ | 65 | */ | |
66 | #define S11 3 | 66 | #define S11 3 | |
67 | #define S12 7 | 67 | #define S12 7 | |
68 | #define S13 11 | 68 | #define S13 11 | |
69 | #define S14 19 | 69 | #define S14 19 | |
70 | #define S21 3 | 70 | #define S21 3 | |
71 | #define S22 5 | 71 | #define S22 5 | |
72 | #define S23 9 | 72 | #define S23 9 | |
73 | #define S24 13 | 73 | #define S24 13 | |
74 | #define S31 3 | 74 | #define S31 3 | |
75 | #define S32 9 | 75 | #define S32 9 | |
76 | #define S33 11 | 76 | #define S33 11 | |
77 | #define S34 15 | 77 | #define S34 15 | |
78 | 78 | |||
79 | static void MD4Transform __P((UINT4 [4], const unsigned char [64])); | 79 | static void MD4Transform __P((UINT4 [4], const unsigned char [64])); | |
80 | 80 | |||
81 | static void Encode __P((unsigned char *, UINT4 *, unsigned int)); | 81 | static void Encode __P((unsigned char *, UINT4 *, unsigned int)); | |
82 | static void Decode __P((UINT4 *, const unsigned char *, unsigned int)); | 82 | static void Decode __P((UINT4 *, const unsigned char *, unsigned int)); | |
83 | 83 | |||
84 | static const unsigned char PADDING[64] = { | 84 | static const unsigned char PADDING[64] = { | |
85 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 85 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
86 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 86 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
87 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | 87 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
88 | }; | 88 | }; | |
89 | 89 | |||
90 | /* | 90 | /* | |
91 | * F, G and H are basic MD4 functions. | 91 | * F, G and H are basic MD4 functions. | |
92 | */ | 92 | */ | |
93 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) | 93 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) | |
94 | #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) | 94 | #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) | |
95 | #define H(x, y, z) ((x) ^ (y) ^ (z)) | 95 | #define H(x, y, z) ((x) ^ (y) ^ (z)) | |
96 | 96 | |||
97 | /* | 97 | /* | |
98 | * ROTATE_LEFT rotates x left n bits. | 98 | * ROTATE_LEFT rotates x left n bits. | |
99 | */ | 99 | */ | |
100 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) | 100 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) | |
101 | 101 | |||
102 | /* | 102 | /* | |
103 | * FF, GG and HH are transformations for rounds 1, 2 and 3. | 103 | * FF, GG and HH are transformations for rounds 1, 2 and 3. | |
104 | * Rotation is separate from addition to prevent recomputation. | 104 | * Rotation is separate from addition to prevent recomputation. | |
105 | */ | 105 | */ | |
106 | #define FF(a, b, c, d, x, s) { \ | 106 | #define FF(a, b, c, d, x, s) { \ | |
107 | (a) += F ((b), (c), (d)) + (x); \ | 107 | (a) += F ((b), (c), (d)) + (x); \ | |
108 | (a) = ROTATE_LEFT ((a), (s)); \ | 108 | (a) = ROTATE_LEFT ((a), (s)); \ | |
109 | } | 109 | } | |
110 | 110 | |||
111 | #define GG(a, b, c, d, x, s) { \ | 111 | #define GG(a, b, c, d, x, s) { \ | |
112 | (a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \ | 112 | (a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \ | |
113 | (a) = ROTATE_LEFT ((a), (s)); \ | 113 | (a) = ROTATE_LEFT ((a), (s)); \ | |
114 | } | 114 | } | |
115 | 115 | |||
116 | #define HH(a, b, c, d, x, s) { \ | 116 | #define HH(a, b, c, d, x, s) { \ | |
117 | (a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \ | 117 | (a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \ | |
118 | (a) = ROTATE_LEFT ((a), (s)); \ | 118 | (a) = ROTATE_LEFT ((a), (s)); \ | |
119 | } | 119 | } | |
120 | 120 | |||
121 | #if !defined(_KERNEL) && !defined(_STANDALONE) && defined(__weak_alias) | 121 | #if !defined(_KERNEL) && !defined(_STANDALONE) && defined(__weak_alias) | |
122 | __weak_alias(MD4Init,_MD4Init) | 122 | __weak_alias(MD4Init,_MD4Init) | |
123 | __weak_alias(MD4Update,_MD4Update) | 123 | __weak_alias(MD4Update,_MD4Update) | |
124 | __weak_alias(MD4Final,_MD4Final) | 124 | __weak_alias(MD4Final,_MD4Final) | |
125 | __weak_alias(MD4Transform,_MD4Transform) | 125 | __weak_alias(MD4Transform,_MD4Transform) | |
126 | #endif | 126 | #endif | |
127 | 127 | |||
128 | /* | 128 | /* | |
129 | * MD4 initialization. Begins an MD4 operation, writing a new context. | 129 | * MD4 initialization. Begins an MD4 operation, writing a new context. | |
130 | */ | 130 | */ | |
131 | void | 131 | void | |
132 | MD4Init(context) | 132 | MD4Init(MD4_CTX *context) /* context */ | |
133 | MD4_CTX *context; /* context */ | |||
134 | { | 133 | { | |
135 | 134 | |||
136 | _DIAGASSERT(context != 0); | 135 | _DIAGASSERT(context != 0); | |
137 | 136 | |||
138 | context->count[0] = context->count[1] = 0; | 137 | context->count[0] = context->count[1] = 0; | |
139 | 138 | |||
140 | /* Load magic initialization constants. */ | 139 | /* Load magic initialization constants. */ | |
141 | context->state[0] = 0x67452301; | 140 | context->state[0] = 0x67452301; | |
142 | context->state[1] = 0xefcdab89; | 141 | context->state[1] = 0xefcdab89; | |
143 | context->state[2] = 0x98badcfe; | 142 | context->state[2] = 0x98badcfe; | |
144 | context->state[3] = 0x10325476; | 143 | context->state[3] = 0x10325476; | |
145 | } | 144 | } | |
146 | 145 | |||
147 | /* | 146 | /* | |
148 | * MD4 block update operation. Continues an MD4 message-digest | 147 | * MD4 block update operation. Continues an MD4 message-digest | |
149 | * operation, processing another message block, and updating the | 148 | * operation, processing another message block, and updating the | |
150 | * context. | 149 | * context. | |
151 | */ | 150 | */ | |
152 | void | 151 | void | |
153 | MD4Update (context, input, inputLen) | 152 | MD4Update (MD4_CTX *context, /* context */ | |
154 | MD4_CTX *context; /* context */ | 153 | const unsigned char *input, /* input block */ | |
155 | const unsigned char *input; /* input block */ | 154 | unsigned int inputLen) /* length of input block */ | |
156 | unsigned int inputLen; /* length of input block */ | |||
157 | { | 155 | { | |
158 | unsigned int i, idx, partLen; | 156 | unsigned int i, idx, partLen; | |
159 | 157 | |||
160 | _DIAGASSERT(context != 0); | 158 | _DIAGASSERT(context != 0); | |
161 | _DIAGASSERT(input != 0); | 159 | _DIAGASSERT(input != 0); | |
162 | 160 | |||
163 | /* Compute number of bytes mod 64 */ | 161 | /* Compute number of bytes mod 64 */ | |
164 | idx = (unsigned int)((context->count[0] >> 3) & 0x3F); | 162 | idx = (unsigned int)((context->count[0] >> 3) & 0x3F); | |
165 | 163 | |||
166 | /* Update number of bits */ | 164 | /* Update number of bits */ | |
167 | if ((context->count[0] += ((UINT4)inputLen << 3)) | 165 | if ((context->count[0] += ((UINT4)inputLen << 3)) | |
168 | < ((UINT4)inputLen << 3)) | 166 | < ((UINT4)inputLen << 3)) | |
169 | context->count[1]++; | 167 | context->count[1]++; | |
170 | context->count[1] += ((UINT4)inputLen >> 29); | 168 | context->count[1] += ((UINT4)inputLen >> 29); | |
171 | 169 | |||
172 | partLen = 64 - idx; | 170 | partLen = 64 - idx; | |
173 | 171 | |||
174 | /* Transform as many times as possible. */ | 172 | /* Transform as many times as possible. */ | |
175 | if (inputLen >= partLen) { | 173 | if (inputLen >= partLen) { | |
176 | memcpy(&context->buffer[idx], input, partLen); | 174 | memcpy(&context->buffer[idx], input, partLen); | |
177 | MD4Transform(context->state, context->buffer); | 175 | MD4Transform(context->state, context->buffer); | |
178 | 176 | |||
179 | for (i = partLen; i + 63 < inputLen; i += 64) | 177 | for (i = partLen; i + 63 < inputLen; i += 64) | |
180 | MD4Transform(context->state, &input[i]); | 178 | MD4Transform(context->state, &input[i]); | |
181 | 179 | |||
182 | idx = 0; | 180 | idx = 0; | |
183 | } else | 181 | } else | |
184 | i = 0; | 182 | i = 0; | |
185 | 183 | |||
186 | /* Buffer remaining input */ | 184 | /* Buffer remaining input */ | |
187 | memcpy(&context->buffer[idx], &input[i], inputLen - i); | 185 | memcpy(&context->buffer[idx], &input[i], inputLen - i); | |
188 | } | 186 | } | |
189 | 187 | |||
190 | /* | 188 | /* | |
191 | * MD4 finalization. Ends an MD4 message-digest operation, writing the | 189 | * MD4 finalization. Ends an MD4 message-digest operation, writing the | |
192 | * message digest and zeroing the context. | 190 | * message digest and zeroing the context. | |
193 | */ | 191 | */ | |
194 | void | 192 | void | |
195 | MD4Final (digest, context) | 193 | MD4Final (unsigned char digest[16], /* message digest */ | |
196 | unsigned char digest[16]; /* message digest */ | 194 | MD4_CTX *context) /* context */ | |
197 | MD4_CTX *context; /* context */ | |||
198 | { | 195 | { | |
199 | unsigned char bits[8]; | 196 | unsigned char bits[8]; | |
200 | unsigned int idx, padLen; | 197 | unsigned int idx, padLen; | |
201 | 198 | |||
202 | _DIAGASSERT(digest != 0); | 199 | _DIAGASSERT(digest != 0); | |
203 | _DIAGASSERT(context != 0); | 200 | _DIAGASSERT(context != 0); | |
204 | 201 | |||
205 | /* Save number of bits */ | 202 | /* Save number of bits */ | |
206 | Encode(bits, context->count, 8); | 203 | Encode(bits, context->count, 8); | |
207 | 204 | |||
208 | /* Pad out to 56 mod 64. */ | 205 | /* Pad out to 56 mod 64. */ | |
209 | idx = (unsigned int)((context->count[0] >> 3) & 0x3f); | 206 | idx = (unsigned int)((context->count[0] >> 3) & 0x3f); | |
210 | padLen = (idx < 56) ? (56 - idx) : (120 - idx); | 207 | padLen = (idx < 56) ? (56 - idx) : (120 - idx); | |
211 | MD4Update(context, PADDING, padLen); | 208 | MD4Update(context, PADDING, padLen); | |
212 | 209 | |||
213 | /* Append length (before padding) */ | 210 | /* Append length (before padding) */ | |
214 | MD4Update(context, bits, 8); | 211 | MD4Update(context, bits, 8); | |
215 | 212 | |||
216 | /* Store state in digest */ | 213 | /* Store state in digest */ | |
217 | Encode(digest, context->state, 16); | 214 | Encode(digest, context->state, 16); | |
218 | 215 | |||
219 | /* Zeroize sensitive information. */ | 216 | /* Zeroize sensitive information. */ | |
220 | memset(context, 0, sizeof(*context)); | 217 | memset(context, 0, sizeof(*context)); | |
221 | } | 218 | } | |
222 | 219 | |||
223 | /* | 220 | /* | |
224 | * MD4 basic transformation. Transforms state based on block. | 221 | * MD4 basic transformation. Transforms state based on block. | |
225 | */ | 222 | */ | |
226 | static void | 223 | static void | |
227 | MD4Transform (state, block) | 224 | MD4Transform (UINT4 state[4], const unsigned char block[64]) | |
228 | UINT4 state[4]; | |||
229 | const unsigned char block[64]; | |||
230 | { | 225 | { | |
231 | UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; | 226 | UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; | |
232 | 227 | |||
233 | Decode(x, block, 64); | 228 | Decode(x, block, 64); | |
234 | 229 | |||
235 | /* Round 1 */ | 230 | /* Round 1 */ | |
236 | FF (a, b, c, d, x[ 0], S11); /* 1 */ | 231 | FF (a, b, c, d, x[ 0], S11); /* 1 */ | |
237 | FF (d, a, b, c, x[ 1], S12); /* 2 */ | 232 | FF (d, a, b, c, x[ 1], S12); /* 2 */ | |
238 | FF (c, d, a, b, x[ 2], S13); /* 3 */ | 233 | FF (c, d, a, b, x[ 2], S13); /* 3 */ | |
239 | FF (b, c, d, a, x[ 3], S14); /* 4 */ | 234 | FF (b, c, d, a, x[ 3], S14); /* 4 */ | |
240 | FF (a, b, c, d, x[ 4], S11); /* 5 */ | 235 | FF (a, b, c, d, x[ 4], S11); /* 5 */ | |
241 | FF (d, a, b, c, x[ 5], S12); /* 6 */ | 236 | FF (d, a, b, c, x[ 5], S12); /* 6 */ | |
242 | FF (c, d, a, b, x[ 6], S13); /* 7 */ | 237 | FF (c, d, a, b, x[ 6], S13); /* 7 */ | |
243 | FF (b, c, d, a, x[ 7], S14); /* 8 */ | 238 | FF (b, c, d, a, x[ 7], S14); /* 8 */ | |
244 | FF (a, b, c, d, x[ 8], S11); /* 9 */ | 239 | FF (a, b, c, d, x[ 8], S11); /* 9 */ | |
245 | FF (d, a, b, c, x[ 9], S12); /* 10 */ | 240 | FF (d, a, b, c, x[ 9], S12); /* 10 */ | |
246 | FF (c, d, a, b, x[10], S13); /* 11 */ | 241 | FF (c, d, a, b, x[10], S13); /* 11 */ | |
247 | FF (b, c, d, a, x[11], S14); /* 12 */ | 242 | FF (b, c, d, a, x[11], S14); /* 12 */ | |
248 | FF (a, b, c, d, x[12], S11); /* 13 */ | 243 | FF (a, b, c, d, x[12], S11); /* 13 */ | |
249 | FF (d, a, b, c, x[13], S12); /* 14 */ | 244 | FF (d, a, b, c, x[13], S12); /* 14 */ | |
250 | FF (c, d, a, b, x[14], S13); /* 15 */ | 245 | FF (c, d, a, b, x[14], S13); /* 15 */ | |
251 | FF (b, c, d, a, x[15], S14); /* 16 */ | 246 | FF (b, c, d, a, x[15], S14); /* 16 */ | |
252 | 247 | |||
253 | /* Round 2 */ | 248 | /* Round 2 */ | |
254 | GG (a, b, c, d, x[ 0], S21); /* 17 */ | 249 | GG (a, b, c, d, x[ 0], S21); /* 17 */ | |
255 | GG (d, a, b, c, x[ 4], S22); /* 18 */ | 250 | GG (d, a, b, c, x[ 4], S22); /* 18 */ | |
256 | GG (c, d, a, b, x[ 8], S23); /* 19 */ | 251 | GG (c, d, a, b, x[ 8], S23); /* 19 */ | |
257 | GG (b, c, d, a, x[12], S24); /* 20 */ | 252 | GG (b, c, d, a, x[12], S24); /* 20 */ | |
258 | GG (a, b, c, d, x[ 1], S21); /* 21 */ | 253 | GG (a, b, c, d, x[ 1], S21); /* 21 */ | |
259 | GG (d, a, b, c, x[ 5], S22); /* 22 */ | 254 | GG (d, a, b, c, x[ 5], S22); /* 22 */ | |
260 | GG (c, d, a, b, x[ 9], S23); /* 23 */ | 255 | GG (c, d, a, b, x[ 9], S23); /* 23 */ | |
261 | GG (b, c, d, a, x[13], S24); /* 24 */ | 256 | GG (b, c, d, a, x[13], S24); /* 24 */ | |
262 | GG (a, b, c, d, x[ 2], S21); /* 25 */ | 257 | GG (a, b, c, d, x[ 2], S21); /* 25 */ | |
263 | GG (d, a, b, c, x[ 6], S22); /* 26 */ | 258 | GG (d, a, b, c, x[ 6], S22); /* 26 */ | |
264 | GG (c, d, a, b, x[10], S23); /* 27 */ | 259 | GG (c, d, a, b, x[10], S23); /* 27 */ | |
265 | GG (b, c, d, a, x[14], S24); /* 28 */ | 260 | GG (b, c, d, a, x[14], S24); /* 28 */ | |
266 | GG (a, b, c, d, x[ 3], S21); /* 29 */ | 261 | GG (a, b, c, d, x[ 3], S21); /* 29 */ | |
267 | GG (d, a, b, c, x[ 7], S22); /* 30 */ | 262 | GG (d, a, b, c, x[ 7], S22); /* 30 */ | |
268 | GG (c, d, a, b, x[11], S23); /* 31 */ | 263 | GG (c, d, a, b, x[11], S23); /* 31 */ | |
269 | GG (b, c, d, a, x[15], S24); /* 32 */ | 264 | GG (b, c, d, a, x[15], S24); /* 32 */ | |
270 | 265 | |||
271 | /* Round 3 */ | 266 | /* Round 3 */ | |
272 | HH (a, b, c, d, x[ 0], S31); /* 33 */ | 267 | HH (a, b, c, d, x[ 0], S31); /* 33 */ | |
273 | HH (d, a, b, c, x[ 8], S32); /* 34 */ | 268 | HH (d, a, b, c, x[ 8], S32); /* 34 */ | |
274 | HH (c, d, a, b, x[ 4], S33); /* 35 */ | 269 | HH (c, d, a, b, x[ 4], S33); /* 35 */ | |
275 | HH (b, c, d, a, x[12], S34); /* 36 */ | 270 | HH (b, c, d, a, x[12], S34); /* 36 */ | |
276 | HH (a, b, c, d, x[ 2], S31); /* 37 */ | 271 | HH (a, b, c, d, x[ 2], S31); /* 37 */ | |
277 | HH (d, a, b, c, x[10], S32); /* 38 */ | 272 | HH (d, a, b, c, x[10], S32); /* 38 */ | |
278 | HH (c, d, a, b, x[ 6], S33); /* 39 */ | 273 | HH (c, d, a, b, x[ 6], S33); /* 39 */ | |
279 | HH (b, c, d, a, x[14], S34); /* 40 */ | 274 | HH (b, c, d, a, x[14], S34); /* 40 */ | |
280 | HH (a, b, c, d, x[ 1], S31); /* 41 */ | 275 | HH (a, b, c, d, x[ 1], S31); /* 41 */ | |
281 | HH (d, a, b, c, x[ 9], S32); /* 42 */ | 276 | HH (d, a, b, c, x[ 9], S32); /* 42 */ | |
282 | HH (c, d, a, b, x[ 5], S33); /* 43 */ | 277 | HH (c, d, a, b, x[ 5], S33); /* 43 */ | |
283 | HH (b, c, d, a, x[13], S34); /* 44 */ | 278 | HH (b, c, d, a, x[13], S34); /* 44 */ | |
284 | HH (a, b, c, d, x[ 3], S31); /* 45 */ | 279 | HH (a, b, c, d, x[ 3], S31); /* 45 */ | |
285 | HH (d, a, b, c, x[11], S32); /* 46 */ | 280 | HH (d, a, b, c, x[11], S32); /* 46 */ | |
286 | HH (c, d, a, b, x[ 7], S33); /* 47 */ | 281 | HH (c, d, a, b, x[ 7], S33); /* 47 */ | |
287 | HH (b, c, d, a, x[15], S34); /* 48 */ | 282 | HH (b, c, d, a, x[15], S34); /* 48 */ | |
288 | 283 | |||
289 | state[0] += a; | 284 | state[0] += a; | |
290 | state[1] += b; | 285 | state[1] += b; | |
291 | state[2] += c; | 286 | state[2] += c; | |
292 | state[3] += d; | 287 | state[3] += d; | |
293 | 288 | |||
294 | /* Zeroize sensitive information. */ | 289 | /* Zeroize sensitive information. */ | |
295 | memset(x, 0, sizeof (x)); | 290 | memset(x, 0, sizeof (x)); | |
296 | } | 291 | } | |
297 | 292 | |||
298 | /* | 293 | /* | |
299 | * Encodes input (UINT4) into output (unsigned char). Assumes len is | 294 | * Encodes input (UINT4) into output (unsigned char). Assumes len is | |
300 | * a multiple of 4. | 295 | * a multiple of 4. | |
301 | */ | 296 | */ | |
302 | static void | 297 | static void | |
303 | Encode(output, input, len) | 298 | Encode(unsigned char *output, UINT4 *input, unsigned int len) | |
304 | unsigned char *output; | |||
305 | UINT4 *input; | |||
306 | unsigned int len; | |||
307 | { | 299 | { | |
308 | unsigned int i, j; | 300 | unsigned int i, j; | |
309 | 301 | |||
310 | for (i = 0, j = 0; j < len; i++, j += 4) { | 302 | for (i = 0, j = 0; j < len; i++, j += 4) { | |
311 | output[j] = (unsigned char)(input[i] & 0xff); | 303 | output[j] = (unsigned char)(input[i] & 0xff); | |
312 | output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); | 304 | output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); | |
313 | output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); | 305 | output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); | |
314 | output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); | 306 | output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); | |
315 | } | 307 | } | |
316 | } | 308 | } | |
317 | 309 | |||
318 | /* | 310 | /* | |
319 | * Decodes input (unsigned char) into output (UINT4). Assumes len is | 311 | * Decodes input (unsigned char) into output (UINT4). Assumes len is | |
320 | * a multiple of 4. | 312 | * a multiple of 4. | |
321 | */ | 313 | */ | |
322 | static void | 314 | static void | |
323 | Decode(output, input, len) | 315 | Decode(UINT4 *output, const unsigned char *input, unsigned int len) | |
324 | UINT4 *output; | |||
325 | const unsigned char *input; | |||
326 | unsigned int len; | |||
327 | { | 316 | { | |
328 | unsigned int i, j; | 317 | unsigned int i, j; | |
329 | 318 | |||
330 | for (i = 0, j = 0; j < len; i++, j += 4) | 319 | for (i = 0, j = 0; j < len; i++, j += 4) | |
331 | output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | | 320 | output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | | |
332 | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); | 321 | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); | |
333 | } | 322 | } | |
334 | 323 | |||
335 | #endif /* HAVE_MD4_H */ | 324 | #endif /* HAVE_MD4_H */ |
--- src/common/lib/libc/md/md5c.c 2008/02/16 17:37:13 1.3
+++ src/common/lib/libc/md/md5c.c 2009/03/16 05:59:21 1.4
@@ -1,364 +1,357 @@ | @@ -1,364 +1,357 @@ | |||
1 | /* $NetBSD: md5c.c,v 1.3 2008/02/16 17:37:13 apb Exp $ */ | 1 | /* $NetBSD: md5c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * This file is derived from the RSA Data Security, Inc. MD5 Message-Digest | 4 | * This file is derived from the RSA Data Security, Inc. MD5 Message-Digest | |
5 | * Algorithm and has been modified by Jason R. Thorpe <thorpej@NetBSD.org> | 5 | * Algorithm and has been modified by Jason R. Thorpe <thorpej@NetBSD.org> | |
6 | * for portability and formatting. | 6 | * for portability and formatting. | |
7 | */ | 7 | */ | |
8 | 8 | |||
9 | /* | 9 | /* | |
10 | * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All | 10 | * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All | |
11 | * rights reserved. | 11 | * rights reserved. | |
12 | * | 12 | * | |
13 | * License to copy and use this software is granted provided that it | 13 | * License to copy and use this software is granted provided that it | |
14 | * is identified as the "RSA Data Security, Inc. MD5 Message-Digest | 14 | * is identified as the "RSA Data Security, Inc. MD5 Message-Digest | |
15 | * Algorithm" in all material mentioning or referencing this software | 15 | * Algorithm" in all material mentioning or referencing this software | |
16 | * or this function. | 16 | * or this function. | |
17 | * | 17 | * | |
18 | * License is also granted to make and use derivative works provided | 18 | * License is also granted to make and use derivative works provided | |
19 | * that such works are identified as "derived from the RSA Data | 19 | * that such works are identified as "derived from the RSA Data | |
20 | * Security, Inc. MD5 Message-Digest Algorithm" in all material | 20 | * Security, Inc. MD5 Message-Digest Algorithm" in all material | |
21 | * mentioning or referencing the derived work. | 21 | * mentioning or referencing the derived work. | |
22 | * | 22 | * | |
23 | * RSA Data Security, Inc. makes no representations concerning either | 23 | * RSA Data Security, Inc. makes no representations concerning either | |
24 | * the merchantability of this software or the suitability of this | 24 | * the merchantability of this software or the suitability of this | |
25 | * software for any particular purpose. It is provided "as is" | 25 | * software for any particular purpose. It is provided "as is" | |
26 | * without express or implied warranty of any kind. | 26 | * without express or implied warranty of any kind. | |
27 | * | 27 | * | |
28 | * These notices must be retained in any copies of any part of this | 28 | * These notices must be retained in any copies of any part of this | |
29 | * documentation and/or software. | 29 | * documentation and/or software. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if defined(_KERNEL) || defined(_STANDALONE) | 32 | #if defined(_KERNEL) || defined(_STANDALONE) | |
33 | #include <sys/param.h> | 33 | #include <sys/param.h> | |
34 | #include <sys/md5.h> | 34 | #include <sys/md5.h> | |
35 | #include <lib/libkern/libkern.h> | 35 | #include <lib/libkern/libkern.h> | |
36 | #else | 36 | #else | |
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | #if defined(LIBC_SCCS) && !defined(lint) | 38 | #if defined(LIBC_SCCS) && !defined(lint) | |
39 | __RCSID("$NetBSD: md5c.c,v 1.3 2008/02/16 17:37:13 apb Exp $"); | 39 | __RCSID("$NetBSD: md5c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $"); | |
40 | #endif /* LIBC_SCCS and not lint */ | 40 | #endif /* LIBC_SCCS and not lint */ | |
41 | #include "namespace.h" | 41 | #include "namespace.h" | |
42 | #include <sys/types.h> | 42 | #include <sys/types.h> | |
43 | #include <assert.h> | 43 | #include <assert.h> | |
44 | #include <string.h> | 44 | #include <string.h> | |
45 | #include <md5.h> | 45 | #include <md5.h> | |
46 | #endif /* _KERNEL || _STANDALONE */ | 46 | #endif /* _KERNEL || _STANDALONE */ | |
47 | 47 | |||
48 | #if HAVE_NBTOOL_CONFIG_H | 48 | #if HAVE_NBTOOL_CONFIG_H | |
49 | #include "nbtool_config.h" | 49 | #include "nbtool_config.h" | |
50 | #endif | 50 | #endif | |
51 | 51 | |||
52 | #if !HAVE_MD5_H | 52 | #if !HAVE_MD5_H | |
53 | 53 | |||
54 | #define ZEROIZE(d, l) memset((d), 0, (l)) | 54 | #define ZEROIZE(d, l) memset((d), 0, (l)) | |
55 | 55 | |||
56 | typedef unsigned char *POINTER; | 56 | typedef unsigned char *POINTER; | |
57 | typedef uint16_t UINT2; | 57 | typedef uint16_t UINT2; | |
58 | typedef uint32_t UINT4; | 58 | typedef uint32_t UINT4; | |
59 | 59 | |||
60 | /* | 60 | /* | |
61 | * Constants for MD5Transform routine. | 61 | * Constants for MD5Transform routine. | |
62 | */ | 62 | */ | |
63 | #define S11 7 | 63 | #define S11 7 | |
64 | #define S12 12 | 64 | #define S12 12 | |
65 | #define S13 17 | 65 | #define S13 17 | |
66 | #define S14 22 | 66 | #define S14 22 | |
67 | #define S21 5 | 67 | #define S21 5 | |
68 | #define S22 9 | 68 | #define S22 9 | |
69 | #define S23 14 | 69 | #define S23 14 | |
70 | #define S24 20 | 70 | #define S24 20 | |
71 | #define S31 4 | 71 | #define S31 4 | |
72 | #define S32 11 | 72 | #define S32 11 | |
73 | #define S33 16 | 73 | #define S33 16 | |
74 | #define S34 23 | 74 | #define S34 23 | |
75 | #define S41 6 | 75 | #define S41 6 | |
76 | #define S42 10 | 76 | #define S42 10 | |
77 | #define S43 15 | 77 | #define S43 15 | |
78 | #define S44 21 | 78 | #define S44 21 | |
79 | 79 | |||
80 | #if !defined(_KERNEL) && !defined(_STANDALONE) && defined(__weak_alias) | 80 | #if !defined(_KERNEL) && !defined(_STANDALONE) && defined(__weak_alias) | |
81 | __weak_alias(MD5Init,_MD5Init) | 81 | __weak_alias(MD5Init,_MD5Init) | |
82 | __weak_alias(MD5Update,_MD5Update) | 82 | __weak_alias(MD5Update,_MD5Update) | |
83 | __weak_alias(MD5Final,_MD5Final) | 83 | __weak_alias(MD5Final,_MD5Final) | |
84 | __weak_alias(MD5Transform,_MD5Transform) | 84 | __weak_alias(MD5Transform,_MD5Transform) | |
85 | #endif | 85 | #endif | |
86 | 86 | |||
87 | static void MD5Transform __P((UINT4 [4], const unsigned char [64])); | 87 | static void MD5Transform __P((UINT4 [4], const unsigned char [64])); | |
88 | 88 | |||
89 | static void Encode __P((unsigned char *, UINT4 *, unsigned int)); | 89 | static void Encode __P((unsigned char *, UINT4 *, unsigned int)); | |
90 | static void Decode __P((UINT4 *, const unsigned char *, unsigned int)); | 90 | static void Decode __P((UINT4 *, const unsigned char *, unsigned int)); | |
91 | 91 | |||
92 | /* | 92 | /* | |
93 | * Encodes input (UINT4) into output (unsigned char). Assumes len is | 93 | * Encodes input (UINT4) into output (unsigned char). Assumes len is | |
94 | * a multiple of 4. | 94 | * a multiple of 4. | |
95 | */ | 95 | */ | |
96 | static void | 96 | static void | |
97 | Encode (output, input, len) | 97 | Encode (unsigned char *output, | |
98 | unsigned char *output; | 98 | UINT4 *input, | |
99 | UINT4 *input; | 99 | unsigned int len) | |
100 | unsigned int len; | |||
101 | { | 100 | { | |
102 | unsigned int i, j; | 101 | unsigned int i, j; | |
103 | 102 | |||
104 | for (i = 0, j = 0; j < len; i++, j += 4) { | 103 | for (i = 0, j = 0; j < len; i++, j += 4) { | |
105 | output[j] = (unsigned char)(input[i] & 0xff); | 104 | output[j] = (unsigned char)(input[i] & 0xff); | |
106 | output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); | 105 | output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); | |
107 | output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); | 106 | output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); | |
108 | output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); | 107 | output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); | |
109 | } | 108 | } | |
110 | } | 109 | } | |
111 | 110 | |||
112 | /* | 111 | /* | |
113 | * Decodes input (unsigned char) into output (UINT4). Assumes len is | 112 | * Decodes input (unsigned char) into output (UINT4). Assumes len is | |
114 | * a multiple of 4. | 113 | * a multiple of 4. | |
115 | */ | 114 | */ | |
116 | static void | 115 | static void | |
117 | Decode (output, input, len) | 116 | Decode (UINT4 *output, | |
118 | UINT4 *output; | 117 | const unsigned char *input, | |
119 | const unsigned char *input; | 118 | unsigned int len) | |
120 | unsigned int len; | |||
121 | { | 119 | { | |
122 | unsigned int i, j; | 120 | unsigned int i, j; | |
123 | 121 | |||
124 | for (i = 0, j = 0; j < len; i++, j += 4) | 122 | for (i = 0, j = 0; j < len; i++, j += 4) | |
125 | output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | | 123 | output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | | |
126 | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); | 124 | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); | |
127 | } | 125 | } | |
128 | 126 | |||
129 | static const unsigned char PADDING[64] = { | 127 | static const unsigned char PADDING[64] = { | |
130 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 128 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
131 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 129 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
132 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | 130 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
133 | }; | 131 | }; | |
134 | 132 | |||
135 | /* | 133 | /* | |
136 | * F, G, H and I are basic MD5 functions. | 134 | * F, G, H and I are basic MD5 functions. | |
137 | */ | 135 | */ | |
138 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) | 136 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) | |
139 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) | 137 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) | |
140 | #define H(x, y, z) ((x) ^ (y) ^ (z)) | 138 | #define H(x, y, z) ((x) ^ (y) ^ (z)) | |
141 | #define I(x, y, z) ((y) ^ ((x) | (~z))) | 139 | #define I(x, y, z) ((y) ^ ((x) | (~z))) | |
142 | 140 | |||
143 | /* | 141 | /* | |
144 | * ROTATE_LEFT rotates x left n bits. | 142 | * ROTATE_LEFT rotates x left n bits. | |
145 | */ | 143 | */ | |
146 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) | 144 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) | |
147 | 145 | |||
148 | /* | 146 | /* | |
149 | * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. | 147 | * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. | |
150 | * Rotation is separate from addition to prevent recomputation. | 148 | * Rotation is separate from addition to prevent recomputation. | |
151 | */ | 149 | */ | |
152 | #define FF(a, b, c, d, x, s, ac) { \ | 150 | #define FF(a, b, c, d, x, s, ac) { \ | |
153 | (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 151 | (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ | |
154 | (a) = ROTATE_LEFT ((a), (s)); \ | 152 | (a) = ROTATE_LEFT ((a), (s)); \ | |
155 | (a) += (b); \ | 153 | (a) += (b); \ | |
156 | } | 154 | } | |
157 | 155 | |||
158 | #define GG(a, b, c, d, x, s, ac) { \ | 156 | #define GG(a, b, c, d, x, s, ac) { \ | |
159 | (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 157 | (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ | |
160 | (a) = ROTATE_LEFT ((a), (s)); \ | 158 | (a) = ROTATE_LEFT ((a), (s)); \ | |
161 | (a) += (b); \ | 159 | (a) += (b); \ | |
162 | } | 160 | } | |
163 | 161 | |||
164 | #define HH(a, b, c, d, x, s, ac) { \ | 162 | #define HH(a, b, c, d, x, s, ac) { \ | |
165 | (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 163 | (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ | |
166 | (a) = ROTATE_LEFT ((a), (s)); \ | 164 | (a) = ROTATE_LEFT ((a), (s)); \ | |
167 | (a) += (b); \ | 165 | (a) += (b); \ | |
168 | } | 166 | } | |
169 | 167 | |||
170 | #define II(a, b, c, d, x, s, ac) { \ | 168 | #define II(a, b, c, d, x, s, ac) { \ | |
171 | (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 169 | (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ | |
172 | (a) = ROTATE_LEFT ((a), (s)); \ | 170 | (a) = ROTATE_LEFT ((a), (s)); \ | |
173 | (a) += (b); \ | 171 | (a) += (b); \ | |
174 | } | 172 | } | |
175 | 173 | |||
176 | /* | 174 | /* | |
177 | * MD5 initialization. Begins an MD5 operation, writing a new context. | 175 | * MD5 initialization. Begins an MD5 operation, writing a new context. | |
178 | */ | 176 | */ | |
179 | void | 177 | void | |
180 | MD5Init(context) | 178 | MD5Init(MD5_CTX *context) | |
181 | MD5_CTX *context; /* context */ | |||
182 | { | 179 | { | |
183 | 180 | |||
184 | _DIAGASSERT(context != 0); | 181 | _DIAGASSERT(context != 0); | |
185 | 182 | |||
186 | context->count[0] = context->count[1] = 0; | 183 | context->count[0] = context->count[1] = 0; | |
187 | 184 | |||
188 | /* Load magic initialization constants. */ | 185 | /* Load magic initialization constants. */ | |
189 | context->state[0] = 0x67452301; | 186 | context->state[0] = 0x67452301; | |
190 | context->state[1] = 0xefcdab89; | 187 | context->state[1] = 0xefcdab89; | |
191 | context->state[2] = 0x98badcfe; | 188 | context->state[2] = 0x98badcfe; | |
192 | context->state[3] = 0x10325476; | 189 | context->state[3] = 0x10325476; | |
193 | } | 190 | } | |
194 | 191 | |||
195 | /* | 192 | /* | |
196 | * MD5 block update operation. Continues an MD5 message-digest | 193 | * MD5 block update operation. Continues an MD5 message-digest | |
197 | * operation, processing another message block, and updating the | 194 | * operation, processing another message block, and updating the | |
198 | * context. | 195 | * context. | |
199 | */ | 196 | */ | |
200 | void | 197 | void | |
201 | MD5Update(context, input, inputLen) | 198 | MD5Update(MD5_CTX *context, | |
202 | MD5_CTX *context; /* context */ | 199 | const unsigned char *input, /* input block */ | |
203 | const unsigned char *input; /* input block */ | 200 | unsigned int inputLen) /* length of input block */ | |
204 | unsigned int inputLen; /* length of input block */ | |||
205 | { | 201 | { | |
206 | unsigned int i, idx, partLen; | 202 | unsigned int i, idx, partLen; | |
207 | 203 | |||
208 | _DIAGASSERT(context != 0); | 204 | _DIAGASSERT(context != 0); | |
209 | _DIAGASSERT(input != 0); | 205 | _DIAGASSERT(input != 0); | |
210 | 206 | |||
211 | /* Compute number of bytes mod 64 */ | 207 | /* Compute number of bytes mod 64 */ | |
212 | idx = (unsigned int)((context->count[0] >> 3) & 0x3F); | 208 | idx = (unsigned int)((context->count[0] >> 3) & 0x3F); | |
213 | 209 | |||
214 | /* Update number of bits */ | 210 | /* Update number of bits */ | |
215 | if ((context->count[0] += ((UINT4)inputLen << 3)) | 211 | if ((context->count[0] += ((UINT4)inputLen << 3)) | |
216 | < ((UINT4)inputLen << 3)) | 212 | < ((UINT4)inputLen << 3)) | |
217 | context->count[1]++; | 213 | context->count[1]++; | |
218 | context->count[1] += ((UINT4)inputLen >> 29); | 214 | context->count[1] += ((UINT4)inputLen >> 29); | |
219 | 215 | |||
220 | partLen = 64 - idx; | 216 | partLen = 64 - idx; | |
221 | 217 | |||
222 | /* Transform as many times as possible. */ | 218 | /* Transform as many times as possible. */ | |
223 | if (inputLen >= partLen) { | 219 | if (inputLen >= partLen) { | |
224 | memcpy((POINTER)&context->buffer[idx], input, partLen); | 220 | memcpy((POINTER)&context->buffer[idx], input, partLen); | |
225 | MD5Transform(context->state, context->buffer); | 221 | MD5Transform(context->state, context->buffer); | |
226 | 222 | |||
227 | for (i = partLen; i + 63 < inputLen; i += 64) | 223 | for (i = partLen; i + 63 < inputLen; i += 64) | |
228 | MD5Transform(context->state, &input[i]); | 224 | MD5Transform(context->state, &input[i]); | |
229 | 225 | |||
230 | idx = 0; | 226 | idx = 0; | |
231 | } else | 227 | } else | |
232 | i = 0; | 228 | i = 0; | |
233 | 229 | |||
234 | /* Buffer remaining input */ | 230 | /* Buffer remaining input */ | |
235 | memcpy(&context->buffer[idx], &input[i], inputLen - i); | 231 | memcpy(&context->buffer[idx], &input[i], inputLen - i); | |
236 | } | 232 | } | |
237 | 233 | |||
238 | /* | 234 | /* | |
239 | * MD5 finalization. Ends an MD5 message-digest operation, writing the | 235 | * MD5 finalization. Ends an MD5 message-digest operation, writing the | |
240 | * message digest and zeroing the context. | 236 | * message digest and zeroing the context. | |
241 | */ | 237 | */ | |
242 | void | 238 | void | |
243 | MD5Final(digest, context) | 239 | MD5Final(unsigned char digest[16], /* message digest */ | |
244 | unsigned char digest[16]; /* message digest */ | 240 | MD5_CTX *context) /* context */ | |
245 | MD5_CTX *context; /* context */ | |||
246 | { | 241 | { | |
247 | unsigned char bits[8]; | 242 | unsigned char bits[8]; | |
248 | unsigned int idx, padLen; | 243 | unsigned int idx, padLen; | |
249 | 244 | |||
250 | _DIAGASSERT(digest != 0); | 245 | _DIAGASSERT(digest != 0); | |
251 | _DIAGASSERT(context != 0); | 246 | _DIAGASSERT(context != 0); | |
252 | 247 | |||
253 | /* Save number of bits */ | 248 | /* Save number of bits */ | |
254 | Encode(bits, context->count, 8); | 249 | Encode(bits, context->count, 8); | |
255 | 250 | |||
256 | /* Pad out to 56 mod 64. */ | 251 | /* Pad out to 56 mod 64. */ | |
257 | idx = (unsigned int)((context->count[0] >> 3) & 0x3f); | 252 | idx = (unsigned int)((context->count[0] >> 3) & 0x3f); | |
258 | padLen = (idx < 56) ? (56 - idx) : (120 - idx); | 253 | padLen = (idx < 56) ? (56 - idx) : (120 - idx); | |
259 | MD5Update (context, PADDING, padLen); | 254 | MD5Update (context, PADDING, padLen); | |
260 | 255 | |||
261 | /* Append length (before padding) */ | 256 | /* Append length (before padding) */ | |
262 | MD5Update(context, bits, 8); | 257 | MD5Update(context, bits, 8); | |
263 | 258 | |||
264 | /* Store state in digest */ | 259 | /* Store state in digest */ | |
265 | Encode(digest, context->state, 16); | 260 | Encode(digest, context->state, 16); | |
266 | 261 | |||
267 | /* Zeroize sensitive information. */ | 262 | /* Zeroize sensitive information. */ | |
268 | ZEROIZE((POINTER)(void *)context, sizeof(*context)); | 263 | ZEROIZE((POINTER)(void *)context, sizeof(*context)); | |
269 | } | 264 | } | |
270 | 265 | |||
271 | /* | 266 | /* | |
272 | * MD5 basic transformation. Transforms state based on block. | 267 | * MD5 basic transformation. Transforms state based on block. | |
273 | */ | 268 | */ | |
274 | static void | 269 | static void | |
275 | MD5Transform(state, block) | 270 | MD5Transform(UINT4 state[4], const unsigned char block[64]) | |
276 | UINT4 state[4]; | |||
277 | const unsigned char block[64]; | |||
278 | { | 271 | { | |
279 | UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; | 272 | UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; | |
280 | 273 | |||
281 | Decode(x, block, 64); | 274 | Decode(x, block, 64); | |
282 | 275 | |||
283 | /* Round 1 */ | 276 | /* Round 1 */ | |
284 | FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ | 277 | FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ | |
285 | FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ | 278 | FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ | |
286 | FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ | 279 | FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ | |
287 | FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ | 280 | FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ | |
288 | FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ | 281 | FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ | |
289 | FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ | 282 | FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ | |
290 | FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ | 283 | FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ | |
291 | FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ | 284 | FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ | |
292 | FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ | 285 | FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ | |
293 | FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ | 286 | FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ | |
294 | FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ | 287 | FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ | |
295 | FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ | 288 | FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ | |
296 | FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ | 289 | FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ | |
297 | FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ | 290 | FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ | |
298 | FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ | 291 | FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ | |
299 | FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ | 292 | FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ | |
300 | 293 | |||
301 | /* Round 2 */ | 294 | /* Round 2 */ | |
302 | GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ | 295 | GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ | |
303 | GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ | 296 | GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ | |
304 | GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ | 297 | GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ | |
305 | GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ | 298 | GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ | |
306 | GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ | 299 | GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ | |
307 | GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ | 300 | GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ | |
308 | GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ | 301 | GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ | |
309 | GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ | 302 | GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ | |
310 | GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ | 303 | GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ | |
311 | GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ | 304 | GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ | |
312 | GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ | 305 | GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ | |
313 | GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ | 306 | GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ | |
314 | GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ | 307 | GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ | |
315 | GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ | 308 | GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ | |
316 | GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ | 309 | GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ | |
317 | GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ | 310 | GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ | |
318 | 311 | |||
319 | /* Round 3 */ | 312 | /* Round 3 */ | |
320 | HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ | 313 | HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ | |
321 | HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ | 314 | HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ | |
322 | HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ | 315 | HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ | |
323 | HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ | 316 | HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ | |
324 | HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ | 317 | HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ | |
325 | HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ | 318 | HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ | |
326 | HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ | 319 | HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ | |
327 | HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ | 320 | HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ | |
328 | HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ | 321 | HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ | |
329 | HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ | 322 | HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ | |
330 | HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ | 323 | HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ | |
331 | HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ | 324 | HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ | |
332 | HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ | 325 | HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ | |
333 | HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ | 326 | HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ | |
334 | HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ | 327 | HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ | |
335 | HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ | 328 | HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ | |
336 | 329 | |||
337 | /* Round 4 */ | 330 | /* Round 4 */ | |
338 | II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ | 331 | II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ | |
339 | II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ | 332 | II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ | |
340 | II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ | 333 | II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ | |
341 | II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ | 334 | II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ | |
342 | II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ | 335 | II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ | |
343 | II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ | 336 | II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ | |
344 | II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ | 337 | II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ | |
345 | II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ | 338 | II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ | |
346 | II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ | 339 | II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ | |
347 | II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ | 340 | II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ | |
348 | II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ | 341 | II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ | |
349 | II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ | 342 | II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ | |
350 | II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ | 343 | II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ | |
351 | II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ | 344 | II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ | |
352 | II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ | 345 | II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ | |
353 | II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ | 346 | II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ | |
354 | 347 | |||
355 | state[0] += a; | 348 | state[0] += a; | |
356 | state[1] += b; | 349 | state[1] += b; | |
357 | state[2] += c; | 350 | state[2] += c; | |
358 | state[3] += d; | 351 | state[3] += d; | |
359 | 352 | |||
360 | /* Zeroize sensitive information. */ | 353 | /* Zeroize sensitive information. */ | |
361 | ZEROIZE((POINTER)(void *)x, sizeof (x)); | 354 | ZEROIZE((POINTER)(void *)x, sizeof (x)); | |
362 | } | 355 | } | |
363 | 356 | |||
364 | #endif /* HAVE_MD5_H */ | 357 | #endif /* HAVE_MD5_H */ |
--- src/common/lib/libc/net/Attic/__cmsg_alignbytes.c 2008/04/28 20:22:53 1.2
+++ src/common/lib/libc/net/Attic/__cmsg_alignbytes.c 2009/03/16 05:59:21 1.3
@@ -1,74 +1,74 @@ | @@ -1,74 +1,74 @@ | |||
1 | /* $NetBSD: __cmsg_alignbytes.c,v 1.2 2008/04/28 20:22:53 martin Exp $ */ | 1 | /* $NetBSD: __cmsg_alignbytes.c,v 1.3 2009/03/16 05:59:21 cegger Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2000 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2000 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jun-ichiro Hagino. | 8 | * by Jun-ichiro Hagino. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright | |
16 | * notice, this list of conditions and the following disclaimer in the | 16 | * notice, this list of conditions and the following disclaimer in the | |
17 | * documentation and/or other materials provided with the distribution. | 17 | * documentation and/or other materials provided with the distribution. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if !defined(_KERNEL) && !defined(_STANDALONE) | 32 | #if !defined(_KERNEL) && !defined(_STANDALONE) | |
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) | |
35 | __RCSID("$NetBSD: __cmsg_alignbytes.c,v 1.2 2008/04/28 20:22:53 martin Exp $"); | 35 | __RCSID("$NetBSD: __cmsg_alignbytes.c,v 1.3 2009/03/16 05:59:21 cegger Exp $"); | |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ | |
37 | 37 | |||
38 | #include "namespace.h" | 38 | #include "namespace.h" | |
39 | #include <sys/types.h> | 39 | #include <sys/types.h> | |
40 | #include <sys/param.h> | 40 | #include <sys/param.h> | |
41 | #include <sys/sysctl.h> | 41 | #include <sys/sysctl.h> | |
42 | #include <sys/socket.h> | 42 | #include <sys/socket.h> | |
43 | #else | 43 | #else | |
44 | #include <sys/types.h> | 44 | #include <sys/types.h> | |
45 | #include <sys/param.h> | 45 | #include <sys/param.h> | |
46 | #include <sys/socket.h> | 46 | #include <sys/socket.h> | |
47 | #endif | 47 | #endif | |
48 | 48 | |||
49 | int | 49 | int | |
50 | __cmsg_alignbytes() | 50 | __cmsg_alignbytes(void) | |
51 | { | 51 | { | |
52 | static int alignbytes = -1; | 52 | static int alignbytes = -1; | |
53 | #ifdef HW_ALIGNBYTES | 53 | #ifdef HW_ALIGNBYTES | |
54 | int mib[2]; | 54 | int mib[2]; | |
55 | size_t len; | 55 | size_t len; | |
56 | int ret; | 56 | int ret; | |
57 | #endif | 57 | #endif | |
58 | 58 | |||
59 | if (alignbytes > 0) | 59 | if (alignbytes > 0) | |
60 | return alignbytes; | 60 | return alignbytes; | |
61 | 61 | |||
62 | #ifdef HW_ALIGNBYTES | 62 | #ifdef HW_ALIGNBYTES | |
63 | mib[0] = CTL_HW; | 63 | mib[0] = CTL_HW; | |
64 | mib[1] = HW_ALIGNBYTES; | 64 | mib[1] = HW_ALIGNBYTES; | |
65 | len = sizeof(alignbytes); | 65 | len = sizeof(alignbytes); | |
66 | ret = sysctl(mib, (u_int) (sizeof(mib) / sizeof(mib[0])), | 66 | ret = sysctl(mib, (u_int) (sizeof(mib) / sizeof(mib[0])), | |
67 | (void *)&alignbytes, &len, NULL, (size_t)0); | 67 | (void *)&alignbytes, &len, NULL, (size_t)0); | |
68 | if (ret >= 0 && alignbytes >= 0) | 68 | if (ret >= 0 && alignbytes >= 0) | |
69 | return alignbytes; | 69 | return alignbytes; | |
70 | #endif | 70 | #endif | |
71 | /* last resort */ | 71 | /* last resort */ | |
72 | alignbytes = ALIGNBYTES; | 72 | alignbytes = ALIGNBYTES; | |
73 | return alignbytes; | 73 | return alignbytes; | |
74 | } | 74 | } |