]> git.pld-linux.org Git - packages/util-linux.git/blame - util-linux-cryptoapi.patch
- removed obsolete fdisk2 patch
[packages/util-linux.git] / util-linux-cryptoapi.patch
CommitLineData
21d15157 1? defines.h
2? make_include
3? mount/loop.h
4? mount/losetup
5? mount/mount
6? mount/nfsmount.h
7? mount/nfsmount_clnt.c
8? mount/nfsmount_xdr.c
9? mount/pivot_root
10? mount/swapargs.h
11? mount/swapon
12? mount/umount
13Index: mount/Makefile
14===================================================================
15RCS file: /cvsroot/cryptoapi/util-linux/mount/Makefile,v
16retrieving revision 1.1.1.1
17retrieving revision 1.1.1.1.2.1
18diff -u -u -r1.1.1.1 -r1.1.1.1.2.1
19--- mount/Makefile 24 Mar 2002 12:54:13 -0000 1.1.1.1
20+++ mount/Makefile 24 Mar 2002 13:56:39 -0000 1.1.1.1.2.1
966ca26a
JB
21@@ -24,7 +24,7 @@
22
23 MAYBE = pivot_root swapoff
24
25-LO_OBJS = lomount.o $(LIB)/xstrncpy.o
21d15157 26+LO_OBJS = lomount.o $(LIB)/xstrncpy.o sha512.o rmd160.o
966ca26a
JB
27 NFS_OBJS = nfsmount.o nfsmount_xdr.o nfsmount_clnt.o
28 GEN_FILES = nfsmount.h nfsmount_xdr.c nfsmount_clnt.c
29
21d15157 30@@ -57,8 +57,12 @@
966ca26a
JB
31 main_losetup.o: lomount.c
32 $(COMPILE) -DMAIN lomount.c -o $@
33
34-losetup: main_losetup.o $(LIB)/xstrncpy.o
21d15157 35+losetup: main_losetup.o $(LIB)/xstrncpy.o sha512.o rmd160.o
966ca26a 36 $(LINK) $^ -o $@
21d15157 37+
38+rmd160.o lomount.o main_losetup.o: rmd160.h
39+
40+sha512.o lomount.o main_losetup.o: sha512.h
966ca26a
JB
41
42 mount.o umount.o nfsmount.o losetup.o fstab.o realpath.o sundries.o: sundries.h
21d15157 43
44Index: mount/lomount.c
45===================================================================
46RCS file: /cvsroot/cryptoapi/util-linux/mount/lomount.c,v
47retrieving revision 1.1.1.1
48retrieving revision 1.1.1.1.2.3
49diff -u -u -r1.1.1.1 -r1.1.1.1.2.3
50--- mount/lomount.c 24 Mar 2002 12:54:15 -0000 1.1.1.1
51+++ mount/lomount.c 24 Mar 2002 16:02:42 -0000 1.1.1.1.2.3
966ca26a
JB
52@@ -6,6 +6,11 @@
53 * - added Native Language Support
54 * Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
55 * - fixed strerr(errno) in gettext calls
56+ * 2000-09-24 Marc Mutz <Marc@Mutz.com>
57+ * - added long option names and the --pass-fd option to pass
58+ * passphrases via fd's to losetup/mount. Used for encryption in
59+ * non-interactive environments. The idea behind xgetpass() is stolen
60+ * from GnuPG, v.1.0.3 (http://www.gnupg.org/).
61 */
62
63 #define PROC_DEVICES "/proc/devices"
21d15157 64@@ -21,54 +26,109 @@
966ca26a
JB
65 #include <errno.h>
66 #include <stdlib.h>
67 #include <unistd.h>
68+#include <limits.h>
69 #include <sys/ioctl.h>
70 #include <sys/stat.h>
71 #include <sys/mman.h>
72
73 #include "loop.h"
74 #include "lomount.h"
75+#include "rmd160.h"
21d15157 76+#include "sha512.h"
966ca26a
JB
77 #include "xstrncpy.h"
78 #include "nls.h"
79
80+#ifndef LO_CRYPT_CRYPTOAPI
81+#define LO_CRYPT_CRYPTOAPI 18
82+#endif
aa620da5
JB
83+#ifndef LO_CRYPT_NONE
84+#define LO_CRYPT_NONE 0
85+#endif
86+#ifndef LO_CRYPT_XOR
87+#define LO_CRYPT_XOR 1
88+#endif
89+#ifndef LO_CRYPT_DES
90+#define LO_CRYPT_DES 2
91+#endif
92+#ifndef LO_CRYPT_FISH2
93+#define LO_CRYPT_FISH2 3
94+#endif
95+#ifndef LO_CRYPT_BLOW
96+#define LO_CRYPT_BLOW 4
97+#endif
98+#ifndef LO_CRYPT_CAST128
99+#define LO_CRYPT_CAST128 5
100+#endif
101+#ifndef LO_CRYPT_IDEA
102+#define LO_CRYPT_IDEA 6
103+#endif
104+#ifndef LO_CRYPT_SERPENT
105+#define LO_CRYPT_SERPENT 7
106+#endif
107+#ifndef LO_CRYPT_MARS
108+#define LO_CRYPT_MARS 8
109+#endif
110+#ifndef LO_CRYPT_RC6
111+#define LO_CRYPT_RC6 11
112+#endif
113+#ifndef LO_CRYPT_3DES
114+#define LO_CRYPT_3DES 12
115+#endif
116+#ifndef LO_CRYPT_DFC
117+#define LO_CRYPT_DFC 15
118+#endif
119+#ifndef LO_CRYPT_RIJNDAEL
120+#define LO_CRYPT_RIJNDAEL 16
121+#endif
122+
966ca26a
JB
123+
124 extern int verbose;
125 extern char *xstrdup (const char *s); /* not: #include "sundries.h" */
126 extern void error (const char *fmt, ...); /* idem */
127
aa620da5 128+
966ca26a
JB
129+struct cipher_info
130+{
131+ const char *name;
132+ int blocksize;
133+ int keysize_mask;
134+ int ivsize;
135+ int key_schedule_size;
136+};
137+
138+static int set_loop_passwd(struct loop_info *_loopinfo, int pfd, int keysz,
21d15157 139+ const char *phash_name, const char *encryption,
140+ int fd, int ffd);
966ca26a
JB
141+static int get_cipher_info(const char *name, struct cipher_info *res);
142+static int name_to_id(const char *name);
143+#ifdef MAIN
aa620da5 144+static char *id_to_name(int id);
966ca26a 145+#endif
aa620da5 146+
966ca26a
JB
147+
148 #ifdef LOOP_SET_FD
149 struct crypt_type_struct {
150 int id;
151 char *name;
152+ int keylength;
153 } crypt_type_tbl[] = {
154- { LO_CRYPT_NONE, "no" },
155- { LO_CRYPT_NONE, "none" },
156- { LO_CRYPT_XOR, "xor" },
157- { LO_CRYPT_DES, "DES" },
158- { -1, NULL }
aa620da5
JB
159+ { LO_CRYPT_NONE, "none", 0 },
160+ { LO_CRYPT_XOR, "xor", 0 },
161+ { LO_CRYPT_DES, "des", 8 },
162+ { LO_CRYPT_FISH2, "twofish", 20 },
163+ { LO_CRYPT_BLOW, "blowfish", 20 },
164+ { LO_CRYPT_CAST128, "cast", 16 },
165+ { LO_CRYPT_SERPENT, "serpent", 16 },
166+ { LO_CRYPT_MARS, "mars", 16 },
167+ { LO_CRYPT_RC6, "rc6", 16 },
168+ { LO_CRYPT_3DES, "des-ede3", 24 },
169+ { LO_CRYPT_DFC, "dfc", 16 },
170+ { LO_CRYPT_IDEA, "idea", 16 },
171+ { LO_CRYPT_RIJNDAEL, "rijndael", 16 },
966ca26a
JB
172+ { -1, NULL,0 }
173 };
174
175-static int
176-crypt_type (const char *name) {
177- int i;
178-
179- if (name) {
180- for (i = 0; crypt_type_tbl[i].id != -1; i++)
181- if (!strcasecmp (name, crypt_type_tbl[i].name))
182- return crypt_type_tbl[i].id;
183- }
184- return -1;
185-}
186-
187 #ifdef MAIN
188-static char *
189-crypt_name (int id) {
190- int i;
191-
192- for (i = 0; crypt_type_tbl[i].id != -1; i++)
193- if (id == crypt_type_tbl[i].id)
194- return crypt_type_tbl[i].name;
195- return "undefined";
196-}
197-
198 static int
199 show_loop (char *device) {
200 struct loop_info loopinfo;
21d15157 201@@ -90,7 +150,7 @@
966ca26a
JB
202 printf (_("%s: [%04x]:%ld (%s) offset %d, %s encryption\n"),
203 device, loopinfo.lo_device, loopinfo.lo_inode,
204 loopinfo.lo_name, loopinfo.lo_offset,
205- crypt_name (loopinfo.lo_encrypt_type));
206+ id_to_name(loopinfo.lo_encrypt_type));
207 close (fd);
208
209 return 0;
21d15157 210@@ -183,24 +243,62 @@
966ca26a
JB
211 error(_(
212 "mount: Could not find any loop device, and, according to %s,\n"
213 " this kernel does not know about the loop device.\n"
214- " (If so, then recompile or `insmod loop.o'.)"),
215+ " (If so, then recompile or `modprobe loop'.)"),
216 PROC_DEVICES);
217 else
218 error(_(
219 "mount: Could not find any loop device. Maybe this kernel does not know\n"
220- " about the loop device (then recompile or `insmod loop.o'), or\n"
221+ " about the loop device (then recompile or `modprobe loop'), or\n"
222 " maybe /dev/loop# has the wrong major number?"));
223 } else
224 error(_("mount: could not find any free loop device"));
225 return 0;
226 }
227
966ca26a
JB
228+/* A function to read the passphrase either from the terminal or from
229+ * an open file descriptor */
230+static char *
231+xgetpass (int pfd, const char *prompt)
232+{
233+ if (pfd < 0) /* terminal */
234+ return (getpass(prompt));
235+ else { /* file descriptor */
236+ char *pass = NULL;
237+ int buflen, i;
238+
239+ buflen=0;
240+ for (i=0; ; i++) {
241+ if (i >= buflen-1) {
242+ /* we're running out of space in the buffer.
243+ * Make it bigger: */
244+ char *tmppass = pass;
245+ buflen += 128;
246+ pass = realloc(tmppass,buflen);
247+ if (pass == NULL) {
248+ /* realloc failed. Stop reading _now_. */
249+ error("not enough memory while reading passphrase");
250+ pass = tmppass; /* the old buffer hasn't changed */
251+ break;
252+ }
253+ };
254+ if ( read(pfd,pass+i, 1) != 1 || pass[i] == '\n' )
255+ break;
256+ }
257+ if (pass == NULL)
258+ return "";
259+ else {
260+ pass[i] = 0;
261+ return pass;
262+ }
263+ }
264+}
265+
266 int
267 set_loop (const char *device, const char *file, int offset,
268- const char *encryption, int *loopro) {
21d15157 269+ const char *encryption, int pfd, int keysz, int *loopro,
270+ const char *phash_name) {
966ca26a
JB
271 struct loop_info loopinfo;
272- int fd, ffd, mode, i;
273- char *pass;
274+ int fd, ffd, mode, tried_old;
275
276 mode = (*loopro ? O_RDONLY : O_RDWR);
277 if ((ffd = open (file, mode)) < 0) {
aa620da5 278@@ -218,13 +316,10 @@
966ca26a
JB
279 *loopro = (mode == O_RDONLY);
280
281 memset (&loopinfo, 0, sizeof (loopinfo));
282- xstrncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
283- if (encryption && (loopinfo.lo_encrypt_type = crypt_type (encryption))
284- < 0) {
285- fprintf (stderr, _("Unsupported encryption type %s\n"),
286- encryption);
287- return 1;
288- }
289+ snprintf(loopinfo.lo_name, sizeof(loopinfo.lo_name),
aa620da5 290+ "%s-cbc", encryption);
966ca26a
JB
291+ loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
292+ loopinfo.lo_encrypt_type = LO_CRYPT_CRYPTOAPI;
293 loopinfo.lo_offset = offset;
294
295 #ifdef MCL_FUTURE
21d15157 296@@ -240,24 +335,148 @@
966ca26a
JB
297 }
298 #endif
299
300- switch (loopinfo.lo_encrypt_type) {
301+ if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
302+ perror ("ioctl: LOOP_SET_FD");
303+ return 1;
304+ }
305+
306+ tried_old = 0;
307+again:
21d15157 308+ set_loop_passwd(&loopinfo, pfd, keysz, phash_name, encryption, fd, ffd);
966ca26a
JB
309+
310+ if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
311+ /* Try again with old-style LO_CRYPT_XX if
aa620da5 312+ new-style LO_CRYPT_CRYPTOAPI ioctl didn't work */
966ca26a
JB
313+ if (tried_old) {
314+ error("The cipher does not exist, or a cipher module "
315+ "needs to be loaded into the kernel");
316+ perror ("ioctl: LOOP_SET_STATUS");
317+ goto out_ioctl;
318+ }
319+ strncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
320+ loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
321+ loopinfo.lo_encrypt_type = name_to_id (encryption);
322+ tried_old = 1;
323+ goto again;
324+ }
325+ close (fd);
326+ close (ffd);
327+ if (verbose > 1)
328+ printf(_("set_loop(%s,%s,%d): success\n"),
329+ device, file, offset);
330+ return 0;
331+out_ioctl:
332+ (void) ioctl (fd, LOOP_CLR_FD, 0);
333+ return 1;
334+}
335+
21d15157 336+
337+
338+typedef int (*phash_func_t)(char dest[LO_KEY_SIZE], const char src[], size_t src_len);
339+
340+#define PASSWDBUFFLEN 130
341+
342+static int
343+phash_rmd160old (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
344+{
345+ char tmp[PASSWDBUFFLEN] = { 'A', 0, };
346+ char key[RMD160_HASH_SIZE * 2] = { 0, };
347+
348+ strncpy (tmp + 1, src, PASSWDBUFFLEN - 1);
349+ tmp[PASSWDBUFFLEN - 1] = '\0';
350+
351+ rmd160_hash_buffer(key, src, src_len);
352+ rmd160_hash_buffer(key + RMD160_HASH_SIZE, tmp, src_len + 1 /* dangerous! */);
353+
354+ memcpy (dest, key, LO_KEY_SIZE);
355+
356+ return 0;
357+}
358+
359+static int
360+phash_sha256 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
361+{
362+ memset (dest, 0, LO_KEY_SIZE);
363+ sha256_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
364+ return 0;
365+}
366+
367+static int
368+phash_sha384 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
369+{
370+ memset (dest, 0, LO_KEY_SIZE);
371+ sha384_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
372+ return 0;
373+}
374+
375+static int
376+phash_sha512 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
377+{
378+ memset (dest, 0, LO_KEY_SIZE);
379+ sha512_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
380+ return 0;
381+}
382+
383+static int
384+phash_default (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
385+{
386+ fprintf (stderr, "unknown hash type requested\n");
387+ return 1;
388+}
389+
390+static phash_func_t
391+phash_lookup (const char phash_name[])
392+{
393+ struct {
394+ const char *name;
395+ phash_func_t func;
396+ } func_table[] = {
397+ {"rmd160old", phash_rmd160old },
398+ {"sha256", phash_sha256 },
399+ {"sha384", phash_sha384 },
400+ {"sha512", phash_sha512 },
401+ { 0, phash_default }
402+ }, *p = func_table;
403+
404+ for (; p->name; p++)
405+ if (!strcmp (phash_name, p->name))
406+ break;
407+
408+ return p->func;
409+}
410+
411+
966ca26a 412+int
aa620da5 413+set_loop_passwd(struct loop_info *loopinfo, int pfd, int keysz,
21d15157 414+ const char *phash_name, const char *encryption,
415+ int fd, int ffd)
966ca26a
JB
416+{
417+ int i;
418+ int keylength;
419+ char *pass;
966ca26a
JB
420+ struct cipher_info info;
421+
422+ switch (loopinfo->lo_encrypt_type) {
423 case LO_CRYPT_NONE:
424- loopinfo.lo_encrypt_key_size = 0;
425+ loopinfo->lo_encrypt_key_size = 0;
426 break;
427 case LO_CRYPT_XOR:
428- pass = getpass (_("Password: "));
429- xstrncpy (loopinfo.lo_encrypt_key, pass, LO_KEY_SIZE);
430- loopinfo.lo_encrypt_key_size = strlen(loopinfo.lo_encrypt_key);
aa620da5
JB
431+ /* WARNING: xgetpass() can return massive amounts of data,
432+ * not only 128 bytes like the original getpass(3) */
966ca26a 433+ pass = xgetpass (pfd,_("Password: "));
aa620da5 434+ xstrncpy (loopinfo->lo_encrypt_key, pass, LO_KEY_SIZE);
966ca26a
JB
435+ loopinfo->lo_encrypt_key_size = strlen(loopinfo->lo_encrypt_key);
436 break;
437 case LO_CRYPT_DES:
438- pass = getpass (_("Password: "));
439- strncpy (loopinfo.lo_encrypt_key, pass, 8);
440- loopinfo.lo_encrypt_key[8] = 0;
441- loopinfo.lo_encrypt_key_size = 8;
442+ printf(_("WARNING: Use of DES is depreciated.\n"));
443+ pass = xgetpass (pfd,_("Password: "));
444+ strncpy (loopinfo->lo_encrypt_key, pass, 8);
445+ loopinfo->lo_encrypt_key[8] = 0;
446+ loopinfo->lo_encrypt_key_size = 8;
447 pass = getpass (_("Init (up to 16 hex digits): "));
448 for (i = 0; i < 16 && pass[i]; i++)
449 if (isxdigit (pass[i])) {
450- loopinfo.lo_init[i >> 3] |= (pass[i] > '9' ?
451+ loopinfo->lo_init[i >> 3] |= (pass[i] > '9' ?
452 (islower (pass[i]) ? toupper (pass[i]) :
453 pass[i])-'A'+10 : pass[i]-'0') << (i&7) * 4;
454 } else {
21d15157 455@@ -266,29 +485,83 @@
966ca26a
JB
456 return 1;
457 }
458 break;
459+ case LO_CRYPT_FISH2:
460+ case LO_CRYPT_BLOW:
461+ case LO_CRYPT_IDEA:
462+ case LO_CRYPT_CAST128:
aa620da5
JB
463+ case LO_CRYPT_SERPENT:
464+ case LO_CRYPT_MARS:
465+ case LO_CRYPT_RC6:
466+ case LO_CRYPT_3DES:
467+ case LO_CRYPT_DFC:
468+ case LO_CRYPT_RIJNDAEL:
469+ pass = xgetpass(pfd, _("Password: "));
21d15157 470+
471+ if (phash_lookup (phash_name) (loopinfo->lo_encrypt_key, pass, strlen (pass)))
472+ return 1;
473+
966ca26a
JB
474+ keylength=0;
475+ for(i=0; crypt_type_tbl[i].id != -1; i++){
476+ if(loopinfo->lo_encrypt_type == crypt_type_tbl[i].id){
477+ keylength = crypt_type_tbl[i].keylength;
478+ break;
479+ }
480+ }
21d15157 481+ loopinfo->lo_encrypt_key_size = keylength;
966ca26a
JB
482+ break;
483+ case LO_CRYPT_CRYPTOAPI:
484+ /* Give the kernel an opportunity to load the cipher */
485+ (void) ioctl (fd, LOOP_SET_STATUS, loopinfo);
486+ if (get_cipher_info(loopinfo->lo_name, &info) < 0) {
487+ return 1;
488+ }
489+ if (keysz > 0 &&
490+ !((1 << ((keysz / 8) - 1)) & info.keysize_mask)) {
491+ error("The specified keysize is not supported by "
492+ "the selected cipher");
493+ keysz = 0;
494+ }
495+
496+ while (keysz <= 0 ||
497+ !((1 << ((keysz / 8) - 1)) & info.keysize_mask)) {
498+ int i = 0;
499+ int available = 0;
500+ char keysize[200];
501+ printf("Available keysizes (bits): ");
502+ for (; i < 32; i++) {
503+ if (info.keysize_mask & (1 << i)) {
504+ printf("%d ", 8*(i+1));
505+ available = 1;
506+ }
507+ }
508+ if (!available) {
509+ printf("none");
510+ }
511+ printf("\nKeysize: ");
512+ fgets(keysize, sizeof(keysize), stdin);
513+ keysz = atoi(keysize);
514+ }
515+
aa620da5 516+ pass = xgetpass(pfd, _("Password: "));
21d15157 517+
518+ if (phash_lookup (phash_name) (loopinfo->lo_encrypt_key, pass, strlen (pass)))
519+ return 1;
966ca26a
JB
520+
521+ loopinfo->lo_encrypt_key_size=keysz/8;
522+
523+ break;
524 default:
525 fprintf (stderr,
526 _("Don't know how to get key for encryption system %d\n"),
527- loopinfo.lo_encrypt_type);
966ca26a
JB
528+ loopinfo->lo_encrypt_type);
529 return 1;
530 }
21d15157 531- if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
532- perror ("ioctl: LOOP_SET_FD");
533- return 1;
534- }
966ca26a
JB
535- if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
536- (void) ioctl (fd, LOOP_CLR_FD, 0);
537- perror ("ioctl: LOOP_SET_STATUS");
538- return 1;
539- }
540- close (fd);
541- close (ffd);
542- if (verbose > 1)
543- printf(_("set_loop(%s,%s,%d): success\n"),
544- device, file, offset);
545- return 0;
546+ return 0;
547 }
548
549+
550+
551+
552 int
553 del_loop (const char *device) {
554 int fd;
21d15157 555@@ -319,7 +592,7 @@
966ca26a
JB
556
557 int
558 set_loop (const char *device, const char *file, int offset,
559- const char *encryption, int *loopro) {
560+ const char *encryption, int pfd, int *loopro) {
561 mutter();
562 return 1;
563 }
21d15157 564@@ -348,12 +621,45 @@
966ca26a
JB
565 int verbose = 0;
566 static char *progname;
567
568+static struct option longopts[] = {
569+ { "delete", 0, 0, 'd' },
570+ { "detach", 0, 0, 'd' },
571+ { "encryption", 1, 0, 'e' },
572+ { "help", 0, 0, 'h' },
573+ { "offset", 1, 0, 'o' },
574+ { "pass-fd", 1, 0, 'p' },
21d15157 575+ { "phash", 1, 0, 'P' },
966ca26a
JB
576+ { "verbose", 0, 0, 'v' },
577+ { "keybits", 1, 0, 'k' },
578+ { NULL, 0, 0, 0 }
579+};
580+
581+
582 static void
583 usage(void) {
21d15157 584- fprintf(stderr, _("usage:\n\
585+ fprintf(stderr,
586+_("usage:\n\
966ca26a
JB
587 %s loop_device # give info\n\
588 %s -d loop_device # delete\n\
589- %s [ -e encryption ] [ -o offset ] loop_device file # setup\n"),
966ca26a
JB
590+ %s [ options ] loop_device file # setup\n\
591+ where options include\n\
592+ --offset <num>, -o <num>\n\
593+ start at offset <num> into file.\n\
594+ --pass-fd <num>, -p <num>\n\
595+ read passphrase from file descriptor <num>\n\
596+ instead of the terminal.\n\
597+ --encryption <cipher>, -e <cipher>\n\
598+ encrypt with <cipher>.\n\
21d15157 599+ Check /proc/crypto/cipher for available ciphers.\n\
966ca26a
JB
600+ --keybits <num>, -k <num>\n\
601+ specify number of bits in the hashed key given\n\
602+ to the cipher. Some ciphers support several key\n\
603+ sizes and might be more efficient with a smaller\n\
604+ key size. Key sizes < 128 are generally not\n\
21d15157 605+ recommended\n\
606+ --phash <hash>, -P <hash>\n\
607+ specify <hash> to use for hashing the passphrase\n\
608+ (supported: rmd160old, sha256, sha384, sha512)\n"),
609 progname, progname, progname);
966ca26a
JB
610 exit(1);
611 }
21d15157 612@@ -387,19 +693,20 @@
966ca26a
JB
613
614 int
615 main(int argc, char **argv) {
616- char *offset, *encryption;
21d15157 617- int delete,off,c;
618+ char *offset = 0, *encryption = 0, *passfd = 0, *keysize = 0, *phash_name = 0;
619+ int delete = 0, off = 0, c = 0;
620+ int pfd = -1;
966ca26a
JB
621 int res = 0;
622 int ro = 0;
623+ int keysz = 0;
624
625 setlocale(LC_ALL, "");
626 bindtextdomain(PACKAGE, LOCALEDIR);
627 textdomain(PACKAGE);
628
21d15157 629- delete = off = 0;
966ca26a 630- offset = encryption = NULL;
966ca26a 631 progname = argv[0];
21d15157 632- while ((c = getopt(argc,argv,"de:o:v")) != -1) {
633+ while ((c = getopt_long(argc,argv,"de:h:k:o:p:P:v",
634+ longopts, NULL)) != -1) {
966ca26a
JB
635 switch (c) {
636 case 'd':
637 delete = 1;
21d15157 638@@ -407,9 +714,18 @@
966ca26a
JB
639 case 'e':
640 encryption = optarg;
641 break;
642+ case 'k':
643+ keysize = optarg;
644+ break;
645 case 'o':
646 offset = optarg;
647 break;
648+ case 'p':
649+ passfd = optarg;
21d15157 650+ break;
651+ case 'P':
652+ phash_name = optarg;
966ca26a
JB
653+ break;
654 case 'v':
655 verbose = 1;
656 break;
21d15157 657@@ -418,7 +734,7 @@
966ca26a
JB
658 }
659 }
660 if (argc == 1) usage();
661- if ((delete && (argc != optind+1 || encryption || offset)) ||
662+ if ((delete && (argc != optind+1 || encryption || offset || passfd)) ||
663 (!delete && (argc < optind+1 || argc > optind+2)))
664 usage();
665 if (argc == optind+1) {
21d15157 666@@ -429,7 +745,13 @@
966ca26a
JB
667 } else {
668 if (offset && sscanf(offset,"%d",&off) != 1)
669 usage();
670- res = set_loop(argv[optind],argv[optind+1],off,encryption,&ro);
671+ if (passfd && sscanf(passfd,"%d",&pfd) != 1)
672+ usage();
673+ if (keysize && sscanf(keysize,"%d",&keysz) != 1)
674+ usage();
675+ res = set_loop(argv[optind], argv[optind+1], off,
21d15157 676+ encryption, pfd, keysz, &ro,
677+ phash_name ? phash_name : "rmd160old");
966ca26a
JB
678 }
679 return res;
680 }
21d15157 681@@ -445,3 +767,61 @@
966ca26a
JB
682 }
683 #endif
684 #endif
685+
686+static int get_cipher_info(const char *name, struct cipher_info *res)
687+{
688+ char path[PATH_MAX];
689+ char buf[2000];
690+ FILE *f;
691+ struct {
692+ int *out;
693+ const char *prefix;
694+ } fields[] = {{&res->blocksize, "blocksize:"},
695+ {&res->keysize_mask, "keysize_mask:"},
696+ {&res->ivsize, "ivsize:"},
697+ {&res->key_schedule_size, "key_schedule_size:"}};
698+ snprintf(path, sizeof(path), "/proc/crypto/cipher/%s", name);
699+ f = fopen(path, "r");
700+ while(f && fgets(buf, sizeof(buf), f)) {
701+ int i;
702+ for (i = 0; i < sizeof(fields)/sizeof(fields[0]); i++) {
703+ int len = strlen(fields[i].prefix);
704+ if (strncmp(buf, fields[i].prefix, len) == 0) {
705+ *fields[i].out = strtoul(&buf[len+1], NULL, 0);
706+ break;
707+ }
708+ }
709+
710+ }
711+ if (!f)
712+ return -1;
713+ return 0;
714+}
715+
716+
717+static int
718+name_to_id(const char *name)
719+{
720+ int i;
721+
722+ if (name) {
723+ for (i = 0; crypt_type_tbl[i].id != -1; i++)
724+ if (!strcasecmp (name, crypt_type_tbl[i].name))
725+ return crypt_type_tbl[i].id;
726+ } else
727+ return LO_CRYPT_NONE;
728+ return LO_CRYPT_CRYPTOAPI;
729+}
730+
731+#ifdef MAIN
732+static char *
733+id_to_name(int id) {
734+ int i;
735+
736+ for (i = 0; crypt_type_tbl[i].id != -1; i++)
737+ if (id == crypt_type_tbl[i].id)
738+ return crypt_type_tbl[i].name;
739+ return "undefined";
740+}
741+#endif
742+
21d15157 743Index: mount/lomount.h
744===================================================================
745RCS file: /cvsroot/cryptoapi/util-linux/mount/lomount.h,v
746retrieving revision 1.1.1.1
747retrieving revision 1.1.1.1.2.2
748diff -u -u -r1.1.1.1 -r1.1.1.1.2.2
749--- mount/lomount.h 24 Mar 2002 12:54:15 -0000 1.1.1.1
750+++ mount/lomount.h 24 Mar 2002 15:31:25 -0000 1.1.1.1.2.2
966ca26a
JB
751@@ -1,5 +1,6 @@
752 extern int verbose;
753-extern int set_loop (const char *, const char *, int, const char *, int *);
754+extern int set_loop (const char *, const char *, int, const char *,
21d15157 755+ int, int, int *, const char *);
966ca26a
JB
756 extern int del_loop (const char *);
757 extern int is_loop_device (const char *);
758 extern char * find_unused_loop_device (void);
21d15157 759Index: mount/losetup.8
760===================================================================
761RCS file: /cvsroot/cryptoapi/util-linux/mount/losetup.8,v
762retrieving revision 1.1.1.1
763retrieving revision 1.1.1.1.2.1
764diff -u -u -r1.1.1.1 -r1.1.1.1.2.1
765--- mount/losetup.8 24 Mar 2002 12:54:15 -0000 1.1.1.1
766+++ mount/losetup.8 24 Mar 2002 13:56:39 -0000 1.1.1.1.2.1
966ca26a
JB
767@@ -10,6 +10,9 @@
768 ] [
769 .B \-o
770 .I offset
771+] [
772+.B \-p
773+.I num
774 ]
775 .I loop_device file
776 .br
777@@ -26,9 +29,9 @@
778 \fIloop_device\fP argument is given, the status of the corresponding loop
779 device is shown.
780 .SH OPTIONS
781-.IP \fB\-d\fP
782+.IP "\fB\-\-delete, \-\-detach, \-d\fP"
783 detach the file or device associated with the specified loop device.
784-.IP "\fB\-e \fIencryption\fP"
785+.IP "\fB\-\-encryption, \-e \fIencryption\fP"
786 .RS
787 enable data encryption. The following keywords are recognized:
788 .IP \fBNONE\fP
789@@ -36,16 +39,62 @@
790 .PD 0
791 .IP \fBXOR\fP
792 use a simple XOR encryption.
793+.IP \fBAES\fP
794+use Advanced Encryption Standard encryption. AES encryption is only available
795+if you are using the international kernel and AES encryption has been enabled
796+in the Crypto API.
797+enabled in the Crypto API.
798+.IP \fBBlowfish\fP
799+use Blowfish encryption. Blowfish encryption is only available if you
800+are using the international kernel and Blowfish encryption has been
801+enabled in the Crypto API.
802+.IP \fBTwofish\fP
803+use Twofish encryption. Twofish encryption is only available if you
804+are using the international kernel and Twofish encryption has been
805+enabled in the Crypto API.
806+.IP \fBCAST\fP
807+use CAST encryption. CAST encryption is only available if you
808+are using the international kernel and CAST encryption has been
809+enabled in the Crypto API.
810 .IP \fBDES\fP
811 use DES encryption. DES encryption is only available if the optional
812 DES package has been added to the kernel. DES encryption uses an additional
813 start value that is used to protect passwords against dictionary
814-attacks.
815+attacks. Use of DES is deprecated.
816+.IP \fBDFC\fP
817+use DFC encryption. DFC encryption is only available if you
818+are using the international kernel and DFC encryption has been
819+enabled in the Crypto API.
820+.IP \fBIDEA\fP
821+use IDEA encryption. IDEA encryption is only available if you
822+are using the international kernel and IDEA encryption has been
823+enabled in the Crypto API.
824+.IP \fBMARS\fP
825+use MARS encryption. MARS encryption is only available if you
826+are using the international kernel and MARS encryption has been
827+enabled in the Crypto API.
828+.IP \fBRC5\fP
829+use RC5 encryption. RC5 encryption is only available if you
830+are using the international kernel and RC5 encryption has been
831+enabled in the Crypto API.
832+.IP \fBRC6\fP
833+use RC6 encryption. RC6 encryption is only available if you
834+are using the international kernel and RC6 encryption has been
835+enabled in the Crypto API.
836+.IP \fBSerpent\fP
837+use Serpent encryption. Serpent encryption is only available if you
838+are using the international kernel and Serpent encryption has been
839+enabled in the Crypto API.
840 .PD
841 .RE
842-.IP "\fB\-o \fIoffset\fP"
843+.IP "\fB\-\-offset, \-o \fIoffset\fP"
844 the data start is moved \fIoffset\fP bytes into the specified file or
845 device.
846+.IP "\fB\-\-pass-fd, \-p \fInum\fP"
847+read the passphrase from file descriptor \fInum\fP instead of the
848+terminal.
849+.IP "\fB\-\-keybits, \-k \fInum\fP"
850+set the number of bits to use in key to \fInum\fP.
851 .SH RETURN VALUE
852 .B losetup
853 returns 0 on success, nonzero on failure. When
854@@ -58,6 +107,7 @@
855 .SH FILES
856 .nf
857 /dev/loop0,/dev/loop1,... loop devices (major=7)
858+/proc/cipher/* available ciphers
859 .fi
860 .SH EXAMPLE
861 If you are using the loadable module you must have the module loaded
862@@ -69,9 +119,8 @@
863 .nf
864 .IP
865 dd if=/dev/zero of=/file bs=1k count=100
866-losetup -e des /dev/loop0 /file
867-Password:
868-Init (up to 16 hex digits):
869+losetup -e blowfish /dev/loop0 /file
870+Password :
871 mkfs -t ext2 /dev/loop0 100
872 mount -t ext2 /dev/loop0 /mnt
873 ...
874@@ -85,8 +134,12 @@
875 # rmmod loop
876 .LP
877 .fi
878-.SH RESTRICTION
879-DES encryption is painfully slow. On the other hand, XOR is terribly weak.
880+.SH RESTRICTIONS
881+DES encryption is painfully slow. On the other hand, XOR is terribly
882+weak. Both are insecure nowadays. Some ciphers require a licence for
883+you to be allowed to use them.
884+.SH BUGS
885+CAST, DES, RC5 and Twofish are currently broken and cannot be used.
886 .SH AUTHORS
887 .nf
888 Original version: Theodore Ts'o <tytso@athena.mit.edu>
21d15157 889Index: mount/mount.8
890===================================================================
891RCS file: /cvsroot/cryptoapi/util-linux/mount/mount.8,v
892retrieving revision 1.1.1.1
893retrieving revision 1.1.1.1.2.1
894diff -u -u -r1.1.1.1 -r1.1.1.1.2.1
895--- mount/mount.8 24 Mar 2002 12:54:16 -0000 1.1.1.1
896+++ mount/mount.8 24 Mar 2002 13:56:39 -0000 1.1.1.1.2.1
897@@ -258,6 +258,12 @@
966ca26a
JB
898 .B \-v
899 Verbose mode.
900 .TP
901+.B \-p "\fInum\fP"
902+If the mount requires a passphrase to be entered, read it from file
903+descriptor
904+.IR num\fP
905+instead of from the terminal.
906+.TP
907 .B \-a
908 Mount all filesystems (of the given types) mentioned in
909 .IR fstab .
21d15157 910@@ -563,6 +569,15 @@
966ca26a
JB
911 .BR noexec ", " nosuid ", and " nodev
912 (unless overridden by subsequent options, as in the option line
aa5ab37a 913 .BR users,exec,dev,suid ).
966ca26a
JB
914+.TP
915+.B encryption
916+Specifies an encryption algorithm to use. Used in conjunction with the
917+.BR loop " option."
918+.TP
919+.B keybits
920+Specifies the key size to use for an encryption algorithm. Used in conjunction
921+with the
922+.BR loop " and " encryption " options."
923 .RE
21d15157 924 .TP
925 .B \-\-bind
926@@ -1581,7 +1596,10 @@
966ca26a
JB
927 .BR loop ", " offset " and " encryption ,
928 that are really options to
929 .BR losetup (8).
930-If no explicit loop device is mentioned
931+If the mount requires a passphrase, you will be prompted for one unless
932+you specify a file descriptor to read from instead with the
933+.BR \-\-pass-fd
934+option. If no explicit loop device is mentioned
935 (but just an option `\fB\-o loop\fP' is given), then
936 .B mount
937 will try to find some unused loop device and use that.
21d15157 938Index: mount/mount.c
939===================================================================
940RCS file: /cvsroot/cryptoapi/util-linux/mount/mount.c,v
941retrieving revision 1.1.1.1
942retrieving revision 1.1.1.1.2.3
943diff -u -u -r1.1.1.1 -r1.1.1.1.2.3
944--- mount/mount.c 24 Mar 2002 12:54:18 -0000 1.1.1.1
945+++ mount/mount.c 24 Mar 2002 16:41:46 -0000 1.1.1.1.2.3
aa620da5 946@@ -108,6 +108,9 @@
966ca26a
JB
947 /* True if ruid != euid. */
948 static int suid = 0;
949
950+/* Contains the fd no. to read the passphrase from, if any */
951+static int pfd = -1;
966ca26a
JB
952+
953 /* Map from -o and fstab option strings to the flag argument to mount(2). */
954 struct opt_map {
955 const char *opt; /* option name */
aa620da5
JB
956@@ -184,7 +187,7 @@
957 };
958
959 static char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption,
960- *opt_speed;
21d15157 961+ *opt_keybits, *opt_speed, *opt_phash;
aa620da5
JB
962
963 static struct string_opt_map {
964 char *tag;
21d15157 965@@ -195,6 +198,8 @@
aa620da5
JB
966 { "vfs=", 1, &opt_vfstype },
967 { "offset=", 0, &opt_offset },
968 { "encryption=", 0, &opt_encryption },
969+ { "keybits=", 0, &opt_keybits },
21d15157 970+ { "phash=", 0, &opt_phash },
aa620da5
JB
971 { "speed=", 0, &opt_speed },
972 { NULL, 0, NULL }
973 };
21d15157 974@@ -544,7 +549,7 @@
aa620da5
JB
975 static int
976 loop_check(char **spec, char **type, int *flags,
977 int *loop, char **loopdev, char **loopfile) {
978- int looptype, offset;
979+ int looptype, offset, keybits;
980
981 /*
982 * In the case of a loop mount, either type is of the form lo@/dev/loop5
21d15157 983@@ -587,7 +592,10 @@
966ca26a
JB
984 if (verbose)
985 printf(_("mount: going to use the loop device %s\n"), *loopdev);
986 offset = opt_offset ? strtoul(opt_offset, NULL, 0) : 0;
987- if (set_loop (*loopdev, *loopfile, offset, opt_encryption, &loopro)) {
aa620da5 988+ keybits = opt_keybits ? strtoul(opt_keybits, NULL, 0) : 0;
966ca26a 989+ if (set_loop (*loopdev, *loopfile, offset, opt_encryption, pfd,
21d15157 990+ keybits, &loopro,
991+ opt_phash ? opt_phash : "rmd160old")) {
966ca26a
JB
992 if (verbose)
993 printf(_("mount: failed setting up loop device\n"));
994 return EX_FAIL;
21d15157 995@@ -1305,6 +1313,7 @@
966ca26a
JB
996 { "read-write", 0, 0, 'w' },
997 { "rw", 0, 0, 'w' },
998 { "options", 1, 0, 'o' },
999+ { "pass-fd", 1, 0, 'p' },
966ca26a
JB
1000 { "types", 1, 0, 't' },
1001 { "bind", 0, 0, 128 },
1002 { "replace", 0, 0, 129 },
21d15157 1003@@ -1340,7 +1349,7 @@
1004 " mount --move olddir newdir\n"
966ca26a
JB
1005 "A device can be given by name, say /dev/hda1 or /dev/cdrom,\n"
1006 "or by label, using -L label or by uuid, using -U uuid .\n"
1007- "Other options: [-nfFrsvw] [-o options].\n"
1008+ "Other options: [-nfFrsvw] [-o options] [-p num].\n"
1009 "For many more details, say man 8 mount .\n"
1010 ));
1011 /*
21d15157 1012@@ -1356,6 +1365,7 @@
966ca26a
JB
1013 int c, result = 0, specseen;
1014 char *options = NULL, *spec, *node;
1015 char *volumelabel = NULL;
1016+ char *passfd = NULL;
966ca26a 1017 char *uuid = NULL;
aa620da5 1018 char *types = NULL;
966ca26a 1019 struct mntentchn *mc;
21d15157 1020@@ -1377,7 +1387,7 @@
966ca26a
JB
1021 initproctitle(argc, argv);
1022 #endif
1023
1024- while ((c = getopt_long (argc, argv, "afFhlL:no:rsU:vVwt:",
1025+ while ((c = getopt_long (argc, argv, "afFhlL:no:p:rsU:vVwt:",
21d15157 1026 longopts, NULL)) != -1) {
966ca26a
JB
1027 switch (c) {
1028 case 'a': /* mount everything in fstab */
21d15157 1029@@ -1407,6 +1417,9 @@
966ca26a
JB
1030 else
1031 options = xstrdup(optarg);
1032 break;
1033+ case 'p': /* read passphrase from given fd */
1034+ passfd = optarg;
1035+ break;
1036 case 'r': /* mount readonly */
1037 readonly = 1;
1038 readwrite = 0;
21d15157 1039@@ -1504,6 +1517,9 @@
1040 printf(_("mount: mounting %s\n"), spec);
966ca26a
JB
1041 } else
1042 spec = NULL; /* just for gcc */
21d15157 1043+
966ca26a
JB
1044+ if (passfd && sscanf(passfd,"%d",&pfd) != 1)
1045+ die (EX_USAGE, _("mount: argument to --pass-fd or -p must be a number"));
21d15157 1046
966ca26a
JB
1047 switch (argc+specseen) {
1048 case 0:
21d15157 1049Index: mount/rmd160.c
1050===================================================================
1051RCS file: mount/rmd160.c
1052diff -N mount/rmd160.c
1053--- /dev/null 1 Jan 1970 00:00:00 -0000
1054+++ mount/rmd160.c 24 Mar 2002 13:56:39 -0000 1.1.2.1
966ca26a
JB
1055@@ -0,0 +1,532 @@
1056+/* rmd160.c - RIPE-MD160
1057+ * Copyright (C) 1998 Free Software Foundation, Inc.
1058+ */
1059+
1060+/* This file was part of GnuPG. Modified for use within the Linux
1061+ * mount utility by Marc Mutz <Marc@Mutz.com>. None of this code is
1062+ * by myself. I just removed everything that you don't need when all
1063+ * you want to do is to use rmd160_hash_buffer().
1064+ * My comments are marked with (mm). */
1065+
1066+/* GnuPG is free software; you can redistribute it and/or modify
1067+ * it under the terms of the GNU General Public License as published by
1068+ * the Free Software Foundation; either version 2 of the License, or
1069+ * (at your option) any later version.
1070+ *
1071+ * GnuPG is distributed in the hope that it will be useful,
1072+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1073+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1074+ * GNU General Public License for more details.
1075+ *
1076+ * You should have received a copy of the GNU General Public License
1077+ * along with this program; if not, write to the Free Software
1078+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */
1079+
1080+#include <string.h> /* (mm) for memcpy */
1081+#include <endian.h> /* (mm) for BIG_ENDIAN and BYTE_ORDER */
1082+#include "rmd160.h"
1083+
1084+/* (mm) these are used by the original GnuPG file. In order to modify
1085+ * that file not too much, we keep the notations. maybe it would be
1086+ * better to include linux/types.h and typedef __u32 to u32 and __u8
1087+ * to byte? */
1088+typedef unsigned int u32; /* taken from e.g. util-linux's minix.h */
1089+typedef unsigned char byte;
1090+
1091+typedef struct {
1092+ u32 h0,h1,h2,h3,h4;
1093+ u32 nblocks;
1094+ byte buf[64];
1095+ int count;
1096+} RMD160_CONTEXT;
1097+
1098+/****************
1099+ * Rotate a 32 bit integer by n bytes
1100+ */
1101+#if defined(__GNUC__) && defined(__i386__)
1102+static inline u32
1103+rol( u32 x, int n)
1104+{
1105+ __asm__("roll %%cl,%0"
1106+ :"=r" (x)
1107+ :"0" (x),"c" (n));
1108+ return x;
1109+}
1110+#else
1111+ #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
1112+#endif
1113+
1114+/*********************************
1115+ * RIPEMD-160 is not patented, see (as of 25.10.97)
1116+ * http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
1117+ * Note that the code uses Little Endian byteorder, which is good for
1118+ * 386 etc, but we must add some conversion when used on a big endian box.
1119+ *
1120+ *
1121+ * Pseudo-code for RIPEMD-160
1122+ *
1123+ * RIPEMD-160 is an iterative hash function that operates on 32-bit words.
1124+ * The round function takes as input a 5-word chaining variable and a 16-word
1125+ * message block and maps this to a new chaining variable. All operations are
1126+ * defined on 32-bit words. Padding is identical to that of MD4.
1127+ *
1128+ *
1129+ * RIPEMD-160: definitions
1130+ *
1131+ *
1132+ * nonlinear functions at bit level: exor, mux, -, mux, -
1133+ *
1134+ * f(j, x, y, z) = x XOR y XOR z (0 <= j <= 15)
1135+ * f(j, x, y, z) = (x AND y) OR (NOT(x) AND z) (16 <= j <= 31)
1136+ * f(j, x, y, z) = (x OR NOT(y)) XOR z (32 <= j <= 47)
1137+ * f(j, x, y, z) = (x AND z) OR (y AND NOT(z)) (48 <= j <= 63)
1138+ * f(j, x, y, z) = x XOR (y OR NOT(z)) (64 <= j <= 79)
1139+ *
1140+ *
1141+ * added constants (hexadecimal)
1142+ *
1143+ * K(j) = 0x00000000 (0 <= j <= 15)
1144+ * K(j) = 0x5A827999 (16 <= j <= 31) int(2**30 x sqrt(2))
1145+ * K(j) = 0x6ED9EBA1 (32 <= j <= 47) int(2**30 x sqrt(3))
1146+ * K(j) = 0x8F1BBCDC (48 <= j <= 63) int(2**30 x sqrt(5))
1147+ * K(j) = 0xA953FD4E (64 <= j <= 79) int(2**30 x sqrt(7))
1148+ * K'(j) = 0x50A28BE6 (0 <= j <= 15) int(2**30 x cbrt(2))
1149+ * K'(j) = 0x5C4DD124 (16 <= j <= 31) int(2**30 x cbrt(3))
1150+ * K'(j) = 0x6D703EF3 (32 <= j <= 47) int(2**30 x cbrt(5))
1151+ * K'(j) = 0x7A6D76E9 (48 <= j <= 63) int(2**30 x cbrt(7))
1152+ * K'(j) = 0x00000000 (64 <= j <= 79)
1153+ *
1154+ *
1155+ * selection of message word
1156+ *
1157+ * r(j) = j (0 <= j <= 15)
1158+ * r(16..31) = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8
1159+ * r(32..47) = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12
1160+ * r(48..63) = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2
1161+ * r(64..79) = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
1162+ * r0(0..15) = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12
1163+ * r0(16..31)= 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2
1164+ * r0(32..47)= 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13
1165+ * r0(48..63)= 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14
1166+ * r0(64..79)= 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
1167+ *
1168+ *
1169+ * amount for rotate left (rol)
1170+ *
1171+ * s(0..15) = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8
1172+ * s(16..31) = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12
1173+ * s(32..47) = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5
1174+ * s(48..63) = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12
1175+ * s(64..79) = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
1176+ * s'(0..15) = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6
1177+ * s'(16..31)= 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11
1178+ * s'(32..47)= 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5
1179+ * s'(48..63)= 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8
1180+ * s'(64..79)= 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
1181+ *
1182+ *
1183+ * initial value (hexadecimal)
1184+ *
1185+ * h0 = 0x67452301; h1 = 0xEFCDAB89; h2 = 0x98BADCFE; h3 = 0x10325476;
1186+ * h4 = 0xC3D2E1F0;
1187+ *
1188+ *
1189+ * RIPEMD-160: pseudo-code
1190+ *
1191+ * It is assumed that the message after padding consists of t 16-word blocks
1192+ * that will be denoted with X[i][j], with 0 <= i <= t-1 and 0 <= j <= 15.
1193+ * The symbol [+] denotes addition modulo 2**32 and rol_s denotes cyclic left
1194+ * shift (rotate) over s positions.
1195+ *
1196+ *
1197+ * for i := 0 to t-1 {
1198+ * A := h0; B := h1; C := h2; D = h3; E = h4;
1199+ * A' := h0; B' := h1; C' := h2; D' = h3; E' = h4;
1200+ * for j := 0 to 79 {
1201+ * T := rol_s(j)(A [+] f(j, B, C, D) [+] X[i][r(j)] [+] K(j)) [+] E;
1202+ * A := E; E := D; D := rol_10(C); C := B; B := T;
1203+ * T := rol_s'(j)(A' [+] f(79-j, B', C', D') [+] X[i][r'(j)]
1204+ [+] K'(j)) [+] E';
1205+ * A' := E'; E' := D'; D' := rol_10(C'); C' := B'; B' := T;
1206+ * }
1207+ * T := h1 [+] C [+] D'; h1 := h2 [+] D [+] E'; h2 := h3 [+] E [+] A';
1208+ * h3 := h4 [+] A [+] B'; h4 := h0 [+] B [+] C'; h0 := T;
1209+ * }
1210+ */
1211+
1212+/* Some examples:
1213+ * "" 9c1185a5c5e9fc54612808977ee8f548b2258d31
1214+ * "a" 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe
1215+ * "abc" 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
1216+ * "message digest" 5d0689ef49d2fae572b881b123a85ffa21595f36
1217+ * "a...z" f71c27109c692c1b56bbdceb5b9d2865b3708dbc
1218+ * "abcdbcde...nopq" 12a053384a9c0c88e405a06c27dcf49ada62eb2b
1219+ * "A...Za...z0...9" b0e20b6e3116640286ed3a87a5713079b21f5189
1220+ * 8 times "1234567890" 9b752e45573d4b39f4dbd3323cab82bf63326bfb
1221+ * 1 million times "a" 52783243c1697bdbe16d37f97f68f08325dc1528
1222+ */
1223+
1224+
1225+static void
1226+rmd160_init( RMD160_CONTEXT *hd )
1227+{
1228+ hd->h0 = 0x67452301;
1229+ hd->h1 = 0xEFCDAB89;
1230+ hd->h2 = 0x98BADCFE;
1231+ hd->h3 = 0x10325476;
1232+ hd->h4 = 0xC3D2E1F0;
1233+ hd->nblocks = 0;
1234+ hd->count = 0;
1235+}
1236+
1237+
1238+
1239+/****************
1240+ * Transform the message X which consists of 16 32-bit-words
1241+ */
1242+static void
1243+transform( RMD160_CONTEXT *hd, byte *data )
1244+{
1245+ u32 a,b,c,d,e,aa,bb,cc,dd,ee,t;
1246+ #if BYTE_ORDER == BIG_ENDIAN
1247+ u32 x[16];
1248+ { int i;
1249+ byte *p2, *p1;
1250+ for(i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 ) {
1251+ p2[3] = *p1++;
1252+ p2[2] = *p1++;
1253+ p2[1] = *p1++;
1254+ p2[0] = *p1++;
1255+ }
1256+ }
1257+ #else
1258+ #if 0
1259+ u32 *x =(u32*)data;
1260+ #else
1261+ /* this version is better because it is always aligned;
1262+ * The performance penalty on a 586-100 is about 6% which
1263+ * is acceptable - because the data is more local it might
1264+ * also be possible that this is faster on some machines.
1265+ * This function (when compiled with -02 on gcc 2.7.2)
1266+ * executes on a 586-100 (39.73 bogomips) at about 1900kb/sec;
1267+ * [measured with a 4MB data and "gpgm --print-md rmd160"] */
1268+ u32 x[16];
1269+ memcpy( x, data, 64 );
1270+ #endif
1271+ #endif
1272+
1273+
1274+#define K0 0x00000000
1275+#define K1 0x5A827999
1276+#define K2 0x6ED9EBA1
1277+#define K3 0x8F1BBCDC
1278+#define K4 0xA953FD4E
1279+#define KK0 0x50A28BE6
1280+#define KK1 0x5C4DD124
1281+#define KK2 0x6D703EF3
1282+#define KK3 0x7A6D76E9
1283+#define KK4 0x00000000
1284+#define F0(x,y,z) ( (x) ^ (y) ^ (z) )
1285+#define F1(x,y,z) ( ((x) & (y)) | (~(x) & (z)) )
1286+#define F2(x,y,z) ( ((x) | ~(y)) ^ (z) )
1287+#define F3(x,y,z) ( ((x) & (z)) | ((y) & ~(z)) )
1288+#define F4(x,y,z) ( (x) ^ ((y) | ~(z)) )
1289+#define R(a,b,c,d,e,f,k,r,s) do { t = a + f(b,c,d) + k + x[r]; \
1290+ a = rol(t,s) + e; \
1291+ c = rol(c,10); \
1292+ } while(0)
1293+
1294+ /* left lane */
1295+ a = hd->h0;
1296+ b = hd->h1;
1297+ c = hd->h2;
1298+ d = hd->h3;
1299+ e = hd->h4;
1300+ R( a, b, c, d, e, F0, K0, 0, 11 );
1301+ R( e, a, b, c, d, F0, K0, 1, 14 );
1302+ R( d, e, a, b, c, F0, K0, 2, 15 );
1303+ R( c, d, e, a, b, F0, K0, 3, 12 );
1304+ R( b, c, d, e, a, F0, K0, 4, 5 );
1305+ R( a, b, c, d, e, F0, K0, 5, 8 );
1306+ R( e, a, b, c, d, F0, K0, 6, 7 );
1307+ R( d, e, a, b, c, F0, K0, 7, 9 );
1308+ R( c, d, e, a, b, F0, K0, 8, 11 );
1309+ R( b, c, d, e, a, F0, K0, 9, 13 );
1310+ R( a, b, c, d, e, F0, K0, 10, 14 );
1311+ R( e, a, b, c, d, F0, K0, 11, 15 );
1312+ R( d, e, a, b, c, F0, K0, 12, 6 );
1313+ R( c, d, e, a, b, F0, K0, 13, 7 );
1314+ R( b, c, d, e, a, F0, K0, 14, 9 );
1315+ R( a, b, c, d, e, F0, K0, 15, 8 );
1316+ R( e, a, b, c, d, F1, K1, 7, 7 );
1317+ R( d, e, a, b, c, F1, K1, 4, 6 );
1318+ R( c, d, e, a, b, F1, K1, 13, 8 );
1319+ R( b, c, d, e, a, F1, K1, 1, 13 );
1320+ R( a, b, c, d, e, F1, K1, 10, 11 );
1321+ R( e, a, b, c, d, F1, K1, 6, 9 );
1322+ R( d, e, a, b, c, F1, K1, 15, 7 );
1323+ R( c, d, e, a, b, F1, K1, 3, 15 );
1324+ R( b, c, d, e, a, F1, K1, 12, 7 );
1325+ R( a, b, c, d, e, F1, K1, 0, 12 );
1326+ R( e, a, b, c, d, F1, K1, 9, 15 );
1327+ R( d, e, a, b, c, F1, K1, 5, 9 );
1328+ R( c, d, e, a, b, F1, K1, 2, 11 );
1329+ R( b, c, d, e, a, F1, K1, 14, 7 );
1330+ R( a, b, c, d, e, F1, K1, 11, 13 );
1331+ R( e, a, b, c, d, F1, K1, 8, 12 );
1332+ R( d, e, a, b, c, F2, K2, 3, 11 );
1333+ R( c, d, e, a, b, F2, K2, 10, 13 );
1334+ R( b, c, d, e, a, F2, K2, 14, 6 );
1335+ R( a, b, c, d, e, F2, K2, 4, 7 );
1336+ R( e, a, b, c, d, F2, K2, 9, 14 );
1337+ R( d, e, a, b, c, F2, K2, 15, 9 );
1338+ R( c, d, e, a, b, F2, K2, 8, 13 );
1339+ R( b, c, d, e, a, F2, K2, 1, 15 );
1340+ R( a, b, c, d, e, F2, K2, 2, 14 );
1341+ R( e, a, b, c, d, F2, K2, 7, 8 );
1342+ R( d, e, a, b, c, F2, K2, 0, 13 );
1343+ R( c, d, e, a, b, F2, K2, 6, 6 );
1344+ R( b, c, d, e, a, F2, K2, 13, 5 );
1345+ R( a, b, c, d, e, F2, K2, 11, 12 );
1346+ R( e, a, b, c, d, F2, K2, 5, 7 );
1347+ R( d, e, a, b, c, F2, K2, 12, 5 );
1348+ R( c, d, e, a, b, F3, K3, 1, 11 );
1349+ R( b, c, d, e, a, F3, K3, 9, 12 );
1350+ R( a, b, c, d, e, F3, K3, 11, 14 );
1351+ R( e, a, b, c, d, F3, K3, 10, 15 );
1352+ R( d, e, a, b, c, F3, K3, 0, 14 );
1353+ R( c, d, e, a, b, F3, K3, 8, 15 );
1354+ R( b, c, d, e, a, F3, K3, 12, 9 );
1355+ R( a, b, c, d, e, F3, K3, 4, 8 );
1356+ R( e, a, b, c, d, F3, K3, 13, 9 );
1357+ R( d, e, a, b, c, F3, K3, 3, 14 );
1358+ R( c, d, e, a, b, F3, K3, 7, 5 );
1359+ R( b, c, d, e, a, F3, K3, 15, 6 );
1360+ R( a, b, c, d, e, F3, K3, 14, 8 );
1361+ R( e, a, b, c, d, F3, K3, 5, 6 );
1362+ R( d, e, a, b, c, F3, K3, 6, 5 );
1363+ R( c, d, e, a, b, F3, K3, 2, 12 );
1364+ R( b, c, d, e, a, F4, K4, 4, 9 );
1365+ R( a, b, c, d, e, F4, K4, 0, 15 );
1366+ R( e, a, b, c, d, F4, K4, 5, 5 );
1367+ R( d, e, a, b, c, F4, K4, 9, 11 );
1368+ R( c, d, e, a, b, F4, K4, 7, 6 );
1369+ R( b, c, d, e, a, F4, K4, 12, 8 );
1370+ R( a, b, c, d, e, F4, K4, 2, 13 );
1371+ R( e, a, b, c, d, F4, K4, 10, 12 );
1372+ R( d, e, a, b, c, F4, K4, 14, 5 );
1373+ R( c, d, e, a, b, F4, K4, 1, 12 );
1374+ R( b, c, d, e, a, F4, K4, 3, 13 );
1375+ R( a, b, c, d, e, F4, K4, 8, 14 );
1376+ R( e, a, b, c, d, F4, K4, 11, 11 );
1377+ R( d, e, a, b, c, F4, K4, 6, 8 );
1378+ R( c, d, e, a, b, F4, K4, 15, 5 );
1379+ R( b, c, d, e, a, F4, K4, 13, 6 );
1380+
1381+ aa = a; bb = b; cc = c; dd = d; ee = e;
1382+
1383+ /* right lane */
1384+ a = hd->h0;
1385+ b = hd->h1;
1386+ c = hd->h2;
1387+ d = hd->h3;
1388+ e = hd->h4;
1389+ R( a, b, c, d, e, F4, KK0, 5, 8);
1390+ R( e, a, b, c, d, F4, KK0, 14, 9);
1391+ R( d, e, a, b, c, F4, KK0, 7, 9);
1392+ R( c, d, e, a, b, F4, KK0, 0, 11);
1393+ R( b, c, d, e, a, F4, KK0, 9, 13);
1394+ R( a, b, c, d, e, F4, KK0, 2, 15);
1395+ R( e, a, b, c, d, F4, KK0, 11, 15);
1396+ R( d, e, a, b, c, F4, KK0, 4, 5);
1397+ R( c, d, e, a, b, F4, KK0, 13, 7);
1398+ R( b, c, d, e, a, F4, KK0, 6, 7);
1399+ R( a, b, c, d, e, F4, KK0, 15, 8);
1400+ R( e, a, b, c, d, F4, KK0, 8, 11);
1401+ R( d, e, a, b, c, F4, KK0, 1, 14);
1402+ R( c, d, e, a, b, F4, KK0, 10, 14);
1403+ R( b, c, d, e, a, F4, KK0, 3, 12);
1404+ R( a, b, c, d, e, F4, KK0, 12, 6);
1405+ R( e, a, b, c, d, F3, KK1, 6, 9);
1406+ R( d, e, a, b, c, F3, KK1, 11, 13);
1407+ R( c, d, e, a, b, F3, KK1, 3, 15);
1408+ R( b, c, d, e, a, F3, KK1, 7, 7);
1409+ R( a, b, c, d, e, F3, KK1, 0, 12);
1410+ R( e, a, b, c, d, F3, KK1, 13, 8);
1411+ R( d, e, a, b, c, F3, KK1, 5, 9);
1412+ R( c, d, e, a, b, F3, KK1, 10, 11);
1413+ R( b, c, d, e, a, F3, KK1, 14, 7);
1414+ R( a, b, c, d, e, F3, KK1, 15, 7);
1415+ R( e, a, b, c, d, F3, KK1, 8, 12);
1416+ R( d, e, a, b, c, F3, KK1, 12, 7);
1417+ R( c, d, e, a, b, F3, KK1, 4, 6);
1418+ R( b, c, d, e, a, F3, KK1, 9, 15);
1419+ R( a, b, c, d, e, F3, KK1, 1, 13);
1420+ R( e, a, b, c, d, F3, KK1, 2, 11);
1421+ R( d, e, a, b, c, F2, KK2, 15, 9);
1422+ R( c, d, e, a, b, F2, KK2, 5, 7);
1423+ R( b, c, d, e, a, F2, KK2, 1, 15);
1424+ R( a, b, c, d, e, F2, KK2, 3, 11);
1425+ R( e, a, b, c, d, F2, KK2, 7, 8);
1426+ R( d, e, a, b, c, F2, KK2, 14, 6);
1427+ R( c, d, e, a, b, F2, KK2, 6, 6);
1428+ R( b, c, d, e, a, F2, KK2, 9, 14);
1429+ R( a, b, c, d, e, F2, KK2, 11, 12);
1430+ R( e, a, b, c, d, F2, KK2, 8, 13);
1431+ R( d, e, a, b, c, F2, KK2, 12, 5);
1432+ R( c, d, e, a, b, F2, KK2, 2, 14);
1433+ R( b, c, d, e, a, F2, KK2, 10, 13);
1434+ R( a, b, c, d, e, F2, KK2, 0, 13);
1435+ R( e, a, b, c, d, F2, KK2, 4, 7);
1436+ R( d, e, a, b, c, F2, KK2, 13, 5);
1437+ R( c, d, e, a, b, F1, KK3, 8, 15);
1438+ R( b, c, d, e, a, F1, KK3, 6, 5);
1439+ R( a, b, c, d, e, F1, KK3, 4, 8);
1440+ R( e, a, b, c, d, F1, KK3, 1, 11);
1441+ R( d, e, a, b, c, F1, KK3, 3, 14);
1442+ R( c, d, e, a, b, F1, KK3, 11, 14);
1443+ R( b, c, d, e, a, F1, KK3, 15, 6);
1444+ R( a, b, c, d, e, F1, KK3, 0, 14);
1445+ R( e, a, b, c, d, F1, KK3, 5, 6);
1446+ R( d, e, a, b, c, F1, KK3, 12, 9);
1447+ R( c, d, e, a, b, F1, KK3, 2, 12);
1448+ R( b, c, d, e, a, F1, KK3, 13, 9);
1449+ R( a, b, c, d, e, F1, KK3, 9, 12);
1450+ R( e, a, b, c, d, F1, KK3, 7, 5);
1451+ R( d, e, a, b, c, F1, KK3, 10, 15);
1452+ R( c, d, e, a, b, F1, KK3, 14, 8);
1453+ R( b, c, d, e, a, F0, KK4, 12, 8);
1454+ R( a, b, c, d, e, F0, KK4, 15, 5);
1455+ R( e, a, b, c, d, F0, KK4, 10, 12);
1456+ R( d, e, a, b, c, F0, KK4, 4, 9);
1457+ R( c, d, e, a, b, F0, KK4, 1, 12);
1458+ R( b, c, d, e, a, F0, KK4, 5, 5);
1459+ R( a, b, c, d, e, F0, KK4, 8, 14);
1460+ R( e, a, b, c, d, F0, KK4, 7, 6);
1461+ R( d, e, a, b, c, F0, KK4, 6, 8);
1462+ R( c, d, e, a, b, F0, KK4, 2, 13);
1463+ R( b, c, d, e, a, F0, KK4, 13, 6);
1464+ R( a, b, c, d, e, F0, KK4, 14, 5);
1465+ R( e, a, b, c, d, F0, KK4, 0, 15);
1466+ R( d, e, a, b, c, F0, KK4, 3, 13);
1467+ R( c, d, e, a, b, F0, KK4, 9, 11);
1468+ R( b, c, d, e, a, F0, KK4, 11, 11);
1469+
1470+
1471+ t = hd->h1 + d + cc;
1472+ hd->h1 = hd->h2 + e + dd;
1473+ hd->h2 = hd->h3 + a + ee;
1474+ hd->h3 = hd->h4 + b + aa;
1475+ hd->h4 = hd->h0 + c + bb;
1476+ hd->h0 = t;
1477+}
1478+
1479+
1480+/* Update the message digest with the contents
1481+ * of INBUF with length INLEN.
1482+ */
1483+static void
1484+rmd160_write( RMD160_CONTEXT *hd, byte *inbuf, size_t inlen)
1485+{
1486+ if( hd->count == 64 ) { /* flush the buffer */
1487+ transform( hd, hd->buf );
1488+ hd->count = 0;
1489+ hd->nblocks++;
1490+ }
1491+ if( !inbuf )
1492+ return;
1493+ if( hd->count ) {
1494+ for( ; inlen && hd->count < 64; inlen-- )
1495+ hd->buf[hd->count++] = *inbuf++;
1496+ rmd160_write( hd, NULL, 0 );
1497+ if( !inlen )
1498+ return;
1499+ }
1500+
1501+ while( inlen >= 64 ) {
1502+ transform( hd, inbuf );
1503+ hd->count = 0;
1504+ hd->nblocks++;
1505+ inlen -= 64;
1506+ inbuf += 64;
1507+ }
1508+ for( ; inlen && hd->count < 64; inlen-- )
1509+ hd->buf[hd->count++] = *inbuf++;
1510+}
1511+
1512+/* The routine terminates the computation
1513+ */
1514+
1515+static void
1516+rmd160_final( RMD160_CONTEXT *hd )
1517+{
1518+ u32 t, msb, lsb;
1519+ byte *p;
1520+
1521+ rmd160_write(hd, NULL, 0); /* flush */;
1522+
1523+ msb = 0;
1524+ t = hd->nblocks;
1525+ if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */
1526+ msb++;
1527+ msb += t >> 26;
1528+ t = lsb;
1529+ if( (lsb = t + hd->count) < t ) /* add the count */
1530+ msb++;
1531+ t = lsb;
1532+ if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */
1533+ msb++;
1534+ msb += t >> 29;
1535+
1536+ if( hd->count < 56 ) { /* enough room */
1537+ hd->buf[hd->count++] = 0x80; /* pad */
1538+ while( hd->count < 56 )
1539+ hd->buf[hd->count++] = 0; /* pad */
1540+ }
1541+ else { /* need one extra block */
1542+ hd->buf[hd->count++] = 0x80; /* pad character */
1543+ while( hd->count < 64 )
1544+ hd->buf[hd->count++] = 0;
1545+ rmd160_write(hd, NULL, 0); /* flush */;
1546+ memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
1547+ }
1548+ /* append the 64 bit count */
1549+ hd->buf[56] = lsb ;
1550+ hd->buf[57] = lsb >> 8;
1551+ hd->buf[58] = lsb >> 16;
1552+ hd->buf[59] = lsb >> 24;
1553+ hd->buf[60] = msb ;
1554+ hd->buf[61] = msb >> 8;
1555+ hd->buf[62] = msb >> 16;
1556+ hd->buf[63] = msb >> 24;
1557+ transform( hd, hd->buf );
1558+
1559+ p = hd->buf;
1560+ #if BYTE_ORDER == BIG_ENDIAN
1561+ #define X(a) do { *p++ = hd->h##a ; *p++ = hd->h##a >> 8; \
1562+ *p++ = hd->h##a >> 16; *p++ = hd->h##a >> 24; } while(0)
1563+ #else /* little endian */
1564+ #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
1565+ #endif
1566+ X(0);
1567+ X(1);
1568+ X(2);
1569+ X(3);
1570+ X(4);
1571+ #undef X
1572+}
1573+
1574+/****************
1575+ * Shortcut functions which puts the hash value of the supplied buffer
1576+ * into outbuf which must have a size of 20 bytes.
1577+ */
1578+void
1579+rmd160_hash_buffer( char *outbuf, const char *buffer, size_t length )
1580+{
1581+ RMD160_CONTEXT hd;
1582+
1583+ rmd160_init( &hd );
1584+ rmd160_write( &hd, (byte*)buffer, length );
1585+ rmd160_final( &hd );
1586+ memcpy( outbuf, hd.buf, 20 );
1587+}
21d15157 1588Index: mount/rmd160.h
1589===================================================================
1590RCS file: mount/rmd160.h
1591diff -N mount/rmd160.h
1592--- /dev/null 1 Jan 1970 00:00:00 -0000
1593+++ mount/rmd160.h 24 Mar 2002 15:31:25 -0000 1.1.2.2
966ca26a
JB
1594@@ -0,0 +1,9 @@
1595+#ifndef RMD160_H
1596+#define RMD160_H
1597+
21d15157 1598+#define RMD160_HASH_SIZE 20
1599+
966ca26a 1600+void
21d15157 1601+rmd160_hash_buffer (char *outbuf, const char *buffer, size_t length);
966ca26a
JB
1602+
1603+#endif /*RMD160_H*/
21d15157 1604Index: mount/sha512.c
1605===================================================================
1606RCS file: mount/sha512.c
1607diff -N mount/sha512.c
1608--- /dev/null 1 Jan 1970 00:00:00 -0000
1609+++ mount/sha512.c 24 Mar 2002 13:56:39 -0000 1.1.2.1
1610@@ -0,0 +1,432 @@
1611+/*
1612+ * sha512.c
1613+ *
1614+ * Written by Jari Ruusu, April 16 2001
1615+ *
1616+ * Copyright 2001 by Jari Ruusu.
1617+ * Redistribution of this file is permitted under the GNU Public License.
1618+ */
1619+
1620+#include <string.h>
1621+#include <sys/types.h>
1622+#include "sha512.h"
1623+
1624+/* Define one or more of these. If none is defined, you get all of them */
1625+#if !defined(SHA256_NEEDED)&&!defined(SHA512_NEEDED)&&!defined(SHA384_NEEDED)
1626+# define SHA256_NEEDED 1
1627+# define SHA512_NEEDED 1
1628+# define SHA384_NEEDED 1
1629+#endif
1630+
1631+#if defined(SHA256_NEEDED)
1632+static const u_int32_t sha256_hashInit[8] = {
1633+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,
1634+ 0x1f83d9ab, 0x5be0cd19
1635+};
1636+static const u_int32_t sha256_K[64] = {
1637+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
1638+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
1639+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
1640+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
1641+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
1642+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
1643+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
1644+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
1645+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
1646+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
1647+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
1648+};
1649+#endif
1650+
1651+#if defined(SHA512_NEEDED)
1652+static const u_int64_t sha512_hashInit[8] = {
1653+ 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,
1654+ 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
1655+ 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
1656+};
1657+#endif
1658+
1659+#if defined(SHA384_NEEDED)
1660+static const u_int64_t sha384_hashInit[8] = {
1661+ 0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL, 0x9159015a3070dd17ULL,
1662+ 0x152fecd8f70e5939ULL, 0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL,
1663+ 0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL
1664+};
1665+#endif
1666+
1667+#if defined(SHA512_NEEDED) || defined(SHA384_NEEDED)
1668+static const u_int64_t sha512_K[80] = {
1669+ 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL,
1670+ 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
1671+ 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL,
1672+ 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
1673+ 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL,
1674+ 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
1675+ 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL,
1676+ 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
1677+ 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL,
1678+ 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
1679+ 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL,
1680+ 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
1681+ 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL,
1682+ 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
1683+ 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL,
1684+ 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
1685+ 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL,
1686+ 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
1687+ 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL,
1688+ 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
1689+ 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL,
1690+ 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
1691+ 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL,
1692+ 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
1693+ 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL,
1694+ 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
1695+ 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
1696+};
1697+#endif
1698+
1699+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
1700+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
1701+#define R(x,y) ((y) >> (x))
1702+
1703+#if defined(SHA256_NEEDED)
1704+void sha256_init(sha256_context *ctx)
1705+{
1706+ memcpy(&ctx->sha_H[0], &sha256_hashInit[0], sizeof(ctx->sha_H));
1707+ ctx->sha_blocks = 0;
1708+ ctx->sha_bufCnt = 0;
1709+}
1710+
1711+#define S(x,y) (((y) >> (x)) | ((y) << (32 - (x))))
1712+#define uSig0(x) ((S(2,(x))) ^ (S(13,(x))) ^ (S(22,(x))))
1713+#define uSig1(x) ((S(6,(x))) ^ (S(11,(x))) ^ (S(25,(x))))
1714+#define lSig0(x) ((S(7,(x))) ^ (S(18,(x))) ^ (R(3,(x))))
1715+#define lSig1(x) ((S(17,(x))) ^ (S(19,(x))) ^ (R(10,(x))))
1716+
1717+static void sha256_transform(sha256_context *ctx, unsigned char *datap)
1718+{
1719+ register int j;
1720+ u_int32_t a, b, c, d, e, f, g, h;
1721+ u_int32_t T1, T2, W[64], Wm2, Wm15;
1722+
1723+ /* read the data, big endian byte order */
1724+ j = 0;
1725+ do {
1726+ W[j] = (((u_int32_t)(datap[0]))<<24) | (((u_int32_t)(datap[1]))<<16) |
1727+ (((u_int32_t)(datap[2]))<<8 ) | ((u_int32_t)(datap[3]));
1728+ datap += 4;
1729+ } while(++j < 16);
1730+
1731+ /* initialize variables a...h */
1732+ a = ctx->sha_H[0];
1733+ b = ctx->sha_H[1];
1734+ c = ctx->sha_H[2];
1735+ d = ctx->sha_H[3];
1736+ e = ctx->sha_H[4];
1737+ f = ctx->sha_H[5];
1738+ g = ctx->sha_H[6];
1739+ h = ctx->sha_H[7];
1740+
1741+ /* apply compression function */
1742+ j = 0;
1743+ do {
1744+ if(j >= 16) {
1745+ Wm2 = W[j - 2];
1746+ Wm15 = W[j - 15];
1747+ W[j] = lSig1(Wm2) + W[j - 7] + lSig0(Wm15) + W[j - 16];
1748+ }
1749+ T1 = h + uSig1(e) + Ch(e,f,g) + sha256_K[j] + W[j];
1750+ T2 = uSig0(a) + Maj(a,b,c);
1751+ h = g; g = f; f = e;
1752+ e = d + T1;
1753+ d = c; c = b; b = a;
1754+ a = T1 + T2;
1755+ } while(++j < 64);
1756+
1757+ /* compute intermediate hash value */
1758+ ctx->sha_H[0] += a;
1759+ ctx->sha_H[1] += b;
1760+ ctx->sha_H[2] += c;
1761+ ctx->sha_H[3] += d;
1762+ ctx->sha_H[4] += e;
1763+ ctx->sha_H[5] += f;
1764+ ctx->sha_H[6] += g;
1765+ ctx->sha_H[7] += h;
1766+
1767+ ctx->sha_blocks++;
1768+}
966ca26a 1769+
21d15157 1770+void sha256_write(sha256_context *ctx, unsigned char *datap, int length)
1771+{
1772+ while(length > 0) {
1773+ if(!ctx->sha_bufCnt) {
1774+ while(length >= sizeof(ctx->sha_out)) {
1775+ sha256_transform(ctx, datap);
1776+ datap += sizeof(ctx->sha_out);
1777+ length -= sizeof(ctx->sha_out);
1778+ }
1779+ if(!length) return;
1780+ }
1781+ ctx->sha_out[ctx->sha_bufCnt] = *datap++;
1782+ length--;
1783+ if(++ctx->sha_bufCnt == sizeof(ctx->sha_out)) {
1784+ sha256_transform(ctx, &ctx->sha_out[0]);
1785+ ctx->sha_bufCnt = 0;
1786+ }
1787+ }
1788+}
1789+
1790+void sha256_final(sha256_context *ctx)
1791+{
1792+ register int j;
1793+ u_int64_t bitLength;
1794+ u_int32_t i;
1795+ unsigned char padByte, *datap;
1796+
1797+ bitLength = (ctx->sha_blocks << 9) | (ctx->sha_bufCnt << 3);
1798+ padByte = 0x80;
1799+ sha256_write(ctx, &padByte, 1);
1800+
1801+ /* pad extra space with zeroes */
1802+ padByte = 0;
1803+ while(ctx->sha_bufCnt != 56) {
1804+ sha256_write(ctx, &padByte, 1);
1805+ }
1806+
1807+ /* write bit length, big endian byte order */
1808+ ctx->sha_out[56] = bitLength >> 56;
1809+ ctx->sha_out[57] = bitLength >> 48;
1810+ ctx->sha_out[58] = bitLength >> 40;
1811+ ctx->sha_out[59] = bitLength >> 32;
1812+ ctx->sha_out[60] = bitLength >> 24;
1813+ ctx->sha_out[61] = bitLength >> 16;
1814+ ctx->sha_out[62] = bitLength >> 8;
1815+ ctx->sha_out[63] = bitLength;
1816+ sha256_transform(ctx, &ctx->sha_out[0]);
1817+
1818+ /* return results in ctx->sha_out[0...31] */
1819+ datap = &ctx->sha_out[0];
1820+ j = 0;
1821+ do {
1822+ i = ctx->sha_H[j];
1823+ datap[0] = i >> 24;
1824+ datap[1] = i >> 16;
1825+ datap[2] = i >> 8;
1826+ datap[3] = i;
1827+ datap += 4;
1828+ } while(++j < 8);
1829+
1830+ /* clear sensitive information */
1831+ memset(&ctx->sha_out[32], 0, sizeof(sha256_context) - 32);
1832+}
966ca26a 1833+
21d15157 1834+void sha256_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
1835+{
1836+ sha256_context ctx;
1837+
1838+ if(ole < 1) return;
1839+ memset(ob, 0, ole);
1840+ if(ole > 32) ole = 32;
1841+ sha256_init(&ctx);
1842+ sha256_write(&ctx, ib, ile);
1843+ sha256_final(&ctx);
1844+ memcpy(ob, &ctx.sha_out[0], ole);
1845+ memset(&ctx, 0, sizeof(ctx));
1846+}
1847+
1848+#endif
1849+
1850+#if defined(SHA512_NEEDED)
1851+void sha512_init(sha512_context *ctx)
1852+{
1853+ memcpy(&ctx->sha_H[0], &sha512_hashInit[0], sizeof(ctx->sha_H));
1854+ ctx->sha_blocks = 0;
1855+ ctx->sha_blocksMSB = 0;
1856+ ctx->sha_bufCnt = 0;
1857+}
1858+#endif
1859+
1860+#if defined(SHA512_NEEDED) || defined(SHA384_NEEDED)
1861+#undef S
1862+#undef uSig0
1863+#undef uSig1
1864+#undef lSig0
1865+#undef lSig1
1866+#define S(x,y) (((y) >> (x)) | ((y) << (64 - (x))))
1867+#define uSig0(x) ((S(28,(x))) ^ (S(34,(x))) ^ (S(39,(x))))
1868+#define uSig1(x) ((S(14,(x))) ^ (S(18,(x))) ^ (S(41,(x))))
1869+#define lSig0(x) ((S(1,(x))) ^ (S(8,(x))) ^ (R(7,(x))))
1870+#define lSig1(x) ((S(19,(x))) ^ (S(61,(x))) ^ (R(6,(x))))
1871+
1872+static void sha512_transform(sha512_context *ctx, unsigned char *datap)
1873+{
1874+ register int j;
1875+ u_int64_t a, b, c, d, e, f, g, h;
1876+ u_int64_t T1, T2, W[80], Wm2, Wm15;
1877+
1878+ /* read the data, big endian byte order */
1879+ j = 0;
1880+ do {
1881+ W[j] = (((u_int64_t)(datap[0]))<<56) | (((u_int64_t)(datap[1]))<<48) |
1882+ (((u_int64_t)(datap[2]))<<40) | (((u_int64_t)(datap[3]))<<32) |
1883+ (((u_int64_t)(datap[4]))<<24) | (((u_int64_t)(datap[5]))<<16) |
1884+ (((u_int64_t)(datap[6]))<<8 ) | ((u_int64_t)(datap[7]));
1885+ datap += 8;
1886+ } while(++j < 16);
1887+
1888+ /* initialize variables a...h */
1889+ a = ctx->sha_H[0];
1890+ b = ctx->sha_H[1];
1891+ c = ctx->sha_H[2];
1892+ d = ctx->sha_H[3];
1893+ e = ctx->sha_H[4];
1894+ f = ctx->sha_H[5];
1895+ g = ctx->sha_H[6];
1896+ h = ctx->sha_H[7];
1897+
1898+ /* apply compression function */
1899+ j = 0;
1900+ do {
1901+ if(j >= 16) {
1902+ Wm2 = W[j - 2];
1903+ Wm15 = W[j - 15];
1904+ W[j] = lSig1(Wm2) + W[j - 7] + lSig0(Wm15) + W[j - 16];
1905+ }
1906+ T1 = h + uSig1(e) + Ch(e,f,g) + sha512_K[j] + W[j];
1907+ T2 = uSig0(a) + Maj(a,b,c);
1908+ h = g; g = f; f = e;
1909+ e = d + T1;
1910+ d = c; c = b; b = a;
1911+ a = T1 + T2;
1912+ } while(++j < 80);
1913+
1914+ /* compute intermediate hash value */
1915+ ctx->sha_H[0] += a;
1916+ ctx->sha_H[1] += b;
1917+ ctx->sha_H[2] += c;
1918+ ctx->sha_H[3] += d;
1919+ ctx->sha_H[4] += e;
1920+ ctx->sha_H[5] += f;
1921+ ctx->sha_H[6] += g;
1922+ ctx->sha_H[7] += h;
1923+
1924+ ctx->sha_blocks++;
1925+ if(!ctx->sha_blocks) ctx->sha_blocksMSB++;
1926+}
1927+
1928+void sha512_write(sha512_context *ctx, unsigned char *datap, int length)
1929+{
1930+ while(length > 0) {
1931+ if(!ctx->sha_bufCnt) {
1932+ while(length >= sizeof(ctx->sha_out)) {
1933+ sha512_transform(ctx, datap);
1934+ datap += sizeof(ctx->sha_out);
1935+ length -= sizeof(ctx->sha_out);
1936+ }
1937+ if(!length) return;
1938+ }
1939+ ctx->sha_out[ctx->sha_bufCnt] = *datap++;
1940+ length--;
1941+ if(++ctx->sha_bufCnt == sizeof(ctx->sha_out)) {
1942+ sha512_transform(ctx, &ctx->sha_out[0]);
1943+ ctx->sha_bufCnt = 0;
1944+ }
1945+ }
1946+}
1947+
1948+void sha512_final(sha512_context *ctx)
1949+{
1950+ register int j;
1951+ u_int64_t bitLength, bitLengthMSB;
1952+ u_int64_t i;
1953+ unsigned char padByte, *datap;
1954+
1955+ bitLength = (ctx->sha_blocks << 10) | (ctx->sha_bufCnt << 3);
1956+ bitLengthMSB = (ctx->sha_blocksMSB << 10) | (ctx->sha_blocks >> 54);
1957+ padByte = 0x80;
1958+ sha512_write(ctx, &padByte, 1);
1959+
1960+ /* pad extra space with zeroes */
1961+ padByte = 0;
1962+ while(ctx->sha_bufCnt != 112) {
1963+ sha512_write(ctx, &padByte, 1);
1964+ }
1965+
1966+ /* write bit length, big endian byte order */
1967+ ctx->sha_out[112] = bitLengthMSB >> 56;
1968+ ctx->sha_out[113] = bitLengthMSB >> 48;
1969+ ctx->sha_out[114] = bitLengthMSB >> 40;
1970+ ctx->sha_out[115] = bitLengthMSB >> 32;
1971+ ctx->sha_out[116] = bitLengthMSB >> 24;
1972+ ctx->sha_out[117] = bitLengthMSB >> 16;
1973+ ctx->sha_out[118] = bitLengthMSB >> 8;
1974+ ctx->sha_out[119] = bitLengthMSB;
1975+ ctx->sha_out[120] = bitLength >> 56;
1976+ ctx->sha_out[121] = bitLength >> 48;
1977+ ctx->sha_out[122] = bitLength >> 40;
1978+ ctx->sha_out[123] = bitLength >> 32;
1979+ ctx->sha_out[124] = bitLength >> 24;
1980+ ctx->sha_out[125] = bitLength >> 16;
1981+ ctx->sha_out[126] = bitLength >> 8;
1982+ ctx->sha_out[127] = bitLength;
1983+ sha512_transform(ctx, &ctx->sha_out[0]);
1984+
1985+ /* return results in ctx->sha_out[0...63] */
1986+ datap = &ctx->sha_out[0];
1987+ j = 0;
1988+ do {
1989+ i = ctx->sha_H[j];
1990+ datap[0] = i >> 56;
1991+ datap[1] = i >> 48;
1992+ datap[2] = i >> 40;
1993+ datap[3] = i >> 32;
1994+ datap[4] = i >> 24;
1995+ datap[5] = i >> 16;
1996+ datap[6] = i >> 8;
1997+ datap[7] = i;
1998+ datap += 8;
1999+ } while(++j < 8);
2000+
2001+ /* clear sensitive information */
2002+ memset(&ctx->sha_out[64], 0, sizeof(sha512_context) - 64);
2003+}
2004+
2005+void sha512_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
2006+{
2007+ sha512_context ctx;
2008+
2009+ if(ole < 1) return;
2010+ memset(ob, 0, ole);
2011+ if(ole > 64) ole = 64;
2012+ sha512_init(&ctx);
2013+ sha512_write(&ctx, ib, ile);
2014+ sha512_final(&ctx);
2015+ memcpy(ob, &ctx.sha_out[0], ole);
2016+ memset(&ctx, 0, sizeof(ctx));
2017+}
2018+#endif
2019+
2020+#if defined(SHA384_NEEDED)
2021+void sha384_init(sha512_context *ctx)
2022+{
2023+ memcpy(&ctx->sha_H[0], &sha384_hashInit[0], sizeof(ctx->sha_H));
2024+ ctx->sha_blocks = 0;
2025+ ctx->sha_blocksMSB = 0;
2026+ ctx->sha_bufCnt = 0;
2027+}
2028+
2029+void sha384_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
2030+{
2031+ sha512_context ctx;
2032+
2033+ if(ole < 1) return;
2034+ memset(ob, 0, ole);
2035+ if(ole > 48) ole = 48;
2036+ sha384_init(&ctx);
2037+ sha512_write(&ctx, ib, ile);
2038+ sha512_final(&ctx);
2039+ memcpy(ob, &ctx.sha_out[0], ole);
2040+ memset(&ctx, 0, sizeof(ctx));
2041+}
2042+#endif
2043Index: mount/sha512.h
2044===================================================================
2045RCS file: mount/sha512.h
2046diff -N mount/sha512.h
2047--- /dev/null 1 Jan 1970 00:00:00 -0000
2048+++ mount/sha512.h 24 Mar 2002 13:56:39 -0000 1.1.2.1
2049@@ -0,0 +1,45 @@
2050+/*
2051+ * sha512.h
2052+ *
2053+ * Written by Jari Ruusu, April 16 2001
2054+ *
2055+ * Copyright 2001 by Jari Ruusu.
2056+ * Redistribution of this file is permitted under the GNU Public License.
2057+ */
2058+
2059+#include <sys/types.h>
2060+
2061+typedef struct {
2062+ unsigned char sha_out[64]; /* results are here, bytes 0...31 */
2063+ u_int32_t sha_H[8];
2064+ u_int64_t sha_blocks;
2065+ int sha_bufCnt;
2066+} sha256_context;
2067+
2068+typedef struct {
2069+ unsigned char sha_out[128]; /* results are here, bytes 0...63 */
2070+ u_int64_t sha_H[8];
2071+ u_int64_t sha_blocks;
2072+ u_int64_t sha_blocksMSB;
2073+ int sha_bufCnt;
2074+} sha512_context;
2075+
2076+/* no sha384_context, use sha512_context */
2077+
2078+/* 256 bit hash, provides 128 bits of security against collision attacks */
2079+extern void sha256_init(sha256_context *);
2080+extern void sha256_write(sha256_context *, unsigned char *, int);
2081+extern void sha256_final(sha256_context *);
2082+extern void sha256_hash_buffer(unsigned char *, int, unsigned char *, int);
2083+
2084+/* 512 bit hash, provides 256 bits of security against collision attacks */
2085+extern void sha512_init(sha512_context *);
2086+extern void sha512_write(sha512_context *, unsigned char *, int);
2087+extern void sha512_final(sha512_context *);
2088+extern void sha512_hash_buffer(unsigned char *, int, unsigned char *, int);
2089+
2090+/* 384 bit hash, provides 192 bits of security against collision attacks */
2091+extern void sha384_init(sha512_context *);
2092+/* no sha384_write(), use sha512_write() */
2093+/* no sha384_final(), use sha512_final(), result in ctx->sha_out[0...47] */
2094+extern void sha384_hash_buffer(unsigned char *, int, unsigned char *, int);
2095Index: mount/sundries.c
2096===================================================================
2097RCS file: /cvsroot/cryptoapi/util-linux/mount/sundries.c,v
2098retrieving revision 1.1.1.1
2099retrieving revision 1.1.1.1.2.1
2100diff -u -u -r1.1.1.1 -r1.1.1.1.2.1
2101--- mount/sundries.c 24 Mar 2002 12:54:19 -0000 1.1.1.1
2102+++ mount/sundries.c 24 Mar 2002 13:56:39 -0000 1.1.1.1.2.1
aa620da5
JB
2103@@ -162,7 +162,7 @@
2104 return 1;
2105
2106 no = 0;
2107- if (!strncmp(types, "no", 2)) {
2108+ if (types && !strncmp(types, "no", 2)) {
2109 no = 1;
2110 types += 2;
2111 }
This page took 0.282041 seconds and 4 git commands to generate.