--- util-linux-2.12/mount/lomount.c-fixed-key-size 2003-07-16 19:56:53.000000000 -0400 +++ util-linux-2.12/mount/lomount.c 2003-09-16 23:48:26.000000000 -0400 @@ -24,12 +24,15 @@ #include #include #include +#include #include #include +#include #include #include #include #include +#include #include "loop.h" #include "lomount.h" @@ -275,9 +278,38 @@ if (digits_only(encryption)) { loopinfo64.lo_encrypt_type = atoi(encryption); } else { + regex_t keysize_re; + regmatch_t keysize_rm; + int rerror; + char rerror_buf[LINE_MAX+1], + *encryption_dup = xstrdup(encryption); + loopinfo64.lo_encrypt_type = LO_CRYPT_CRYPTOAPI; + + if ((rerror = regcomp(&keysize_re, "-[[:digit:]]+$", + REG_EXTENDED)) != 0) { + fprintf(stderr, _("RE error: ")); + regerror(rerror, &keysize_re, rerror_buf, LINE_MAX); + fprintf(stderr, "%s\n", rerror_buf); + return -1; + } else if (regexec(&keysize_re, encryption_dup, + 1, &keysize_rm, 0) != 0) { + fprintf(stderr, + _("You must specify a key size (in bits) " + "for use with CryptoAPI encryption.\n")); + regfree(&keysize_re); + return -1; + } + regfree(&keysize_re); + + /* convert the key size from #bits to #bytes */ + loopinfo64.lo_encrypt_key_size = + atoi(encryption_dup + keysize_rm.rm_so + 1) / 8; + /* now cut off the key size */ + encryption_dup[keysize_rm.rm_so] = '\0'; snprintf(loopinfo64.lo_crypt_name, LO_NAME_SIZE, - "%s", encryption); + "%s", encryption_dup); + free(encryption_dup); } } @@ -309,7 +341,6 @@ default: pass = xgetpass(pfd, _("Password: ")); xstrncpy(loopinfo64.lo_encrypt_key, pass, LO_KEY_SIZE); - loopinfo64.lo_encrypt_key_size = LO_KEY_SIZE; } if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {