MySQL 9.1.0
Source Code Documentation
aes.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef AES_INCLUDED
25#define AES_INCLUDED
26
27#include <functional>
28#include <map>
29#include <string>
30#include <utility>
31
32#include <openssl/evp.h>
33
35
36/** Supported AES cipher/block mode combos */
43 /* Add new values above this */
45};
46
56};
57
58using block_mode_key = std::pair<std::string, size_t>;
59using Known_block_mode_map = std::map<block_mode_key, Keyring_aes_opmode>;
60
62 public:
63 Aes_operation_context(std::string data_id, std::string auth_id,
64 const std::string &mode, size_t block_size);
66 std::string data_id() const { return data_id_; }
67 std::string auth_id() const { return auth_id_; }
68 Keyring_aes_opmode opmode() const { return opmode_; }
69 bool valid() const { return valid_; }
71
72 private:
73 std::string data_id_;
74 std::string auth_id_;
76 bool valid_;
77};
78
79const EVP_CIPHER *aes_evp_type(Keyring_aes_opmode mode);
80
81size_t get_ciphertext_size(size_t input_size, Keyring_aes_opmode mode);
82
83aes_return_status aes_encrypt(const unsigned char *source,
84 unsigned int source_length, unsigned char *dest,
85 const unsigned char *key, unsigned int key_length,
86 Keyring_aes_opmode mode, const unsigned char *iv,
87 bool padding, size_t *encrypted_length);
88
89aes_return_status aes_decrypt(const unsigned char *source,
90 unsigned int source_length, unsigned char *dest,
91 const unsigned char *key, unsigned int key_length,
92 Keyring_aes_opmode mode, const unsigned char *iv,
93 bool padding, size_t *decrypted_length);
94
95} // namespace keyring_common::aes_encryption
96
97#endif // !AES_INCLUDED
Keyring_aes_opmode opmode() const
Definition: aes.h:68
std::string data_id() const
Definition: aes.h:66
std::string auth_id() const
Definition: aes.h:67
Keyring_aes_opmode opmode_
Definition: aes.h:75
Aes_operation_context(std::string data_id, std::string auth_id, const std::string &mode, size_t block_size)
Definition: aes.cc:47
static const Known_block_mode_map s_blockmodes
Definition: aes.h:70
Definition: aes.cc:38
aes_return_status
Definition: aes.h:47
@ AES_OP_OK
Definition: aes.h:48
@ AES_DECRYPTION_ERROR
Definition: aes.h:55
@ AES_IV_EMPTY
Definition: aes.h:53
@ AES_CTX_ALLOCATION_ERROR
Definition: aes.h:51
@ AES_INVALID_BLOCK_MODE
Definition: aes.h:52
@ AES_KEY_TRANSFORMATION_ERROR
Definition: aes.h:50
@ AES_OUTPUT_SIZE_NULL
Definition: aes.h:49
@ AES_ENCRYPTION_ERROR
Definition: aes.h:54
const EVP_CIPHER * aes_evp_type(const Keyring_aes_opmode mode)
Definition: aes.cc:70
aes_return_status aes_decrypt(const unsigned char *source, unsigned int source_length, unsigned char *dest, const unsigned char *key, unsigned int key_length, enum Keyring_aes_opmode mode, const unsigned char *iv, bool padding, size_t *decrypted_length)
Definition: aes.cc:187
aes_return_status aes_encrypt(const unsigned char *source, unsigned int source_length, unsigned char *dest, const unsigned char *key, unsigned int key_length, Keyring_aes_opmode mode, const unsigned char *iv, bool padding, size_t *encrypted_length)
Definition: aes.cc:137
Keyring_aes_opmode
Supported AES cipher/block mode combos.
Definition: aes.h:37
std::pair< std::string, size_t > block_mode_key
Definition: aes.h:58
size_t get_ciphertext_size(size_t input_size, const Keyring_aes_opmode mode)
Definition: aes.cc:127
std::map< block_mode_key, Keyring_aes_opmode > Known_block_mode_map
Definition: aes.h:59
mode
Definition: file_handle.h:61
required string key
Definition: replication_asynchronous_connection_failover.proto:60
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42