Index: mount/lomount.c
===================================================================
RCS file: /cvsroot/kerneli/util-linux/mount/lomount.c,v
retrieving revision 1.1.1.2.2.1
diff -u -r1.1.1.2.2.1 lomount.c
--- mount/lomount.c	6 Jan 2003 20:59:33 -0000	1.1.1.2.2.1
+++ mount/lomount.c	6 Feb 2003 12:45:59 -0000
@@ -299,7 +299,7 @@
 	  const char *encryption, int pfd, int keysz, int *loopro, 
 	  const char *phash_name, const char *blockmode) {
 	struct loop_info loopinfo;
-	int fd, ffd, mode, tried_old;
+	int fd, ffd, mode;
 
 	mode = (*loopro ? O_RDONLY : O_RDWR);
 	if ((ffd = open (file, mode)) < 0) {
@@ -341,24 +341,24 @@
 		return 1;
 	}
 
-	tried_old = 0;
-again:
 	set_loop_passwd(&loopinfo, pfd, keysz, phash_name, encryption, fd, ffd);
 
 	if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
 		/* Try again with old-style LO_CRYPT_XX if
                    new-style LO_CRYPT_CRYPTOAPI ioctl didn't work */
-		if (tried_old) {
+		strncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
+		loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
+		loopinfo.lo_encrypt_type = name_to_id (encryption);
+
+		set_loop_passwd(&loopinfo, pfd, keysz, phash_name, encryption, fd, ffd);
+
+		if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
 			error("The cipher does not exist, or a cipher module "
 			      "needs to be loaded into the kernel");
 			perror ("ioctl: LOOP_SET_STATUS");
-			goto out_ioctl;
+			(void) ioctl (fd, LOOP_CLR_FD, 0);
+			return 1;
 		}
-		strncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
-		loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
-		loopinfo.lo_encrypt_type = name_to_id (encryption);
-		tried_old = 1;
-		goto again;
 	}
 	close (fd);
 	close (ffd);
@@ -366,9 +366,6 @@
 		printf(_("set_loop(%s,%s,%d): success\n"),
 		       device, file, offset);
 	return 0;
-out_ioctl:
-	(void) ioctl (fd, LOOP_CLR_FD, 0);
-	return 1;
 }
 
 
@@ -785,7 +782,78 @@
 #endif
 #endif
 
-static int get_cipher_info(const char *name, struct cipher_info *res)
+
+static int get_cipher_info25(const char *requested_cipher, struct cipher_info *res)
+{
+//	char path[PATH_MAX];
+#define BUFFER_SIZE 2000
+	char buf[BUFFER_SIZE];
+	int eof=0;
+	char name[BUFFER_SIZE];
+	int minkey, maxkey;
+	int j;
+	FILE *f;
+	struct {
+		char *string;
+		int *integer;
+		const char *prefix;
+	} fields[] = {{name, NULL, "name         : "},
+		      {NULL, NULL, "module       : "},
+		      {NULL, &res->blocksize, "blocksize    : "},
+		      {NULL, &minkey, "min keysize  : "},
+		      {NULL, &maxkey, "max keysize  : "},
+		      {NULL, &res->ivsize, "ivsize       : "},
+		      {NULL, NULL, "digestsize   : "}};
+	f = fopen("/proc/crypto", "r");
+	
+	if(!f)
+		return -1;
+
+	// CryptoAPI 2.5 doesn't use <name>-<blockmode>, so cut it off
+	if(rindex(requested_cipher,'-') != NULL)
+		*rindex(requested_cipher,'-') = 0;
+
+	// Outer loop searches the requested cipher
+	while(!eof)
+	{	
+		// Inner loop parses individual crypto entries
+		while(!(eof = (fgets(buf, sizeof(buf), f) == NULL))) {
+			int i;
+			for (i = 0; i < sizeof(fields)/sizeof(fields[0]); i++) {
+				int len = strlen(fields[i].prefix);
+				if (strncmp(buf, fields[i].prefix, len) == 0) {
+					if(fields[i].string != NULL)
+					{
+						int slen = strlen(buf+len)-1;
+						strncpy(fields[i].string,buf+len,slen<BUFFER_SIZE?slen:BUFFER_SIZE);
+						fields[i].string[slen<BUFFER_SIZE?slen:BUFFER_SIZE]=0;
+					}
+					if(fields[i].integer != NULL)
+						*fields[i].integer = strtoul(&buf[len], NULL, 0);
+					break;
+				}
+			}
+
+			// No prefix found? Empty line?
+			if(buf[0] == 0xA)
+				break; 
+
+		}
+		if(strcmp(name,requested_cipher) == 0) break;	
+	}
+	if (eof) 		// Cipher not found
+		return -1;
+
+	res->key_schedule_size = 0;
+
+	// convert keysize mask
+	res->keysize_mask = 0;
+	for(j=minkey-1; j < maxkey; j++)
+		res->keysize_mask = res->keysize_mask | (1 << j);
+	return 0;
+}
+
+static int get_cipher_info24(const char *name, struct cipher_info *res)
 {
 	char path[PATH_MAX];
 	char buf[2000];
@@ -815,6 +883,16 @@
 	return 0;
 }
 
+static int get_cipher_info(const char *name, struct cipher_info *res)
+{
+	int ret;
+	ret = get_cipher_info25(name, res);
+	if(ret == -1)
+		return get_cipher_info24(name,res);	// Fallback to 2.4.x
+	else
+		return ret;
+
+}
 
 static int 
 name_to_id(const char *name) 
