From 935e83ebfa7abbe2841e7f4572373bb3072d0cc5 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Tue, 15 Sep 2009 15:10:23 +0000 Subject: [PATCH] Initialize crypto library before LUKS header load. git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@111 36d66b0a-2a48-0410-832c-cd162a569da5 --- ChangeLog | 3 +++ lib/gcrypt.c | 14 ++++++++++++++ lib/internal.h | 1 + lib/setup.c | 6 ++++++ luks/pbkdf.c | 14 +------------- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 091ff46..bbcd624 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-09-15 Milan Broz + * Initialize crypto library before LUKS header load. + 2009-09-10 Milan Broz * Clean up Makefiles and configure script. * Version 1.1.0-test0. diff --git a/lib/gcrypt.c b/lib/gcrypt.c index 0d6099c..0971daf 100644 --- a/lib/gcrypt.c +++ b/lib/gcrypt.c @@ -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) { diff --git a/lib/internal.h b/lib/internal.h index bf0e5fb..55a7bc0 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -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, diff --git a/lib/setup.c b/lib/setup.c index add1bfb..e623c6a 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -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) { diff --git a/luks/pbkdf.c b/luks/pbkdf.c index 15c2de1..fa1f720 100644 --- a/luks/pbkdf.c +++ b/luks/pbkdf.c @@ -32,19 +32,7 @@ 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 -- 2.7.4