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); rc = mbedtls_ctr_drbg_seed(&ssh_mbedtls_ctr_drbg, mbedtls_entropy_func, &ssh_mbedtls_entropy, NULL, 0); if (rc != 0) { mbedtls_ctr_drbg_free(&ssh_mbedtls_ctr_drbg); } for (i = 0; ssh_ciphertab[i].name != NULL; i++) { int cmp; cmp = strcmp(ssh_ciphertab[i].name, "*****@*****.**"); if (cmp == 0) { memcpy(&ssh_ciphertab[i], ssh_get_chacha20poly1305_cipher(), sizeof(struct ssh_cipher_struct)); break; } } libmbedcrypto_initialized = 1; return SSH_OK; }
/** * @internal * @brief Initialize libcrypto's subsystem */ int ssh_crypto_init(void) { size_t i; if (libcrypto_initialized) { return SSH_OK; } if (SSLeay() != OPENSSL_VERSION_NUMBER){ SSH_LOG(SSH_LOG_WARNING, "libssh compiled with %s " "headers, currently running with %s.", OPENSSL_VERSION_TEXT, SSLeay_version(SSLeay()) ); } #ifdef CAN_DISABLE_AESNI /* * disable AES-NI when running within Valgrind, because they generate * too many "uninitialized memory access" false positives */ if (RUNNING_ON_VALGRIND){ SSH_LOG(SSH_LOG_INFO, "Running within Valgrind, disabling AES-NI"); /* Bit #57 denotes AES-NI instruction set extension */ OPENSSL_ia32cap &= ~(1LL << 57); } #endif #if OPENSSL_VERSION_NUMBER < 0x10100000L OpenSSL_add_all_algorithms(); #endif for (i = 0; ssh_ciphertab[i].name != NULL; i++) { int cmp; cmp = strcmp(ssh_ciphertab[i].name, "*****@*****.**"); if (cmp == 0) { memcpy(&ssh_ciphertab[i], ssh_get_chacha20poly1305_cipher(), sizeof(struct ssh_cipher_struct)); break; } } libcrypto_initialized = 1; return SSH_OK; }
/** * @internal * * @brief Initialize libgcrypt's subsystem */ int ssh_crypto_init(void) { size_t i; if (libgcrypt_initialized) { return SSH_OK; } gcry_check_version(NULL); /* While the secure memory is not set up */ gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P, 0)) { gcry_control(GCRYCTL_INIT_SECMEM, 4096); gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); } /* Re-enable warning */ gcry_control (GCRYCTL_RESUME_SECMEM_WARN); for (i = 0; ssh_ciphertab[i].name != NULL; i++) { int cmp; cmp = strcmp(ssh_ciphertab[i].name, "*****@*****.**"); if (cmp == 0) { memcpy(&ssh_ciphertab[i], ssh_get_chacha20poly1305_cipher(), sizeof(struct ssh_cipher_struct)); break; } } libgcrypt_initialized = 1; return SSH_OK; }