Commit bc0b96b54a21246e377122d54569eef71cec535f
1 parent
de96355c11
Exists in
master
and in
4 other branches
crypto: Move md5_transform to lib/md5.c
We are going to use this for TCP/IP sequence number and fragment ID generation. Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 4 changed files with 102 additions and 92 deletions Inline Diff
crypto/md5.c
1 | /* | 1 | /* |
2 | * Cryptographic API. | 2 | * Cryptographic API. |
3 | * | 3 | * |
4 | * MD5 Message Digest Algorithm (RFC1321). | 4 | * MD5 Message Digest Algorithm (RFC1321). |
5 | * | 5 | * |
6 | * Derived from cryptoapi implementation, originally based on the | 6 | * Derived from cryptoapi implementation, originally based on the |
7 | * public domain implementation written by Colin Plumb in 1993. | 7 | * public domain implementation written by Colin Plumb in 1993. |
8 | * | 8 | * |
9 | * Copyright (c) Cryptoapi developers. | 9 | * Copyright (c) Cryptoapi developers. |
10 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | 10 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or modify it | 12 | * This program is free software; you can redistribute it and/or modify it |
13 | * under the terms of the GNU General Public License as published by the Free | 13 | * under the terms of the GNU General Public License as published by the Free |
14 | * Software Foundation; either version 2 of the License, or (at your option) | 14 | * Software Foundation; either version 2 of the License, or (at your option) |
15 | * any later version. | 15 | * any later version. |
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | #include <crypto/internal/hash.h> | 18 | #include <crypto/internal/hash.h> |
19 | #include <crypto/md5.h> | 19 | #include <crypto/md5.h> |
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/string.h> | 22 | #include <linux/string.h> |
23 | #include <linux/types.h> | 23 | #include <linux/types.h> |
24 | #include <linux/cryptohash.h> | ||
24 | #include <asm/byteorder.h> | 25 | #include <asm/byteorder.h> |
25 | |||
26 | #define F1(x, y, z) (z ^ (x & (y ^ z))) | ||
27 | #define F2(x, y, z) F1(z, x, y) | ||
28 | #define F3(x, y, z) (x ^ y ^ z) | ||
29 | #define F4(x, y, z) (y ^ (x | ~z)) | ||
30 | |||
31 | #define MD5STEP(f, w, x, y, z, in, s) \ | ||
32 | (w += f(x, y, z) + in, w = (w<<s | w>>(32-s)) + x) | ||
33 | |||
34 | static void md5_transform(u32 *hash, u32 const *in) | ||
35 | { | ||
36 | u32 a, b, c, d; | ||
37 | |||
38 | a = hash[0]; | ||
39 | b = hash[1]; | ||
40 | c = hash[2]; | ||
41 | d = hash[3]; | ||
42 | |||
43 | MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); | ||
44 | MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); | ||
45 | MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); | ||
46 | MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); | ||
47 | MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); | ||
48 | MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); | ||
49 | MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); | ||
50 | MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); | ||
51 | MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); | ||
52 | MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); | ||
53 | MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); | ||
54 | MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); | ||
55 | MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); | ||
56 | MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); | ||
57 | MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); | ||
58 | MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); | ||
59 | |||
60 | MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); | ||
61 | MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); | ||
62 | MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); | ||
63 | MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); | ||
64 | MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); | ||
65 | MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); | ||
66 | MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); | ||
67 | MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); | ||
68 | MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); | ||
69 | MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); | ||
70 | MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); | ||
71 | MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); | ||
72 | MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); | ||
73 | MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); | ||
74 | MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); | ||
75 | MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); | ||
76 | |||
77 | MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); | ||
78 | MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); | ||
79 | MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); | ||
80 | MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); | ||
81 | MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); | ||
82 | MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); | ||
83 | MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); | ||
84 | MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); | ||
85 | MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); | ||
86 | MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); | ||
87 | MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); | ||
88 | MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); | ||
89 | MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); | ||
90 | MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); | ||
91 | MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); | ||
92 | MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); | ||
93 | |||
94 | MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); | ||
95 | MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); | ||
96 | MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); | ||
97 | MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); | ||
98 | MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); | ||
99 | MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); | ||
100 | MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); | ||
101 | MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); | ||
102 | MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); | ||
103 | MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); | ||
104 | MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); | ||
105 | MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); | ||
106 | MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); | ||
107 | MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); | ||
108 | MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); | ||
109 | MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); | ||
110 | |||
111 | hash[0] += a; | ||
112 | hash[1] += b; | ||
113 | hash[2] += c; | ||
114 | hash[3] += d; | ||
115 | } | ||
116 | 26 | ||
117 | /* XXX: this stuff can be optimized */ | 27 | /* XXX: this stuff can be optimized */ |
118 | static inline void le32_to_cpu_array(u32 *buf, unsigned int words) | 28 | static inline void le32_to_cpu_array(u32 *buf, unsigned int words) |
119 | { | 29 | { |
120 | while (words--) { | 30 | while (words--) { |
121 | __le32_to_cpus(buf); | 31 | __le32_to_cpus(buf); |
122 | buf++; | 32 | buf++; |
123 | } | 33 | } |
124 | } | 34 | } |
125 | 35 | ||
126 | static inline void cpu_to_le32_array(u32 *buf, unsigned int words) | 36 | static inline void cpu_to_le32_array(u32 *buf, unsigned int words) |
127 | { | 37 | { |
128 | while (words--) { | 38 | while (words--) { |
129 | __cpu_to_le32s(buf); | 39 | __cpu_to_le32s(buf); |
130 | buf++; | 40 | buf++; |
131 | } | 41 | } |
132 | } | 42 | } |
133 | 43 | ||
134 | static inline void md5_transform_helper(struct md5_state *ctx) | 44 | static inline void md5_transform_helper(struct md5_state *ctx) |
135 | { | 45 | { |
136 | le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(u32)); | 46 | le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(u32)); |
137 | md5_transform(ctx->hash, ctx->block); | 47 | md5_transform(ctx->hash, ctx->block); |
138 | } | 48 | } |
139 | 49 | ||
140 | static int md5_init(struct shash_desc *desc) | 50 | static int md5_init(struct shash_desc *desc) |
141 | { | 51 | { |
142 | struct md5_state *mctx = shash_desc_ctx(desc); | 52 | struct md5_state *mctx = shash_desc_ctx(desc); |
143 | 53 | ||
144 | mctx->hash[0] = 0x67452301; | 54 | mctx->hash[0] = 0x67452301; |
145 | mctx->hash[1] = 0xefcdab89; | 55 | mctx->hash[1] = 0xefcdab89; |
146 | mctx->hash[2] = 0x98badcfe; | 56 | mctx->hash[2] = 0x98badcfe; |
147 | mctx->hash[3] = 0x10325476; | 57 | mctx->hash[3] = 0x10325476; |
148 | mctx->byte_count = 0; | 58 | mctx->byte_count = 0; |
149 | 59 | ||
150 | return 0; | 60 | return 0; |
151 | } | 61 | } |
152 | 62 | ||
153 | static int md5_update(struct shash_desc *desc, const u8 *data, unsigned int len) | 63 | static int md5_update(struct shash_desc *desc, const u8 *data, unsigned int len) |
154 | { | 64 | { |
155 | struct md5_state *mctx = shash_desc_ctx(desc); | 65 | struct md5_state *mctx = shash_desc_ctx(desc); |
156 | const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); | 66 | const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); |
157 | 67 | ||
158 | mctx->byte_count += len; | 68 | mctx->byte_count += len; |
159 | 69 | ||
160 | if (avail > len) { | 70 | if (avail > len) { |
161 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), | 71 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), |
162 | data, len); | 72 | data, len); |
163 | return 0; | 73 | return 0; |
164 | } | 74 | } |
165 | 75 | ||
166 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), | 76 | memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), |
167 | data, avail); | 77 | data, avail); |
168 | 78 | ||
169 | md5_transform_helper(mctx); | 79 | md5_transform_helper(mctx); |
170 | data += avail; | 80 | data += avail; |
171 | len -= avail; | 81 | len -= avail; |
172 | 82 | ||
173 | while (len >= sizeof(mctx->block)) { | 83 | while (len >= sizeof(mctx->block)) { |
174 | memcpy(mctx->block, data, sizeof(mctx->block)); | 84 | memcpy(mctx->block, data, sizeof(mctx->block)); |
175 | md5_transform_helper(mctx); | 85 | md5_transform_helper(mctx); |
176 | data += sizeof(mctx->block); | 86 | data += sizeof(mctx->block); |
177 | len -= sizeof(mctx->block); | 87 | len -= sizeof(mctx->block); |
178 | } | 88 | } |
179 | 89 | ||
180 | memcpy(mctx->block, data, len); | 90 | memcpy(mctx->block, data, len); |
181 | 91 | ||
182 | return 0; | 92 | return 0; |
183 | } | 93 | } |
184 | 94 | ||
185 | static int md5_final(struct shash_desc *desc, u8 *out) | 95 | static int md5_final(struct shash_desc *desc, u8 *out) |
186 | { | 96 | { |
187 | struct md5_state *mctx = shash_desc_ctx(desc); | 97 | struct md5_state *mctx = shash_desc_ctx(desc); |
188 | const unsigned int offset = mctx->byte_count & 0x3f; | 98 | const unsigned int offset = mctx->byte_count & 0x3f; |
189 | char *p = (char *)mctx->block + offset; | 99 | char *p = (char *)mctx->block + offset; |
190 | int padding = 56 - (offset + 1); | 100 | int padding = 56 - (offset + 1); |
191 | 101 | ||
192 | *p++ = 0x80; | 102 | *p++ = 0x80; |
193 | if (padding < 0) { | 103 | if (padding < 0) { |
194 | memset(p, 0x00, padding + sizeof (u64)); | 104 | memset(p, 0x00, padding + sizeof (u64)); |
195 | md5_transform_helper(mctx); | 105 | md5_transform_helper(mctx); |
196 | p = (char *)mctx->block; | 106 | p = (char *)mctx->block; |
197 | padding = 56; | 107 | padding = 56; |
198 | } | 108 | } |
199 | 109 | ||
200 | memset(p, 0, padding); | 110 | memset(p, 0, padding); |
201 | mctx->block[14] = mctx->byte_count << 3; | 111 | mctx->block[14] = mctx->byte_count << 3; |
202 | mctx->block[15] = mctx->byte_count >> 29; | 112 | mctx->block[15] = mctx->byte_count >> 29; |
203 | le32_to_cpu_array(mctx->block, (sizeof(mctx->block) - | 113 | le32_to_cpu_array(mctx->block, (sizeof(mctx->block) - |
204 | sizeof(u64)) / sizeof(u32)); | 114 | sizeof(u64)) / sizeof(u32)); |
205 | md5_transform(mctx->hash, mctx->block); | 115 | md5_transform(mctx->hash, mctx->block); |
206 | cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32)); | 116 | cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32)); |
207 | memcpy(out, mctx->hash, sizeof(mctx->hash)); | 117 | memcpy(out, mctx->hash, sizeof(mctx->hash)); |
208 | memset(mctx, 0, sizeof(*mctx)); | 118 | memset(mctx, 0, sizeof(*mctx)); |
209 | 119 | ||
210 | return 0; | 120 | return 0; |
211 | } | 121 | } |
212 | 122 | ||
213 | static int md5_export(struct shash_desc *desc, void *out) | 123 | static int md5_export(struct shash_desc *desc, void *out) |
214 | { | 124 | { |
215 | struct md5_state *ctx = shash_desc_ctx(desc); | 125 | struct md5_state *ctx = shash_desc_ctx(desc); |
216 | 126 | ||
217 | memcpy(out, ctx, sizeof(*ctx)); | 127 | memcpy(out, ctx, sizeof(*ctx)); |
218 | return 0; | 128 | return 0; |
219 | } | 129 | } |
220 | 130 | ||
221 | static int md5_import(struct shash_desc *desc, const void *in) | 131 | static int md5_import(struct shash_desc *desc, const void *in) |
222 | { | 132 | { |
223 | struct md5_state *ctx = shash_desc_ctx(desc); | 133 | struct md5_state *ctx = shash_desc_ctx(desc); |
224 | 134 | ||
225 | memcpy(ctx, in, sizeof(*ctx)); | 135 | memcpy(ctx, in, sizeof(*ctx)); |
226 | return 0; | 136 | return 0; |
227 | } | 137 | } |
228 | 138 | ||
229 | static struct shash_alg alg = { | 139 | static struct shash_alg alg = { |
230 | .digestsize = MD5_DIGEST_SIZE, | 140 | .digestsize = MD5_DIGEST_SIZE, |
231 | .init = md5_init, | 141 | .init = md5_init, |
232 | .update = md5_update, | 142 | .update = md5_update, |
233 | .final = md5_final, | 143 | .final = md5_final, |
234 | .export = md5_export, | 144 | .export = md5_export, |
235 | .import = md5_import, | 145 | .import = md5_import, |
236 | .descsize = sizeof(struct md5_state), | 146 | .descsize = sizeof(struct md5_state), |
237 | .statesize = sizeof(struct md5_state), | 147 | .statesize = sizeof(struct md5_state), |
238 | .base = { | 148 | .base = { |
239 | .cra_name = "md5", | 149 | .cra_name = "md5", |
240 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, | 150 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
241 | .cra_blocksize = MD5_HMAC_BLOCK_SIZE, | 151 | .cra_blocksize = MD5_HMAC_BLOCK_SIZE, |
242 | .cra_module = THIS_MODULE, | 152 | .cra_module = THIS_MODULE, |
243 | } | 153 | } |
244 | }; | 154 | }; |
245 | 155 | ||
246 | static int __init md5_mod_init(void) | 156 | static int __init md5_mod_init(void) |
247 | { | 157 | { |
248 | return crypto_register_shash(&alg); | 158 | return crypto_register_shash(&alg); |
249 | } | 159 | } |
250 | 160 | ||
251 | static void __exit md5_mod_fini(void) | 161 | static void __exit md5_mod_fini(void) |
252 | { | 162 | { |
253 | crypto_unregister_shash(&alg); | 163 | crypto_unregister_shash(&alg); |
254 | } | 164 | } |
255 | 165 | ||
256 | module_init(md5_mod_init); | 166 | module_init(md5_mod_init); |
257 | module_exit(md5_mod_fini); | 167 | module_exit(md5_mod_fini); |
258 | 168 | ||
259 | MODULE_LICENSE("GPL"); | 169 | MODULE_LICENSE("GPL"); |
260 | MODULE_DESCRIPTION("MD5 Message Digest Algorithm"); | 170 | MODULE_DESCRIPTION("MD5 Message Digest Algorithm"); |
include/linux/cryptohash.h
1 | #ifndef __CRYPTOHASH_H | 1 | #ifndef __CRYPTOHASH_H |
2 | #define __CRYPTOHASH_H | 2 | #define __CRYPTOHASH_H |
3 | 3 | ||
4 | #define SHA_DIGEST_WORDS 5 | 4 | #define SHA_DIGEST_WORDS 5 |
5 | #define SHA_MESSAGE_BYTES (512 /*bits*/ / 8) | 5 | #define SHA_MESSAGE_BYTES (512 /*bits*/ / 8) |
6 | #define SHA_WORKSPACE_WORDS 80 | 6 | #define SHA_WORKSPACE_WORDS 80 |
7 | 7 | ||
8 | void sha_init(__u32 *buf); | 8 | void sha_init(__u32 *buf); |
9 | void sha_transform(__u32 *digest, const char *data, __u32 *W); | 9 | void sha_transform(__u32 *digest, const char *data, __u32 *W); |
10 | 10 | ||
11 | #define MD5_DIGEST_WORDS 4 | ||
12 | #define MD5_MESSAGE_BYTES 64 | ||
13 | |||
14 | void md5_transform(__u32 *hash, __u32 const *in); | ||
15 | |||
11 | __u32 half_md4_transform(__u32 buf[4], __u32 const in[8]); | 16 | __u32 half_md4_transform(__u32 buf[4], __u32 const in[8]); |
12 | 17 | ||
13 | #endif | 18 | #endif |
14 | 19 |
lib/Makefile
1 | # | 1 | # |
2 | # Makefile for some libs needed in the kernel. | 2 | # Makefile for some libs needed in the kernel. |
3 | # | 3 | # |
4 | 4 | ||
5 | ifdef CONFIG_FUNCTION_TRACER | 5 | ifdef CONFIG_FUNCTION_TRACER |
6 | ORIG_CFLAGS := $(KBUILD_CFLAGS) | 6 | ORIG_CFLAGS := $(KBUILD_CFLAGS) |
7 | KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS)) | 7 | KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS)) |
8 | endif | 8 | endif |
9 | 9 | ||
10 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ | 10 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ |
11 | rbtree.o radix-tree.o dump_stack.o timerqueue.o\ | 11 | rbtree.o radix-tree.o dump_stack.o timerqueue.o\ |
12 | idr.o int_sqrt.o extable.o prio_tree.o \ | 12 | idr.o int_sqrt.o extable.o prio_tree.o \ |
13 | sha1.o irq_regs.o reciprocal_div.o argv_split.o \ | 13 | sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \ |
14 | proportions.o prio_heap.o ratelimit.o show_mem.o \ | 14 | proportions.o prio_heap.o ratelimit.o show_mem.o \ |
15 | is_single_threaded.o plist.o decompress.o find_next_bit.o | 15 | is_single_threaded.o plist.o decompress.o find_next_bit.o |
16 | 16 | ||
17 | lib-$(CONFIG_MMU) += ioremap.o | 17 | lib-$(CONFIG_MMU) += ioremap.o |
18 | lib-$(CONFIG_SMP) += cpumask.o | 18 | lib-$(CONFIG_SMP) += cpumask.o |
19 | 19 | ||
20 | lib-y += kobject.o kref.o klist.o | 20 | lib-y += kobject.o kref.o klist.o |
21 | 21 | ||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ | 24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ |
25 | bsearch.o find_last_bit.o | 25 | bsearch.o find_last_bit.o |
26 | obj-y += kstrtox.o | 26 | obj-y += kstrtox.o |
27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | 27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o |
28 | 28 | ||
29 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 29 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
30 | CFLAGS_kobject.o += -DDEBUG | 30 | CFLAGS_kobject.o += -DDEBUG |
31 | CFLAGS_kobject_uevent.o += -DDEBUG | 31 | CFLAGS_kobject_uevent.o += -DDEBUG |
32 | endif | 32 | endif |
33 | 33 | ||
34 | lib-$(CONFIG_HOTPLUG) += kobject_uevent.o | 34 | lib-$(CONFIG_HOTPLUG) += kobject_uevent.o |
35 | obj-$(CONFIG_GENERIC_IOMAP) += iomap.o | 35 | obj-$(CONFIG_GENERIC_IOMAP) += iomap.o |
36 | obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o | 36 | obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o |
37 | obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o | 37 | obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o |
38 | obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o | 38 | obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o |
39 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o | 39 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o |
40 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o | 40 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o |
41 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | 41 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o |
42 | 42 | ||
43 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) | 43 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) |
44 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o | 44 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o |
45 | 45 | ||
46 | obj-$(CONFIG_BTREE) += btree.o | 46 | obj-$(CONFIG_BTREE) += btree.o |
47 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o | 47 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o |
48 | obj-$(CONFIG_DEBUG_LIST) += list_debug.o | 48 | obj-$(CONFIG_DEBUG_LIST) += list_debug.o |
49 | obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o | 49 | obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o |
50 | 50 | ||
51 | ifneq ($(CONFIG_HAVE_DEC_LOCK),y) | 51 | ifneq ($(CONFIG_HAVE_DEC_LOCK),y) |
52 | lib-y += dec_and_lock.o | 52 | lib-y += dec_and_lock.o |
53 | endif | 53 | endif |
54 | 54 | ||
55 | obj-$(CONFIG_BITREVERSE) += bitrev.o | 55 | obj-$(CONFIG_BITREVERSE) += bitrev.o |
56 | obj-$(CONFIG_RATIONAL) += rational.o | 56 | obj-$(CONFIG_RATIONAL) += rational.o |
57 | obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o | 57 | obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o |
58 | obj-$(CONFIG_CRC16) += crc16.o | 58 | obj-$(CONFIG_CRC16) += crc16.o |
59 | obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o | 59 | obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o |
60 | obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o | 60 | obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o |
61 | obj-$(CONFIG_CRC32) += crc32.o | 61 | obj-$(CONFIG_CRC32) += crc32.o |
62 | obj-$(CONFIG_CRC7) += crc7.o | 62 | obj-$(CONFIG_CRC7) += crc7.o |
63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o | 63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o |
64 | obj-$(CONFIG_CRC8) += crc8.o | 64 | obj-$(CONFIG_CRC8) += crc8.o |
65 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o | 65 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o |
66 | 66 | ||
67 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ | 67 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ |
68 | obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/ | 68 | obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/ |
69 | obj-$(CONFIG_REED_SOLOMON) += reed_solomon/ | 69 | obj-$(CONFIG_REED_SOLOMON) += reed_solomon/ |
70 | obj-$(CONFIG_BCH) += bch.o | 70 | obj-$(CONFIG_BCH) += bch.o |
71 | obj-$(CONFIG_LZO_COMPRESS) += lzo/ | 71 | obj-$(CONFIG_LZO_COMPRESS) += lzo/ |
72 | obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ | 72 | obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ |
73 | obj-$(CONFIG_XZ_DEC) += xz/ | 73 | obj-$(CONFIG_XZ_DEC) += xz/ |
74 | obj-$(CONFIG_RAID6_PQ) += raid6/ | 74 | obj-$(CONFIG_RAID6_PQ) += raid6/ |
75 | 75 | ||
76 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o | 76 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o |
77 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o | 77 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o |
78 | lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o | 78 | lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o |
79 | lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o | 79 | lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o |
80 | lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o | 80 | lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o |
81 | 81 | ||
82 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o | 82 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o |
83 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o | 83 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o |
84 | obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o | 84 | obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o |
85 | obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o | 85 | obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o |
86 | obj-$(CONFIG_SMP) += percpu_counter.o | 86 | obj-$(CONFIG_SMP) += percpu_counter.o |
87 | obj-$(CONFIG_AUDIT_GENERIC) += audit.o | 87 | obj-$(CONFIG_AUDIT_GENERIC) += audit.o |
88 | 88 | ||
89 | obj-$(CONFIG_SWIOTLB) += swiotlb.o | 89 | obj-$(CONFIG_SWIOTLB) += swiotlb.o |
90 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o | 90 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o |
91 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o | 91 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o |
92 | obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o | 92 | obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o |
93 | 93 | ||
94 | lib-$(CONFIG_GENERIC_BUG) += bug.o | 94 | lib-$(CONFIG_GENERIC_BUG) += bug.o |
95 | 95 | ||
96 | obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o | 96 | obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o |
97 | 97 | ||
98 | obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o | 98 | obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o |
99 | 99 | ||
100 | obj-$(CONFIG_NLATTR) += nlattr.o | 100 | obj-$(CONFIG_NLATTR) += nlattr.o |
101 | 101 | ||
102 | obj-$(CONFIG_LRU_CACHE) += lru_cache.o | 102 | obj-$(CONFIG_LRU_CACHE) += lru_cache.o |
103 | 103 | ||
104 | obj-$(CONFIG_DMA_API_DEBUG) += dma-debug.o | 104 | obj-$(CONFIG_DMA_API_DEBUG) += dma-debug.o |
105 | 105 | ||
106 | obj-$(CONFIG_GENERIC_CSUM) += checksum.o | 106 | obj-$(CONFIG_GENERIC_CSUM) += checksum.o |
107 | 107 | ||
108 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o | 108 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o |
109 | 109 | ||
110 | obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o | 110 | obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o |
111 | 111 | ||
112 | obj-$(CONFIG_AVERAGE) += average.o | 112 | obj-$(CONFIG_AVERAGE) += average.o |
113 | 113 | ||
114 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o | 114 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o |
115 | 115 | ||
116 | obj-$(CONFIG_CORDIC) += cordic.o | 116 | obj-$(CONFIG_CORDIC) += cordic.o |
117 | 117 | ||
118 | obj-$(CONFIG_LLIST) += llist.o | 118 | obj-$(CONFIG_LLIST) += llist.o |
119 | 119 | ||
120 | hostprogs-y := gen_crc32table | 120 | hostprogs-y := gen_crc32table |
121 | clean-files := crc32table.h | 121 | clean-files := crc32table.h |
122 | 122 | ||
123 | $(obj)/crc32.o: $(obj)/crc32table.h | 123 | $(obj)/crc32.o: $(obj)/crc32table.h |
124 | 124 | ||
125 | quiet_cmd_crc32 = GEN $@ | 125 | quiet_cmd_crc32 = GEN $@ |
126 | cmd_crc32 = $< > $@ | 126 | cmd_crc32 = $< > $@ |
127 | 127 | ||
128 | $(obj)/crc32table.h: $(obj)/gen_crc32table | 128 | $(obj)/crc32table.h: $(obj)/gen_crc32table |
129 | $(call cmd,crc32) | 129 | $(call cmd,crc32) |
130 | 130 |
lib/md5.c
File was created | 1 | #include <linux/kernel.h> | |
2 | #include <linux/module.h> | ||
3 | #include <linux/cryptohash.h> | ||
4 | |||
5 | #define F1(x, y, z) (z ^ (x & (y ^ z))) | ||
6 | #define F2(x, y, z) F1(z, x, y) | ||
7 | #define F3(x, y, z) (x ^ y ^ z) | ||
8 | #define F4(x, y, z) (y ^ (x | ~z)) | ||
9 | |||
10 | #define MD5STEP(f, w, x, y, z, in, s) \ | ||
11 | (w += f(x, y, z) + in, w = (w<<s | w>>(32-s)) + x) | ||
12 | |||
13 | void md5_transform(__u32 *hash, __u32 const *in) | ||
14 | { | ||
15 | u32 a, b, c, d; | ||
16 | |||
17 | a = hash[0]; | ||
18 | b = hash[1]; | ||
19 | c = hash[2]; | ||
20 | d = hash[3]; | ||
21 | |||
22 | MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); | ||
23 | MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); | ||
24 | MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); | ||
25 | MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); | ||
26 | MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); | ||
27 | MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); | ||
28 | MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); | ||
29 | MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); | ||
30 | MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); | ||
31 | MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); | ||
32 | MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); | ||
33 | MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); | ||
34 | MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); | ||
35 | MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); | ||
36 | MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); | ||
37 | MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); | ||
38 | |||
39 | MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); | ||
40 | MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); | ||
41 | MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); | ||
42 | MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); | ||
43 | MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); | ||
44 | MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); | ||
45 | MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); | ||
46 | MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); | ||
47 | MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); | ||
48 | MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); | ||
49 | MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); | ||
50 | MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); | ||
51 | MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); | ||
52 | MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); | ||
53 | MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); | ||
54 | MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); | ||
55 | |||
56 | MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); | ||
57 | MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); | ||
58 | MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); | ||
59 | MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); | ||
60 | MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); | ||
61 | MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); | ||
62 | MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); | ||
63 | MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); | ||
64 | MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); | ||
65 | MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); | ||
66 | MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); | ||
67 | MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); | ||
68 | MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); | ||
69 | MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); | ||
70 | MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); | ||
71 | MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); | ||
72 | |||
73 | MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); | ||
74 | MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); | ||
75 | MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); | ||
76 | MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); | ||
77 | MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); | ||
78 | MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); | ||
79 | MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); | ||
80 | MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); | ||
81 | MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); | ||
82 | MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); | ||
83 | MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); | ||
84 | MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); | ||
85 | MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); | ||
86 | MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); | ||
87 | MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); | ||
88 | MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); | ||
89 | |||
90 | hash[0] += a; | ||
91 | hash[1] += b; | ||
92 | hash[2] += c; | ||
93 | hash[3] += d; | ||
94 | } | ||
95 | EXPORT_SYMBOL(md5_transform); | ||
96 |