MySQL 8.0.30
Source Code Documentation
Aes_ctr_cipher< TYPE > Class Template Reference

The class implements AES-CTR encryption/decryption. More...

#include <stream_cipher.h>

Inheritance diagram for Aes_ctr_cipher< TYPE >:
[legend]

Public Member Functions

 ~Aes_ctr_cipher () override
 
bool open (const Key_string &password, int header_size) override
 Open the cipher with given password. More...
 
void close () override
 Close the cipher. More...
 
bool encrypt (unsigned char *dest, const unsigned char *src, int length) override
 Encrypt data. More...
 
bool decrypt (unsigned char *dest, const unsigned char *src, int length) override
 Decrypt data. More...
 
bool set_stream_offset (uint64_t offset) override
 Support encrypting/decrypting data at random position of a stream. More...
 
- Public Member Functions inherited from Stream_cipher
virtual ~Stream_cipher ()=default
 
int get_header_size ()
 Returns the size of the header of the stream being encrypted/decrypted. More...
 

Static Public Attributes

static const int PASSWORD_LENGTH = Aes_ctr::PASSWORD_LENGTH
 
static const int AES_BLOCK_SIZE = Aes_ctr::AES_BLOCK_SIZE
 
static const int FILE_KEY_LENGTH = Aes_ctr::FILE_KEY_LENGTH
 

Private Member Functions

bool init_cipher (uint64_t offset)
 Initialize OpenSSL cipher related context and IV. More...
 
void deinit_cipher ()
 Destroy OpenSSL cipher related context. More...
 

Private Attributes

EVP_CIPHER_CTX * m_ctx = nullptr
 
unsigned char m_file_key [FILE_KEY_LENGTH]
 
unsigned char m_iv [AES_BLOCK_SIZE]
 

Additional Inherited Members

- Protected Attributes inherited from Stream_cipher
int m_header_size = 0
 

Detailed Description

template<Cipher_type TYPE>
class Aes_ctr_cipher< TYPE >

The class implements AES-CTR encryption/decryption.

It supports to encrypt/decrypt a stream in both sequential and random way.

Constructor & Destructor Documentation

◆ ~Aes_ctr_cipher()

template<Cipher_type TYPE>
Aes_ctr_cipher< TYPE >::~Aes_ctr_cipher< TYPE >
override

Member Function Documentation

◆ close()

template<Cipher_type TYPE>
void Aes_ctr_cipher< TYPE >::close ( )
overridevirtual

Close the cipher.

Implements Stream_cipher.

◆ decrypt()

template<Cipher_type TYPE>
bool Aes_ctr_cipher< TYPE >::decrypt ( unsigned char *  dest,
const unsigned char *  src,
int  length 
)
overridevirtual

Decrypt data.

Parameters
[in]destThe buffer for storing decrypted data. It should be at least 'length' bytes.
[in]srcThe data which will be decrypted.
[in]lengthLength of the data.
Return values
falseSuccess.
trueError.

Implements Stream_cipher.

◆ deinit_cipher()

template<Cipher_type TYPE>
void Aes_ctr_cipher< TYPE >::deinit_cipher
private

Destroy OpenSSL cipher related context.

◆ encrypt()

template<Cipher_type TYPE>
bool Aes_ctr_cipher< TYPE >::encrypt ( unsigned char *  dest,
const unsigned char *  src,
int  length 
)
overridevirtual

Encrypt data.

Parameters
[in]destThe buffer for storing encrypted data. It should be at least 'length' bytes.
[in]srcThe data which will be encrypted.
[in]lengthLength of the data.
Return values
falseSuccess.
trueError.

Implements Stream_cipher.

◆ init_cipher()

template<Cipher_type TYPE>
bool Aes_ctr_cipher< TYPE >::init_cipher ( uint64_t  offset)
private

Initialize OpenSSL cipher related context and IV.

Parameters
[in]offsetThe stream offset to compute the AES-CTR counter which will be set into IV.
Return values
falseSuccess.
trueError.

◆ open()

template<Cipher_type TYPE>
bool Aes_ctr_cipher< TYPE >::open ( const Key_string password,
int  header_size 
)
overridevirtual

Open the cipher with given password.

Parameters
[in]passwordThe password which is used to initialize the cipher.
[in]header_sizeThe encrypted stream offset wrt the down stream.
Return values
falseSuccess.
trueError.

Implements Stream_cipher.

◆ set_stream_offset()

template<Cipher_type TYPE>
bool Aes_ctr_cipher< TYPE >::set_stream_offset ( uint64_t  offset)
overridevirtual

Support encrypting/decrypting data at random position of a stream.

Parameters
[in]offsetThe stream offset of the data which will be encrypted/ decrypted in next encrypt()/decrypt() call.
Return values
falseSuccess.
trueError.

Implements Stream_cipher.

Member Data Documentation

◆ AES_BLOCK_SIZE

template<Cipher_type TYPE>
const int Aes_ctr_cipher< TYPE >::AES_BLOCK_SIZE = Aes_ctr::AES_BLOCK_SIZE
static

◆ FILE_KEY_LENGTH

template<Cipher_type TYPE>
const int Aes_ctr_cipher< TYPE >::FILE_KEY_LENGTH = Aes_ctr::FILE_KEY_LENGTH
static

◆ m_ctx

template<Cipher_type TYPE>
EVP_CIPHER_CTX* Aes_ctr_cipher< TYPE >::m_ctx = nullptr
private

◆ m_file_key

template<Cipher_type TYPE>
unsigned char Aes_ctr_cipher< TYPE >::m_file_key[FILE_KEY_LENGTH]
private

◆ m_iv

template<Cipher_type TYPE>
unsigned char Aes_ctr_cipher< TYPE >::m_iv[AES_BLOCK_SIZE]
private

◆ PASSWORD_LENGTH

template<Cipher_type TYPE>
const int Aes_ctr_cipher< TYPE >::PASSWORD_LENGTH = Aes_ctr::PASSWORD_LENGTH
static

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