aboutsummaryrefslogtreecommitdiff
path: root/src/libmbedcrypto.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/libmbedcrypto.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/libmbedcrypto.c')
-rw-r--r--src/libmbedcrypto.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/libmbedcrypto.c b/src/libmbedcrypto.c
index 03281f47..10a35270 100644
--- a/src/libmbedcrypto.c
+++ b/src/libmbedcrypto.c
@@ -34,6 +34,7 @@ struct ssh_mac_ctx_struct {
enum ssh_mac_e mac_type;
mbedtls_md_context_t ctx;
};
+static int libmbedcrypto_initialized = 0;
void ssh_reseed(void)
{
@@ -947,11 +948,15 @@ struct ssh_cipher_struct *ssh_get_ciphertab(void)
return ssh_ciphertab;
}
-void ssh_mbedtls_init(void)
+int ssh_crypto_init(void)
{
size_t i;
int rc;
+ if (libmbedcrypto_initialized) {
+ return SSH_OK;
+ }
+
mbedtls_entropy_init(&ssh_mbedtls_entropy);
mbedtls_ctr_drbg_init(&ssh_mbedtls_ctr_drbg);
@@ -972,6 +977,10 @@ void ssh_mbedtls_init(void)
break;
}
}
+
+ libmbedcrypto_initialized = 1;
+
+ return SSH_OK;
}
int ssh_mbedtls_random(void *where, int len, int strong)
@@ -990,10 +999,16 @@ int ssh_mbedtls_random(void *where, int len, int strong)
return !rc;
}
-void ssh_mbedtls_cleanup(void)
+void ssh_crypto_finalize(void)
{
+ if (!libmbedcrypto_initialized) {
+ return;
+ }
+
mbedtls_ctr_drbg_free(&ssh_mbedtls_ctr_drbg);
mbedtls_entropy_free(&ssh_mbedtls_entropy);
+
+ libmbedcrypto_initialized = 0;
}
#endif /* HAVE_LIBMBEDCRYPTO */