23 #include <core/exceptions/software.h> 24 #include <netcomm/crypto/decrypt.h> 26 # include <openssl/evp.h> 73 plain_buffer_length = 0;
75 crypt_buffer_length = 0;
96 plain_buffer = buffer;
97 plain_buffer_length = buffer_length;
109 crypt_buffer = buffer;
110 crypt_buffer_length = buffer_length;
121 if ( (plain_buffer == NULL) || (plain_buffer_length == 0) ||
122 (crypt_buffer == NULL) || (crypt_buffer_length == 0) ) {
126 #ifdef HAVE_LIBCRYPTO 127 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
128 if ( ! EVP_DecryptInit(ctx, EVP_aes_128_ecb(), key, iv) ) {
129 EVP_CIPHER_CTX_free(ctx);
133 int outl = plain_buffer_length;
134 if ( ! EVP_DecryptUpdate(ctx,
135 (
unsigned char *)plain_buffer, &outl,
136 (
unsigned char *)crypt_buffer, crypt_buffer_length) ) {
137 EVP_CIPHER_CTX_free(ctx);
142 if ( ! EVP_DecryptFinal(ctx, (
unsigned char *)plain_buffer + outl, &plen) ) {
143 EVP_CIPHER_CTX_free(ctx);
148 EVP_CIPHER_CTX_free(ctx);
154 throw Exception(
"Decryption support not available");
Fawkes library namespace.
Exception()
Constructor for subclasses.
void set_plain_buffer(void *buffer, size_t buffer_length)
Set plain buffer.
~MessageDecryptor()
Empty destructor.
Base class for exceptions in Fawkes.
MessageDecryptor(const unsigned char *key, const unsigned char *iv)
Constructor.
void set_crypt_buffer(void *buffer, size_t buffer_length)
Set crypted buffer.
MessageDecryptionException(const char *msg)
Constructor.
Expected parameter is missing.