| 1 |
/* Copyright (c) 2021, 2026, Oracle and/or its affiliates. |
| 2 |
|
| 3 |
This program is free software; you can redistribute it and/or modify |
| 4 |
it under the terms of the GNU General Public License, version 2.0, |
| 5 |
as published by the Free Software Foundation. |
| 6 |
|
| 7 |
This program is designed to work with certain software (including |
| 8 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 9 |
as designated in a particular file or component or in included license |
| 10 |
documentation. The authors of MySQL hereby grant you an additional |
| 11 |
permission to link the program and your derivative works with the |
| 12 |
separately licensed software that they have either included with |
| 13 |
the program or referenced in the documentation. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License, version 2.0, for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program; if not, write to the Free Software |
| 22 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 |
|
| 24 |
#ifndef KEYRING_ENCRYPTION_SERVICE_IMPL_INCLUDED |
| 25 |
#define KEYRING_ENCRYPTION_SERVICE_IMPL_INCLUDED |
| 26 |
|
| 27 |
#include <mysql/components/component_implementation.h> |
| 28 |
#include <mysql/components/service_implementation.h> |
| 29 |
|
| 30 |
#include <mysql/components/services/keyring_aes.h> |
| 31 |
|
| 32 |
namespace keyring_common { |
| 33 |
namespace service_definition { |
| 34 |
|
| 35 |
class Keyring_aes_service_impl { |
| 36 |
public: |
| 37 |
/** |
| 38 |
Retrieve required out buffer length information |
| 39 |
|
| 40 |
@param [in] input_length Length of input text |
| 41 |
@param [in] mode AES mode |
| 42 |
@param [in] block_size AES block size information |
| 43 |
@param [out] out_size Size of output buffer |
| 44 |
|
| 45 |
@returns Output buffer length or error |
| 46 |
@retval false Success |
| 47 |
@retval true Error processing given mode and/or block size |
| 48 |
*/ |
| 49 |
static DEFINE_BOOL_METHOD(get_size, (size_t input_length, const char *mode, |
| 50 |
size_t block_size, size_t *out_size)); |
| 51 |
|
| 52 |
/** |
| 53 |
Encrypt given piece of plaintext |
| 54 |
|
| 55 |
@param [in] data_id Name of the key |
| 56 |
@param [in] auth_id Owner of the key |
| 57 |
@param [in] mode AES mode |
| 58 |
@param [in] block_size AES block size information |
| 59 |
@param [in] iv Initialization vector |
| 60 |
@param [in] padding padding preference (0 implies no padding) |
| 61 |
@param [in] data_buffer Input buffer |
| 62 |
@param [in] data_buffer_length Input buffer length |
| 63 |
@param [out] out_buffer Output buffer |
| 64 |
@param [in] out_buffer_length Output buffer length |
| 65 |
@param [out] out_length Length of encrypted data |
| 66 |
|
| 67 |
@returns status of the operation |
| 68 |
@retval false Success |
| 69 |
@retval true Failure |
| 70 |
|
| 71 |
*/ |
| 72 |
static DEFINE_BOOL_METHOD( |
| 73 |
encrypt, (const char *data_id, const char *auth_id, const char *mode, |
| 74 |
size_t block_size, const unsigned char *iv, int padding, |
| 75 |
const unsigned char *data_buffer, size_t data_buffer_length, |
| 76 |
unsigned char *out_buffer, size_t out_buffer_length, |
| 77 |
size_t *out_length)); |
| 78 |
|
| 79 |
/** |
| 80 |
Decrypt given piece ciphertext |
| 81 |
|
| 82 |
@param [in] data_id Name of the key |
| 83 |
@param [in] auth_id Owner of the key |
| 84 |
@param [in] mode AES mode |
| 85 |
@param [in] block_size AES block size information |
| 86 |
@param [in] iv Initialization vector |
| 87 |
@param [in] padding padding preference (0 implies no padding) |
| 88 |
@param [in] data_buffer Input buffer |
| 89 |
@param [in] data_buffer_length Input buffer length |
| 90 |
@param [out] out_buffer Output buffer |
| 91 |
@param [in] out_buffer_length Output buffer length |
| 92 |
@param [out] out_length Length of decrypted data |
| 93 |
|
| 94 |
@returns status of the operation |
| 95 |
@retval false Success |
| 96 |
@retval true Failure |
| 97 |
|
| 98 |
*/ |
| 99 |
static DEFINE_BOOL_METHOD( |
| 100 |
decrypt, (const char *data_id, const char *auth_id, const char *mode, |
| 101 |
size_t block_size, const unsigned char *iv, int padding, |
| 102 |
const unsigned char *data_buffer, size_t data_buffer_length, |
| 103 |
unsigned char *out_buffer, size_t out_buffer_length, |
| 104 |
size_t *out_length)); |
| 105 |
}; |
| 106 |
|
| 107 |
} // namespace service_definition |
| 108 |
} // namespace keyring_common |
| 109 |
|
| 110 |
#define KEYRING_AES_IMPLEMENTOR(component_name) \ |
| 111 |
BEGIN_SERVICE_IMPLEMENTATION(component_name, keyring_aes) \ |
| 112 |
keyring_common::service_definition::Keyring_aes_service_impl::get_size, \ |
| 113 |
keyring_common::service_definition::Keyring_aes_service_impl::encrypt, \ |
| 114 |
keyring_common::service_definition::Keyring_aes_service_impl::decrypt \ |
| 115 |
END_SERVICE_IMPLEMENTATION() |
| 116 |
|
| 117 |
#endif // KEYRING_ENCRYPTION_SERVICE_IMPL_INCLUDED |