4 * \brief XTEA block cipher (32-bit)
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: GPL-2.0
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * This file is part of mbed TLS (https://tls.mbed.org)
25 #ifndef MBEDTLS_XTEA_H
26 #define MBEDTLS_XTEA_H
28 #if !defined(MBEDTLS_CONFIG_FILE)
31 #include MBEDTLS_CONFIG_FILE
37 #define MBEDTLS_XTEA_ENCRYPT 1
38 #define MBEDTLS_XTEA_DECRYPT 0
40 #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
42 #if !defined(MBEDTLS_XTEA_ALT)
43 // Regular implementation
51 * \brief XTEA context structure
55 uint32_t k
[4]; /*!< key */
60 * \brief Initialize XTEA context
62 * \param ctx XTEA context to be initialized
64 void mbedtls_xtea_init( mbedtls_xtea_context
*ctx
);
67 * \brief Clear XTEA context
69 * \param ctx XTEA context to be cleared
71 void mbedtls_xtea_free( mbedtls_xtea_context
*ctx
);
74 * \brief XTEA key schedule
76 * \param ctx XTEA context to be initialized
77 * \param key the secret key
79 void mbedtls_xtea_setup( mbedtls_xtea_context
*ctx
, const unsigned char key
[16] );
82 * \brief XTEA cipher function
84 * \param ctx XTEA context
85 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
86 * \param input 8-byte input block
87 * \param output 8-byte output block
89 * \return 0 if successful
91 int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context
*ctx
,
93 const unsigned char input
[8],
94 unsigned char output
[8] );
96 #if defined(MBEDTLS_CIPHER_MODE_CBC)
98 * \brief XTEA CBC cipher function
100 * \param ctx XTEA context
101 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
102 * \param length the length of input, multiple of 8
103 * \param iv initialization vector for CBC mode
104 * \param input input block
105 * \param output output block
107 * \return 0 if successful,
108 * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
110 int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context
*ctx
,
114 const unsigned char *input
,
115 unsigned char *output
);
116 #endif /* MBEDTLS_CIPHER_MODE_CBC */
122 #else /* MBEDTLS_XTEA_ALT */
123 #include "xtea_alt.h"
124 #endif /* MBEDTLS_XTEA_ALT */
131 * \brief Checkup routine
133 * \return 0 if successful, or 1 if the test failed
135 int mbedtls_xtea_self_test( int verbose
);