23 #include <netcomm/crypto/encrypt.h> 24 #include <core/exceptions/software.h> 27 # include <openssl/evp.h> 88 plain_buffer_length = 0;
90 crypt_buffer_length = 0;
113 plain_buffer = buffer;
114 plain_buffer_length = buffer_length;
133 if ( plain_buffer_length == 0 ) {
137 #ifdef HAVE_LIBCRYPTO 138 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
139 EVP_EncryptInit(ctx, EVP_aes_128_ecb(), key, iv);
140 size_t rv = plain_buffer_length + EVP_CIPHER_CTX_block_size(ctx);
141 EVP_CIPHER_CTX_free(ctx);
144 return plain_buffer_length;
157 crypt_buffer = buffer;
158 crypt_buffer_length = buffer_length;
169 if ( (plain_buffer == NULL) || (plain_buffer_length == 0) ||
170 (crypt_buffer == NULL) || (crypt_buffer_length == 0) ) {
174 #ifdef HAVE_LIBCRYPTO 175 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
176 if ( ! EVP_EncryptInit(ctx, EVP_aes_128_ecb(), key, iv) ) {
177 EVP_CIPHER_CTX_free(ctx);
182 int outl = crypt_buffer_length;
183 if ( ! EVP_EncryptUpdate(ctx,
184 (
unsigned char *)crypt_buffer, &outl,
185 (
unsigned char *)plain_buffer, plain_buffer_length) ) {
186 EVP_CIPHER_CTX_free(ctx);
191 if ( ! EVP_EncryptFinal_ex(ctx, (
unsigned char *)crypt_buffer + outl, &plen) ) {
192 EVP_CIPHER_CTX_free(ctx);
197 EVP_CIPHER_CTX_free(ctx);
204 throw Exception(
"Encryption support not available");
size_t recommended_crypt_buffer_size()
Get recommended crypted buffer size.
Fawkes library namespace.
Exception()
Constructor for subclasses.
MessageEncryptor(const unsigned char *key, const unsigned char *iv)
Constructor.
Base class for exceptions in Fawkes.
void set_plain_buffer(void *buffer, size_t buffer_length)
Set plain buffer.
void set_crypt_buffer(void *buffer, size_t buffer_length)
Set crypted buffer.
~MessageEncryptor()
Empty destructor.
MessageEncryptionException(const char *msg)
Constructor.
Expected parameter is missing.