cfb8: Fix decrypt path
[gd/nettle] / xts.h
1 /* xts.h
2
3    XEX-based tweaked-codebook mode with ciphertext stealing (XTS)
4
5    Copyright (C) 2005 Niels Möller
6    Copyright (C) 2018 Red Hat, Inc.
7
8    This file is part of GNU Nettle.
9
10    GNU Nettle is free software: you can redistribute it and/or
11    modify it under the terms of either:
12
13      * the GNU Lesser General Public License as published by the Free
14        Software Foundation; either version 3 of the License, or (at your
15        option) any later version.
16
17    or
18
19      * the GNU General Public License as published by the Free
20        Software Foundation; either version 2 of the License, or (at your
21        option) any later version.
22
23    or both in parallel, as here.
24
25    GNU Nettle is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28    General Public License for more details.
29
30    You should have received copies of the GNU General Public License and
31    the GNU Lesser General Public License along with this program.  If
32    not, see http://www.gnu.org/licenses/.
33 */
34
35
36 #ifndef NETTLE_XTS_H_INCLUDED
37 #define NETTLE_XTS_H_INCLUDED
38
39 #include "nettle-types.h"
40 #include "aes.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Name mangling */
47 #define xts_encrypt_message nettle_xts_encrypt_message
48 #define xts_decrypt_message nettle_xts_decrypt_message
49 #define xts_aes128_set_encrypt_key nettle_xts_aes128_set_encrypt_key
50 #define xts_aes128_set_decrypt_key nettle_xts_aes128_set_decrypt_key
51 #define xts_aes128_encrypt_message nettle_xts_aes128_encrypt_message
52 #define xts_aes128_decrypt_message nettle_xts_aes128_decrypt_message
53 #define xts_aes256_set_encrypt_key nettle_xts_aes256_set_encrypt_key
54 #define xts_aes256_set_decrypt_key nettle_xts_aes256_set_decrypt_key
55 #define xts_aes256_encrypt_message nettle_xts_aes256_encrypt_message
56 #define xts_aes256_decrypt_message nettle_xts_aes256_decrypt_message
57
58 #define XTS_BLOCK_SIZE 16
59
60 void
61 xts_encrypt_message(const void *enc_ctx, const void *twk_ctx,
62                 nettle_cipher_func *encf,
63                 const uint8_t *tweak, size_t length,
64                 uint8_t *dst, const uint8_t *src);
65 void
66 xts_decrypt_message(const void *dec_ctx, const void *twk_ctx,
67                     nettle_cipher_func *decf, nettle_cipher_func *encf,
68                     const uint8_t *tweak, size_t length,
69                     uint8_t *dst, const uint8_t *src);
70
71 /* XTS Mode with AES-128 */
72 struct xts_aes128_key {
73     struct aes128_ctx cipher;
74     struct aes128_ctx tweak_cipher;
75 };
76
77 void
78 xts_aes128_set_encrypt_key(struct xts_aes128_key *xts_key,
79                            const uint8_t *key);
80
81 void
82 xts_aes128_set_decrypt_key(struct xts_aes128_key *xts_key,
83                            const uint8_t *key);
84
85 void
86 xts_aes128_encrypt_message(struct xts_aes128_key *xtskey,
87                            const uint8_t *tweak, size_t length,
88                            uint8_t *dst, const uint8_t *src);
89
90 void
91 xts_aes128_decrypt_message(struct xts_aes128_key *xts_key,
92                            const uint8_t *tweak, size_t length,
93                            uint8_t *dst, const uint8_t *src);
94
95 /* XTS Mode with AES-256 */
96 struct xts_aes256_key {
97     struct aes256_ctx cipher;
98     struct aes256_ctx tweak_cipher;
99 };
100
101 void
102 xts_aes256_set_encrypt_key(struct xts_aes256_key *xts_key,
103                            const uint8_t *key);
104
105 void
106 xts_aes256_set_decrypt_key(struct xts_aes256_key *xts_key,
107                            const uint8_t *key);
108
109 void
110 xts_aes256_encrypt_message(struct xts_aes256_key *xts_key,
111                            const uint8_t *tweak, size_t length,
112                            uint8_t *dst, const uint8_t *src);
113
114 void
115 xts_aes256_decrypt_message(struct xts_aes256_key *xts_key,
116                            const uint8_t *tweak, size_t length,
117                            uint8_t *dst, const uint8_t *src);
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif /* NETTLE_XTS_H_INCLUDED */