23 #include <core/exceptions/software.h>
24 #include <netcomm/crypto/decrypt.h>
26 # include <openssl/evp.h>
70 plain_buffer_length = 0;
72 crypt_buffer_length = 0;
91 plain_buffer = buffer;
92 plain_buffer_length = buffer_length;
103 crypt_buffer = buffer;
104 crypt_buffer_length = buffer_length;
114 if ((plain_buffer == NULL) || (plain_buffer_length == 0) || (crypt_buffer == NULL)
115 || (crypt_buffer_length == 0)) {
119 #ifdef HAVE_LIBCRYPTO
120 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
121 if (!EVP_DecryptInit(ctx, EVP_aes_128_ecb(), key, iv)) {
122 EVP_CIPHER_CTX_free(ctx);
126 int outl = plain_buffer_length;
127 if (!EVP_DecryptUpdate(ctx,
128 (
unsigned char *)plain_buffer,
130 (
unsigned char *)crypt_buffer,
131 crypt_buffer_length)) {
132 EVP_CIPHER_CTX_free(ctx);
137 if (!EVP_DecryptFinal(ctx, (
unsigned char *)plain_buffer + outl, &plen)) {
138 EVP_CIPHER_CTX_free(ctx);
143 EVP_CIPHER_CTX_free(ctx);
149 throw Exception(
"Decryption support not available");