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

Functions

void my_aes_create_key (const unsigned char *key, uint key_length, uint8 *rkey, enum my_aes_opmode opmode)
 Transforms an arbitrary long key into a fixed length AES key. More...
 
static const EVP_CIPHER * aes_evp_type (const my_aes_opmode mode)
 
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)
 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)
 Decrypt an AES encrypted buffer. More...
 
int my_aes_get_size (uint32 source_length, my_aes_opmode opmode)
 Calculate the size of a buffer large enough for encrypted data. More...
 

Variables

static uint my_aes_opmode_key_sizes_impl []
 This is a copy of mysys/my_aes_openssl.cc with some parts that we do not need removed. More...
 

Function Documentation

◆ aes_evp_type()

static const EVP_CIPHER* aes_evp_type ( const my_aes_opmode  mode)
static

◆ my_aes_create_key()

void my_aes_create_key ( const unsigned char *  key,
uint  key_length,
uint8 rkey,
enum my_aes_opmode  opmode 
)

Transforms an arbitrary long key into a fixed length AES key.

AES keys are of fixed length. This routine takes an arbitrary long key iterates over it in AES key length increment and XORs the bytes with the AES key buffer being prepared. The bytes from the last incomplete iteration are XORed to the start of the key until their depletion. Needed since crypto function routines expect a fixed length key.

Parameters
[in]keyKey to use for real key creation
[in]key_lengthLength of the key
[out]rkeyReal key (used by OpenSSL)
[out]opmodeencryption mode

◆ 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 
)

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.
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 
)

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)
[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.
Returns
size of encrypted data, or negative in case of error

◆ my_aes_get_size()

int 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

Variable Documentation

◆ 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
}

This is a copy of mysys/my_aes_openssl.cc with some parts that we do not need removed.

It's copied because the original file includes global my_aes_opmode_names which symbol is currently exposed from libmysqlclient. That is causing ODR violations. On the other hand we do not want to depend on my_aes_* functions being accessible from libmysqlclient, as this can change in the future.