Convert hash name to lower case for compatibility reasons.
authorMilan Broz <gmazyland@gmail.com>
Sun, 10 Jan 2010 20:40:59 +0000 (20:40 +0000)
committerMilan Broz <gmazyland@gmail.com>
Sun, 10 Jan 2010 20:40:59 +0000 (20:40 +0000)
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@173 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
luks/keymanage.c

index 01568f3..a4c78fd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-01-10  Milan Broz  <mbroz@redhat.com>
+       * Fix initialisation of gcrypt duting luksFormat.
+       * Convert hash name to lower case in header (fix sha1 backward comatible header)
+
 2009-12-30  Milan Broz  <mbroz@redhat.com>
        * Fix key slot iteration count calculation (small -i value was the same as default).
        * The slot and key digest iteration minimun is now 1000.
index 729944d..f6ffa25 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "luks.h"
 #include "af.h"
@@ -277,6 +278,20 @@ static int _check_and_convert_hdr(const char *device,
        return r;
 }
 
+static void _to_lower(char *str)
+{
+       for(; *str; str++)
+               if (isupper(*str))
+                       *str = tolower(*str);
+}
+
+static void LUKS_fix_header_compatible(struct luks_phdr *header)
+{
+       /* Old cryptsetup expects "sha1", gcrypt allows case insensistive names,
+        * so always convert hash to lower case in header */
+       _to_lower(header->hashSpec);
+}
+
 int LUKS_read_phdr_backup(const char *backup_file,
                          const char *device,
                          struct luks_phdr *hdr,
@@ -296,8 +311,10 @@ int LUKS_read_phdr_backup(const char *backup_file,
 
        if(read(devfd, hdr, sizeof(struct luks_phdr)) < sizeof(struct luks_phdr))
                r = -EIO;
-       else
+       else {
+               LUKS_fix_header_compatible(hdr);
                r = _check_and_convert_hdr(backup_file, hdr, require_luks_device, ctx);
+       }
 
        close(devfd);
        return r;
@@ -430,6 +447,8 @@ int LUKS_generate_phdr(struct luks_phdr *header,
 
        header->keyBytes=mk->keyLength;
 
+       LUKS_fix_header_compatible(header);
+
        log_dbg("Generating LUKS header version %d using hash %s, %s, %s, MK %d bytes",
                header->version, header->hashSpec ,header->cipherName, header->cipherMode,
                header->keyBytes);