mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-07 10:40:28 +09:00
crypto: Split init and finalize functions
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
38c53db953
commit
2b40ad29c0
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user