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

#include <aes.hpp>

Classes

struct  impl
 

Public Member Functions

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

Detailed Description

Definition at line 22 of file aes.hpp.

Member Function Documentation

◆ decode()

uint32_t fc::aes_decoder::decode ( const char * ciphertxt,
uint32_t len,
char * plaintext )

Definition at line 116 of file aes.cpp.

117{
118 int plaintext_len = 0;
119 /* Provide the message to be decrypted, and obtain the decrypted output.
120 * * EVP_DecryptUpdate can be called multiple times if necessary
121 * */
122 if (1 != EVP_DecryptUpdate(my->ctx, (unsigned char*)plaintext, &plaintext_len, (const unsigned char*)ciphertxt, ciphertxt_len))
123 {
124 FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc decryption update",
125 ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
126 }
127 FC_ASSERT( ciphertxt_len == static_cast<unsigned>(plaintext_len), "", ("ciphertxt_len",ciphertxt_len)("plaintext_len",plaintext_len) );
128 return plaintext_len;
129}
#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_decoder::init ( const fc::sha256 & key,
const fc::uint128 & init_value )

Definition at line 93 of file aes.cpp.

94{
95 my->ctx.obj = EVP_CIPHER_CTX_new();
96 /* Create and initialise the context */
97 if(!my->ctx)
98 {
99 FC_THROW_EXCEPTION( aes_exception, "error allocating evp cipher context",
100 ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
101 }
102
103 /* Initialise the encryption operation. IMPORTANT - ensure you use a key
104 * and IV size appropriate for your cipher
105 * In this example we are using 256 bit AES (i.e. a 256 bit key). The
106 * IV size for *most* modes is the same as the block size. For AES this
107 * is 128 bits */
108 if(1 != EVP_DecryptInit_ex(my->ctx, EVP_aes_256_cbc(), NULL, (unsigned char*)&key, (unsigned char*)&init_value))
109 {
110 FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc encryption init",
111 ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
112 }
113 EVP_CIPHER_CTX_set_padding( my->ctx, 0 );
114}

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