Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:16

0001 /* xts.h
0002 
0003    XEX-based tweaked-codebook mode with ciphertext stealing (XTS)
0004 
0005    Copyright (C) 2005 Niels Möller
0006    Copyright (C) 2018 Red Hat, Inc.
0007 
0008    This file is part of GNU Nettle.
0009 
0010    GNU Nettle is free software: you can redistribute it and/or
0011    modify it under the terms of either:
0012 
0013      * the GNU Lesser General Public License as published by the Free
0014        Software Foundation; either version 3 of the License, or (at your
0015        option) any later version.
0016 
0017    or
0018 
0019      * the GNU General Public License as published by the Free
0020        Software Foundation; either version 2 of the License, or (at your
0021        option) any later version.
0022 
0023    or both in parallel, as here.
0024 
0025    GNU Nettle is distributed in the hope that it will be useful,
0026    but WITHOUT ANY WARRANTY; without even the implied warranty of
0027    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028    General Public License for more details.
0029 
0030    You should have received copies of the GNU General Public License and
0031    the GNU Lesser General Public License along with this program.  If
0032    not, see http://www.gnu.org/licenses/.
0033 */
0034 
0035 
0036 #ifndef NETTLE_XTS_H_INCLUDED
0037 #define NETTLE_XTS_H_INCLUDED
0038 
0039 #include "nettle-types.h"
0040 #include "aes.h"
0041 
0042 #ifdef __cplusplus
0043 extern "C" {
0044 #endif
0045 
0046 /* Name mangling */
0047 #define xts_encrypt_message nettle_xts_encrypt_message
0048 #define xts_decrypt_message nettle_xts_decrypt_message
0049 #define xts_aes128_set_encrypt_key nettle_xts_aes128_set_encrypt_key
0050 #define xts_aes128_set_decrypt_key nettle_xts_aes128_set_decrypt_key
0051 #define xts_aes128_encrypt_message nettle_xts_aes128_encrypt_message
0052 #define xts_aes128_decrypt_message nettle_xts_aes128_decrypt_message
0053 #define xts_aes256_set_encrypt_key nettle_xts_aes256_set_encrypt_key
0054 #define xts_aes256_set_decrypt_key nettle_xts_aes256_set_decrypt_key
0055 #define xts_aes256_encrypt_message nettle_xts_aes256_encrypt_message
0056 #define xts_aes256_decrypt_message nettle_xts_aes256_decrypt_message
0057 
0058 #define XTS_BLOCK_SIZE 16
0059 
0060 void
0061 xts_encrypt_message(const void *enc_ctx, const void *twk_ctx,
0062                 nettle_cipher_func *encf,
0063                 const uint8_t *tweak, size_t length,
0064                 uint8_t *dst, const uint8_t *src);
0065 void
0066 xts_decrypt_message(const void *dec_ctx, const void *twk_ctx,
0067                     nettle_cipher_func *decf, nettle_cipher_func *encf,
0068                     const uint8_t *tweak, size_t length,
0069                     uint8_t *dst, const uint8_t *src);
0070 
0071 /* XTS Mode with AES-128 */
0072 struct xts_aes128_key {
0073     struct aes128_ctx cipher;
0074     struct aes128_ctx tweak_cipher;
0075 };
0076 
0077 void
0078 xts_aes128_set_encrypt_key(struct xts_aes128_key *xts_key,
0079                            const uint8_t *key);
0080 
0081 void
0082 xts_aes128_set_decrypt_key(struct xts_aes128_key *xts_key,
0083                            const uint8_t *key);
0084 
0085 void
0086 xts_aes128_encrypt_message(const struct xts_aes128_key *xtskey,
0087                            const uint8_t *tweak, size_t length,
0088                            uint8_t *dst, const uint8_t *src);
0089 
0090 void
0091 xts_aes128_decrypt_message(const struct xts_aes128_key *xts_key,
0092                            const uint8_t *tweak, size_t length,
0093                            uint8_t *dst, const uint8_t *src);
0094 
0095 /* XTS Mode with AES-256 */
0096 struct xts_aes256_key {
0097     struct aes256_ctx cipher;
0098     struct aes256_ctx tweak_cipher;
0099 };
0100 
0101 void
0102 xts_aes256_set_encrypt_key(struct xts_aes256_key *xts_key,
0103                            const uint8_t *key);
0104 
0105 void
0106 xts_aes256_set_decrypt_key(struct xts_aes256_key *xts_key,
0107                            const uint8_t *key);
0108 
0109 void
0110 xts_aes256_encrypt_message(const struct xts_aes256_key *xts_key,
0111                            const uint8_t *tweak, size_t length,
0112                            uint8_t *dst, const uint8_t *src);
0113 
0114 void
0115 xts_aes256_decrypt_message(const struct xts_aes256_key *xts_key,
0116                            const uint8_t *tweak, size_t length,
0117                            uint8_t *dst, const uint8_t *src);
0118 
0119 #ifdef __cplusplus
0120 }
0121 #endif
0122 
0123 #endif /* NETTLE_XTS_H_INCLUDED */