7 ? mount/nfsmount_clnt.c
14 ===================================================================
15 RCS file: /cvsroot/cryptoapi/util-linux/mount/Makefile,v
16 retrieving revision 1.1.1.1
17 retrieving revision 1.1.1.1.2.1
18 diff -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
23 MAYBE = pivot_root swapoff
25 -LO_OBJS = lomount.o $(LIB)/xstrncpy.o
26 +LO_OBJS = lomount.o $(LIB)/xstrncpy.o sha512.o rmd160.o
27 NFS_OBJS = nfsmount.o nfsmount_xdr.o nfsmount_clnt.o
28 GEN_FILES = nfsmount.h nfsmount_xdr.c nfsmount_clnt.c
31 main_losetup.o: lomount.c
32 $(COMPILE) -DMAIN lomount.c -o $@
34 -losetup: main_losetup.o $(LIB)/xstrncpy.o
35 +losetup: main_losetup.o $(LIB)/xstrncpy.o sha512.o rmd160.o
38 +rmd160.o lomount.o main_losetup.o: rmd160.h
40 +sha512.o lomount.o main_losetup.o: sha512.h
42 mount.o umount.o nfsmount.o losetup.o fstab.o realpath.o sundries.o: sundries.h
44 Index: mount/lomount.c
45 ===================================================================
46 RCS file: /cvsroot/cryptoapi/util-linux/mount/lomount.c,v
47 retrieving revision 1.1.1.1
48 retrieving revision 1.1.1.1.2.3
49 diff -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
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/).
63 #define PROC_DEVICES "/proc/devices"
69 #include <sys/ioctl.h>
80 +#ifndef LO_CRYPT_CRYPTOAPI
81 +#define LO_CRYPT_CRYPTOAPI 18
83 +#ifndef LO_CRYPT_NONE
84 +#define LO_CRYPT_NONE 0
87 +#define LO_CRYPT_XOR 1
90 +#define LO_CRYPT_DES 2
92 +#ifndef LO_CRYPT_FISH2
93 +#define LO_CRYPT_FISH2 3
95 +#ifndef LO_CRYPT_BLOW
96 +#define LO_CRYPT_BLOW 4
98 +#ifndef LO_CRYPT_CAST128
99 +#define LO_CRYPT_CAST128 5
101 +#ifndef LO_CRYPT_IDEA
102 +#define LO_CRYPT_IDEA 6
104 +#ifndef LO_CRYPT_SERPENT
105 +#define LO_CRYPT_SERPENT 7
107 +#ifndef LO_CRYPT_MARS
108 +#define LO_CRYPT_MARS 8
110 +#ifndef LO_CRYPT_RC6
111 +#define LO_CRYPT_RC6 11
113 +#ifndef LO_CRYPT_3DES
114 +#define LO_CRYPT_3DES 12
116 +#ifndef LO_CRYPT_DFC
117 +#define LO_CRYPT_DFC 15
119 +#ifndef LO_CRYPT_RIJNDAEL
120 +#define LO_CRYPT_RIJNDAEL 16
125 extern char *xstrdup (const char *s); /* not: #include "sundries.h" */
126 extern void error (const char *fmt, ...); /* idem */
135 + int key_schedule_size;
138 +static int set_loop_passwd(struct loop_info *_loopinfo, int pfd, int keysz,
139 + const char *phash_name, const char *encryption,
141 +static int get_cipher_info(const char *name, struct cipher_info *res);
142 +static int name_to_id(const char *name);
144 +static char *id_to_name(int id);
149 struct crypt_type_struct {
153 } crypt_type_tbl[] = {
154 - { LO_CRYPT_NONE, "no" },
155 - { LO_CRYPT_NONE, "none" },
156 - { LO_CRYPT_XOR, "xor" },
157 - { LO_CRYPT_DES, "DES" },
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 },
176 -crypt_type (const char *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;
189 -crypt_name (int id) {
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";
199 show_loop (char *device) {
200 struct loop_info loopinfo;
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));
210 @@ -183,24 +243,62 @@
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'.)"),
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?"));
224 error(_("mount: could not find any free loop device"));
228 +/* A function to read the passphrase either from the terminal or from
229 + * an open file descriptor */
231 +xgetpass (int pfd, const char *prompt)
233 + if (pfd < 0) /* terminal */
234 + return (getpass(prompt));
235 + else { /* file descriptor */
241 + if (i >= buflen-1) {
242 + /* we're running out of space in the buffer.
243 + * Make it bigger: */
244 + char *tmppass = pass;
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 */
254 + if ( read(pfd,pass+i, 1) != 1 || pass[i] == '\n' )
267 set_loop (const char *device, const char *file, int offset,
268 - const char *encryption, int *loopro) {
269 + const char *encryption, int pfd, int keysz, int *loopro,
270 + const char *phash_name) {
271 struct loop_info loopinfo;
272 - int fd, ffd, mode, i;
274 + int fd, ffd, mode, tried_old;
276 mode = (*loopro ? O_RDONLY : O_RDWR);
277 if ((ffd = open (file, mode)) < 0) {
278 @@ -218,13 +316,10 @@
279 *loopro = (mode == O_RDONLY);
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))
285 - fprintf (stderr, _("Unsupported encryption type %s\n"),
289 + snprintf(loopinfo.lo_name, sizeof(loopinfo.lo_name),
290 + "%s-cbc", encryption);
291 + loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
292 + loopinfo.lo_encrypt_type = LO_CRYPT_CRYPTOAPI;
293 loopinfo.lo_offset = offset;
296 @@ -240,24 +335,148 @@
300 - switch (loopinfo.lo_encrypt_type) {
301 + if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
302 + perror ("ioctl: LOOP_SET_FD");
308 + set_loop_passwd(&loopinfo, pfd, keysz, phash_name, encryption, fd, ffd);
310 + if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
311 + /* Try again with old-style LO_CRYPT_XX if
312 + new-style LO_CRYPT_CRYPTOAPI ioctl didn't work */
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");
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);
328 + printf(_("set_loop(%s,%s,%d): success\n"),
329 + device, file, offset);
332 + (void) ioctl (fd, LOOP_CLR_FD, 0);
338 +typedef int (*phash_func_t)(char dest[LO_KEY_SIZE], const char src[], size_t src_len);
340 +#define PASSWDBUFFLEN 130
343 +phash_rmd160old (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
345 + char tmp[PASSWDBUFFLEN] = { 'A', 0, };
346 + char key[RMD160_HASH_SIZE * 2] = { 0, };
348 + strncpy (tmp + 1, src, PASSWDBUFFLEN - 1);
349 + tmp[PASSWDBUFFLEN - 1] = '\0';
351 + rmd160_hash_buffer(key, src, src_len);
352 + rmd160_hash_buffer(key + RMD160_HASH_SIZE, tmp, src_len + 1 /* dangerous! */);
354 + memcpy (dest, key, LO_KEY_SIZE);
360 +phash_sha256 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
362 + memset (dest, 0, LO_KEY_SIZE);
363 + sha256_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
368 +phash_sha384 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
370 + memset (dest, 0, LO_KEY_SIZE);
371 + sha384_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
376 +phash_sha512 (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
378 + memset (dest, 0, LO_KEY_SIZE);
379 + sha512_hash_buffer ((char *) src, src_len, dest, LO_KEY_SIZE);
384 +phash_default (char dest[LO_KEY_SIZE], const char src[], size_t src_len)
386 + fprintf (stderr, "unknown hash type requested\n");
391 +phash_lookup (const char phash_name[])
397 + {"rmd160old", phash_rmd160old },
398 + {"sha256", phash_sha256 },
399 + {"sha384", phash_sha384 },
400 + {"sha512", phash_sha512 },
401 + { 0, phash_default }
402 + }, *p = func_table;
404 + for (; p->name; p++)
405 + if (!strcmp (phash_name, p->name))
413 +set_loop_passwd(struct loop_info *loopinfo, int pfd, int keysz,
414 + const char *phash_name, const char *encryption,
420 + struct cipher_info info;
422 + switch (loopinfo->lo_encrypt_type) {
424 - loopinfo.lo_encrypt_key_size = 0;
425 + loopinfo->lo_encrypt_key_size = 0;
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);
431 + /* WARNING: xgetpass() can return massive amounts of data,
432 + * not only 128 bytes like the original getpass(3) */
433 + pass = xgetpass (pfd,_("Password: "));
434 + xstrncpy (loopinfo->lo_encrypt_key, pass, LO_KEY_SIZE);
435 + loopinfo->lo_encrypt_key_size = strlen(loopinfo->lo_encrypt_key);
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;
455 @@ -266,29 +485,83 @@
459 + case LO_CRYPT_FISH2:
460 + case LO_CRYPT_BLOW:
461 + case LO_CRYPT_IDEA:
462 + case LO_CRYPT_CAST128:
463 + case LO_CRYPT_SERPENT:
464 + case LO_CRYPT_MARS:
466 + case LO_CRYPT_3DES:
468 + case LO_CRYPT_RIJNDAEL:
469 + pass = xgetpass(pfd, _("Password: "));
471 + if (phash_lookup (phash_name) (loopinfo->lo_encrypt_key, pass, strlen (pass)))
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;
481 + loopinfo->lo_encrypt_key_size = keylength;
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) {
490 + !((1 << ((keysz / 8) - 1)) & info.keysize_mask)) {
491 + error("The specified keysize is not supported by "
492 + "the selected cipher");
496 + while (keysz <= 0 ||
497 + !((1 << ((keysz / 8) - 1)) & info.keysize_mask)) {
501 + printf("Available keysizes (bits): ");
502 + for (; i < 32; i++) {
503 + if (info.keysize_mask & (1 << i)) {
504 + printf("%d ", 8*(i+1));
511 + printf("\nKeysize: ");
512 + fgets(keysize, sizeof(keysize), stdin);
513 + keysz = atoi(keysize);
516 + pass = xgetpass(pfd, _("Password: "));
518 + if (phash_lookup (phash_name) (loopinfo->lo_encrypt_key, pass, strlen (pass)))
521 + loopinfo->lo_encrypt_key_size=keysz/8;
526 _("Don't know how to get key for encryption system %d\n"),
527 - loopinfo.lo_encrypt_type);
528 + loopinfo->lo_encrypt_type);
531 - if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
532 - perror ("ioctl: LOOP_SET_FD");
535 - if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
536 - (void) ioctl (fd, LOOP_CLR_FD, 0);
537 - perror ("ioctl: LOOP_SET_STATUS");
543 - printf(_("set_loop(%s,%s,%d): success\n"),
544 - device, file, offset);
553 del_loop (const char *device) {
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) {
564 @@ -348,12 +621,45 @@
566 static char *progname;
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' },
575 + { "phash", 1, 0, 'P' },
576 + { "verbose", 0, 0, 'v' },
577 + { "keybits", 1, 0, 'k' },
584 - fprintf(stderr, _("usage:\n\
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"),
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\
599 + Check /proc/crypto/cipher for available ciphers.\n\
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\
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);
612 @@ -387,19 +693,20 @@
615 main(int argc, char **argv) {
616 - char *offset, *encryption;
618 + char *offset = 0, *encryption = 0, *passfd = 0, *keysize = 0, *phash_name = 0;
619 + int delete = 0, off = 0, c = 0;
625 setlocale(LC_ALL, "");
626 bindtextdomain(PACKAGE, LOCALEDIR);
630 - offset = encryption = NULL;
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) {
652 + phash_name = optarg;
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)))
665 if (argc == optind+1) {
668 if (offset && sscanf(offset,"%d",&off) != 1)
670 - res = set_loop(argv[optind],argv[optind+1],off,encryption,&ro);
671 + if (passfd && sscanf(passfd,"%d",&pfd) != 1)
673 + if (keysize && sscanf(keysize,"%d",&keysz) != 1)
675 + res = set_loop(argv[optind], argv[optind+1], off,
676 + encryption, pfd, keysz, &ro,
677 + phash_name ? phash_name : "rmd160old");
686 +static int get_cipher_info(const char *name, struct cipher_info *res)
688 + char path[PATH_MAX];
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)) {
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);
718 +name_to_id(const char *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;
727 + return LO_CRYPT_NONE;
728 + return LO_CRYPT_CRYPTOAPI;
733 +id_to_name(int id) {
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";
743 Index: mount/lomount.h
744 ===================================================================
745 RCS file: /cvsroot/cryptoapi/util-linux/mount/lomount.h,v
746 retrieving revision 1.1.1.1
747 retrieving revision 1.1.1.1.2.2
748 diff -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
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 *,
755 + int, int, int *, const char *);
756 extern int del_loop (const char *);
757 extern int is_loop_device (const char *);
758 extern char * find_unused_loop_device (void);
759 Index: mount/losetup.8
760 ===================================================================
761 RCS file: /cvsroot/cryptoapi/util-linux/mount/losetup.8,v
762 retrieving revision 1.1.1.1
763 retrieving revision 1.1.1.1.2.1
764 diff -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
778 \fIloop_device\fP argument is given, the status of the corresponding loop
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"
787 enable data encryption. The following keywords are recognized:
792 use a simple XOR encryption.
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
797 +enabled in the Crypto API.
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.
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.
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.
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
815 +attacks. Use of DES is deprecated.
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.
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.
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.
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.
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.
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.
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
846 +.IP "\fB\-\-pass-fd, \-p \fInum\fP"
847 +read the passphrase from file descriptor \fInum\fP instead of the
849 +.IP "\fB\-\-keybits, \-k \fInum\fP"
850 +set the number of bits to use in key to \fInum\fP.
853 returns 0 on success, nonzero on failure. When
857 /dev/loop0,/dev/loop1,... loop devices (major=7)
858 +/proc/cipher/* available ciphers
861 If you are using the loadable module you must have the module loaded
865 dd if=/dev/zero of=/file bs=1k count=100
866 -losetup -e des /dev/loop0 /file
868 -Init (up to 16 hex digits):
869 +losetup -e blowfish /dev/loop0 /file
871 mkfs -t ext2 /dev/loop0 100
872 mount -t ext2 /dev/loop0 /mnt
879 -DES encryption is painfully slow. On the other hand, XOR is terribly weak.
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.
885 +CAST, DES, RC5 and Twofish are currently broken and cannot be used.
888 Original version: Theodore Ts'o <tytso@athena.mit.edu>
890 ===================================================================
891 RCS file: /cvsroot/cryptoapi/util-linux/mount/mount.8,v
892 retrieving revision 1.1.1.1
893 retrieving revision 1.1.1.1.2.1
894 diff -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
902 +If the mount requires a passphrase to be entered, read it from file
905 +instead of from the terminal.
908 Mount all filesystems (of the given types) mentioned in
911 .BR noexec ", " nosuid ", and " nodev
912 (unless overridden by subsequent options, as in the option line
913 .BR users,exec,dev,suid ).
916 +Specifies an encryption algorithm to use. Used in conjunction with the
920 +Specifies the key size to use for an encryption algorithm. Used in conjunction
922 +.BR loop " and " encryption " options."
926 @@ -1581,7 +1596,10 @@
927 .BR loop ", " offset " and " encryption ,
928 that are really options to
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
934 +option. If no explicit loop device is mentioned
935 (but just an option `\fB\-o loop\fP' is given), then
937 will try to find some unused loop device and use that.
939 ===================================================================
940 RCS file: /cvsroot/cryptoapi/util-linux/mount/mount.c,v
941 retrieving revision 1.1.1.1
942 retrieving revision 1.1.1.1.2.3
943 diff -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
947 /* True if ruid != euid. */
950 +/* Contains the fd no. to read the passphrase from, if any */
951 +static int pfd = -1;
953 /* Map from -o and fstab option strings to the flag argument to mount(2). */
955 const char *opt; /* option name */
959 static char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption,
961 + *opt_keybits, *opt_speed, *opt_phash;
963 static struct string_opt_map {
966 { "vfs=", 1, &opt_vfstype },
967 { "offset=", 0, &opt_offset },
968 { "encryption=", 0, &opt_encryption },
969 + { "keybits=", 0, &opt_keybits },
970 + { "phash=", 0, &opt_phash },
971 { "speed=", 0, &opt_speed },
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;
982 * In the case of a loop mount, either type is of the form lo@/dev/loop5
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)) {
988 + keybits = opt_keybits ? strtoul(opt_keybits, NULL, 0) : 0;
989 + if (set_loop (*loopdev, *loopfile, offset, opt_encryption, pfd,
991 + opt_phash ? opt_phash : "rmd160old")) {
993 printf(_("mount: failed setting up loop device\n"));
995 @@ -1305,6 +1313,7 @@
996 { "read-write", 0, 0, 'w' },
998 { "options", 1, 0, 'o' },
999 + { "pass-fd", 1, 0, 'p' },
1000 { "types", 1, 0, 't' },
1001 { "bind", 0, 0, 128 },
1002 { "replace", 0, 0, 129 },
1003 @@ -1340,7 +1349,7 @@
1004 " mount --move olddir newdir\n"
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"
1012 @@ -1356,6 +1365,7 @@
1013 int c, result = 0, specseen;
1014 char *options = NULL, *spec, *node;
1015 char *volumelabel = NULL;
1016 + char *passfd = NULL;
1019 struct mntentchn *mc;
1020 @@ -1377,7 +1387,7 @@
1021 initproctitle(argc, argv);
1024 - while ((c = getopt_long (argc, argv, "afFhlL:no:rsU:vVwt:",
1025 + while ((c = getopt_long (argc, argv, "afFhlL:no:p:rsU:vVwt:",
1026 longopts, NULL)) != -1) {
1028 case 'a': /* mount everything in fstab */
1029 @@ -1407,6 +1417,9 @@
1031 options = xstrdup(optarg);
1033 + case 'p': /* read passphrase from given fd */
1036 case 'r': /* mount readonly */
1039 @@ -1504,6 +1517,9 @@
1040 printf(_("mount: mounting %s\n"), spec);
1042 spec = NULL; /* just for gcc */
1044 + if (passfd && sscanf(passfd,"%d",&pfd) != 1)
1045 + die (EX_USAGE, _("mount: argument to --pass-fd or -p must be a number"));
1047 switch (argc+specseen) {
1049 Index: mount/rmd160.c
1050 ===================================================================
1051 RCS file: mount/rmd160.c
1052 diff -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
1056 +/* rmd160.c - RIPE-MD160
1057 + * Copyright (C) 1998 Free Software Foundation, Inc.
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). */
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.
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.
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 */
1080 +#include <string.h> /* (mm) for memcpy */
1081 +#include <endian.h> /* (mm) for BIG_ENDIAN and BYTE_ORDER */
1082 +#include "rmd160.h"
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
1088 +typedef unsigned int u32; /* taken from e.g. util-linux's minix.h */
1089 +typedef unsigned char byte;
1092 + u32 h0,h1,h2,h3,h4;
1099 + * Rotate a 32 bit integer by n bytes
1101 +#if defined(__GNUC__) && defined(__i386__)
1105 + __asm__("roll %%cl,%0"
1107 + :"0" (x),"c" (n));
1111 + #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
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.
1121 + * Pseudo-code for RIPEMD-160
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.
1129 + * RIPEMD-160: definitions
1132 + * nonlinear functions at bit level: exor, mux, -, mux, -
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)
1141 + * added constants (hexadecimal)
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)
1155 + * selection of message word
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
1169 + * amount for rotate left (rol)
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
1183 + * initial value (hexadecimal)
1185 + * h0 = 0x67452301; h1 = 0xEFCDAB89; h2 = 0x98BADCFE; h3 = 0x10325476;
1186 + * h4 = 0xC3D2E1F0;
1189 + * RIPEMD-160: pseudo-code
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.
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;
1207 + * T := h1 [+] C [+] D'; h1 := h2 [+] D [+] E'; h2 := h3 [+] E [+] A';
1208 + * h3 := h4 [+] A [+] B'; h4 := h0 [+] B [+] C'; h0 := T;
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
1226 +rmd160_init( RMD160_CONTEXT *hd )
1228 + hd->h0 = 0x67452301;
1229 + hd->h1 = 0xEFCDAB89;
1230 + hd->h2 = 0x98BADCFE;
1231 + hd->h3 = 0x10325476;
1232 + hd->h4 = 0xC3D2E1F0;
1240 + * Transform the message X which consists of 16 32-bit-words
1243 +transform( RMD160_CONTEXT *hd, byte *data )
1245 + u32 a,b,c,d,e,aa,bb,cc,dd,ee,t;
1246 + #if BYTE_ORDER == BIG_ENDIAN
1250 + for(i=0, p1=data, p2=(byte*)x; i < 16; i++, p2 += 4 ) {
1259 + u32 *x =(u32*)data;
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"] */
1269 + memcpy( x, data, 64 );
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; \
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 );
1381 + aa = a; bb = b; cc = c; dd = d; ee = e;
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);
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;
1480 +/* Update the message digest with the contents
1481 + * of INBUF with length INLEN.
1484 +rmd160_write( RMD160_CONTEXT *hd, byte *inbuf, size_t inlen)
1486 + if( hd->count == 64 ) { /* flush the buffer */
1487 + transform( hd, hd->buf );
1494 + for( ; inlen && hd->count < 64; inlen-- )
1495 + hd->buf[hd->count++] = *inbuf++;
1496 + rmd160_write( hd, NULL, 0 );
1501 + while( inlen >= 64 ) {
1502 + transform( hd, inbuf );
1508 + for( ; inlen && hd->count < 64; inlen-- )
1509 + hd->buf[hd->count++] = *inbuf++;
1512 +/* The routine terminates the computation
1516 +rmd160_final( RMD160_CONTEXT *hd )
1521 + rmd160_write(hd, NULL, 0); /* flush */;
1525 + if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */
1529 + if( (lsb = t + hd->count) < t ) /* add the count */
1532 + if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */
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 */
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 */
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 );
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)
1575 + * Shortcut functions which puts the hash value of the supplied buffer
1576 + * into outbuf which must have a size of 20 bytes.
1579 +rmd160_hash_buffer( char *outbuf, const char *buffer, size_t length )
1581 + RMD160_CONTEXT hd;
1583 + rmd160_init( &hd );
1584 + rmd160_write( &hd, (byte*)buffer, length );
1585 + rmd160_final( &hd );
1586 + memcpy( outbuf, hd.buf, 20 );
1588 Index: mount/rmd160.h
1589 ===================================================================
1590 RCS file: mount/rmd160.h
1591 diff -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
1598 +#define RMD160_HASH_SIZE 20
1601 +rmd160_hash_buffer (char *outbuf, const char *buffer, size_t length);
1603 +#endif /*RMD160_H*/
1604 Index: mount/sha512.c
1605 ===================================================================
1606 RCS file: mount/sha512.c
1607 diff -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
1614 + * Written by Jari Ruusu, April 16 2001
1616 + * Copyright 2001 by Jari Ruusu.
1617 + * Redistribution of this file is permitted under the GNU Public License.
1620 +#include <string.h>
1621 +#include <sys/types.h>
1622 +#include "sha512.h"
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
1631 +#if defined(SHA256_NEEDED)
1632 +static const u_int32_t sha256_hashInit[8] = {
1633 + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,
1634 + 0x1f83d9ab, 0x5be0cd19
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
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
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
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
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))
1703 +#if defined(SHA256_NEEDED)
1704 +void sha256_init(sha256_context *ctx)
1706 + memcpy(&ctx->sha_H[0], &sha256_hashInit[0], sizeof(ctx->sha_H));
1707 + ctx->sha_blocks = 0;
1708 + ctx->sha_bufCnt = 0;
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))))
1717 +static void sha256_transform(sha256_context *ctx, unsigned char *datap)
1720 + u_int32_t a, b, c, d, e, f, g, h;
1721 + u_int32_t T1, T2, W[64], Wm2, Wm15;
1723 + /* read the data, big endian byte order */
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]));
1729 + } while(++j < 16);
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];
1741 + /* apply compression function */
1747 + W[j] = lSig1(Wm2) + W[j - 7] + lSig0(Wm15) + W[j - 16];
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;
1753 + d = c; c = b; b = a;
1755 + } while(++j < 64);
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;
1767 + ctx->sha_blocks++;
1770 +void sha256_write(sha256_context *ctx, unsigned char *datap, int length)
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);
1779 + if(!length) return;
1781 + ctx->sha_out[ctx->sha_bufCnt] = *datap++;
1783 + if(++ctx->sha_bufCnt == sizeof(ctx->sha_out)) {
1784 + sha256_transform(ctx, &ctx->sha_out[0]);
1785 + ctx->sha_bufCnt = 0;
1790 +void sha256_final(sha256_context *ctx)
1793 + u_int64_t bitLength;
1795 + unsigned char padByte, *datap;
1797 + bitLength = (ctx->sha_blocks << 9) | (ctx->sha_bufCnt << 3);
1799 + sha256_write(ctx, &padByte, 1);
1801 + /* pad extra space with zeroes */
1803 + while(ctx->sha_bufCnt != 56) {
1804 + sha256_write(ctx, &padByte, 1);
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]);
1818 + /* return results in ctx->sha_out[0...31] */
1819 + datap = &ctx->sha_out[0];
1822 + i = ctx->sha_H[j];
1823 + datap[0] = i >> 24;
1824 + datap[1] = i >> 16;
1825 + datap[2] = i >> 8;
1830 + /* clear sensitive information */
1831 + memset(&ctx->sha_out[32], 0, sizeof(sha256_context) - 32);
1834 +void sha256_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
1836 + sha256_context ctx;
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));
1850 +#if defined(SHA512_NEEDED)
1851 +void sha512_init(sha512_context *ctx)
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;
1860 +#if defined(SHA512_NEEDED) || defined(SHA384_NEEDED)
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))))
1872 +static void sha512_transform(sha512_context *ctx, unsigned char *datap)
1875 + u_int64_t a, b, c, d, e, f, g, h;
1876 + u_int64_t T1, T2, W[80], Wm2, Wm15;
1878 + /* read the data, big endian byte order */
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]));
1886 + } while(++j < 16);
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];
1898 + /* apply compression function */
1904 + W[j] = lSig1(Wm2) + W[j - 7] + lSig0(Wm15) + W[j - 16];
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;
1910 + d = c; c = b; b = a;
1912 + } while(++j < 80);
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;
1924 + ctx->sha_blocks++;
1925 + if(!ctx->sha_blocks) ctx->sha_blocksMSB++;
1928 +void sha512_write(sha512_context *ctx, unsigned char *datap, int length)
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);
1937 + if(!length) return;
1939 + ctx->sha_out[ctx->sha_bufCnt] = *datap++;
1941 + if(++ctx->sha_bufCnt == sizeof(ctx->sha_out)) {
1942 + sha512_transform(ctx, &ctx->sha_out[0]);
1943 + ctx->sha_bufCnt = 0;
1948 +void sha512_final(sha512_context *ctx)
1951 + u_int64_t bitLength, bitLengthMSB;
1953 + unsigned char padByte, *datap;
1955 + bitLength = (ctx->sha_blocks << 10) | (ctx->sha_bufCnt << 3);
1956 + bitLengthMSB = (ctx->sha_blocksMSB << 10) | (ctx->sha_blocks >> 54);
1958 + sha512_write(ctx, &padByte, 1);
1960 + /* pad extra space with zeroes */
1962 + while(ctx->sha_bufCnt != 112) {
1963 + sha512_write(ctx, &padByte, 1);
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]);
1985 + /* return results in ctx->sha_out[0...63] */
1986 + datap = &ctx->sha_out[0];
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;
2001 + /* clear sensitive information */
2002 + memset(&ctx->sha_out[64], 0, sizeof(sha512_context) - 64);
2005 +void sha512_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
2007 + sha512_context ctx;
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));
2020 +#if defined(SHA384_NEEDED)
2021 +void sha384_init(sha512_context *ctx)
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;
2029 +void sha384_hash_buffer(unsigned char *ib, int ile, unsigned char *ob, int ole)
2031 + sha512_context ctx;
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));
2043 Index: mount/sha512.h
2044 ===================================================================
2045 RCS file: mount/sha512.h
2046 diff -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
2053 + * Written by Jari Ruusu, April 16 2001
2055 + * Copyright 2001 by Jari Ruusu.
2056 + * Redistribution of this file is permitted under the GNU Public License.
2059 +#include <sys/types.h>
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;
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;
2076 +/* no sha384_context, use sha512_context */
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);
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);
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);
2095 Index: mount/sundries.c
2096 ===================================================================
2097 RCS file: /cvsroot/cryptoapi/util-linux/mount/sundries.c,v
2098 retrieving revision 1.1.1.1
2099 retrieving revision 1.1.1.1.2.1
2100 diff -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
2107 - if (!strncmp(types, "no", 2)) {
2108 + if (types && !strncmp(types, "no", 2)) {