xref: /openbmc/qemu/include/crypto/xts.h (revision d5938f29)
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.1 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 
30 #define XTS_BLOCK_SIZE 16
31 
32 typedef void xts_cipher_func(const void *ctx,
33                              size_t length,
34                              uint8_t *dst,
35                              const uint8_t *src);
36 
37 /**
38  * xts_decrypt:
39  * @datactx: the cipher context for data decryption
40  * @tweakctx: the cipher context for tweak decryption
41  * @encfunc: the cipher function for encryption
42  * @decfunc: the cipher function for decryption
43  * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes
44  * @length: the length of @dst and @src
45  * @dst: buffer to hold the decrypted plaintext
46  * @src: buffer providing the ciphertext
47  *
48  * Decrypts @src into @dst
49  */
50 void xts_decrypt(const void *datactx,
51                  const void *tweakctx,
52                  xts_cipher_func *encfunc,
53                  xts_cipher_func *decfunc,
54                  uint8_t *iv,
55                  size_t length,
56                  uint8_t *dst,
57                  const uint8_t *src);
58 
59 /**
60  * xts_decrypt:
61  * @datactx: the cipher context for data encryption
62  * @tweakctx: the cipher context for tweak encryption
63  * @encfunc: the cipher function for encryption
64  * @decfunc: the cipher function for decryption
65  * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes
66  * @length: the length of @dst and @src
67  * @dst: buffer to hold the encrypted ciphertext
68  * @src: buffer providing the plaintext
69  *
70  * Decrypts @src into @dst
71  */
72 void xts_encrypt(const void *datactx,
73                  const void *tweakctx,
74                  xts_cipher_func *encfunc,
75                  xts_cipher_func *decfunc,
76                  uint8_t *iv,
77                  size_t length,
78                  uint8_t *dst,
79                  const uint8_t *src);
80 
81 
82 #endif /* QCRYPTO_XTS_H */
83