1 diff -Nur util-linux-2.11zorg/mount/Makefile util-linux-2.11z/mount/Makefile
2 --- util-linux-2.11zorg/mount/Makefile Tue Nov 26 09:53:59 2002
3 +++ util-linux-2.11z/mount/Makefile Fri Mar 28 21:43:00 2003
6 MAYBE = pivot_root swapoff
8 -LO_OBJS = lomount.o $(LIB)/xstrncpy.o
9 +LO_OBJS = lomount.o $(LIB)/xstrncpy.o sha512.o rmd160.o
10 NFS_OBJS = nfsmount.o nfsmount_xdr.o nfsmount_clnt.o
11 GEN_FILES = nfsmount.h nfsmount_xdr.c nfsmount_clnt.c
14 main_losetup.o: lomount.c
15 $(COMPILE) -DMAIN lomount.c -o $@
17 -losetup: main_losetup.o $(LIB)/xstrncpy.o
18 +losetup: main_losetup.o $(LIB)/xstrncpy.o sha512.o rmd160.o
21 +rmd160.o lomount.o main_losetup.o: rmd160.h
23 +sha512.o lomount.o main_losetup.o: sha512.h
25 mount.o umount.o nfsmount.o losetup.o fstab.o realpath.o sundries.o: sundries.h
27 mount.o umount.o fstab.o sundries.o: fstab.h
28 diff -Nur util-linux-2.11zorg/mount/lomount.c util-linux-2.11z/mount/lomount.c
29 --- util-linux-2.11zorg/mount/lomount.c Fri Nov 1 01:58:51 2002
30 +++ util-linux-2.11z/mount/lomount.c Fri Mar 28 21:43:00 2003
32 * - added Native Language Support
33 * Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
34 * - fixed strerr(errno) in gettext calls
35 + * 2000-09-24 Marc Mutz <Marc@Mutz.com>
36 + * - added long option names and the --pass-fd option to pass
37 + * passphrases via fd's to losetup/mount. Used for encryption in
38 + * non-interactive environments. The idea behind xgetpass() is stolen
39 + * from GnuPG, v.1.0.3 (http://www.gnupg.org/).
42 #define PROC_DEVICES "/proc/devices"
48 #include <sys/ioctl.h>
60 +#ifndef LO_CRYPT_CRYPTOAPI
61 +#define LO_CRYPT_CRYPTOAPI 18
63 +#ifndef LO_CRYPT_NONE
64 +#define LO_CRYPT_NONE 0
67 +#define LO_CRYPT_XOR 1
70 +#define LO_CRYPT_DES 2
72 +#ifndef LO_CRYPT_FISH2
73 +#define LO_CRYPT_FISH2 3
75 +#ifndef LO_CRYPT_BLOW
76 +#define LO_CRYPT_BLOW 4
78 +#ifndef LO_CRYPT_CAST128
79 +#define LO_CRYPT_CAST128 5
81 +#ifndef LO_CRYPT_IDEA
82 +#define LO_CRYPT_IDEA 6
84 +#ifndef LO_CRYPT_SERPENT
85 +#define LO_CRYPT_SERPENT 7
87 +#ifndef LO_CRYPT_MARS
88 +#define LO_CRYPT_MARS 8
91 +#define LO_CRYPT_RC6 11
93 +#ifndef LO_CRYPT_3DES
94 +#define LO_CRYPT_3DES 12
97 +#define LO_CRYPT_DFC 15
99 +#ifndef LO_CRYPT_RIJNDAEL
100 +#define LO_CRYPT_RIJNDAEL 16
105 extern char *xstrdup (const char *s); /* not: #include "sundries.h" */
106 extern void error (const char *fmt, ...); /* idem */
115 + int key_schedule_size;
118 +static int set_loop_passwd(struct loop_info *_loopinfo, int pfd, int keysz,
119 + const char *phash_name, const char *encryption,
121 +static int get_cipher_info(const char *name, struct cipher_info *res);
122 +static int name_to_id(const char *name);
124 +static char *id_to_name(int id);
129 struct crypt_type_struct {
133 } crypt_type_tbl[] = {
134 - { LO_CRYPT_NONE, "no" },
135 - { LO_CRYPT_NONE, "none" },
136 - { LO_CRYPT_XOR, "xor" },
137 - { LO_CRYPT_DES, "DES" },
139 + { LO_CRYPT_NONE, "none", 0 },
140 + { LO_CRYPT_XOR, "xor", 0 },
141 + { LO_CRYPT_DES, "des", 8 },
142 + { LO_CRYPT_FISH2, "twofish", 20 },
143 + { LO_CRYPT_BLOW, "blowfish", 20 },
144 + { LO_CRYPT_CAST128, "cast", 16 },
145 + { LO_CRYPT_SERPENT, "serpent", 16 },
146 + { LO_CRYPT_MARS, "mars", 16 },
147 + { LO_CRYPT_RC6, "rc6", 16 },
148 + { LO_CRYPT_3DES, "des-ede3", 24 },
149 + { LO_CRYPT_DFC, "dfc", 16 },
150 + { LO_CRYPT_IDEA, "idea", 16 },
151 + { LO_CRYPT_RIJNDAEL, "rijndael", 16 },
156 -crypt_type (const char *name) {
160 - for (i = 0; crypt_type_tbl[i].id != -1; i++)
161 - if (!strcasecmp (name, crypt_type_tbl[i].name))
162 - return crypt_type_tbl[i].id;
169 -crypt_name (int id) {
172 - for (i = 0; crypt_type_tbl[i].id != -1; i++)
173 - if (id == crypt_type_tbl[i].id)
174 - return crypt_type_tbl[i].name;
175 - return "undefined";
179 show_loop (char *device) {
180 struct loop_info loopinfo;
182 printf (_("%s: [%04x]:%ld (%s) offset %d, %s encryption\n"),
183 device, loopinfo.lo_device, loopinfo.lo_inode,
184 loopinfo.lo_name, loopinfo.lo_offset,
185 - crypt_name (loopinfo.lo_encrypt_type));
186 + id_to_name(loopinfo.lo_encrypt_type));
190 @@ -184,24 +244,62 @@
192 "mount: Could not find any loop device, and, according to %s,\n"
193 " this kernel does not know about the loop device.\n"
194 - " (If so, then recompile or `insmod loop.o'.)"),
195 + " (If so, then recompile or `modprobe loop'.)"),
199 "mount: Could not find any loop device. Maybe this kernel does not know\n"
200 - " about the loop device (then recompile or `insmod loop.o'), or\n"
201 + " about the loop device (then recompile or `modprobe loop'), or\n"
202 " maybe /dev/loop# has the wrong major number?"));
204 error(_("mount: could not find any free loop device"));
208 +/* A function to read the passphrase either from the terminal or from
209 + * an open file descriptor */
211 +xgetpass (int pfd, const char *prompt)
213 + if (pfd < 0) /* terminal */
214 + return (getpass(prompt));
215 + else { /* file descriptor */
221 + if (i >= buflen-1) {
222 + /* we're running out of space in the buffer.
223 + * Make it bigger: */
224 + char *tmppass = pass;
226 + pass = realloc(tmppass,buflen);
227 + if (pass == NULL) {
228 + /* realloc failed. Stop reading _now_. */
229 + error("not enough memory while reading passphrase");
230 + pass = tmppass; /* the old buffer hasn't changed */
234 + if ( read(pfd,pass+i, 1) != 1 || pass[i] == '\n' )
247 set_loop (const char *device, const char *file, int offset,
248 - const char *encryption, int *loopro) {
249 + const char *encryption, int pfd, int keysz, int *loopro,
250 + const char *phash_name) {
251 struct loop_info loopinfo;
252 - int fd, ffd, mode, i;
254 + int fd, ffd, mode, tried_old;
256 mode = (*loopro ? O_RDONLY : O_RDWR);
257 if ((ffd = open (file, mode)) < 0) {
258 @@ -219,13 +317,10 @@
259 *loopro = (mode == O_RDONLY);
261 memset (&loopinfo, 0, sizeof (loopinfo));
262 - xstrncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
263 - if (encryption && (loopinfo.lo_encrypt_type = crypt_type (encryption))
265 - fprintf (stderr, _("Unsupported encryption type %s\n"),
269 + snprintf(loopinfo.lo_name, sizeof(loopinfo.lo_name),
270 + "%s-cbc", encryption);
271 + loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
272 + loopinfo.lo_encrypt_type = LO_CRYPT_CRYPTOAPI;
273 loopinfo.lo_offset = offset;
276 @@ -241,24 +336,148 @@
280 - switch (loopinfo.lo_encrypt_type) {
281 + if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
282 + perror ("ioctl: LOOP_SET_FD");
288 + set_loop_passwd(&loopinfo, pfd, keysz, phash_name, encryption, fd, ffd);
290 + if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
291 + /* Try again with old-style LO_CRYPT_XX if
292 + new-style LO_CRYPT_CRYPTOAPI ioctl didn't work */
294 + error("The cipher does not exist, or a cipher module "
295 + "needs to be loaded into the kernel");
296 + perror ("ioctl: LOOP_SET_STATUS");
299 + strncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
300 + loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
301 + loopinfo.lo_encrypt_type = name_to_id (encryption);
308 + printf(_("set_loop(%s,%s,%d): success\n"),
309 + device, file, offset);
312 + (void) ioctl (fd, LOOP_CLR_FD, 0);
318 +typedef int (*phash_func_t)(char dest[LO_KEY_SIZE], const char src[], size_t src_len);
320 +#define PASSWDBUFFLEN 130
323 +phash_rmd160old (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
325 + char tmp[PASSWDBUFFLEN] = { 'A', 0, };
326 + char key[RMD160_HASH_SIZE * 2] = { 0, };
328 + strncpy (tmp + 1, src, PASSWDBUFFLEN - 1);
329 + tmp[PASSWDBUFFLEN - 1] = '\0';
331 + rmd160_hash_buffer(key, src, src_len);
332 + rmd160_hash_buffer(key + RMD160_HASH_SIZE, tmp, src_len + 1 /* dangerous! */);
334 + memcpy (dest, key, LO_KEY_SIZE);
340 +phash_sha256 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
342 + memset (dest, 0, LO_KEY_SIZE);
343 + sha256_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
348 +phash_sha384 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
350 + memset (dest, 0, LO_KEY_SIZE);
351 + sha384_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
356 +phash_sha512 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
358 + memset (dest, 0, LO_KEY_SIZE);
359 + sha512_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
364 +phash_default (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
366 + fprintf (stderr, "unknown hash type requested\n");
371 +phash_lookup (const char phash_name[])
377 + {"rmd160old", phash_rmd160old },
378 + {"sha256", phash_sha256 },
379 + {"sha384", phash_sha384 },
380 + {"sha512", phash_sha512 },
381 + { 0, phash_default }
382 + }, *p = func_table;
384 + for (; p->name; p++)
385 + if (!strcmp (phash_name, p->name))
393 +set_loop_passwd(struct loop_info *loopinfo, int pfd, int keysz,
394 + const char *phash_name, const char *encryption,
400 + struct cipher_info info;
402 + switch (loopinfo->lo_encrypt_type) {
404 - loopinfo.lo_encrypt_key_size = 0;
405 + loopinfo->lo_encrypt_key_size = 0;
408 - pass = getpass (_("Password: "));
409 - xstrncpy (loopinfo.lo_encrypt_key, pass, LO_KEY_SIZE);
410 - loopinfo.lo_encrypt_key_size = strlen(loopinfo.lo_encrypt_key);
411 + /* WARNING: xgetpass() can return massive amounts of data,
412 + * not only 128 bytes like the original getpass(3) */
413 + pass = xgetpass (pfd,_("Password: "));
414 + xstrncpy (loopinfo->lo_encrypt_key, pass, LO_KEY_SIZE);
415 + loopinfo->lo_encrypt_key_size = strlen(loopinfo->lo_encrypt_key);
418 - pass = getpass (_("Password: "));
419 - strncpy (loopinfo.lo_encrypt_key, pass, 8);
420 - loopinfo.lo_encrypt_key[8] = 0;
421 - loopinfo.lo_encrypt_key_size = 8;
422 + printf(_("WARNING: Use of DES is depreciated.\n"));
423 + pass = xgetpass (pfd,_("Password: "));
424 + strncpy (loopinfo->lo_encrypt_key, pass, 8);
425 + loopinfo->lo_encrypt_key[8] = 0;
426 + loopinfo->lo_encrypt_key_size = 8;
427 pass = getpass (_("Init (up to 16 hex digits): "));
428 for (i = 0; i < 16 && pass[i]; i++)
429 if (isxdigit (pass[i])) {
430 - loopinfo.lo_init[i >> 3] |= (pass[i] > '9' ?
431 + loopinfo->lo_init[i >> 3] |= (pass[i] > '9' ?
432 (islower (pass[i]) ? toupper (pass[i]) :
433 pass[i])-'A'+10 : pass[i]-'0') << (i&7) * 4;
435 @@ -267,29 +486,83 @@
439 + case LO_CRYPT_FISH2:
440 + case LO_CRYPT_BLOW:
441 + case LO_CRYPT_IDEA:
442 + case LO_CRYPT_CAST128:
443 + case LO_CRYPT_SERPENT:
444 + case LO_CRYPT_MARS:
446 + case LO_CRYPT_3DES:
448 + case LO_CRYPT_RIJNDAEL:
449 + pass = xgetpass(pfd, _("Password: "));
451 + if (phash_lookup (phash_name) (loopinfo->lo_encrypt_key, pass, strlen (pass)))
455 + for(i=0; crypt_type_tbl[i].id != -1; i++){
456 + if(loopinfo->lo_encrypt_type == crypt_type_tbl[i].id){
457 + keylength = crypt_type_tbl[i].keylength;
461 + loopinfo->lo_encrypt_key_size = keylength;
463 + case LO_CRYPT_CRYPTOAPI:
464 + /* Give the kernel an opportunity to load the cipher */
465 + (void) ioctl (fd, LOOP_SET_STATUS, loopinfo);
466 + if (get_cipher_info(loopinfo->lo_name, &info) < 0) {
470 + !((1 << ((keysz / 8) - 1)) & info.keysize_mask)) {
471 + error("The specified keysize is not supported by "
472 + "the selected cipher");
476 + while (keysz <= 0 ||
477 + !((1 << ((keysz / 8) - 1)) & info.keysize_mask)) {
481 + printf("Available keysizes (bits): ");
482 + for (; i < 32; i++) {
483 + if (info.keysize_mask & (1 << i)) {
484 + printf("%d ", 8*(i+1));
491 + printf("\nKeysize: ");
492 + fgets(keysize, sizeof(keysize), stdin);
493 + keysz = atoi(keysize);
496 + pass = xgetpass(pfd, _("Password: "));
498 + if (phash_lookup (phash_name) (loopinfo->lo_encrypt_key, pass, strlen (pass)))
501 + loopinfo->lo_encrypt_key_size=keysz/8;
506 _("Don't know how to get key for encryption system %d\n"),
507 - loopinfo.lo_encrypt_type);
508 + loopinfo->lo_encrypt_type);
511 - if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
512 - perror ("ioctl: LOOP_SET_FD");
515 - if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
516 - (void) ioctl (fd, LOOP_CLR_FD, 0);
517 - perror ("ioctl: LOOP_SET_STATUS");
523 - printf(_("set_loop(%s,%s,%d): success\n"),
524 - device, file, offset);
533 del_loop (const char *device) {
538 set_loop (const char *device, const char *file, int offset,
539 - const char *encryption, int *loopro) {
540 + const char *encryption, int pfd, int *loopro) {
544 @@ -349,12 +622,45 @@
546 static char *progname;
548 +static struct option longopts[] = {
549 + { "delete", 0, 0, 'd' },
550 + { "detach", 0, 0, 'd' },
551 + { "encryption", 1, 0, 'e' },
552 + { "help", 0, 0, 'h' },
553 + { "offset", 1, 0, 'o' },
554 + { "pass-fd", 1, 0, 'p' },
555 + { "phash", 1, 0, 'P' },
556 + { "verbose", 0, 0, 'v' },
557 + { "keybits", 1, 0, 'k' },
564 - fprintf(stderr, _("usage:\n\
567 %s loop_device # give info\n\
568 %s -d loop_device # delete\n\
569 - %s [ -e encryption ] [ -o offset ] loop_device file # setup\n"),
570 + %s [ options ] loop_device file # setup\n\
571 + where options include\n\
572 + --offset <num>, -o <num>\n\
573 + start at offset <num> into file.\n\
574 + --pass-fd <num>, -p <num>\n\
575 + read passphrase from file descriptor <num>\n\
576 + instead of the terminal.\n\
577 + --encryption <cipher>, -e <cipher>\n\
578 + encrypt with <cipher>.\n\
579 + Check /proc/crypto/cipher for available ciphers.\n\
580 + --keybits <num>, -k <num>\n\
581 + specify number of bits in the hashed key given\n\
582 + to the cipher. Some ciphers support several key\n\
583 + sizes and might be more efficient with a smaller\n\
584 + key size. Key sizes < 128 are generally not\n\
586 + --phash <hash>, -P <hash>\n\
587 + specify <hash> to use for hashing the passphrase\n\
588 + (supported: rmd160old, sha256, sha384, sha512)\n"),
589 progname, progname, progname);
592 @@ -388,19 +694,20 @@
595 main(int argc, char **argv) {
596 - char *offset, *encryption;
598 + char *offset = 0, *encryption = 0, *passfd = 0, *keysize = 0, *phash_name = 0;
599 + int delete = 0, off = 0, c = 0;
605 setlocale(LC_ALL, "");
606 bindtextdomain(PACKAGE, LOCALEDIR);
610 - offset = encryption = NULL;
612 - while ((c = getopt(argc,argv,"de:o:v")) != -1) {
613 + while ((c = getopt_long(argc,argv,"de:h:k:o:p:P:v",
614 + longopts, NULL)) != -1) {
632 + phash_name = optarg;
640 if (argc == 1) usage();
641 - if ((delete && (argc != optind+1 || encryption || offset)) ||
642 + if ((delete && (argc != optind+1 || encryption || offset || passfd)) ||
643 (!delete && (argc < optind+1 || argc > optind+2)))
645 if (argc == optind+1) {
648 if (offset && sscanf(offset,"%d",&off) != 1)
650 - res = set_loop(argv[optind],argv[optind+1],off,encryption,&ro);
651 + if (passfd && sscanf(passfd,"%d",&pfd) != 1)
653 + if (keysize && sscanf(keysize,"%d",&keysz) != 1)
655 + res = set_loop(argv[optind], argv[optind+1], off,
656 + encryption, pfd, keysz, &ro,
657 + phash_name ? phash_name : "rmd160old");
666 +static int get_cipher_info(const char *name, struct cipher_info *res)
668 + char path[PATH_MAX];
673 + const char *prefix;
674 + } fields[] = {{&res->blocksize, "blocksize:"},
675 + {&res->keysize_mask, "keysize_mask:"},
676 + {&res->ivsize, "ivsize:"},
677 + {&res->key_schedule_size, "key_schedule_size:"}};
678 + snprintf(path, sizeof(path), "/proc/crypto/cipher/%s", name);
679 + f = fopen(path, "r");
680 + while(f && fgets(buf, sizeof(buf), f)) {
682 + for (i = 0; i < sizeof(fields)/sizeof(fields[0]); i++) {
683 + int len = strlen(fields[i].prefix);
684 + if (strncmp(buf, fields[i].prefix, len) == 0) {
685 + *fields[i].out = strtoul(&buf[len+1], NULL, 0);
698 +name_to_id(const char *name)
703 + for (i = 0; crypt_type_tbl[i].id != -1; i++)
704 + if (!strcasecmp (name, crypt_type_tbl[i].name))
705 + return crypt_type_tbl[i].id;
707 + return LO_CRYPT_NONE;
708 + return LO_CRYPT_CRYPTOAPI;
713 +id_to_name(int id) {
716 + for (i = 0; crypt_type_tbl[i].id != -1; i++)
717 + if (id == crypt_type_tbl[i].id)
718 + return crypt_type_tbl[i].name;
719 + return "undefined";
723 diff -Nur util-linux-2.11zorg/mount/lomount.h util-linux-2.11z/mount/lomount.h
724 --- util-linux-2.11zorg/mount/lomount.h Fri Dec 8 18:08:02 2000
725 +++ util-linux-2.11z/mount/lomount.h Fri Mar 28 21:43:00 2003
728 -extern int set_loop (const char *, const char *, int, const char *, int *);
729 +extern int set_loop (const char *, const char *, int, const char *,
730 + int, int, int *, const char *);
731 extern int del_loop (const char *);
732 extern int is_loop_device (const char *);
733 extern char * find_unused_loop_device (void);
734 diff -Nur util-linux-2.11zorg/mount/losetup.8 util-linux-2.11z/mount/losetup.8
735 --- util-linux-2.11zorg/mount/losetup.8 Fri Aug 11 11:11:30 2000
736 +++ util-linux-2.11z/mount/losetup.8 Fri Mar 28 21:43:00 2003
748 \fIloop_device\fP argument is given, the status of the corresponding loop
752 +.IP "\fB\-\-delete, \-\-detach, \-d\fP"
753 detach the file or device associated with the specified loop device.
754 -.IP "\fB\-e \fIencryption\fP"
755 +.IP "\fB\-\-encryption, \-e \fIencryption\fP"
757 enable data encryption. The following keywords are recognized:
762 use a simple XOR encryption.
764 +use Advanced Encryption Standard encryption. AES encryption is only available
765 +if you are using the international kernel and AES encryption has been enabled
767 +enabled in the Crypto API.
769 +use Blowfish encryption. Blowfish encryption is only available if you
770 +are using the international kernel and Blowfish encryption has been
771 +enabled in the Crypto API.
773 +use Twofish encryption. Twofish encryption is only available if you
774 +are using the international kernel and Twofish encryption has been
775 +enabled in the Crypto API.
777 +use CAST encryption. CAST encryption is only available if you
778 +are using the international kernel and CAST encryption has been
779 +enabled in the Crypto API.
781 use DES encryption. DES encryption is only available if the optional
782 DES package has been added to the kernel. DES encryption uses an additional
783 start value that is used to protect passwords against dictionary
785 +attacks. Use of DES is deprecated.
787 +use DFC encryption. DFC encryption is only available if you
788 +are using the international kernel and DFC encryption has been
789 +enabled in the Crypto API.
791 +use IDEA encryption. IDEA encryption is only available if you
792 +are using the international kernel and IDEA encryption has been
793 +enabled in the Crypto API.
795 +use MARS encryption. MARS encryption is only available if you
796 +are using the international kernel and MARS encryption has been
797 +enabled in the Crypto API.
799 +use RC5 encryption. RC5 encryption is only available if you
800 +are using the international kernel and RC5 encryption has been
801 +enabled in the Crypto API.
803 +use RC6 encryption. RC6 encryption is only available if you
804 +are using the international kernel and RC6 encryption has been
805 +enabled in the Crypto API.
807 +use Serpent encryption. Serpent encryption is only available if you
808 +are using the international kernel and Serpent encryption has been
809 +enabled in the Crypto API.
812 -.IP "\fB\-o \fIoffset\fP"
813 +.IP "\fB\-\-offset, \-o \fIoffset\fP"
814 the data start is moved \fIoffset\fP bytes into the specified file or
816 +.IP "\fB\-\-pass-fd, \-p \fInum\fP"
817 +read the passphrase from file descriptor \fInum\fP instead of the
819 +.IP "\fB\-\-keybits, \-k \fInum\fP"
820 +set the number of bits to use in key to \fInum\fP.
823 returns 0 on success, nonzero on failure. When
827 /dev/loop0,/dev/loop1,... loop devices (major=7)
828 +/proc/cipher/* available ciphers
831 If you are using the loadable module you must have the module loaded
835 dd if=/dev/zero of=/file bs=1k count=100
836 -losetup -e des /dev/loop0 /file
838 -Init (up to 16 hex digits):
839 +losetup -e blowfish /dev/loop0 /file
841 mkfs -t ext2 /dev/loop0 100
842 mount -t ext2 /dev/loop0 /mnt
849 -DES encryption is painfully slow. On the other hand, XOR is terribly weak.
851 +DES encryption is painfully slow. On the other hand, XOR is terribly
852 +weak. Both are insecure nowadays. Some ciphers require a licence for
853 +you to be allowed to use them.
855 +CAST, DES, RC5 and Twofish are currently broken and cannot be used.
858 Original version: Theodore Ts'o <tytso@athena.mit.edu>
859 diff -Nur util-linux-2.11zorg/mount/mount.8 util-linux-2.11z/mount/mount.8
860 --- util-linux-2.11zorg/mount/mount.8 Tue Jan 21 13:45:54 2003
861 +++ util-linux-2.11z/mount/mount.8 Fri Mar 28 21:43:00 2003
867 +If the mount requires a passphrase to be entered, read it from file
870 +instead of from the terminal.
873 Mount all filesystems (of the given types) mentioned in
876 .BR noexec ", " nosuid ", and " nodev
877 (unless overridden by subsequent options, as in the option line
878 .BR users,exec,dev,suid ).
881 +Specifies an encryption algorithm to use. Used in conjunction with the
885 +Specifies the key size to use for an encryption algorithm. Used in conjunction
887 +.BR loop " and " encryption " options."
891 @@ -1688,7 +1703,10 @@
892 .BR loop ", " offset " and " encryption ,
893 that are really options to
895 -If no explicit loop device is mentioned
896 +If the mount requires a passphrase, you will be prompted for one unless
897 +you specify a file descriptor to read from instead with the
899 +option. If no explicit loop device is mentioned
900 (but just an option `\fB\-o loop\fP' is given), then
902 will try to find some unused loop device and use that.
903 diff -Nur util-linux-2.11zorg/mount/mount.c util-linux-2.11z/mount/mount.c
904 --- util-linux-2.11zorg/mount/mount.c Thu Jan 2 19:38:44 2003
905 +++ util-linux-2.11z/mount/mount.c Fri Mar 28 21:44:26 2003
907 /* True if ruid != euid. */
910 +/* Contains the fd no. to read the passphrase from, if any */
911 +static int pfd = -1;
913 /* Map from -o and fstab option strings to the flag argument to mount(2). */
915 const char *opt; /* option name */
919 static char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption,
921 + *opt_keybits, *opt_speed, *opt_phash;
923 static struct string_opt_map {
926 { "vfs=", 1, &opt_vfstype },
927 { "offset=", 0, &opt_offset },
928 { "encryption=", 0, &opt_encryption },
929 + { "keybits=", 0, &opt_keybits },
930 + { "phash=", 0, &opt_phash },
931 { "speed=", 0, &opt_speed },
936 loop_check(char **spec, char **type, int *flags,
937 int *loop, char **loopdev, char **loopfile) {
938 - int looptype, offset;
939 + int looptype, offset, keybits;
942 * In the case of a loop mount, either type is of the form lo@/dev/loop5
945 printf(_("mount: going to use the loop device %s\n"), *loopdev);
946 offset = opt_offset ? strtoul(opt_offset, NULL, 0) : 0;
947 - if (set_loop (*loopdev, *loopfile, offset, opt_encryption, &loopro)) {
948 + keybits = opt_keybits ? strtoul(opt_keybits, NULL, 0) : 0;
949 + if (set_loop (*loopdev, *loopfile, offset, opt_encryption, pfd,
951 + opt_phash ? opt_phash : "rmd160old")) {
953 printf(_("mount: failed setting up loop device\n"));
955 @@ -1352,6 +1360,7 @@
957 { "options", 1, 0, 'o' },
958 { "test-opts", 1, 0, 'O' },
959 + { "pass-fd", 1, 0, 'p' },
960 { "types", 1, 0, 't' },
961 { "bind", 0, 0, 128 },
962 { "replace", 0, 0, 129 },
963 @@ -1389,7 +1398,7 @@
964 " mount --move olddir newdir\n"
965 "A device can be given by name, say /dev/hda1 or /dev/cdrom,\n"
966 "or by label, using -L label or by uuid, using -U uuid .\n"
967 - "Other options: [-nfFrsvw] [-o options].\n"
968 + "Other options: [-nfFrsvw] [-o options] [-p num].\n"
969 "For many more details, say man 8 mount .\n"
972 @@ -1405,6 +1414,7 @@
973 int c, result = 0, specseen;
974 char *options = NULL, *test_opts = NULL, *spec, *node;
975 char *volumelabel = NULL;
976 + char *passfd = NULL;
979 struct mntentchn *mc;
980 @@ -1428,7 +1438,7 @@
981 initproctitle(argc, argv);
984 - while ((c = getopt_long (argc, argv, "afFhilL:no:O:rsU:vVwt:",
985 + while ((c = getopt_long (argc, argv, "afFhilL:no:O:p:rsU:vVwt:",
986 longopts, NULL)) != -1) {
988 case 'a': /* mount everything in fstab */
989 @@ -1467,6 +1477,9 @@
991 test_opts = xstrdup(optarg);
993 + case 'p': /* read passphrase from given fd */
996 case 'r': /* mount readonly */
999 @@ -1576,6 +1589,9 @@
1001 spec = NULL; /* just for gcc */
1003 + if (passfd && sscanf(passfd,"%d",&pfd) != 1)
1004 + die (EX_USAGE, _("mount: argument to --pass-fd or -p must be a number"));
1006 switch (argc+specseen) {
1009 diff -Nur util-linux-2.11zorg/mount/rmd160.c util-linux-2.11z/mount/rmd160.c
1010 --- util-linux-2.11zorg/mount/rmd160.c Thu Jan 1 00:00:00 1970
1011 +++ util-linux-2.11z/mount/rmd160.c Fri Mar 28 21:43:00 2003
1013 +/* rmd160.c - RIPE-MD160
1014 + * Copyright (C) 1998 Free Software Foundation, Inc.
1017 +/* This file was part of GnuPG. Modified for use within the Linux
1018 + * mount utility by Marc Mutz <Marc@Mutz.com>. None of this code is
1019 + * by myself. I just removed everything that you don't need when all
1020 + * you want to do is to use rmd160_hash_buffer().
1021 + * My comments are marked with (mm). */
1023 +/* GnuPG is free software; you can redistribute it and/or modify
1024 + * it under the terms of the GNU General Public License as published by
1025 + * the Free Software Foundation; either version 2 of the License, or
1026 + * (at your option) any later version.
1028 + * GnuPG is distributed in the hope that it will be useful,
1029 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1030 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1031 + * GNU General Public License for more details.
1033 + * You should have received a copy of the GNU General Public License
1034 + * along with this program; if not, write to the Free Software
1035 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */
1037 +#include <string.h> /* (mm) for memcpy */
1038 +#include <endian.h> /* (mm) for BIG_ENDIAN and BYTE_ORDER */
1039 +#include "rmd160.h"
1041 +/* (mm) these are used by the original GnuPG file. In order to modify
1042 + * that file not too much, we keep the notations. maybe it would be
1043 + * better to include linux/types.h and typedef __u32 to u32 and __u8
1045 +typedef unsigned int u32; /* taken from e.g. util-linux's minix.h */
1046 +typedef unsigned char byte;
1049 + u32 h0,h1,h2,h3,h4;
1056 + * Rotate a 32 bit integer by n bytes
1058 +#if defined(__GNUC__) && defined(__i386__)
1062 + __asm__("roll %%cl,%0"
1064 + :"0" (x),"c" (n));
1068 + #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
1071 +/*********************************
1072 + * RIPEMD-160 is not patented, see (as of 25.10.97)
1073 + * http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
1074 + * Note that the code uses Little Endian byteorder, which is good for
1075 + * 386 etc, but we must add some conversion when used on a big endian box.
1078 + * Pseudo-code for RIPEMD-160
1080 + * RIPEMD-160 is an iterative hash function that operates on 32-bit words.
1081 + * The round function takes as input a 5-word chaining variable and a 16-word
1082 + * message block and maps this to a new chaining variable. All operations are
1083 + * defined on 32-bit words. Padding is identical to that of MD4.
1086 + * RIPEMD-160: definitions
1089 + * nonlinear functions at bit level: exor, mux, -, mux, -
1091 + * f(j, x, y, z) = x XOR y XOR z (0 <= j <= 15)
1092 + * f(j, x, y, z) = (x AND y) OR (NOT(x) AND z) (16 <= j <= 31)
1093 + * f(j, x, y, z) = (x OR NOT(y)) XOR z (32 <= j <= 47)
1094 + * f(j, x, y, z) = (x AND z) OR (y AND NOT(z)) (48 <= j <= 63)
1095 + * f(j, x, y, z) = x XOR (y OR NOT(z)) (64 <= j <= 79)
1098 + * added constants (hexadecimal)
1100 + * K(j) = 0x00000000 (0 <= j <= 15)
1101 + * K(j) = 0x5A827999 (16 <= j <= 31) int(2**30 x sqrt(2))
1102 + * K(j) = 0x6ED9EBA1 (32 <= j <= 47) int(2**30 x sqrt(3))
1103 + * K(j) = 0x8F1BBCDC (48 <= j <= 63) int(2**30 x sqrt(5))
1104 + * K(j) = 0xA953FD4E (64 <= j <= 79) int(2**30 x sqrt(7))
1105 + * K'(j) = 0x50A28BE6 (0 <= j <= 15) int(2**30 x cbrt(2))
1106 + * K'(j) = 0x5C4DD124 (16 <= j <= 31) int(2**30 x cbrt(3))
1107 + * K'(j) = 0x6D703EF3 (32 <= j <= 47) int(2**30 x cbrt(5))
1108 + * K'(j) = 0x7A6D76E9 (48 <= j <= 63) int(2**30 x cbrt(7))
1109 + * K'(j) = 0x00000000 (64 <= j <= 79)
1112 + * selection of message word
1114 + * r(j) = j (0 <= j <= 15)
1115 + * r(16..31) = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8
1116 + * r(32..47) = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12
1117 + * r(48..63) = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2
1118 + * r(64..79) = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
1119 + * r0(0..15) = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12
1120 + * r0(16..31)= 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2
1121 + * r0(32..47)= 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13
1122 + * r0(48..63)= 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14
1123 + * r0(64..79)= 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
1126 + * amount for rotate left (rol)
1128 + * s(0..15) = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8
1129 + * s(16..31) = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12
1130 + * s(32..47) = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5
1131 + * s(48..63) = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12
1132 + * s(64..79) = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
1133 + * s'(0..15) = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6
1134 + * s'(16..31)= 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11
1135 + * s'(32..47)= 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5
1136 + * s'(48..63)= 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8
1137 + * s'(64..79)= 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
1140 + * initial value (hexadecimal)
1142 + * h0 = 0x67452301; h1 = 0xEFCDAB89; h2 = 0x98BADCFE; h3 = 0x10325476;
1143 + * h4 = 0xC3D2E1F0;
1146 + * RIPEMD-160: pseudo-code
1148 + * It is assumed that the message after padding consists of t 16-word blocks
1149 + * that will be denoted with X[i][j], with 0 <= i <= t-1 and 0 <= j <= 15.
1150 + * The symbol [+] denotes addition modulo 2**32 and rol_s denotes cyclic left
1151 + * shift (rotate) over s positions.
1154 + * for i := 0 to t-1 {
1155 + * A := h0; B := h1; C := h2; D = h3; E = h4;
1156 + * A' := h0; B' := h1; C' := h2; D' = h3; E' = h4;
1157 + * for j := 0 to 79 {
1158 + * T := rol_s(j)(A [+] f(j, B, C, D) [+] X[i][r(j)] [+] K(j)) [+] E;
1159 + * A := E; E := D; D := rol_10(C); C := B; B := T;
1160 + * T := rol_s'(j)(A' [+] f(79-j, B', C', D') [+] X[i][r'(j)]
1161 + [+] K'(j)) [+] E';
1162 + * A' := E'; E' := D'; D' := rol_10(C'); C' := B'; B' := T;
1164 + * T := h1 [+] C [+] D'; h1 := h2 [+] D [+] E'; h2 := h3 [+] E [+] A';
1165 + * h3 := h4 [+] A [+] B'; h4 := h0 [+] B [+] C'; h0 := T;
1170 + * "" 9c1185a5c5e9fc54612808977ee8f548b2258d31
1171 + * "a" 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe
1172 + * "abc" 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
1173 + * "message digest" 5d0689ef49d2fae572b881b123a85ffa21595f36
1174 + * "a...z" f71c27109c692c1b56bbdceb5b9d2865b3708dbc
1175 + * "abcdbcde...nopq" 12a053384a9c0c88e405a06c27dcf49ada62eb2b
1176 + * "A...Za...z0...9" b0e20b6e3116640286ed3a87a5713079b21f5189
1177 + * 8 times "1234567890" 9b752e45573d4b39f4dbd3323cab82bf63326bfb
1178 + * 1 million times "a" 52783243c1697bdbe16d37f97f68f08325dc1528
1183 +rmd160_init( RMD160_CONTEXT *hd )
1185 + hd->h0 = 0x67452301;
1186 + hd->h1 = 0xEFCDAB89;
1187 + hd->h2 = 0x98BADCFE;
1188 + hd->h3 = 0x10325476;
1189 + hd->h4 = 0xC3D2E1F0;
1197 + * Transform the message X which consists of 16 32-bit-words
1200 +transform( RMD160_CONTEXT *hd, byte *data )
1202 + u32 a,b,c,d,e,aa,bb,cc,dd,ee,t;
1203 + #if BYTE_ORDER == BIG_ENDIAN
1207 + for(i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 ) {
1216 + u32 *x =(u32*)data;
1218 + /* this version is better because it is always aligned;
1219 + * The performance penalty on a 586-100 is about 6% which
1220 + * is acceptable - because the data is more local it might
1221 + * also be possible that this is faster on some machines.
1222 + * This function (when compiled with -02 on gcc 2.7.2)
1223 + * executes on a 586-100 (39.73 bogomips) at about 1900kb/sec;
1224 + * [measured with a 4MB data and "gpgm --print-md rmd160"] */
1226 + memcpy( x, data, 64 );
1231 +#define K0 0x00000000
1232 +#define K1 0x5A827999
1233 +#define K2 0x6ED9EBA1
1234 +#define K3 0x8F1BBCDC
1235 +#define K4 0xA953FD4E
1236 +#define KK0 0x50A28BE6
1237 +#define KK1 0x5C4DD124
1238 +#define KK2 0x6D703EF3
1239 +#define KK3 0x7A6D76E9
1240 +#define KK4 0x00000000
1241 +#define F0(x,y,z) ( (x) ^ (y) ^ (z) )
1242 +#define F1(x,y,z) ( ((x) & (y)) | (~(x) & (z)) )
1243 +#define F2(x,y,z) ( ((x) | ~(y)) ^ (z) )
1244 +#define F3(x,y,z) ( ((x) & (z)) | ((y) & ~(z)) )
1245 +#define F4(x,y,z) ( (x) ^ ((y) | ~(z)) )
1246 +#define R(a,b,c,d,e,f,k,r,s) do { t = a + f(b,c,d) + k + x[r]; \
1247 + a = rol(t,s) + e; \
1257 + R( a, b, c, d, e, F0, K0, 0, 11 );
1258 + R( e, a, b, c, d, F0, K0, 1, 14 );
1259 + R( d, e, a, b, c, F0, K0, 2, 15 );
1260 + R( c, d, e, a, b, F0, K0, 3, 12 );
1261 + R( b, c, d, e, a, F0, K0, 4, 5 );
1262 + R( a, b, c, d, e, F0, K0, 5, 8 );
1263 + R( e, a, b, c, d, F0, K0, 6, 7 );
1264 + R( d, e, a, b, c, F0, K0, 7, 9 );
1265 + R( c, d, e, a, b, F0, K0, 8, 11 );
1266 + R( b, c, d, e, a, F0, K0, 9, 13 );
1267 + R( a, b, c, d, e, F0, K0, 10, 14 );
1268 + R( e, a, b, c, d, F0, K0, 11, 15 );
1269 + R( d, e, a, b, c, F0, K0, 12, 6 );
1270 + R( c, d, e, a, b, F0, K0, 13, 7 );
1271 + R( b, c, d, e, a, F0, K0, 14, 9 );
1272 + R( a, b, c, d, e, F0, K0, 15, 8 );
1273 + R( e, a, b, c, d, F1, K1, 7, 7 );
1274 + R( d, e, a, b, c, F1, K1, 4, 6 );
1275 + R( c, d, e, a, b, F1, K1, 13, 8 );
1276 + R( b, c, d, e, a, F1, K1, 1, 13 );
1277 + R( a, b, c, d, e, F1, K1, 10, 11 );
1278 + R( e, a, b, c, d, F1, K1, 6, 9 );
1279 + R( d, e, a, b, c, F1, K1, 15, 7 );
1280 + R( c, d, e, a, b, F1, K1, 3, 15 );
1281 + R( b, c, d, e, a, F1, K1, 12, 7 );
1282 + R( a, b, c, d, e, F1, K1, 0, 12 );
1283 + R( e, a, b, c, d, F1, K1, 9, 15 );
1284 + R( d, e, a, b, c, F1, K1, 5, 9 );
1285 + R( c, d, e, a, b, F1, K1, 2, 11 );
1286 + R( b, c, d, e, a, F1, K1, 14, 7 );
1287 + R( a, b, c, d, e, F1, K1, 11, 13 );
1288 + R( e, a, b, c, d, F1, K1, 8, 12 );
1289 + R( d, e, a, b, c, F2, K2, 3, 11 );
1290 + R( c, d, e, a, b, F2, K2, 10, 13 );
1291 + R( b, c, d, e, a, F2, K2, 14, 6 );
1292 + R( a, b, c, d, e, F2, K2, 4, 7 );
1293 + R( e, a, b, c, d, F2, K2, 9, 14 );
1294 + R( d, e, a, b, c, F2, K2, 15, 9 );
1295 + R( c, d, e, a, b, F2, K2, 8, 13 );
1296 + R( b, c, d, e, a, F2, K2, 1, 15 );
1297 + R( a, b, c, d, e, F2, K2, 2, 14 );
1298 + R( e, a, b, c, d, F2, K2, 7, 8 );
1299 + R( d, e, a, b, c, F2, K2, 0, 13 );
1300 + R( c, d, e, a, b, F2, K2, 6, 6 );
1301 + R( b, c, d, e, a, F2, K2, 13, 5 );
1302 + R( a, b, c, d, e, F2, K2, 11, 12 );
1303 + R( e, a, b, c, d, F2, K2, 5, 7 );
1304 + R( d, e, a, b, c, F2, K2, 12, 5 );
1305 + R( c, d, e, a, b, F3, K3, 1, 11 );
1306 + R( b, c, d, e, a, F3, K3, 9, 12 );
1307 + R( a, b, c, d, e, F3, K3, 11, 14 );
1308 + R( e, a, b, c, d, F3, K3, 10, 15 );
1309 + R( d, e, a, b, c, F3, K3, 0, 14 );
1310 + R( c, d, e, a, b, F3, K3, 8, 15 );
1311 + R( b, c, d, e, a, F3, K3, 12, 9 );
1312 + R( a, b, c, d, e, F3, K3, 4, 8 );
1313 + R( e, a, b, c, d, F3, K3, 13, 9 );
1314 + R( d, e, a, b, c, F3, K3, 3, 14 );
1315 + R( c, d, e, a, b, F3, K3, 7, 5 );
1316 + R( b, c, d, e, a, F3, K3, 15, 6 );
1317 + R( a, b, c, d, e, F3, K3, 14, 8 );
1318 + R( e, a, b, c, d, F3, K3, 5, 6 );
1319 + R( d, e, a, b, c, F3, K3, 6, 5 );
1320 + R( c, d, e, a, b, F3, K3, 2, 12 );
1321 + R( b, c, d, e, a, F4, K4, 4, 9 );
1322 + R( a, b, c, d, e, F4, K4, 0, 15 );
1323 + R( e, a, b, c, d, F4, K4, 5, 5 );
1324 + R( d, e, a, b, c, F4, K4, 9, 11 );
1325 + R( c, d, e, a, b, F4, K4, 7, 6 );
1326 + R( b, c, d, e, a, F4, K4, 12, 8 );
1327 + R( a, b, c, d, e, F4, K4, 2, 13 );
1328 + R( e, a, b, c, d, F4, K4, 10, 12 );
1329 + R( d, e, a, b, c, F4, K4, 14, 5 );
1330 + R( c, d, e, a, b, F4, K4, 1, 12 );
1331 + R( b, c, d, e, a, F4, K4, 3, 13 );
1332 + R( a, b, c, d, e, F4, K4, 8, 14 );
1333 + R( e, a, b, c, d, F4, K4, 11, 11 );
1334 + R( d, e, a, b, c, F4, K4, 6, 8 );
1335 + R( c, d, e, a, b, F4, K4, 15, 5 );
1336 + R( b, c, d, e, a, F4, K4, 13, 6 );
1338 + aa = a; bb = b; cc = c; dd = d; ee = e;
1346 + R( a, b, c, d, e, F4, KK0, 5, 8);
1347 + R( e, a, b, c, d, F4, KK0, 14, 9);
1348 + R( d, e, a, b, c, F4, KK0, 7, 9);
1349 + R( c, d, e, a, b, F4, KK0, 0, 11);
1350 + R( b, c, d, e, a, F4, KK0, 9, 13);
1351 + R( a, b, c, d, e, F4, KK0, 2, 15);
1352 + R( e, a, b, c, d, F4, KK0, 11, 15);
1353 + R( d, e, a, b, c, F4, KK0, 4, 5);
1354 + R( c, d, e, a, b, F4, KK0, 13, 7);
1355 + R( b, c, d, e, a, F4, KK0, 6, 7);
1356 + R( a, b, c, d, e, F4, KK0, 15, 8);
1357 + R( e, a, b, c, d, F4, KK0, 8, 11);
1358 + R( d, e, a, b, c, F4, KK0, 1, 14);
1359 + R( c, d, e, a, b, F4, KK0, 10, 14);
1360 + R( b, c, d, e, a, F4, KK0, 3, 12);
1361 + R( a, b, c, d, e, F4, KK0, 12, 6);
1362 + R( e, a, b, c, d, F3, KK1, 6, 9);
1363 + R( d, e, a, b, c, F3, KK1, 11, 13);
1364 + R( c, d, e, a, b, F3, KK1, 3, 15);
1365 + R( b, c, d, e, a, F3, KK1, 7, 7);
1366 + R( a, b, c, d, e, F3, KK1, 0, 12);
1367 + R( e, a, b, c, d, F3, KK1, 13, 8);
1368 + R( d, e, a, b, c, F3, KK1, 5, 9);
1369 + R( c, d, e, a, b, F3, KK1, 10, 11);
1370 + R( b, c, d, e, a, F3, KK1, 14, 7);
1371 + R( a, b, c, d, e, F3, KK1, 15, 7);
1372 + R( e, a, b, c, d, F3, KK1, 8, 12);
1373 + R( d, e, a, b, c, F3, KK1, 12, 7);
1374 + R( c, d, e, a, b, F3, KK1, 4, 6);
1375 + R( b, c, d, e, a, F3, KK1, 9, 15);
1376 + R( a, b, c, d, e, F3, KK1, 1, 13);
1377 + R( e, a, b, c, d, F3, KK1, 2, 11);
1378 + R( d, e, a, b, c, F2, KK2, 15, 9);
1379 + R( c, d, e, a, b, F2, KK2, 5, 7);
1380 + R( b, c, d, e, a, F2, KK2, 1, 15);
1381 + R( a, b, c, d, e, F2, KK2, 3, 11);
1382 + R( e, a, b, c, d, F2, KK2, 7, 8);
1383 + R( d, e, a, b, c, F2, KK2, 14, 6);
1384 + R( c, d, e, a, b, F2, KK2, 6, 6);
1385 + R( b, c, d, e, a, F2, KK2, 9, 14);
1386 + R( a, b, c, d, e, F2, KK2, 11, 12);
1387 + R( e, a, b, c, d, F2, KK2, 8, 13);
1388 + R( d, e, a, b, c, F2, KK2, 12, 5);
1389 + R( c, d, e, a, b, F2, KK2, 2, 14);
1390 + R( b, c, d, e, a, F2, KK2, 10, 13);
1391 + R( a, b, c, d, e, F2, KK2, 0, 13);
1392 + R( e, a, b, c, d, F2, KK2, 4, 7);
1393 + R( d, e, a, b, c, F2, KK2, 13, 5);
1394 + R( c, d, e, a, b, F1, KK3, 8, 15);
1395 + R( b, c, d, e, a, F1, KK3, 6, 5);
1396 + R( a, b, c, d, e, F1, KK3, 4, 8);
1397 + R( e, a, b, c, d, F1, KK3, 1, 11);
1398 + R( d, e, a, b, c, F1, KK3, 3, 14);
1399 + R( c, d, e, a, b, F1, KK3, 11, 14);
1400 + R( b, c, d, e, a, F1, KK3, 15, 6);
1401 + R( a, b, c, d, e, F1, KK3, 0, 14);
1402 + R( e, a, b, c, d, F1, KK3, 5, 6);
1403 + R( d, e, a, b, c, F1, KK3, 12, 9);
1404 + R( c, d, e, a, b, F1, KK3, 2, 12);
1405 + R( b, c, d, e, a, F1, KK3, 13, 9);
1406 + R( a, b, c, d, e, F1, KK3, 9, 12);
1407 + R( e, a, b, c, d, F1, KK3, 7, 5);
1408 + R( d, e, a, b, c, F1, KK3, 10, 15);
1409 + R( c, d, e, a, b, F1, KK3, 14, 8);
1410 + R( b, c, d, e, a, F0, KK4, 12, 8);
1411 + R( a, b, c, d, e, F0, KK4, 15, 5);
1412 + R( e, a, b, c, d, F0, KK4, 10, 12);
1413 + R( d, e, a, b, c, F0, KK4, 4, 9);
1414 + R( c, d, e, a, b, F0, KK4, 1, 12);
1415 + R( b, c, d, e, a, F0, KK4, 5, 5);
1416 + R( a, b, c, d, e, F0, KK4, 8, 14);
1417 + R( e, a, b, c, d, F0, KK4, 7, 6);
1418 + R( d, e, a, b, c, F0, KK4, 6, 8);
1419 + R( c, d, e, a, b, F0, KK4, 2, 13);
1420 + R( b, c, d, e, a, F0, KK4, 13, 6);
1421 + R( a, b, c, d, e, F0, KK4, 14, 5);
1422 + R( e, a, b, c, d, F0, KK4, 0, 15);
1423 + R( d, e, a, b, c, F0, KK4, 3, 13);
1424 + R( c, d, e, a, b, F0, KK4, 9, 11);
1425 + R( b, c, d, e, a, F0, KK4, 11, 11);
1428 + t = hd->h1 + d + cc;
1429 + hd->h1 = hd->h2 + e + dd;
1430 + hd->h2 = hd->h3 + a + ee;
1431 + hd->h3 = hd->h4 + b + aa;
1432 + hd->h4 = hd->h0 + c + bb;
1437 +/* Update the message digest with the contents
1438 + * of INBUF with length INLEN.
1441 +rmd160_write( RMD160_CONTEXT *hd, byte *inbuf, size_t inlen)
1443 + if( hd->count == 64 ) { /* flush the buffer */
1444 + transform( hd, hd->buf );
1451 + for( ; inlen && hd->count < 64; inlen-- )
1452 + hd->buf[hd->count++] = *inbuf++;
1453 + rmd160_write( hd, NULL, 0 );
1458 + while( inlen >= 64 ) {
1459 + transform( hd, inbuf );
1465 + for( ; inlen && hd->count < 64; inlen-- )
1466 + hd->buf[hd->count++] = *inbuf++;
1469 +/* The routine terminates the computation
1473 +rmd160_final( RMD160_CONTEXT *hd )
1478 + rmd160_write(hd, NULL, 0); /* flush */;
1482 + if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */
1486 + if( (lsb = t + hd->count) < t ) /* add the count */
1489 + if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */
1493 + if( hd->count < 56 ) { /* enough room */
1494 + hd->buf[hd->count++] = 0x80; /* pad */
1495 + while( hd->count < 56 )
1496 + hd->buf[hd->count++] = 0; /* pad */
1498 + else { /* need one extra block */
1499 + hd->buf[hd->count++] = 0x80; /* pad character */
1500 + while( hd->count < 64 )
1501 + hd->buf[hd->count++] = 0;
1502 + rmd160_write(hd, NULL, 0); /* flush */;
1503 + memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
1505 + /* append the 64 bit count */
1506 + hd->buf[56] = lsb ;
1507 + hd->buf[57] = lsb >> 8;
1508 + hd->buf[58] = lsb >> 16;
1509 + hd->buf[59] = lsb >> 24;
1510 + hd->buf[60] = msb ;
1511 + hd->buf[61] = msb >> 8;
1512 + hd->buf[62] = msb >> 16;
1513 + hd->buf[63] = msb >> 24;
1514 + transform( hd, hd->buf );
1517 + #if BYTE_ORDER == BIG_ENDIAN
1518 + #define X(a) do { *p++ = hd->h##a ; *p++ = hd->h##a >> 8; \
1519 + *p++ = hd->h##a >> 16; *p++ = hd->h##a >> 24; } while(0)
1520 + #else /* little endian */
1521 + #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
1532 + * Shortcut functions which puts the hash value of the supplied buffer
1533 + * into outbuf which must have a size of 20 bytes.
1536 +rmd160_hash_buffer( char *outbuf, const char *buffer, size_t length )
1538 + RMD160_CONTEXT hd;
1540 + rmd160_init( &hd );
1541 + rmd160_write( &hd, (byte*)buffer, length );
1542 + rmd160_final( &hd );
1543 + memcpy( outbuf, hd.buf, 20 );
1545 diff -Nur util-linux-2.11zorg/mount/rmd160.h util-linux-2.11z/mount/rmd160.h
1546 --- util-linux-2.11zorg/mount/rmd160.h Thu Jan 1 00:00:00 1970
1547 +++ util-linux-2.11z/mount/rmd160.h Fri Mar 28 21:43:00 2003
1552 +#define RMD160_HASH_SIZE 20
1555 +rmd160_hash_buffer (char *outbuf, const char *buffer, size_t length);
1557 +#endif /*RMD160_H*/
1558 diff -Nur util-linux-2.11zorg/mount/sha512.c util-linux-2.11z/mount/sha512.c
1559 --- util-linux-2.11zorg/mount/sha512.c Thu Jan 1 00:00:00 1970
1560 +++ util-linux-2.11z/mount/sha512.c Fri Mar 28 21:43:00 2003
1565 + * Written by Jari Ruusu, April 16 2001
1567 + * Copyright 2001 by Jari Ruusu.
1568 + * Redistribution of this file is permitted under the GNU Public License.
1571 +#include <string.h>
1572 +#include <sys/types.h>
1573 +#include "sha512.h"
1575 +/* Define one or more of these. If none is defined, you get all of them */
1576 +#if !defined(SHA256_NEEDED)&&!defined(SHA512_NEEDED)&&!defined(SHA384_NEEDED)
1577 +# define SHA256_NEEDED 1
1578 +# define SHA512_NEEDED 1
1579 +# define SHA384_NEEDED 1
1582 +#if defined(SHA256_NEEDED)
1583 +static const u_int32_t sha256_hashInit[8] = {
1584 + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,
1585 + 0x1f83d9ab, 0x5be0cd19
1587 +static const u_int32_t sha256_K[64] = {
1588 + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
1589 + 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
1590 + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
1591 + 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
1592 + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
1593 + 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
1594 + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
1595 + 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
1596 + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
1597 + 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
1598 + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
1602 +#if defined(SHA512_NEEDED)
1603 +static const u_int64_t sha512_hashInit[8] = {
1604 + 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,
1605 + 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
1606 + 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
1610 +#if defined(SHA384_NEEDED)
1611 +static const u_int64_t sha384_hashInit[8] = {
1612 + 0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL, 0x9159015a3070dd17ULL,
1613 + 0x152fecd8f70e5939ULL, 0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL,
1614 + 0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL
1618 +#if defined(SHA512_NEEDED) || defined(SHA384_NEEDED)
1619 +static const u_int64_t sha512_K[80] = {
1620 + 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL,
1621 + 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
1622 + 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL,
1623 + 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
1624 + 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL,
1625 + 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
1626 + 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL,
1627 + 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
1628 + 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL,
1629 + 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
1630 + 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL,
1631 + 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
1632 + 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL,
1633 + 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
1634 + 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL,
1635 + 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
1636 + 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL,
1637 + 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
1638 + 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL,
1639 + 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
1640 + 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL,
1641 + 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
1642 + 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL,
1643 + 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
1644 + 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL,
1645 + 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
1646 + 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
1650 +#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
1651 +#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
1652 +#define R(x,y) ((y) >> (x))
1654 +#if defined(SHA256_NEEDED)
1655 +void sha256_init(sha256_context *ctx)
1657 + memcpy(&ctx->sha_H[0], &sha256_hashInit[0], sizeof(ctx->sha_H));
1658 + ctx->sha_blocks = 0;
1659 + ctx->sha_bufCnt = 0;
1662 +#define S(x,y) (((y) >> (x)) | ((y) << (32 - (x))))
1663 +#define uSig0(x) ((S(2,(x))) ^ (S(13,(x))) ^ (S(22,(x))))
1664 +#define uSig1(x) ((S(6,(x))) ^ (S(11,(x))) ^ (S(25,(x))))
1665 +#define lSig0(x) ((S(7,(x))) ^ (S(18,(x))) ^ (R(3,(x))))
1666 +#define lSig1(x) ((S(17,(x))) ^ (S(19,(x))) ^ (R(10,(x))))
1668 +static void sha256_transform(sha256_context *ctx, unsigned char *datap)
1671 + u_int32_t a, b, c, d, e, f, g, h;
1672 + u_int32_t T1, T2, W[64], Wm2, Wm15;
1674 + /* read the data, big endian byte order */
1677 + W[j] = (((u_int32_t)(datap[0]))<<24) | (((u_int32_t)(datap[1]))<<16) |
1678 + (((u_int32_t)(datap[2]))<<8 ) | ((u_int32_t)(datap[3]));
1680 + } while(++j < 16);
1682 + /* initialize variables a...h */
1683 + a = ctx->sha_H[0];
1684 + b = ctx->sha_H[1];
1685 + c = ctx->sha_H[2];
1686 + d = ctx->sha_H[3];
1687 + e = ctx->sha_H[4];
1688 + f = ctx->sha_H[5];
1689 + g = ctx->sha_H[6];
1690 + h = ctx->sha_H[7];
1692 + /* apply compression function */
1698 + W[j] = lSig1(Wm2) + W[j - 7] + lSig0(Wm15) + W[j - 16];
1700 + T1 = h + uSig1(e) + Ch(e,f,g) + sha256_K[j] + W[j];
1701 + T2 = uSig0(a) + Maj(a,b,c);
1702 + h = g; g = f; f = e;
1704 + d = c; c = b; b = a;
1706 + } while(++j < 64);
1708 + /* compute intermediate hash value */
1709 + ctx->sha_H[0] += a;
1710 + ctx->sha_H[1] += b;
1711 + ctx->sha_H[2] += c;
1712 + ctx->sha_H[3] += d;
1713 + ctx->sha_H[4] += e;
1714 + ctx->sha_H[5] += f;
1715 + ctx->sha_H[6] += g;
1716 + ctx->sha_H[7] += h;
1718 + ctx->sha_blocks++;
1721 +void sha256_write(sha256_context *ctx, unsigned char *datap, int length)
1723 + while(length > 0) {
1724 + if(!ctx->sha_bufCnt) {
1725 + while(length >= sizeof(ctx->sha_out)) {
1726 + sha256_transform(ctx, datap);
1727 + datap += sizeof(ctx->sha_out);
1728 + length -= sizeof(ctx->sha_out);
1730 + if(!length) return;
1732 + ctx->sha_out[ctx->sha_bufCnt] = *datap++;
1734 + if(++ctx->sha_bufCnt == sizeof(ctx->sha_out)) {
1735 + sha256_transform(ctx, &ctx->sha_out[0]);
1736 + ctx->sha_bufCnt = 0;
1741 +void sha256_final(sha256_context *ctx)
1744 + u_int64_t bitLength;
1746 + unsigned char padByte, *datap;
1748 + bitLength = (ctx->sha_blocks << 9) | (ctx->sha_bufCnt << 3);
1750 + sha256_write(ctx, &padByte, 1);
1752 + /* pad extra space with zeroes */
1754 + while(ctx->sha_bufCnt != 56) {
1755 + sha256_write(ctx, &padByte, 1);
1758 + /* write bit length, big endian byte order */
1759 + ctx->sha_out[56] = bitLength >> 56;
1760 + ctx->sha_out[57] = bitLength >> 48;
1761 + ctx->sha_out[58] = bitLength >> 40;
1762 + ctx->sha_out[59] = bitLength >> 32;
1763 + ctx->sha_out[60] = bitLength >> 24;
1764 + ctx->sha_out[61] = bitLength >> 16;
1765 + ctx->sha_out[62] = bitLength >> 8;
1766 + ctx->sha_out[63] = bitLength;
1767 + sha256_transform(ctx, &ctx->sha_out[0]);
1769 + /* return results in ctx->sha_out[0...31] */
1770 + datap = &ctx->sha_out[0];
1773 + i = ctx->sha_H[j];
1774 + datap[0] = i >> 24;
1775 + datap[1] = i >> 16;
1776 + datap[2] = i >> 8;
1781 + /* clear sensitive information */
1782 + memset(&ctx->sha_out[32], 0, sizeof(sha256_context) - 32);
1785 +void sha256_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
1787 + sha256_context ctx;
1789 + if(ole < 1) return;
1790 + memset(ob, 0, ole);
1791 + if(ole > 32) ole = 32;
1792 + sha256_init(&ctx);
1793 + sha256_write(&ctx, ib, ile);
1794 + sha256_final(&ctx);
1795 + memcpy(ob, &ctx.sha_out[0], ole);
1796 + memset(&ctx, 0, sizeof(ctx));
1801 +#if defined(SHA512_NEEDED)
1802 +void sha512_init(sha512_context *ctx)
1804 + memcpy(&ctx->sha_H[0], &sha512_hashInit[0], sizeof(ctx->sha_H));
1805 + ctx->sha_blocks = 0;
1806 + ctx->sha_blocksMSB = 0;
1807 + ctx->sha_bufCnt = 0;
1811 +#if defined(SHA512_NEEDED) || defined(SHA384_NEEDED)
1817 +#define S(x,y) (((y) >> (x)) | ((y) << (64 - (x))))
1818 +#define uSig0(x) ((S(28,(x))) ^ (S(34,(x))) ^ (S(39,(x))))
1819 +#define uSig1(x) ((S(14,(x))) ^ (S(18,(x))) ^ (S(41,(x))))
1820 +#define lSig0(x) ((S(1,(x))) ^ (S(8,(x))) ^ (R(7,(x))))
1821 +#define lSig1(x) ((S(19,(x))) ^ (S(61,(x))) ^ (R(6,(x))))
1823 +static void sha512_transform(sha512_context *ctx, unsigned char *datap)
1826 + u_int64_t a, b, c, d, e, f, g, h;
1827 + u_int64_t T1, T2, W[80], Wm2, Wm15;
1829 + /* read the data, big endian byte order */
1832 + W[j] = (((u_int64_t)(datap[0]))<<56) | (((u_int64_t)(datap[1]))<<48) |
1833 + (((u_int64_t)(datap[2]))<<40) | (((u_int64_t)(datap[3]))<<32) |
1834 + (((u_int64_t)(datap[4]))<<24) | (((u_int64_t)(datap[5]))<<16) |
1835 + (((u_int64_t)(datap[6]))<<8 ) | ((u_int64_t)(datap[7]));
1837 + } while(++j < 16);
1839 + /* initialize variables a...h */
1840 + a = ctx->sha_H[0];
1841 + b = ctx->sha_H[1];
1842 + c = ctx->sha_H[2];
1843 + d = ctx->sha_H[3];
1844 + e = ctx->sha_H[4];
1845 + f = ctx->sha_H[5];
1846 + g = ctx->sha_H[6];
1847 + h = ctx->sha_H[7];
1849 + /* apply compression function */
1855 + W[j] = lSig1(Wm2) + W[j - 7] + lSig0(Wm15) + W[j - 16];
1857 + T1 = h + uSig1(e) + Ch(e,f,g) + sha512_K[j] + W[j];
1858 + T2 = uSig0(a) + Maj(a,b,c);
1859 + h = g; g = f; f = e;
1861 + d = c; c = b; b = a;
1863 + } while(++j < 80);
1865 + /* compute intermediate hash value */
1866 + ctx->sha_H[0] += a;
1867 + ctx->sha_H[1] += b;
1868 + ctx->sha_H[2] += c;
1869 + ctx->sha_H[3] += d;
1870 + ctx->sha_H[4] += e;
1871 + ctx->sha_H[5] += f;
1872 + ctx->sha_H[6] += g;
1873 + ctx->sha_H[7] += h;
1875 + ctx->sha_blocks++;
1876 + if(!ctx->sha_blocks) ctx->sha_blocksMSB++;
1879 +void sha512_write(sha512_context *ctx, unsigned char *datap, int length)
1881 + while(length > 0) {
1882 + if(!ctx->sha_bufCnt) {
1883 + while(length >= sizeof(ctx->sha_out)) {
1884 + sha512_transform(ctx, datap);
1885 + datap += sizeof(ctx->sha_out);
1886 + length -= sizeof(ctx->sha_out);
1888 + if(!length) return;
1890 + ctx->sha_out[ctx->sha_bufCnt] = *datap++;
1892 + if(++ctx->sha_bufCnt == sizeof(ctx->sha_out)) {
1893 + sha512_transform(ctx, &ctx->sha_out[0]);
1894 + ctx->sha_bufCnt = 0;
1899 +void sha512_final(sha512_context *ctx)
1902 + u_int64_t bitLength, bitLengthMSB;
1904 + unsigned char padByte, *datap;
1906 + bitLength = (ctx->sha_blocks << 10) | (ctx->sha_bufCnt << 3);
1907 + bitLengthMSB = (ctx->sha_blocksMSB << 10) | (ctx->sha_blocks >> 54);
1909 + sha512_write(ctx, &padByte, 1);
1911 + /* pad extra space with zeroes */
1913 + while(ctx->sha_bufCnt != 112) {
1914 + sha512_write(ctx, &padByte, 1);
1917 + /* write bit length, big endian byte order */
1918 + ctx->sha_out[112] = bitLengthMSB >> 56;
1919 + ctx->sha_out[113] = bitLengthMSB >> 48;
1920 + ctx->sha_out[114] = bitLengthMSB >> 40;
1921 + ctx->sha_out[115] = bitLengthMSB >> 32;
1922 + ctx->sha_out[116] = bitLengthMSB >> 24;
1923 + ctx->sha_out[117] = bitLengthMSB >> 16;
1924 + ctx->sha_out[118] = bitLengthMSB >> 8;
1925 + ctx->sha_out[119] = bitLengthMSB;
1926 + ctx->sha_out[120] = bitLength >> 56;
1927 + ctx->sha_out[121] = bitLength >> 48;
1928 + ctx->sha_out[122] = bitLength >> 40;
1929 + ctx->sha_out[123] = bitLength >> 32;
1930 + ctx->sha_out[124] = bitLength >> 24;
1931 + ctx->sha_out[125] = bitLength >> 16;
1932 + ctx->sha_out[126] = bitLength >> 8;
1933 + ctx->sha_out[127] = bitLength;
1934 + sha512_transform(ctx, &ctx->sha_out[0]);
1936 + /* return results in ctx->sha_out[0...63] */
1937 + datap = &ctx->sha_out[0];
1940 + i = ctx->sha_H[j];
1941 + datap[0] = i >> 56;
1942 + datap[1] = i >> 48;
1943 + datap[2] = i >> 40;
1944 + datap[3] = i >> 32;
1945 + datap[4] = i >> 24;
1946 + datap[5] = i >> 16;
1947 + datap[6] = i >> 8;
1952 + /* clear sensitive information */
1953 + memset(&ctx->sha_out[64], 0, sizeof(sha512_context) - 64);
1956 +void sha512_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
1958 + sha512_context ctx;
1960 + if(ole < 1) return;
1961 + memset(ob, 0, ole);
1962 + if(ole > 64) ole = 64;
1963 + sha512_init(&ctx);
1964 + sha512_write(&ctx, ib, ile);
1965 + sha512_final(&ctx);
1966 + memcpy(ob, &ctx.sha_out[0], ole);
1967 + memset(&ctx, 0, sizeof(ctx));
1971 +#if defined(SHA384_NEEDED)
1972 +void sha384_init(sha512_context *ctx)
1974 + memcpy(&ctx->sha_H[0], &sha384_hashInit[0], sizeof(ctx->sha_H));
1975 + ctx->sha_blocks = 0;
1976 + ctx->sha_blocksMSB = 0;
1977 + ctx->sha_bufCnt = 0;
1980 +void sha384_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
1982 + sha512_context ctx;
1984 + if(ole < 1) return;
1985 + memset(ob, 0, ole);
1986 + if(ole > 48) ole = 48;
1987 + sha384_init(&ctx);
1988 + sha512_write(&ctx, ib, ile);
1989 + sha512_final(&ctx);
1990 + memcpy(ob, &ctx.sha_out[0], ole);
1991 + memset(&ctx, 0, sizeof(ctx));
1994 diff -Nur util-linux-2.11zorg/mount/sha512.h util-linux-2.11z/mount/sha512.h
1995 --- util-linux-2.11zorg/mount/sha512.h Thu Jan 1 00:00:00 1970
1996 +++ util-linux-2.11z/mount/sha512.h Fri Mar 28 21:43:00 2003
2001 + * Written by Jari Ruusu, April 16 2001
2003 + * Copyright 2001 by Jari Ruusu.
2004 + * Redistribution of this file is permitted under the GNU Public License.
2007 +#include <sys/types.h>
2010 + unsigned char sha_out[64]; /* results are here, bytes 0...31 */
2011 + u_int32_t sha_H[8];
2012 + u_int64_t sha_blocks;
2017 + unsigned char sha_out[128]; /* results are here, bytes 0...63 */
2018 + u_int64_t sha_H[8];
2019 + u_int64_t sha_blocks;
2020 + u_int64_t sha_blocksMSB;
2024 +/* no sha384_context, use sha512_context */
2026 +/* 256 bit hash, provides 128 bits of security against collision attacks */
2027 +extern void sha256_init(sha256_context *);
2028 +extern void sha256_write(sha256_context *, unsigned char *, int);
2029 +extern void sha256_final(sha256_context *);
2030 +extern void sha256_hash_buffer(unsigned char *, int, unsigned char *, int);
2032 +/* 512 bit hash, provides 256 bits of security against collision attacks */
2033 +extern void sha512_init(sha512_context *);
2034 +extern void sha512_write(sha512_context *, unsigned char *, int);
2035 +extern void sha512_final(sha512_context *);
2036 +extern void sha512_hash_buffer(unsigned char *, int, unsigned char *, int);
2038 +/* 384 bit hash, provides 192 bits of security against collision attacks */
2039 +extern void sha384_init(sha512_context *);
2040 +/* no sha384_write(), use sha512_write() */
2041 +/* no sha384_final(), use sha512_final(), result in ctx->sha_out[0...47] */
2042 +extern void sha384_hash_buffer(unsigned char *, int, unsigned char *, int);
2043 diff -Nur util-linux-2.11zorg/mount/sundries.c util-linux-2.11z/mount/sundries.c
2044 --- util-linux-2.11zorg/mount/sundries.c Fri Nov 1 01:00:50 2002
2045 +++ util-linux-2.11z/mount/sundries.c Fri Mar 28 21:43:00 2003
2050 - if (!strncmp(types, "no", 2)) {
2051 + if (types && !strncmp(types, "no", 2)) {