fixed setting of variable key length

This commit is contained in:
Andreas Steffen
2009-05-14 13:55:56 +02:00
parent 6e0ff31e07
commit 24400cf617
@@ -131,10 +131,12 @@ static void crypt(private_openssl_crypter_t *this, chunk_t data,
} }
EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx); EVP_CIPHER_CTX_init(&ctx);
EVP_CipherInit_ex(&ctx, this->cipher, NULL, this->key.ptr, iv.ptr, enc); 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_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);
EVP_CipherFinal_ex(&ctx, out, &len); /* since padding is disabled this does nothing */ EVP_CipherFinal_ex(&ctx, out + len, &len); /* since padding is disabled this does nothing */
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_cleanup(&ctx);
} }