aboutsummaryrefslogtreecommitdiff
path: root/src/libcrypto.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2015-12-31 10:56:47 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-07-05 12:55:23 +0200
commit2b40ad29c02da4004dec3a0e51ea8cef4ebac01e (patch)
tree6f7754b58ac58ec92886a29c08ca7cff97d1d6fc /src/libcrypto.c
parent38c53db9533a3e0ac446ee0a83dac8768d282de9 (diff)
downloadlibssh-2b40ad29c02da4004dec3a0e51ea8cef4ebac01e.tar.gz
libssh-2b40ad29c02da4004dec3a0e51ea8cef4ebac01e.tar.xz
libssh-2b40ad29c02da4004dec3a0e51ea8cef4ebac01e.zip
crypto: Split init and finalize functions
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/libcrypto.c')
-rw-r--r--src/libcrypto.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/libcrypto.c b/src/libcrypto.c
index 846e37e1..b24a18f8 100644
--- a/src/libcrypto.c
+++ b/src/libcrypto.c
@@ -70,6 +70,8 @@ struct ssh_mac_ctx_struct {
} ctx;
};
+static int libcrypto_initialized = 0;
+
void ssh_reseed(void){
#ifndef _WIN32
struct timeval tv;
@@ -787,10 +789,25 @@ static struct ssh_cipher_struct ssh_ciphertab[] = {
}
};
-void libcrypto_init(void)
+struct ssh_cipher_struct *ssh_get_ciphertab(void)
+{
+ return ssh_ciphertab;
+}
+
+/**
+ * @internal
+ * @brief Initialize libcrypto's subsystem
+ */
+int ssh_crypto_init(void)
{
size_t i;
+ if (libcrypto_initialized) {
+ return SSH_OK;
+ }
+
+ OpenSSL_add_all_algorithms();
+
for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
int cmp;
@@ -802,11 +819,26 @@ void libcrypto_init(void)
break;
}
}
+
+ libcrypto_initialized = 1;
+
+ return SSH_OK;
}
-struct ssh_cipher_struct *ssh_get_ciphertab(void)
+/**
+ * @internal
+ * @brief Finalize libcrypto's subsystem
+ */
+void ssh_crypto_finalize(void)
{
- return ssh_ciphertab;
+ if (!libcrypto_initialized) {
+ return;
+ }
+
+ EVP_cleanup();
+ CRYPTO_cleanup_all_ex_data();
+
+ libcrypto_initialized = 0;
}
#endif /* LIBCRYPTO */