]>
Commit | Line | Data |
---|---|---|
bf46eb01 AM |
1 | diff -urN util-linux-2.11d.org/mount/Makefile util-linux-2.11d/mount/Makefile |
2 | --- util-linux-2.11d.org/mount/Makefile Sun Jun 3 22:25:41 2001 | |
3 | +++ util-linux-2.11d/mount/Makefile Sun Jun 3 22:26:34 2001 | |
50adfa79 | 4 | @@ -24,7 +24,7 @@ |
2ad55559 | 5 | |
50adfa79 | 6 | MAYBE = pivot_root swapoff |
2ad55559 | 7 | |
50adfa79 AM |
8 | -LO_OBJS = lomount.o $(LIB)/xstrncpy.o |
9 | +LO_OBJS = lomount.o rmd160.o $(LIB)/xstrncpy.o | |
10 | NFS_OBJS = nfsmount.o nfsmount_xdr.o nfsmount_clnt.o | |
11 | GEN_FILES = nfsmount.h nfsmount_xdr.c nfsmount_clnt.c | |
2ad55559 | 12 | |
bf46eb01 | 13 | @@ -54,10 +54,10 @@ |
50adfa79 | 14 | swapon: swapon.o version.o |
2ad55559 | 15 | $(LINK) $^ -o $@ |
16 | ||
50adfa79 AM |
17 | -main_losetup.o: lomount.c |
18 | +main_losetup.o: lomount.c rmd160.o | |
19 | $(COMPILE) -DMAIN lomount.c -o $@ | |
20 | ||
bf46eb01 AM |
21 | -losetup: main_losetup.o $(LIB)/xstrncpy.o |
22 | +losetup: main_losetup.o rmd160.o $(LIB)/xstrncpy.o | |
23 | $(LINK) $^ -o $@ | |
24 | ||
25 | mount.o umount.o nfsmount.o losetup.o fstab.o realpath.o sundries.o: sundries.h | |
26 | diff -urN util-linux-2.11d.org/mount/lomount.c util-linux-2.11d/mount/lomount.c | |
27 | --- util-linux-2.11d.org/mount/lomount.c Sun Jun 3 22:25:41 2001 | |
28 | +++ util-linux-2.11d/mount/lomount.c Sun Jun 3 22:26:06 2001 | |
8c2034f5 | 29 | @@ -27,6 +27,7 @@ |
2ad55559 | 30 | |
31 | #include "loop.h" | |
32 | #include "lomount.h" | |
33 | +#include "rmd160.h" | |
50adfa79 | 34 | #include "xstrncpy.h" |
2ad55559 | 35 | #include "nls.h" |
36 | ||
50adfa79 | 37 | @@ -38,12 +39,22 @@ |
8c2034f5 | 38 | struct crypt_type_struct { |
39 | int id; | |
40 | char *name; | |
41 | + int keylength; | |
42 | } crypt_type_tbl[] = { | |
43 | - { LO_CRYPT_NONE, "no" }, | |
44 | - { LO_CRYPT_NONE, "none" }, | |
45 | - { LO_CRYPT_XOR, "xor" }, | |
46 | - { LO_CRYPT_DES, "DES" }, | |
47 | - { -1, NULL } | |
48 | + { LO_CRYPT_NONE, "no",0 }, | |
49 | + { LO_CRYPT_NONE, "none",0 }, | |
50 | + { LO_CRYPT_XOR, "xor",0 }, | |
51 | + { LO_CRYPT_DES, "DES",8 }, | |
52 | + { LO_CRYPT_FISH2, "twofish",20 }, | |
53 | + { LO_CRYPT_BLOW, "blowfish",20 }, | |
54 | + { LO_CRYPT_CAST128, "cast128", 16}, | |
55 | + { LO_CRYPT_SERPENT, "serpent", 16}, | |
56 | + { LO_CRYPT_MARS, "mars",16 }, | |
57 | + { LO_CRYPT_RC6, "rc6",16 }, | |
58 | + { LO_CRYPT_DES_EDE3, "DES_EDE3",24}, | |
59 | + { LO_CRYPT_DFC, "dfc",16 }, | |
60 | + { LO_CRYPT_IDEA, "idea",16}, | |
61 | + { -1, NULL,0 } | |
2ad55559 | 62 | }; |
63 | ||
8c2034f5 | 64 | static int |
50adfa79 | 65 | @@ -195,12 +206,18 @@ |
8c2034f5 | 66 | return 0; |
67 | } | |
68 | ||
69 | +#define HASHLENGTH 20 | |
70 | +#define PASSWDBUFFLEN 130 /* getpass returns only max. 128 bytes, see man getpass */ | |
71 | + | |
72 | int | |
73 | set_loop (const char *device, const char *file, int offset, | |
74 | const char *encryption, int *loopro) { | |
75 | struct loop_info loopinfo; | |
76 | int fd, ffd, mode, i; | |
77 | + int keylength; | |
78 | char *pass; | |
79 | + char keybits[2*HASHLENGTH]; | |
80 | + char passwdbuff[PASSWDBUFFLEN]; | |
81 | ||
82 | mode = (*loopro ? O_RDONLY : O_RDWR); | |
83 | if ((ffd = open (file, mode)) < 0) { | |
50adfa79 | 84 | @@ -250,6 +267,7 @@ |
8c2034f5 | 85 | loopinfo.lo_encrypt_key_size = strlen(loopinfo.lo_encrypt_key); |
86 | break; | |
87 | case LO_CRYPT_DES: | |
88 | + printf(_("WARNING: Use of DES is depreciated.\n")); | |
89 | pass = getpass (_("Password: ")); | |
90 | strncpy (loopinfo.lo_encrypt_key, pass, 8); | |
91 | loopinfo.lo_encrypt_key[8] = 0; | |
50adfa79 | 92 | @@ -266,6 +284,30 @@ |
8c2034f5 | 93 | return 1; |
94 | } | |
95 | break; | |
96 | + case LO_CRYPT_FISH2: | |
97 | + case LO_CRYPT_BLOW: | |
98 | + case LO_CRYPT_IDEA: | |
99 | + case LO_CRYPT_CAST128: | |
100 | + case LO_CRYPT_SERPENT: | |
101 | + case LO_CRYPT_MARS: | |
102 | + case LO_CRYPT_RC6: | |
103 | + case LO_CRYPT_DES_EDE3: | |
104 | + case LO_CRYPT_DFC: | |
105 | + pass = getpass("Password :"); | |
106 | + strncpy(passwdbuff+1,pass,PASSWDBUFFLEN-1); | |
107 | + passwdbuff[0] = 'A'; | |
108 | + rmd160_hash_buffer(keybits,pass,strlen(pass)); | |
109 | + rmd160_hash_buffer(keybits+HASHLENGTH,passwdbuff,strlen(pass)+1); | |
110 | + memcpy((char*)loopinfo.lo_encrypt_key,keybits,2*HASHLENGTH); | |
111 | + keylength=0; | |
112 | + for(i=0; crypt_type_tbl[i].id != -1; i++){ | |
113 | + if(loopinfo.lo_encrypt_type == crypt_type_tbl[i].id){ | |
114 | + keylength = crypt_type_tbl[i].keylength; | |
115 | + break; | |
116 | + } | |
117 | + } | |
118 | + loopinfo.lo_encrypt_key_size=keylength; | |
119 | + break; | |
120 | default: | |
121 | fprintf (stderr, | |
122 | _("Don't know how to get key for encryption system %d\n"), | |
50adfa79 | 123 | @@ -350,11 +392,18 @@ |
8c2034f5 | 124 | |
125 | static void | |
126 | usage(void) { | |
127 | + struct crypt_type_struct *c; | |
128 | fprintf(stderr, _("usage:\n\ | |
129 | %s loop_device # give info\n\ | |
130 | %s -d loop_device # delete\n\ | |
131 | %s [ -e encryption ] [ -o offset ] loop_device file # setup\n"), | |
132 | progname, progname, progname); | |
133 | + fprintf(stderr, " where encryption is one of:\n"); | |
134 | + c = &crypt_type_tbl[0]; | |
135 | + while(c->name) { | |
136 | + fprintf(stderr, " %s\n", c->name); | |
137 | + c++; | |
138 | + } | |
139 | exit(1); | |
140 | } | |
141 | ||
bf46eb01 AM |
142 | diff -urN util-linux-2.11d.org/mount/losetup.8 util-linux-2.11d/mount/losetup.8 |
143 | --- util-linux-2.11d.org/mount/losetup.8 Sun Jun 3 22:25:41 2001 | |
144 | +++ util-linux-2.11d/mount/losetup.8 Sun Jun 3 22:26:06 2001 | |
2ad55559 | 145 | @@ -36,11 +36,47 @@ |
146 | .PD 0 | |
147 | .IP \fBXOR\fP | |
148 | use a simple XOR encryption. | |
149 | +.IP \fBBlowfish\fP | |
150 | +use Blowfish encryption. Blowfish encryption is only available if you | |
151 | +are using the international kernel and Blowfish encryption has been | |
152 | +enabled in the Crypto API. | |
153 | +.IP \fBTwofish\fP | |
154 | +use Twofish encryption. Twofish encryption is only available if you | |
155 | +are using the international kernel and Twofish encryption has been | |
156 | +enabled in the Crypto API. | |
157 | +.IP \fBCAST\fP | |
158 | +use CAST encryption. CAST encryption is only available if you | |
159 | +are using the international kernel and CAST encryption has been | |
160 | +enabled in the Crypto API. | |
161 | .IP \fBDES\fP | |
162 | use DES encryption. DES encryption is only available if the optional | |
163 | DES package has been added to the kernel. DES encryption uses an additional | |
164 | start value that is used to protect passwords against dictionary | |
165 | -attacks. | |
166 | +attacks. Use of DES is deprecated. | |
167 | +.IP \fBDFC\fP | |
168 | +use DFC encryption. DFC encryption is only available if you | |
169 | +are using the international kernel and DFC encryption has been | |
170 | +enabled in the Crypto API. | |
171 | +.IP \fBIDEA\fP | |
172 | +use IDEA encryption. IDEA encryption is only available if you | |
173 | +are using the international kernel and IDEA encryption has been | |
174 | +enabled in the Crypto API. | |
175 | +.IP \fBMARS\fP | |
176 | +use MARS encryption. MARS encryption is only available if you | |
177 | +are using the international kernel and MARS encryption has been | |
178 | +enabled in the Crypto API. | |
179 | +.IP \fBRC5\fP | |
180 | +use RC5 encryption. RC5 encryption is only available if you | |
181 | +are using the international kernel and RC5 encryption has been | |
182 | +enabled in the Crypto API. | |
183 | +.IP \fBRC6\fP | |
184 | +use RC6 encryption. RC6 encryption is only available if you | |
185 | +are using the international kernel and RC6 encryption has been | |
186 | +enabled in the Crypto API. | |
187 | +.IP \fBSerpent\fP | |
188 | +use Serpent encryption. Serpent encryption is only available if you | |
189 | +are using the international kernel and Serpent encryption has been | |
190 | +enabled in the Crypto API. | |
191 | .PD | |
192 | .RE | |
193 | .IP "\fB\-o \fIoffset\fP" | |
8c2034f5 | 194 | @@ -58,6 +94,7 @@ |
2ad55559 | 195 | .SH FILES |
196 | .nf | |
197 | /dev/loop0,/dev/loop1,... loop devices (major=7) | |
198 | +/proc/cipher/* available ciphers | |
199 | .fi | |
200 | .SH EXAMPLE | |
201 | If you are using the loadable module you must have the module loaded | |
8c2034f5 | 202 | @@ -69,9 +106,8 @@ |
2ad55559 | 203 | .nf |
204 | .IP | |
205 | dd if=/dev/zero of=/file bs=1k count=100 | |
206 | -losetup -e des /dev/loop0 /file | |
207 | -Password: | |
208 | -Init (up to 16 hex digits): | |
209 | +losetup -e blowfish /dev/loop0 /file | |
210 | +Password : | |
211 | mkfs -t ext2 /dev/loop0 100 | |
212 | mount -t ext2 /dev/loop0 /mnt | |
213 | ... | |
8c2034f5 | 214 | @@ -85,8 +121,12 @@ |
2ad55559 | 215 | # rmmod loop |
216 | .LP | |
217 | .fi | |
218 | -.SH RESTRICTION | |
219 | -DES encryption is painfully slow. On the other hand, XOR is terribly weak. | |
220 | +.SH RESTRICTIONS | |
221 | +DES encryption is painfully slow. On the other hand, XOR is terribly | |
222 | +weak. Both are insecure nowadays. Some ciphers require a licence for | |
223 | +you to be allowed to use them. | |
224 | +.SH BUGS | |
225 | +CAST, DES, RC5 and Twofish are currently broken and cannot be used. | |
226 | .SH AUTHORS | |
227 | .nf | |
228 | Original version: Theodore Ts'o <tytso@athena.mit.edu> | |
bf46eb01 AM |
229 | diff -urN util-linux-2.11d.org/mount/rmd160.c util-linux-2.11d/mount/rmd160.c |
230 | --- util-linux-2.11d.org/mount/rmd160.c Thu Jan 1 01:00:00 1970 | |
231 | +++ util-linux-2.11d/mount/rmd160.c Sun Jun 3 22:26:06 2001 | |
8c2034f5 | 232 | @@ -0,0 +1,532 @@ |
233 | +/* rmd160.c - RIPE-MD160 | |
234 | + * Copyright (C) 1998 Free Software Foundation, Inc. | |
235 | + */ | |
2ad55559 | 236 | + |
8c2034f5 | 237 | +/* This file was part of GnuPG. Modified for use within the Linux |
238 | + * mount utility by Marc Mutz <Marc@Mutz.com>. None of this code is | |
239 | + * by myself. I just removed everything that you don't need when all | |
240 | + * you want to do is to use rmd160_hash_buffer(). | |
241 | + * My comments are marked with (mm). */ | |
2ad55559 | 242 | + |
8c2034f5 | 243 | +/* GnuPG is free software; you can redistribute it and/or modify |
244 | + * it under the terms of the GNU General Public License as published by | |
245 | + * the Free Software Foundation; either version 2 of the License, or | |
246 | + * (at your option) any later version. | |
247 | + * | |
248 | + * GnuPG is distributed in the hope that it will be useful, | |
249 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
250 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
251 | + * GNU General Public License for more details. | |
252 | + * | |
253 | + * You should have received a copy of the GNU General Public License | |
254 | + * along with this program; if not, write to the Free Software | |
255 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ | |
2ad55559 | 256 | + |
8c2034f5 | 257 | +#include <string.h> /* (mm) for memcpy */ |
258 | +#include <endian.h> /* (mm) for BIG_ENDIAN and BYTE_ORDER */ | |
259 | +#include "rmd160.h" | |
2ad55559 | 260 | + |
8c2034f5 | 261 | +/* (mm) these are used by the original GnuPG file. In order to modify |
262 | + * that file not too much, we keep the notations. maybe it would be | |
263 | + * better to include linux/types.h and typedef __u32 to u32 and __u8 | |
264 | + * to byte? */ | |
265 | +typedef unsigned int u32; /* taken from e.g. util-linux's minix.h */ | |
266 | +typedef unsigned char byte; | |
267 | + | |
268 | +typedef struct { | |
269 | + u32 h0,h1,h2,h3,h4; | |
270 | + u32 nblocks; | |
271 | + byte buf[64]; | |
272 | + int count; | |
273 | +} RMD160_CONTEXT; | |
274 | + | |
275 | +/**************** | |
276 | + * Rotate a 32 bit integer by n bytes | |
277 | + */ | |
278 | +#if defined(__GNUC__) && defined(__i386__) | |
279 | +static inline u32 | |
280 | +rol( u32 x, int n) | |
2ad55559 | 281 | +{ |
8c2034f5 | 282 | + __asm__("roll %%cl,%0" |
283 | + :"=r" (x) | |
284 | + :"0" (x),"c" (n)); | |
285 | + return x; | |
2ad55559 | 286 | +} |
8c2034f5 | 287 | +#else |
288 | + #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) | |
289 | +#endif | |
290 | + | |
291 | +/********************************* | |
292 | + * RIPEMD-160 is not patented, see (as of 25.10.97) | |
293 | + * http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html | |
294 | + * Note that the code uses Little Endian byteorder, which is good for | |
295 | + * 386 etc, but we must add some conversion when used on a big endian box. | |
296 | + * | |
297 | + * | |
298 | + * Pseudo-code for RIPEMD-160 | |
299 | + * | |
300 | + * RIPEMD-160 is an iterative hash function that operates on 32-bit words. | |
301 | + * The round function takes as input a 5-word chaining variable and a 16-word | |
302 | + * message block and maps this to a new chaining variable. All operations are | |
303 | + * defined on 32-bit words. Padding is identical to that of MD4. | |
304 | + * | |
305 | + * | |
306 | + * RIPEMD-160: definitions | |
2ad55559 | 307 | + * |
2ad55559 | 308 | + * |
8c2034f5 | 309 | + * nonlinear functions at bit level: exor, mux, -, mux, - |
2ad55559 | 310 | + * |
8c2034f5 | 311 | + * f(j, x, y, z) = x XOR y XOR z (0 <= j <= 15) |
312 | + * f(j, x, y, z) = (x AND y) OR (NOT(x) AND z) (16 <= j <= 31) | |
313 | + * f(j, x, y, z) = (x OR NOT(y)) XOR z (32 <= j <= 47) | |
314 | + * f(j, x, y, z) = (x AND z) OR (y AND NOT(z)) (48 <= j <= 63) | |
315 | + * f(j, x, y, z) = x XOR (y OR NOT(z)) (64 <= j <= 79) | |
2ad55559 | 316 | + * |
2ad55559 | 317 | + * |
8c2034f5 | 318 | + * added constants (hexadecimal) |
319 | + * | |
320 | + * K(j) = 0x00000000 (0 <= j <= 15) | |
321 | + * K(j) = 0x5A827999 (16 <= j <= 31) int(2**30 x sqrt(2)) | |
322 | + * K(j) = 0x6ED9EBA1 (32 <= j <= 47) int(2**30 x sqrt(3)) | |
323 | + * K(j) = 0x8F1BBCDC (48 <= j <= 63) int(2**30 x sqrt(5)) | |
324 | + * K(j) = 0xA953FD4E (64 <= j <= 79) int(2**30 x sqrt(7)) | |
325 | + * K'(j) = 0x50A28BE6 (0 <= j <= 15) int(2**30 x cbrt(2)) | |
326 | + * K'(j) = 0x5C4DD124 (16 <= j <= 31) int(2**30 x cbrt(3)) | |
327 | + * K'(j) = 0x6D703EF3 (32 <= j <= 47) int(2**30 x cbrt(5)) | |
328 | + * K'(j) = 0x7A6D76E9 (48 <= j <= 63) int(2**30 x cbrt(7)) | |
329 | + * K'(j) = 0x00000000 (64 <= j <= 79) | |
330 | + * | |
331 | + * | |
332 | + * selection of message word | |
333 | + * | |
334 | + * r(j) = j (0 <= j <= 15) | |
335 | + * r(16..31) = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8 | |
336 | + * r(32..47) = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12 | |
337 | + * r(48..63) = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2 | |
338 | + * r(64..79) = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 | |
339 | + * r0(0..15) = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12 | |
340 | + * r0(16..31)= 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2 | |
341 | + * r0(32..47)= 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13 | |
342 | + * r0(48..63)= 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14 | |
343 | + * r0(64..79)= 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 | |
344 | + * | |
345 | + * | |
346 | + * amount for rotate left (rol) | |
347 | + * | |
348 | + * s(0..15) = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8 | |
349 | + * s(16..31) = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12 | |
350 | + * s(32..47) = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5 | |
351 | + * s(48..63) = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12 | |
352 | + * s(64..79) = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 | |
353 | + * s'(0..15) = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6 | |
354 | + * s'(16..31)= 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11 | |
355 | + * s'(32..47)= 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5 | |
356 | + * s'(48..63)= 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8 | |
357 | + * s'(64..79)= 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 | |
358 | + * | |
359 | + * | |
360 | + * initial value (hexadecimal) | |
361 | + * | |
362 | + * h0 = 0x67452301; h1 = 0xEFCDAB89; h2 = 0x98BADCFE; h3 = 0x10325476; | |
363 | + * h4 = 0xC3D2E1F0; | |
364 | + * | |
365 | + * | |
366 | + * RIPEMD-160: pseudo-code | |
367 | + * | |
368 | + * It is assumed that the message after padding consists of t 16-word blocks | |
369 | + * that will be denoted with X[i][j], with 0 <= i <= t-1 and 0 <= j <= 15. | |
370 | + * The symbol [+] denotes addition modulo 2**32 and rol_s denotes cyclic left | |
371 | + * shift (rotate) over s positions. | |
372 | + * | |
373 | + * | |
374 | + * for i := 0 to t-1 { | |
375 | + * A := h0; B := h1; C := h2; D = h3; E = h4; | |
376 | + * A' := h0; B' := h1; C' := h2; D' = h3; E' = h4; | |
377 | + * for j := 0 to 79 { | |
378 | + * T := rol_s(j)(A [+] f(j, B, C, D) [+] X[i][r(j)] [+] K(j)) [+] E; | |
379 | + * A := E; E := D; D := rol_10(C); C := B; B := T; | |
380 | + * T := rol_s'(j)(A' [+] f(79-j, B', C', D') [+] X[i][r'(j)] | |
381 | + [+] K'(j)) [+] E'; | |
382 | + * A' := E'; E' := D'; D' := rol_10(C'); C' := B'; B' := T; | |
383 | + * } | |
384 | + * T := h1 [+] C [+] D'; h1 := h2 [+] D [+] E'; h2 := h3 [+] E [+] A'; | |
385 | + * h3 := h4 [+] A [+] B'; h4 := h0 [+] B [+] C'; h0 := T; | |
386 | + * } | |
387 | + */ | |
388 | + | |
389 | +/* Some examples: | |
390 | + * "" 9c1185a5c5e9fc54612808977ee8f548b2258d31 | |
391 | + * "a" 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe | |
392 | + * "abc" 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc | |
393 | + * "message digest" 5d0689ef49d2fae572b881b123a85ffa21595f36 | |
394 | + * "a...z" f71c27109c692c1b56bbdceb5b9d2865b3708dbc | |
395 | + * "abcdbcde...nopq" 12a053384a9c0c88e405a06c27dcf49ada62eb2b | |
396 | + * "A...Za...z0...9" b0e20b6e3116640286ed3a87a5713079b21f5189 | |
397 | + * 8 times "1234567890" 9b752e45573d4b39f4dbd3323cab82bf63326bfb | |
398 | + * 1 million times "a" 52783243c1697bdbe16d37f97f68f08325dc1528 | |
399 | + */ | |
2ad55559 | 400 | + |
2ad55559 | 401 | + |
8c2034f5 | 402 | +static void |
403 | +rmd160_init( RMD160_CONTEXT *hd ) | |
404 | +{ | |
405 | + hd->h0 = 0x67452301; | |
406 | + hd->h1 = 0xEFCDAB89; | |
407 | + hd->h2 = 0x98BADCFE; | |
408 | + hd->h3 = 0x10325476; | |
409 | + hd->h4 = 0xC3D2E1F0; | |
410 | + hd->nblocks = 0; | |
411 | + hd->count = 0; | |
412 | +} | |
2ad55559 | 413 | + |
2ad55559 | 414 | + |
2ad55559 | 415 | + |
8c2034f5 | 416 | +/**************** |
417 | + * Transform the message X which consists of 16 32-bit-words | |
418 | + */ | |
419 | +static void | |
420 | +transform( RMD160_CONTEXT *hd, byte *data ) | |
421 | +{ | |
422 | + u32 a,b,c,d,e,aa,bb,cc,dd,ee,t; | |
423 | + #if BYTE_ORDER == BIG_ENDIAN | |
424 | + u32 x[16]; | |
425 | + { int i; | |
426 | + byte *p2, *p1; | |
427 | + for(i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 ) { | |
428 | + p2[3] = *p1++; | |
429 | + p2[2] = *p1++; | |
430 | + p2[1] = *p1++; | |
431 | + p2[0] = *p1++; | |
432 | + } | |
433 | + } | |
434 | + #else | |
435 | + #if 0 | |
436 | + u32 *x =(u32*)data; | |
437 | + #else | |
438 | + /* this version is better because it is always aligned; | |
439 | + * The performance penalty on a 586-100 is about 6% which | |
440 | + * is acceptable - because the data is more local it might | |
441 | + * also be possible that this is faster on some machines. | |
442 | + * This function (when compiled with -02 on gcc 2.7.2) | |
443 | + * executes on a 586-100 (39.73 bogomips) at about 1900kb/sec; | |
444 | + * [measured with a 4MB data and "gpgm --print-md rmd160"] */ | |
445 | + u32 x[16]; | |
446 | + memcpy( x, data, 64 ); | |
447 | + #endif | |
448 | + #endif | |
449 | + | |
450 | + | |
451 | +#define K0 0x00000000 | |
452 | +#define K1 0x5A827999 | |
453 | +#define K2 0x6ED9EBA1 | |
454 | +#define K3 0x8F1BBCDC | |
455 | +#define K4 0xA953FD4E | |
456 | +#define KK0 0x50A28BE6 | |
457 | +#define KK1 0x5C4DD124 | |
458 | +#define KK2 0x6D703EF3 | |
459 | +#define KK3 0x7A6D76E9 | |
460 | +#define KK4 0x00000000 | |
461 | +#define F0(x,y,z) ( (x) ^ (y) ^ (z) ) | |
462 | +#define F1(x,y,z) ( ((x) & (y)) | (~(x) & (z)) ) | |
463 | +#define F2(x,y,z) ( ((x) | ~(y)) ^ (z) ) | |
464 | +#define F3(x,y,z) ( ((x) & (z)) | ((y) & ~(z)) ) | |
465 | +#define F4(x,y,z) ( (x) ^ ((y) | ~(z)) ) | |
466 | +#define R(a,b,c,d,e,f,k,r,s) do { t = a + f(b,c,d) + k + x[r]; \ | |
467 | + a = rol(t,s) + e; \ | |
468 | + c = rol(c,10); \ | |
469 | + } while(0) | |
470 | + | |
471 | + /* left lane */ | |
472 | + a = hd->h0; | |
473 | + b = hd->h1; | |
474 | + c = hd->h2; | |
475 | + d = hd->h3; | |
476 | + e = hd->h4; | |
477 | + R( a, b, c, d, e, F0, K0, 0, 11 ); | |
478 | + R( e, a, b, c, d, F0, K0, 1, 14 ); | |
479 | + R( d, e, a, b, c, F0, K0, 2, 15 ); | |
480 | + R( c, d, e, a, b, F0, K0, 3, 12 ); | |
481 | + R( b, c, d, e, a, F0, K0, 4, 5 ); | |
482 | + R( a, b, c, d, e, F0, K0, 5, 8 ); | |
483 | + R( e, a, b, c, d, F0, K0, 6, 7 ); | |
484 | + R( d, e, a, b, c, F0, K0, 7, 9 ); | |
485 | + R( c, d, e, a, b, F0, K0, 8, 11 ); | |
486 | + R( b, c, d, e, a, F0, K0, 9, 13 ); | |
487 | + R( a, b, c, d, e, F0, K0, 10, 14 ); | |
488 | + R( e, a, b, c, d, F0, K0, 11, 15 ); | |
489 | + R( d, e, a, b, c, F0, K0, 12, 6 ); | |
490 | + R( c, d, e, a, b, F0, K0, 13, 7 ); | |
491 | + R( b, c, d, e, a, F0, K0, 14, 9 ); | |
492 | + R( a, b, c, d, e, F0, K0, 15, 8 ); | |
493 | + R( e, a, b, c, d, F1, K1, 7, 7 ); | |
494 | + R( d, e, a, b, c, F1, K1, 4, 6 ); | |
495 | + R( c, d, e, a, b, F1, K1, 13, 8 ); | |
496 | + R( b, c, d, e, a, F1, K1, 1, 13 ); | |
497 | + R( a, b, c, d, e, F1, K1, 10, 11 ); | |
498 | + R( e, a, b, c, d, F1, K1, 6, 9 ); | |
499 | + R( d, e, a, b, c, F1, K1, 15, 7 ); | |
500 | + R( c, d, e, a, b, F1, K1, 3, 15 ); | |
501 | + R( b, c, d, e, a, F1, K1, 12, 7 ); | |
502 | + R( a, b, c, d, e, F1, K1, 0, 12 ); | |
503 | + R( e, a, b, c, d, F1, K1, 9, 15 ); | |
504 | + R( d, e, a, b, c, F1, K1, 5, 9 ); | |
505 | + R( c, d, e, a, b, F1, K1, 2, 11 ); | |
506 | + R( b, c, d, e, a, F1, K1, 14, 7 ); | |
507 | + R( a, b, c, d, e, F1, K1, 11, 13 ); | |
508 | + R( e, a, b, c, d, F1, K1, 8, 12 ); | |
509 | + R( d, e, a, b, c, F2, K2, 3, 11 ); | |
510 | + R( c, d, e, a, b, F2, K2, 10, 13 ); | |
511 | + R( b, c, d, e, a, F2, K2, 14, 6 ); | |
512 | + R( a, b, c, d, e, F2, K2, 4, 7 ); | |
513 | + R( e, a, b, c, d, F2, K2, 9, 14 ); | |
514 | + R( d, e, a, b, c, F2, K2, 15, 9 ); | |
515 | + R( c, d, e, a, b, F2, K2, 8, 13 ); | |
516 | + R( b, c, d, e, a, F2, K2, 1, 15 ); | |
517 | + R( a, b, c, d, e, F2, K2, 2, 14 ); | |
518 | + R( e, a, b, c, d, F2, K2, 7, 8 ); | |
519 | + R( d, e, a, b, c, F2, K2, 0, 13 ); | |
520 | + R( c, d, e, a, b, F2, K2, 6, 6 ); | |
521 | + R( b, c, d, e, a, F2, K2, 13, 5 ); | |
522 | + R( a, b, c, d, e, F2, K2, 11, 12 ); | |
523 | + R( e, a, b, c, d, F2, K2, 5, 7 ); | |
524 | + R( d, e, a, b, c, F2, K2, 12, 5 ); | |
525 | + R( c, d, e, a, b, F3, K3, 1, 11 ); | |
526 | + R( b, c, d, e, a, F3, K3, 9, 12 ); | |
527 | + R( a, b, c, d, e, F3, K3, 11, 14 ); | |
528 | + R( e, a, b, c, d, F3, K3, 10, 15 ); | |
529 | + R( d, e, a, b, c, F3, K3, 0, 14 ); | |
530 | + R( c, d, e, a, b, F3, K3, 8, 15 ); | |
531 | + R( b, c, d, e, a, F3, K3, 12, 9 ); | |
532 | + R( a, b, c, d, e, F3, K3, 4, 8 ); | |
533 | + R( e, a, b, c, d, F3, K3, 13, 9 ); | |
534 | + R( d, e, a, b, c, F3, K3, 3, 14 ); | |
535 | + R( c, d, e, a, b, F3, K3, 7, 5 ); | |
536 | + R( b, c, d, e, a, F3, K3, 15, 6 ); | |
537 | + R( a, b, c, d, e, F3, K3, 14, 8 ); | |
538 | + R( e, a, b, c, d, F3, K3, 5, 6 ); | |
539 | + R( d, e, a, b, c, F3, K3, 6, 5 ); | |
540 | + R( c, d, e, a, b, F3, K3, 2, 12 ); | |
541 | + R( b, c, d, e, a, F4, K4, 4, 9 ); | |
542 | + R( a, b, c, d, e, F4, K4, 0, 15 ); | |
543 | + R( e, a, b, c, d, F4, K4, 5, 5 ); | |
544 | + R( d, e, a, b, c, F4, K4, 9, 11 ); | |
545 | + R( c, d, e, a, b, F4, K4, 7, 6 ); | |
546 | + R( b, c, d, e, a, F4, K4, 12, 8 ); | |
547 | + R( a, b, c, d, e, F4, K4, 2, 13 ); | |
548 | + R( e, a, b, c, d, F4, K4, 10, 12 ); | |
549 | + R( d, e, a, b, c, F4, K4, 14, 5 ); | |
550 | + R( c, d, e, a, b, F4, K4, 1, 12 ); | |
551 | + R( b, c, d, e, a, F4, K4, 3, 13 ); | |
552 | + R( a, b, c, d, e, F4, K4, 8, 14 ); | |
553 | + R( e, a, b, c, d, F4, K4, 11, 11 ); | |
554 | + R( d, e, a, b, c, F4, K4, 6, 8 ); | |
555 | + R( c, d, e, a, b, F4, K4, 15, 5 ); | |
556 | + R( b, c, d, e, a, F4, K4, 13, 6 ); | |
557 | + | |
558 | + aa = a; bb = b; cc = c; dd = d; ee = e; | |
559 | + | |
560 | + /* right lane */ | |
561 | + a = hd->h0; | |
562 | + b = hd->h1; | |
563 | + c = hd->h2; | |
564 | + d = hd->h3; | |
565 | + e = hd->h4; | |
566 | + R( a, b, c, d, e, F4, KK0, 5, 8); | |
567 | + R( e, a, b, c, d, F4, KK0, 14, 9); | |
568 | + R( d, e, a, b, c, F4, KK0, 7, 9); | |
569 | + R( c, d, e, a, b, F4, KK0, 0, 11); | |
570 | + R( b, c, d, e, a, F4, KK0, 9, 13); | |
571 | + R( a, b, c, d, e, F4, KK0, 2, 15); | |
572 | + R( e, a, b, c, d, F4, KK0, 11, 15); | |
573 | + R( d, e, a, b, c, F4, KK0, 4, 5); | |
574 | + R( c, d, e, a, b, F4, KK0, 13, 7); | |
575 | + R( b, c, d, e, a, F4, KK0, 6, 7); | |
576 | + R( a, b, c, d, e, F4, KK0, 15, 8); | |
577 | + R( e, a, b, c, d, F4, KK0, 8, 11); | |
578 | + R( d, e, a, b, c, F4, KK0, 1, 14); | |
579 | + R( c, d, e, a, b, F4, KK0, 10, 14); | |
580 | + R( b, c, d, e, a, F4, KK0, 3, 12); | |
581 | + R( a, b, c, d, e, F4, KK0, 12, 6); | |
582 | + R( e, a, b, c, d, F3, KK1, 6, 9); | |
583 | + R( d, e, a, b, c, F3, KK1, 11, 13); | |
584 | + R( c, d, e, a, b, F3, KK1, 3, 15); | |
585 | + R( b, c, d, e, a, F3, KK1, 7, 7); | |
586 | + R( a, b, c, d, e, F3, KK1, 0, 12); | |
587 | + R( e, a, b, c, d, F3, KK1, 13, 8); | |
588 | + R( d, e, a, b, c, F3, KK1, 5, 9); | |
589 | + R( c, d, e, a, b, F3, KK1, 10, 11); | |
590 | + R( b, c, d, e, a, F3, KK1, 14, 7); | |
591 | + R( a, b, c, d, e, F3, KK1, 15, 7); | |
592 | + R( e, a, b, c, d, F3, KK1, 8, 12); | |
593 | + R( d, e, a, b, c, F3, KK1, 12, 7); | |
594 | + R( c, d, e, a, b, F3, KK1, 4, 6); | |
595 | + R( b, c, d, e, a, F3, KK1, 9, 15); | |
596 | + R( a, b, c, d, e, F3, KK1, 1, 13); | |
597 | + R( e, a, b, c, d, F3, KK1, 2, 11); | |
598 | + R( d, e, a, b, c, F2, KK2, 15, 9); | |
599 | + R( c, d, e, a, b, F2, KK2, 5, 7); | |
600 | + R( b, c, d, e, a, F2, KK2, 1, 15); | |
601 | + R( a, b, c, d, e, F2, KK2, 3, 11); | |
602 | + R( e, a, b, c, d, F2, KK2, 7, 8); | |
603 | + R( d, e, a, b, c, F2, KK2, 14, 6); | |
604 | + R( c, d, e, a, b, F2, KK2, 6, 6); | |
605 | + R( b, c, d, e, a, F2, KK2, 9, 14); | |
606 | + R( a, b, c, d, e, F2, KK2, 11, 12); | |
607 | + R( e, a, b, c, d, F2, KK2, 8, 13); | |
608 | + R( d, e, a, b, c, F2, KK2, 12, 5); | |
609 | + R( c, d, e, a, b, F2, KK2, 2, 14); | |
610 | + R( b, c, d, e, a, F2, KK2, 10, 13); | |
611 | + R( a, b, c, d, e, F2, KK2, 0, 13); | |
612 | + R( e, a, b, c, d, F2, KK2, 4, 7); | |
613 | + R( d, e, a, b, c, F2, KK2, 13, 5); | |
614 | + R( c, d, e, a, b, F1, KK3, 8, 15); | |
615 | + R( b, c, d, e, a, F1, KK3, 6, 5); | |
616 | + R( a, b, c, d, e, F1, KK3, 4, 8); | |
617 | + R( e, a, b, c, d, F1, KK3, 1, 11); | |
618 | + R( d, e, a, b, c, F1, KK3, 3, 14); | |
619 | + R( c, d, e, a, b, F1, KK3, 11, 14); | |
620 | + R( b, c, d, e, a, F1, KK3, 15, 6); | |
621 | + R( a, b, c, d, e, F1, KK3, 0, 14); | |
622 | + R( e, a, b, c, d, F1, KK3, 5, 6); | |
623 | + R( d, e, a, b, c, F1, KK3, 12, 9); | |
624 | + R( c, d, e, a, b, F1, KK3, 2, 12); | |
625 | + R( b, c, d, e, a, F1, KK3, 13, 9); | |
626 | + R( a, b, c, d, e, F1, KK3, 9, 12); | |
627 | + R( e, a, b, c, d, F1, KK3, 7, 5); | |
628 | + R( d, e, a, b, c, F1, KK3, 10, 15); | |
629 | + R( c, d, e, a, b, F1, KK3, 14, 8); | |
630 | + R( b, c, d, e, a, F0, KK4, 12, 8); | |
631 | + R( a, b, c, d, e, F0, KK4, 15, 5); | |
632 | + R( e, a, b, c, d, F0, KK4, 10, 12); | |
633 | + R( d, e, a, b, c, F0, KK4, 4, 9); | |
634 | + R( c, d, e, a, b, F0, KK4, 1, 12); | |
635 | + R( b, c, d, e, a, F0, KK4, 5, 5); | |
636 | + R( a, b, c, d, e, F0, KK4, 8, 14); | |
637 | + R( e, a, b, c, d, F0, KK4, 7, 6); | |
638 | + R( d, e, a, b, c, F0, KK4, 6, 8); | |
639 | + R( c, d, e, a, b, F0, KK4, 2, 13); | |
640 | + R( b, c, d, e, a, F0, KK4, 13, 6); | |
641 | + R( a, b, c, d, e, F0, KK4, 14, 5); | |
642 | + R( e, a, b, c, d, F0, KK4, 0, 15); | |
643 | + R( d, e, a, b, c, F0, KK4, 3, 13); | |
644 | + R( c, d, e, a, b, F0, KK4, 9, 11); | |
645 | + R( b, c, d, e, a, F0, KK4, 11, 11); | |
646 | + | |
647 | + | |
648 | + t = hd->h1 + d + cc; | |
649 | + hd->h1 = hd->h2 + e + dd; | |
650 | + hd->h2 = hd->h3 + a + ee; | |
651 | + hd->h3 = hd->h4 + b + aa; | |
652 | + hd->h4 = hd->h0 + c + bb; | |
653 | + hd->h0 = t; | |
654 | +} | |
2ad55559 | 655 | + |
2ad55559 | 656 | + |
8c2034f5 | 657 | +/* Update the message digest with the contents |
658 | + * of INBUF with length INLEN. | |
2ad55559 | 659 | + */ |
8c2034f5 | 660 | +static void |
661 | +rmd160_write( RMD160_CONTEXT *hd, byte *inbuf, size_t inlen) | |
662 | +{ | |
663 | + if( hd->count == 64 ) { /* flush the buffer */ | |
664 | + transform( hd, hd->buf ); | |
665 | + hd->count = 0; | |
666 | + hd->nblocks++; | |
667 | + } | |
668 | + if( !inbuf ) | |
669 | + return; | |
670 | + if( hd->count ) { | |
671 | + for( ; inlen && hd->count < 64; inlen-- ) | |
672 | + hd->buf[hd->count++] = *inbuf++; | |
673 | + rmd160_write( hd, NULL, 0 ); | |
674 | + if( !inlen ) | |
675 | + return; | |
676 | + } | |
677 | + | |
678 | + while( inlen >= 64 ) { | |
679 | + transform( hd, inbuf ); | |
680 | + hd->count = 0; | |
681 | + hd->nblocks++; | |
682 | + inlen -= 64; | |
683 | + inbuf += 64; | |
684 | + } | |
685 | + for( ; inlen && hd->count < 64; inlen-- ) | |
686 | + hd->buf[hd->count++] = *inbuf++; | |
687 | +} | |
2ad55559 | 688 | + |
8c2034f5 | 689 | +/* The routine terminates the computation |
2ad55559 | 690 | + */ |
691 | + | |
8c2034f5 | 692 | +static void |
693 | +rmd160_final( RMD160_CONTEXT *hd ) | |
694 | +{ | |
695 | + u32 t, msb, lsb; | |
696 | + byte *p; | |
697 | + | |
698 | + rmd160_write(hd, NULL, 0); /* flush */; | |
699 | + | |
700 | + msb = 0; | |
701 | + t = hd->nblocks; | |
702 | + if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */ | |
703 | + msb++; | |
704 | + msb += t >> 26; | |
705 | + t = lsb; | |
706 | + if( (lsb = t + hd->count) < t ) /* add the count */ | |
707 | + msb++; | |
708 | + t = lsb; | |
709 | + if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */ | |
710 | + msb++; | |
711 | + msb += t >> 29; | |
712 | + | |
713 | + if( hd->count < 56 ) { /* enough room */ | |
714 | + hd->buf[hd->count++] = 0x80; /* pad */ | |
715 | + while( hd->count < 56 ) | |
716 | + hd->buf[hd->count++] = 0; /* pad */ | |
717 | + } | |
718 | + else { /* need one extra block */ | |
719 | + hd->buf[hd->count++] = 0x80; /* pad character */ | |
720 | + while( hd->count < 64 ) | |
721 | + hd->buf[hd->count++] = 0; | |
722 | + rmd160_write(hd, NULL, 0); /* flush */; | |
723 | + memset(hd->buf, 0, 56 ); /* fill next block with zeroes */ | |
724 | + } | |
725 | + /* append the 64 bit count */ | |
726 | + hd->buf[56] = lsb ; | |
727 | + hd->buf[57] = lsb >> 8; | |
728 | + hd->buf[58] = lsb >> 16; | |
729 | + hd->buf[59] = lsb >> 24; | |
730 | + hd->buf[60] = msb ; | |
731 | + hd->buf[61] = msb >> 8; | |
732 | + hd->buf[62] = msb >> 16; | |
733 | + hd->buf[63] = msb >> 24; | |
734 | + transform( hd, hd->buf ); | |
735 | + | |
736 | + p = hd->buf; | |
737 | + #if BYTE_ORDER == BIG_ENDIAN | |
738 | + #define X(a) do { *p++ = hd->h##a ; *p++ = hd->h##a >> 8; \ | |
739 | + *p++ = hd->h##a >> 16; *p++ = hd->h##a >> 24; } while(0) | |
740 | + #else /* little endian */ | |
741 | + #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0) | |
742 | + #endif | |
743 | + X(0); | |
744 | + X(1); | |
745 | + X(2); | |
746 | + X(3); | |
747 | + X(4); | |
748 | + #undef X | |
749 | +} | |
750 | + | |
751 | +/**************** | |
752 | + * Shortcut functions which puts the hash value of the supplied buffer | |
753 | + * into outbuf which must have a size of 20 bytes. | |
2ad55559 | 754 | + */ |
8c2034f5 | 755 | +void |
756 | +rmd160_hash_buffer( char *outbuf, const char *buffer, size_t length ) | |
757 | +{ | |
758 | + RMD160_CONTEXT hd; | |
759 | + | |
760 | + rmd160_init( &hd ); | |
761 | + rmd160_write( &hd, (byte*)buffer, length ); | |
762 | + rmd160_final( &hd ); | |
763 | + memcpy( outbuf, hd.buf, 20 ); | |
764 | +} | |
bf46eb01 AM |
765 | diff -urN util-linux-2.11d.org/mount/rmd160.h util-linux-2.11d/mount/rmd160.h |
766 | --- util-linux-2.11d.org/mount/rmd160.h Thu Jan 1 01:00:00 1970 | |
767 | +++ util-linux-2.11d/mount/rmd160.h Sun Jun 3 22:26:06 2001 | |
8c2034f5 | 768 | @@ -0,0 +1,9 @@ |
769 | +#ifndef RMD160_H | |
770 | +#define RMD160_H | |
2ad55559 | 771 | + |
8c2034f5 | 772 | +void |
773 | +rmd160_hash_buffer( char *outbuf, const char *buffer, size_t length ); | |
2ad55559 | 774 | + |
8c2034f5 | 775 | +#endif /*RMD160_H*/ |
2ad55559 | 776 | + |
2ad55559 | 777 | + |