diff --git a/lib/crypto_backend/crypto_backend.h b/lib/crypto_backend/crypto_backend.h index 93cdd7e9..3e759461 100644 --- a/lib/crypto_backend/crypto_backend.h +++ b/lib/crypto_backend/crypto_backend.h @@ -31,6 +31,7 @@ struct crypt_cipher; struct crypt_storage; int crypt_backend_init(struct crypt_device *ctx); +void crypt_backend_destroy(void); #define CRYPT_BACKEND_KERNEL (1 << 0) /* Crypto uses kernel part, for benchmark */ diff --git a/lib/crypto_backend/crypto_gcrypt.c b/lib/crypto_backend/crypto_gcrypt.c index dde11161..a7b0e4f0 100644 --- a/lib/crypto_backend/crypto_gcrypt.c +++ b/lib/crypto_backend/crypto_gcrypt.c @@ -121,6 +121,14 @@ int crypt_backend_init(struct crypt_device *ctx) return 0; } +void crypt_backend_destroy(void) +{ + if (crypto_backend_initialised) + gcry_control(GCRYCTL_TERM_SECMEM); + + crypto_backend_initialised = 0; +} + const char *crypt_backend_version(void) { return crypto_backend_initialised ? version : ""; diff --git a/lib/crypto_backend/crypto_kernel.c b/lib/crypto_backend/crypto_kernel.c index 2fe1c301..652eed44 100644 --- a/lib/crypto_backend/crypto_kernel.c +++ b/lib/crypto_backend/crypto_kernel.c @@ -38,7 +38,7 @@ #endif static int crypto_backend_initialised = 0; -static char version[64]; +static char version[256]; struct hash_alg { const char *name; @@ -126,6 +126,11 @@ int crypt_backend_init(struct crypt_device *ctx) return 0; } +void crypt_backend_destroy(void) +{ + crypto_backend_initialised = 0; +} + uint32_t crypt_backend_flags(void) { return CRYPT_BACKEND_KERNEL; diff --git a/lib/crypto_backend/crypto_nettle.c b/lib/crypto_backend/crypto_nettle.c index 7aa00458..5b877d8e 100644 --- a/lib/crypto_backend/crypto_nettle.c +++ b/lib/crypto_backend/crypto_nettle.c @@ -143,6 +143,11 @@ int crypt_backend_init(struct crypt_device *ctx) return 0; } +void crypt_backend_destroy(void) +{ + return; +} + const char *crypt_backend_version(void) { return version; diff --git a/lib/crypto_backend/crypto_nss.c b/lib/crypto_backend/crypto_nss.c index 15a8f74f..94eff27b 100644 --- a/lib/crypto_backend/crypto_nss.c +++ b/lib/crypto_backend/crypto_nss.c @@ -88,6 +88,11 @@ int crypt_backend_init(struct crypt_device *ctx) return 0; } +void crypt_backend_destroy(void) +{ + crypto_backend_initialised = 0; +} + uint32_t crypt_backend_flags(void) { return 0; diff --git a/lib/crypto_backend/crypto_openssl.c b/lib/crypto_backend/crypto_openssl.c index 7bfc842a..db08a5d7 100644 --- a/lib/crypto_backend/crypto_openssl.c +++ b/lib/crypto_backend/crypto_openssl.c @@ -116,6 +116,11 @@ int crypt_backend_init(struct crypt_device *ctx) return 0; } +void crypt_backend_destroy(void) +{ + crypto_backend_initialised = 0; +} + uint32_t crypt_backend_flags(void) { return 0; diff --git a/lib/setup.c b/lib/setup.c index eb1d2637..b38721bf 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -3062,3 +3062,8 @@ int crypt_get_integrity_info(struct crypt_device *cd, return -ENOTSUP; } + +static void __attribute__((destructor)) libcryptsetup_exit(void) +{ + crypt_backend_destroy(); +}