1
#pragma GCC system_header
5
* \brief XTEA block cipher (32-bit)
8
* Copyright The Mbed TLS Contributors
9
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
11
* This file is provided under the Apache License 2.0, or the
12
* GNU General Public License v2.0 or later.
17
* Licensed under the Apache License, Version 2.0 (the "License"); you may
18
* not use this file except in compliance with the License.
19
* You may obtain a copy of the License at
21
* http://www.apache.org/licenses/LICENSE-2.0
23
* Unless required by applicable law or agreed to in writing, software
24
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
* See the License for the specific language governing permissions and
27
* limitations under the License.
32
* GNU General Public License v2.0 or later:
34
* This program is free software; you can redistribute it and/or modify
35
* it under the terms of the GNU General Public License as published by
36
* the Free Software Foundation; either version 2 of the License, or
37
* (at your option) any later version.
39
* This program is distributed in the hope that it will be useful,
40
* but WITHOUT ANY WARRANTY; without even the implied warranty of
41
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42
* GNU General Public License for more details.
44
* You should have received a copy of the GNU General Public License along
45
* with this program; if not, write to the Free Software Foundation, Inc.,
46
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50
#ifndef MBEDTLS_XTEA_H
51
#define MBEDTLS_XTEA_H
53
#if !defined(MBEDTLS_CONFIG_FILE)
56
#include MBEDTLS_CONFIG_FILE
62
#define MBEDTLS_XTEA_ENCRYPT 1
63
#define MBEDTLS_XTEA_DECRYPT 0
65
#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
67
/* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */
68
#define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */
74
#if !defined(MBEDTLS_XTEA_ALT)
75
// Regular implementation
79
* \brief XTEA context structure
81
typedef struct mbedtls_xtea_context
83
uint32_t k[4]; /*!< key */
87
#else /* MBEDTLS_XTEA_ALT */
89
#endif /* MBEDTLS_XTEA_ALT */
92
* \brief Initialize XTEA context
94
* \param ctx XTEA context to be initialized
96
void mbedtls_xtea_init( mbedtls_xtea_context *ctx );
99
* \brief Clear XTEA context
101
* \param ctx XTEA context to be cleared
103
void mbedtls_xtea_free( mbedtls_xtea_context *ctx );
106
* \brief XTEA key schedule
108
* \param ctx XTEA context to be initialized
109
* \param key the secret key
111
void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
114
* \brief XTEA cipher function
116
* \param ctx XTEA context
117
* \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
118
* \param input 8-byte input block
119
* \param output 8-byte output block
121
* \return 0 if successful
123
int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,
125
const unsigned char input[8],
126
unsigned char output[8] );
128
#if defined(MBEDTLS_CIPHER_MODE_CBC)
130
* \brief XTEA CBC cipher function
132
* \param ctx XTEA context
133
* \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
134
* \param length the length of input, multiple of 8
135
* \param iv initialization vector for CBC mode
136
* \param input input block
137
* \param output output block
139
* \return 0 if successful,
140
* MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
142
int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
146
const unsigned char *input,
147
unsigned char *output);
148
#endif /* MBEDTLS_CIPHER_MODE_CBC */
150
#if defined(MBEDTLS_SELF_TEST)
153
* \brief Checkup routine
155
* \return 0 if successful, or 1 if the test failed
157
int mbedtls_xtea_self_test( int verbose );
159
#endif /* MBEDTLS_SELF_TEST */