MySQL 8.0.29
Source Code Documentation
my_aes.h
Go to the documentation of this file.
1#ifndef MY_AES_INCLUDED
2#define MY_AES_INCLUDED
3
4/* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file include/my_aes.h
28 Wrapper to give simple interface for MySQL to AES standard encryption.
29*/
30
31#include "my_inttypes.h"
32#include "my_macros.h"
33
34/** AES IV size is 16 bytes for all supported ciphers except ECB */
35#define MY_AES_IV_SIZE 16
36
37/** AES block size is fixed to be 128 bits for CBC and ECB */
38#define MY_AES_BLOCK_SIZE 16
39
40/** Supported AES cipher/block mode combos */
60};
61
62#define MY_AES_BEGIN my_aes_128_ecb
63#define MY_AES_END my_aes_256_ofb
64
65/* If bad data discovered during decoding */
66#define MY_AES_BAD_DATA -1
67
68/** String representations of the supported AES modes. Keep in sync with
69 * my_aes_opmode */
70extern const char *my_aes_opmode_names[];
71
72/**
73 Encrypt a buffer using AES
74
75 @param [in] source Pointer to data for encryption
76 @param [in] source_length Size of encryption data
77 @param [out] dest Buffer to place encrypted data (must be large
78 enough)
79 @param [in] key Key to be used for encryption
80 @param [in] key_length Length of the key. Will handle keys of any length
81 @param [in] mode encryption mode
82 @param [in] iv 16 bytes initialization vector if needed.
83 Otherwise NULL
84 @param [in] padding if padding needed.
85 @return size of encrypted data, or negative in case of error
86*/
87
88int my_aes_encrypt(const unsigned char *source, uint32 source_length,
89 unsigned char *dest, const unsigned char *key,
91 const unsigned char *iv, bool padding = true);
92
93/**
94 Decrypt an AES encrypted buffer
95
96 @param source Pointer to data for decryption
97 @param source_length size of encrypted data
98 @param dest buffer to place decrypted data (must be large enough)
99 @param key Key to be used for decryption
100 @param key_length Length of the key. Will handle keys of any length
101 @param mode encryption mode
102 @param iv 16 bytes initialization vector if needed. Otherwise NULL
103 @param padding if padding needed.
104 @return size of original data.
105*/
106
107int my_aes_decrypt(const unsigned char *source, uint32 source_length,
108 unsigned char *dest, const unsigned char *key,
110 const unsigned char *iv, bool padding = true);
111
112/**
113 Calculate the size of a buffer large enough for encrypted data.
114
115 @param source_length length of data to be encrypted
116 @param opmode encryption mode
117 @return size of buffer required to store encrypted data
118*/
119
120longlong my_aes_get_size(uint32 source_length, enum my_aes_opmode opmode);
121
122/**
123 Return true if the AES cipher and block mode requires an IV.
124
125 @param opmode encryption mode
126
127 @retval true IV needed
128 @retval false IV not needed
129*/
130
131bool my_aes_needs_iv(my_aes_opmode opmode);
132
133#endif /* MY_AES_INCLUDED */
static uint key_length
Definition: mi_test1.cc:42
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.
Definition: my_aes_openssl.cc:160
bool my_aes_needs_iv(my_aes_opmode opmode)
Return true if the AES cipher and block mode requires an IV.
Definition: my_aes_openssl.cc:218
my_aes_opmode
Supported AES cipher/block mode combos.
Definition: my_aes.h:41
@ my_aes_256_cbc
Definition: my_aes.h:47
@ my_aes_128_cbc
Definition: my_aes.h:45
@ my_aes_128_cfb128
Definition: my_aes.h:54
@ my_aes_128_ofb
Definition: my_aes.h:57
@ my_aes_256_cfb1
Definition: my_aes.h:50
@ my_aes_128_cfb1
Definition: my_aes.h:48
@ my_aes_192_cfb8
Definition: my_aes.h:52
@ my_aes_192_ofb
Definition: my_aes.h:58
@ my_aes_128_ecb
Definition: my_aes.h:42
@ my_aes_192_cfb1
Definition: my_aes.h:49
@ my_aes_256_ecb
Definition: my_aes.h:44
@ my_aes_192_ecb
Definition: my_aes.h:43
@ my_aes_128_cfb8
Definition: my_aes.h:51
@ my_aes_192_cfb128
Definition: my_aes.h:55
@ my_aes_256_cfb8
Definition: my_aes.h:53
@ my_aes_256_ofb
Definition: my_aes.h:59
@ my_aes_192_cbc
Definition: my_aes.h:46
@ my_aes_256_cfb128
Definition: my_aes.h:56
longlong my_aes_get_size(uint32 source_length, enum my_aes_opmode opmode)
Calculate the size of a buffer large enough for encrypted data.
Definition: my_aes_openssl.cc:207
const char * my_aes_opmode_names[]
String representations of the supported AES modes.
Definition: my_aes_openssl.cc:49
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.
Definition: my_aes_openssl.cc:116
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:54
uint32_t uint32
Definition: my_inttypes.h:66
Some common macros.
mode
Definition: file_handle.h:59
required string key
Definition: replication_asynchronous_connection_failover.proto:59
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:41