Initialize crypto library before LUKS header load.
authorMilan Broz <gmazyland@gmail.com>
Tue, 15 Sep 2009 15:10:23 +0000 (15:10 +0000)
committerMilan Broz <gmazyland@gmail.com>
Tue, 15 Sep 2009 15:10:23 +0000 (15:10 +0000)
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@111 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/gcrypt.c
lib/internal.h
lib/setup.c
luks/pbkdf.c

index 091ff46..bbcd624 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-09-15  Milan Broz  <mbroz@redhat.com>
+       * Initialize crypto library before LUKS header load.
+
 2009-09-10  Milan Broz  <mbroz@redhat.com>
        * Clean up Makefiles and configure script.
        * Version 1.1.0-test0.
index 0d6099c..0971daf 100644 (file)
@@ -9,6 +9,20 @@
 #define MAX_DIGESTS            64
 #define GCRYPT_REQ_VERSION     "1.1.42"
 
+int init_crypto(void)
+{
+       if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
+               //if (!gcry_check_version (GCRYPT_VERSION))
+               //      return -ENOSYS;
+               gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
+               gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
+               gcry_control (GCRYCTL_RESUME_SECMEM_WARN);
+               gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+       }
+
+       return 0;
+}
+
 static int gcrypt_hash(void *data, int size, char *key,
                        int sizep, const char *passphrase)
 {
index bf0e5fb..55a7bc0 100644 (file)
@@ -58,6 +58,7 @@ void *safe_realloc(void *data, size_t size);
 char *safe_strdup(const char *s);
 void set_debug_level(int level);
 
+int init_crypto(void);
 struct hash_backend *get_hash_backend(const char *name);
 void put_hash_backend(struct hash_backend *backend);
 int hash(const char *backend_name, const char *hash_name,
index add1bfb..e623c6a 100644 (file)
@@ -1108,6 +1108,12 @@ int crypt_load(struct crypt_device *cd,
        if (requested_type && !isPLAIN(requested_type) && !isLUKS(requested_type))
                return -EINVAL;
 
+       /* Some hash functions need initialized gcrypt library */
+       if (init_crypto()) {
+               log_err(cd, _("Cannot initialize crypto backend.\n"));
+               return -ENOSYS;
+       }
+
        r = LUKS_read_phdr(cd->device, &hdr, 0, cd);
 
        if (!r) {
index 15c2de1..fa1f720 100644 (file)
 static volatile uint64_t __PBKDF2_global_j = 0;
 static volatile uint64_t __PBKDF2_performance = 0;
 
-static int init_crypto(void)
-{
-       if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
-               //if (!gcry_check_version (GCRYPT_VERSION))
-               //      return -ENOSYS;
-               gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
-               gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
-               gcry_control (GCRYCTL_RESUME_SECMEM_WARN);
-               gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
-       }
-
-       return 0;
-}
+int init_crypto(void);
 
 /*
  * 5.2 PBKDF2