Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::aes_encoder Class Reference

#include <aes.hpp>

Classes

struct  impl
 

Public Member Functions

void init (const fc::sha256 &key, const fc::uint128 &init_value)
 
uint32_t encode (const char *plaintxt, uint32_t len, char *ciphertxt)
 

Detailed Description

Definition at line 11 of file aes.hpp.

Member Function Documentation

◆ encode()

uint32_t fc::aes_encoder::encode ( const char * plaintxt,
uint32_t len,
char * ciphertxt )

Definition at line 57 of file aes.cpp.

58{
59 int ciphertext_len = 0;
60 /* Provide the message to be encrypted, and obtain the encrypted output.
61 * * EVP_EncryptUpdate can be called multiple times if necessary
62 * */
63 if(1 != EVP_EncryptUpdate(my->ctx, (unsigned char*)ciphertxt, &ciphertext_len, (const unsigned char*)plaintxt, plaintext_len))
64 {
65 FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc encryption update",
66 ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
67 }
68 FC_ASSERT( ciphertext_len == static_cast<int>(plaintext_len), "", ("ciphertext_len",ciphertext_len)("plaintext_len",plaintext_len) );
69 return ciphertext_len;
70}
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.

◆ init()

void fc::aes_encoder::init ( const fc::sha256 & key,
const fc::uint128 & init_value )

Definition at line 34 of file aes.cpp.

35{
36 my->ctx.obj = EVP_CIPHER_CTX_new();
37 /* Create and initialise the context */
38 if(!my->ctx)
39 {
40 FC_THROW_EXCEPTION( aes_exception, "error allocating evp cipher context",
41 ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
42 }
43
44 /* Initialise the encryption operation. IMPORTANT - ensure you use a key
45 * and IV size appropriate for your cipher
46 * In this example we are using 256 bit AES (i.e. a 256 bit key). The
47 * IV size for *most* modes is the same as the block size. For AES this
48 * is 128 bits */
49 if(1 != EVP_EncryptInit_ex(my->ctx, EVP_aes_256_cbc(), NULL, (unsigned char*)&key, (unsigned char*)&init_value))
50 {
51 FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc encryption init",
52 ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
53 }
54 EVP_CIPHER_CTX_set_padding( my->ctx, 0 );
55}

The documentation for this class was generated from the following files: