xref: /qemu/include/crypto/xts.h (revision 7b0f97ba)
1 /*
2  * QEMU Crypto XTS cipher mode
3  *
4  * Copyright (c) 2015-2016 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  *
19  * This code is originally derived from public domain / WTFPL code in
20  * LibTomCrypt crytographic library http://libtom.org. The XTS code
21  * was donated by Elliptic Semiconductor Inc (www.ellipticsemi.com)
22  * to the LibTom Projects
23  *
24  */
25 
26 #ifndef QCRYPTO_XTS_H
27 #define QCRYPTO_XTS_H
28 
29 #include "qemu-common.h"
30 
31 #define XTS_BLOCK_SIZE 16
32 
33 typedef void xts_cipher_func(const void *ctx,
34                              size_t length,
35                              uint8_t *dst,
36                              const uint8_t *src);
37 
38 /**
39  * xts_decrypt:
40  * @datactx: the cipher context for data decryption
41  * @tweakctx: the cipher context for tweak decryption
42  * @encfunc: the cipher function for encryption
43  * @decfunc: the cipher function for decryption
44  * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes
45  * @length: the length of @dst and @src
46  * @dst: buffer to hold the decrypted plaintext
47  * @src: buffer providing the ciphertext
48  *
49  * Decrypts @src into @dst
50  */
51 void xts_decrypt(const void *datactx,
52                  const void *tweakctx,
53                  xts_cipher_func *encfunc,
54                  xts_cipher_func *decfunc,
55                  uint8_t *iv,
56                  size_t length,
57                  uint8_t *dst,
58                  const uint8_t *src);
59 
60 /**
61  * xts_decrypt:
62  * @datactx: the cipher context for data encryption
63  * @tweakctx: the cipher context for tweak encryption
64  * @encfunc: the cipher function for encryption
65  * @decfunc: the cipher function for decryption
66  * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes
67  * @length: the length of @dst and @src
68  * @dst: buffer to hold the encrypted ciphertext
69  * @src: buffer providing the plaintext
70  *
71  * Decrypts @src into @dst
72  */
73 void xts_encrypt(const void *datactx,
74                  const void *tweakctx,
75                  xts_cipher_func *encfunc,
76                  xts_cipher_func *decfunc,
77                  uint8_t *iv,
78                  size_t length,
79                  uint8_t *dst,
80                  const uint8_t *src);
81 
82 
83 #endif /* QCRYPTO_XTS_H */
84