24 #include <core/exceptions/software.h>
25 #include <netcomm/worldinfo/encrypt.h>
28 # include <openssl/evp.h>
89 plain_buffer_length = 0;
91 crypt_buffer_length = 0;
114 plain_buffer = buffer;
115 plain_buffer_length = buffer_length;
134 if ( plain_buffer_length == 0 ) {
138 #ifdef HAVE_LIBCRYPTO
140 EVP_EncryptInit(&ctx, EVP_aes_128_ecb(), key, iv);
141 size_t rv = plain_buffer_length + EVP_CIPHER_CTX_block_size(&ctx);
142 EVP_CIPHER_CTX_cleanup(&ctx);
145 return plain_buffer_length;
158 crypt_buffer = buffer;
159 crypt_buffer_length = buffer_length;
170 if ( (plain_buffer == NULL) || (plain_buffer_length == 0) ||
171 (crypt_buffer == NULL) || (crypt_buffer_length == 0) ) {
175 #ifdef HAVE_LIBCRYPTO
177 if ( ! EVP_EncryptInit(&ctx, EVP_aes_128_ecb(), key, iv) ) {
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) ) {
190 if ( ! EVP_EncryptFinal_ex(&ctx, (
unsigned char *)crypt_buffer + outl, &plen) ) {
198 memcpy(crypt_buffer, plain_buffer, plain_buffer_length);
199 return plain_buffer_length;
size_t recommended_crypt_buffer_size()
Get recommended crypted buffer size.
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.
~WorldInfoMessageEncryptor()
Empty destructor.
Base class for exceptions in Fawkes.
WorldInfoMessageEncryptor(const unsigned char *key, const unsigned char *iv)
Constructor.
Message encryption failed.
MessageEncryptionException(const char *msg)
Constructor.
Expected parameter is missing.