openssl: Update crypter API to OpenSSL 1.1.0

EVP_CIPHER and EVP_CIPHER_CTX are now opaque types, the getters already
existed before.
This commit is contained in:
Tobias Brunner
2016-06-29 11:09:37 +02:00
parent faa904fb0b
commit 1b36fbedf5
@@ -93,8 +93,10 @@ static char* lookup_algorithm(uint16_t ikev2_algo, size_t *key_size)
static bool crypt(private_openssl_crypter_t *this, chunk_t data, chunk_t iv, static bool crypt(private_openssl_crypter_t *this, chunk_t data, chunk_t iv,
chunk_t *dst, int enc) chunk_t *dst, int enc)
{ {
EVP_CIPHER_CTX *ctx;
int len; int len;
u_char *out; u_char *out;
bool success = FALSE;
out = data.ptr; out = data.ptr;
if (dst) if (dst)
@@ -102,16 +104,19 @@ static bool crypt(private_openssl_crypter_t *this, chunk_t data, chunk_t iv,
*dst = chunk_alloc(data.len); *dst = chunk_alloc(data.len);
out = dst->ptr; out = dst->ptr;
} }
EVP_CIPHER_CTX ctx; ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_init(&ctx); if (EVP_CipherInit_ex(ctx, this->cipher, NULL, NULL, NULL, enc) &&
return EVP_CipherInit_ex(&ctx, this->cipher, NULL, NULL, NULL, enc) && EVP_CIPHER_CTX_set_padding(ctx, 0) /* disable padding */ &&
EVP_CIPHER_CTX_set_padding(&ctx, 0) /* disable padding */ && EVP_CIPHER_CTX_set_key_length(ctx, this->key.len) &&
EVP_CIPHER_CTX_set_key_length(&ctx, this->key.len) && EVP_CipherInit_ex(ctx, NULL, NULL, this->key.ptr, iv.ptr, enc) &&
EVP_CipherInit_ex(&ctx, NULL, NULL, this->key.ptr, iv.ptr, enc) && EVP_CipherUpdate(ctx, out, &len, data.ptr, data.len) &&
EVP_CipherUpdate(&ctx, out, &len, data.ptr, data.len) && /* since padding is disabled this does nothing */
/* since padding is disabled this does nothing */ EVP_CipherFinal_ex(ctx, out + len, &len))
EVP_CipherFinal_ex(&ctx, out + len, &len) && {
EVP_CIPHER_CTX_cleanup(&ctx); success = TRUE;
}
EVP_CIPHER_CTX_free(ctx);
return success;
} }
METHOD(crypter_t, decrypt, bool, METHOD(crypter_t, decrypt, bool,
@@ -129,13 +134,13 @@ METHOD(crypter_t, encrypt, bool,
METHOD(crypter_t, get_block_size, size_t, METHOD(crypter_t, get_block_size, size_t,
private_openssl_crypter_t *this) private_openssl_crypter_t *this)
{ {
return this->cipher->block_size; return EVP_CIPHER_block_size(this->cipher);
} }
METHOD(crypter_t, get_iv_size, size_t, METHOD(crypter_t, get_iv_size, size_t,
private_openssl_crypter_t *this) private_openssl_crypter_t *this)
{ {
return this->cipher->iv_len; return EVP_CIPHER_iv_length(this->cipher);
} }
METHOD(crypter_t, get_key_size, size_t, METHOD(crypter_t, get_key_size, size_t,