openssl: fix use of deprecated calls

This commit is contained in:
rdb 2017-05-25 21:34:02 +02:00
parent d6657baf29
commit 4bcf225baf
2 changed files with 14 additions and 5 deletions

View File

@ -236,7 +236,7 @@ open_write(ostream *dest, bool owns_dest, const string &password) {
// Generate a random IV. It doesn't need to be cryptographically secure, // Generate a random IV. It doesn't need to be cryptographically secure,
// just unique. // just unique.
unsigned char *iv = (unsigned char *)alloca(iv_length); unsigned char *iv = (unsigned char *)alloca(iv_length);
RAND_pseudo_bytes(iv, iv_length); RAND_bytes(iv, iv_length);
_write_ctx = EVP_CIPHER_CTX_new(); _write_ctx = EVP_CIPHER_CTX_new();
nassertv(_write_ctx != NULL); nassertv(_write_ctx != NULL);

View File

@ -108,16 +108,25 @@ output_c_string(ostream &out, const string &string_name,
*/ */
EVP_PKEY * EVP_PKEY *
generate_key() { generate_key() {
RSA *rsa = RSA_generate_key(1024, 7, NULL, NULL); RSA *rsa = RSA_new();
BIGNUM *e = BN_new();
if (rsa == (RSA *)NULL) { if (rsa == nullptr || e == nullptr) {
output_ssl_errors(); output_ssl_errors();
exit(1); exit(1);
} }
BN_set_word(e, 7);
if (!RSA_generate_key_ex(rsa, 1024, e, nullptr)) {
BN_free(e);
RSA_free(rsa);
output_ssl_errors();
exit(1);
}
BN_free(e);
EVP_PKEY *pkey = EVP_PKEY_new(); EVP_PKEY *pkey = EVP_PKEY_new();
EVP_PKEY_assign_RSA(pkey, rsa); EVP_PKEY_assign_RSA(pkey, rsa);
return pkey; return pkey;
} }