1
/******************************************************
2
Copyright (c) 2011 Percona Ireland Ltd.
4
The xbcrypt format writer implementation.
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; version 2 of the License.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*******************************************************/
23
struct xb_wcrypt_struct {
25
xb_crypt_write_callback *write;
29
xb_crypt_write_open(void *userdata, xb_crypt_write_callback *onwrite)
35
crypt = (xb_wcrypt_t *) my_malloc(sizeof(xb_wcrypt_t), MYF(MY_FAE));
37
crypt->userdata = userdata;
38
crypt->write = onwrite;
43
int xb_crypt_write_chunk(xb_wcrypt_t *crypt, const void *buf, size_t olen,
46
uchar tmpbuf[XB_CRYPT_CHUNK_MAGIC_SIZE + 8 + 8 + 8 + 4];
50
xb_ad(olen <= INT_MAX);
54
xb_ad(elen <= INT_MAX);
60
memcpy(ptr, XB_CRYPT_CHUNK_MAGIC, XB_CRYPT_CHUNK_MAGIC_SIZE);
61
ptr += XB_CRYPT_CHUNK_MAGIC_SIZE;
63
int8store(ptr, (ulonglong)0); /* reserved */
66
int8store(ptr, (ulonglong)olen); /* original size */
69
int8store(ptr, (ulonglong)elen); /* encrypted (actual) size */
72
checksum = crc32(0, buf, elen);
73
int4store(ptr, checksum); /* checksum */
76
xb_ad(ptr <= tmpbuf + sizeof(tmpbuf));
78
if (crypt->write(crypt->userdata, tmpbuf, ptr-tmpbuf) == -1)
81
if (crypt->write(crypt->userdata, buf, elen) == -1)
87
int xb_crypt_write_close(xb_wcrypt_t *crypt)