MySQL 8.3.0
Source Code Documentation
my_aes_openssl.cc File Reference
#include <assert.h>
#include <openssl/aes.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include "m_string.h"
#include "my_aes.h"
#include "my_aes_impl.h"
#include "mysys/my_kdf.h"

Functions

int dummy_function_needed_by_xplugin ()
 
static const EVP_CIPHER * aes_evp_type (const my_aes_opmode mode)
 
int my_create_key (unsigned char *rkey, const unsigned char *key, uint32 key_length, enum my_aes_opmode mode, vector< string > *kdf_options)
 Creates required length of AES key, Input key size can be smaller or bigger in length, we need exact AES key size. More...
 
int my_aes_encrypt (const unsigned char *source, uint32 source_length, unsigned char *dest, const unsigned char *key, uint32 key_length, enum my_aes_opmode mode, const unsigned char *iv, bool padding, vector< string > *kdf_options)
 Encrypt a buffer using AES. More...
 
int my_aes_decrypt (const unsigned char *source, uint32 source_length, unsigned char *dest, const unsigned char *key, uint32 key_length, enum my_aes_opmode mode, const unsigned char *iv, bool padding, vector< string > *kdf_options)
 Decrypt an AES encrypted buffer. More...
 
longlong my_aes_get_size (uint32 source_length, my_aes_opmode opmode)
 Calculate the size of a buffer large enough for encrypted data. More...
 
bool my_aes_needs_iv (my_aes_opmode opmode)
 Return true if the AES cipher and block mode requires an IV. More...
 

Variables

const char * my_aes_opmode_names []
 String representations of the supported AES modes. More...
 
static uint my_aes_opmode_key_sizes_impl []
 
uint * my_aes_opmode_key_sizes = my_aes_opmode_key_sizes_impl
 

Function Documentation

◆ aes_evp_type()

static const EVP_CIPHER * aes_evp_type ( const my_aes_opmode  mode)
static

◆ dummy_function_needed_by_xplugin()

int dummy_function_needed_by_xplugin ( )

◆ my_aes_decrypt()

int my_aes_decrypt ( const unsigned char *  source,
uint32  source_length,
unsigned char *  dest,
const unsigned char *  key,
uint32  key_length,
enum my_aes_opmode  mode,
const unsigned char *  iv,
bool  padding = true,
vector< string > *  kdf_options = nullptr 
)

Decrypt an AES encrypted buffer.

Parameters
sourcePointer to data for decryption
source_lengthsize of encrypted data
destbuffer to place decrypted data (must be large enough)
keyKey to be used for decryption
key_lengthLength of the key. Will handle keys of any length
modeencryption mode
iv16 bytes initialization vector if needed. Otherwise NULL
paddingif padding needed.
kdf_optionsKDF options
Returns
size of original data.

◆ my_aes_encrypt()

int my_aes_encrypt ( const unsigned char *  source,
uint32  source_length,
unsigned char *  dest,
const unsigned char *  key,
uint32  key_length,
enum my_aes_opmode  mode,
const unsigned char *  iv,
bool  padding = true,
vector< string > *  kdf_options = nullptr 
)

Encrypt a buffer using AES.

Parameters
[in]sourcePointer to data for encryption
[in]source_lengthSize of encryption data
[out]destBuffer to place encrypted data (must be large enough and not overlap with source)
[in]keyKey to be used for encryption
[in]key_lengthLength of the key. Will handle keys of any length
[in]modeencryption mode
[in]iv16 bytes initialization vector if needed. Otherwise NULL
[in]paddingif padding needed.
kdf_optionsKDF options
Returns
size of encrypted data, or negative in case of error

◆ my_aes_get_size()

longlong my_aes_get_size ( uint32  source_length,
enum my_aes_opmode  opmode 
)

Calculate the size of a buffer large enough for encrypted data.

Parameters
source_lengthlength of data to be encrypted
opmodeencryption mode
Returns
size of buffer required to store encrypted data

◆ my_aes_needs_iv()

bool my_aes_needs_iv ( my_aes_opmode  opmode)

Return true if the AES cipher and block mode requires an IV.

Parameters
opmodeencryption mode
Return values
trueIV needed
falseIV not needed

◆ my_create_key()

int my_create_key ( unsigned char *  rkey,
const unsigned char *  key,
uint32  key_length,
enum my_aes_opmode  mode,
vector< string > *  kdf_options 
)

Creates required length of AES key, Input key size can be smaller or bigger in length, we need exact AES key size.

If KDF options are valid and given, use KDF functionality. otherwise use previously used method.

Parameters
[out]rkeyOutput key
keyInput key
key_lengthinput key length
modeAES mode
kdf_optionsKDF function options
Returns
0 on success and 1 on failure

Variable Documentation

◆ my_aes_opmode_key_sizes

uint* my_aes_opmode_key_sizes = my_aes_opmode_key_sizes_impl

◆ my_aes_opmode_key_sizes_impl

uint my_aes_opmode_key_sizes_impl[]
static
Initial value:
= {
128 , 192 ,
256 , 128 ,
192 , 256 ,
128 , 192 ,
256 , 128 ,
192 , 256 ,
128 , 192 ,
256 , 128 ,
192 , 256
}

◆ my_aes_opmode_names

const char* my_aes_opmode_names[]
Initial value:
= {
"aes-128-ecb", "aes-192-ecb", "aes-256-ecb", "aes-128-cbc",
"aes-192-cbc", "aes-256-cbc", "aes-128-cfb1", "aes-192-cfb1",
"aes-256-cfb1", "aes-128-cfb8", "aes-192-cfb8", "aes-256-cfb8",
"aes-128-cfb128", "aes-192-cfb128", "aes-256-cfb128", "aes-128-ofb",
"aes-192-ofb", "aes-256-ofb", nullptr
}

String representations of the supported AES modes.

Keep in sync with my_aes_opmode