1/*****************************************************************************
2
3Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
4Copyright (C) 2014, 2017, MariaDB Corporation. All Rights Reserved.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free Software
8Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program; if not, write to the Free Software Foundation, Inc.,
1651 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18*****************************************************************************/
19/**************************************************//**
20@file include/log0crypt.h
21Innodb log encrypt/decrypt
22
23Created 11/25/2013 Minli Zhu
24Modified Jan Lindström jan.lindstrom@mariadb.com
25MDEV-11782: Rewritten for MariaDB 10.2 by Marko Mäkelä, MariaDB Corporation.
26*******************************************************/
27#ifndef log0crypt_h
28#define log0crypt_h
29
30#include "log0log.h"
31
32/** innodb_encrypt_log: whether to encrypt the redo log */
33extern my_bool srv_encrypt_log;
34
35/** Initialize the redo log encryption key and random parameters
36when creating a new redo log.
37The random parameters will be persisted in the log checkpoint pages.
38@see log_crypt_write_checkpoint_buf()
39@see log_crypt_read_checkpoint_buf()
40@return whether the operation succeeded */
41UNIV_INTERN
42bool
43log_crypt_init();
44
45/*********************************************************************//**
46Writes the crypto (version, msg and iv) info, which has been used for
47log blocks with lsn <= this checkpoint's lsn, to a log header's
48checkpoint buf. */
49UNIV_INTERN
50void
51log_crypt_write_checkpoint_buf(
52/*===========================*/
53 byte* buf); /*!< in/out: checkpoint buffer */
54
55/** Read the MariaDB 10.1 checkpoint crypto (version, msg and iv) info.
56@param[in] buf checkpoint buffer
57@return whether the operation was successful */
58UNIV_INTERN
59bool
60log_crypt_101_read_checkpoint(const byte* buf);
61
62/** Decrypt a MariaDB 10.1 redo log block.
63@param[in,out] buf log block
64@return whether the decryption was successful */
65UNIV_INTERN
66bool
67log_crypt_101_read_block(byte* buf);
68
69/** Read the checkpoint crypto (version, msg and iv) info.
70@param[in] buf checkpoint buffer
71@return whether the operation was successful */
72UNIV_INTERN
73bool
74log_crypt_read_checkpoint_buf(const byte* buf);
75
76/** Encrypt or decrypt log blocks.
77@param[in,out] buf log blocks to encrypt or decrypt
78@param[in] lsn log sequence number of the start of the buffer
79@param[in] size size of the buffer, in bytes
80@param[in] decrypt whether to decrypt instead of encrypting */
81UNIV_INTERN
82void
83log_crypt(byte* buf, lsn_t lsn, ulint size, bool decrypt = false);
84
85/** Encrypt or decrypt a temporary file block.
86@param[in] src block to encrypt or decrypt
87@param[in] size size of the block
88@param[out] dst destination block
89@param[in] offs offset to block
90@param[in] space_id tablespace id
91@param[in] encrypt true=encrypt; false=decrypt
92@return whether the operation succeeded */
93UNIV_INTERN
94bool
95log_tmp_block_encrypt(
96 const byte* src,
97 ulint size,
98 byte* dst,
99 uint64_t offs,
100 ulint space_id,
101 bool encrypt = true)
102 MY_ATTRIBUTE((warn_unused_result, nonnull));
103
104/** Decrypt a temporary file block.
105@param[in] src block to decrypt
106@param[in] size size of the block
107@param[out] dst destination block
108@param[in] offs offset to block
109@param[in] space_id tablespace id
110@return whether the operation succeeded */
111inline
112bool
113log_tmp_block_decrypt(
114 const byte* src,
115 ulint size,
116 byte* dst,
117 uint64_t offs,
118 ulint space_id)
119{
120 return(log_tmp_block_encrypt(src, size, dst, offs, space_id, false));
121}
122
123/** @return whether temporary files are encrypted */
124inline bool log_tmp_is_encrypted() { return srv_encrypt_log; }
125#endif // log0crypt.h
126