4 * \brief XTEA block cipher (32-bit)
\r
7 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
\r
8 * SPDX-License-Identifier: Apache-2.0
\r
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
\r
11 * not use this file except in compliance with the License.
\r
12 * You may obtain a copy of the License at
\r
14 * http://www.apache.org/licenses/LICENSE-2.0
\r
16 * Unless required by applicable law or agreed to in writing, software
\r
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
\r
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
19 * See the License for the specific language governing permissions and
\r
20 * limitations under the License.
\r
22 * This file is part of mbed TLS (https://tls.mbed.org)
\r
24 #ifndef MBEDTLS_XTEA_H
\r
25 #define MBEDTLS_XTEA_H
\r
27 #if !defined(MBEDTLS_CONFIG_FILE)
\r
30 #include MBEDTLS_CONFIG_FILE
\r
36 #define MBEDTLS_XTEA_ENCRYPT 1
\r
37 #define MBEDTLS_XTEA_DECRYPT 0
\r
39 #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
\r
41 /* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */
\r
42 #define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */
\r
48 #if !defined(MBEDTLS_XTEA_ALT)
\r
49 // Regular implementation
\r
53 * \brief XTEA context structure
\r
55 typedef struct mbedtls_xtea_context
\r
57 uint32_t k[4]; /*!< key */
\r
59 mbedtls_xtea_context;
\r
61 #else /* MBEDTLS_XTEA_ALT */
\r
62 #include "xtea_alt.h"
\r
63 #endif /* MBEDTLS_XTEA_ALT */
\r
66 * \brief Initialize XTEA context
\r
68 * \param ctx XTEA context to be initialized
\r
70 void mbedtls_xtea_init( mbedtls_xtea_context *ctx );
\r
73 * \brief Clear XTEA context
\r
75 * \param ctx XTEA context to be cleared
\r
77 void mbedtls_xtea_free( mbedtls_xtea_context *ctx );
\r
80 * \brief XTEA key schedule
\r
82 * \param ctx XTEA context to be initialized
\r
83 * \param key the secret key
\r
85 void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
\r
88 * \brief XTEA cipher function
\r
90 * \param ctx XTEA context
\r
91 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
\r
92 * \param input 8-byte input block
\r
93 * \param output 8-byte output block
\r
95 * \return 0 if successful
\r
97 int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,
\r
99 const unsigned char input[8],
\r
100 unsigned char output[8] );
\r
102 #if defined(MBEDTLS_CIPHER_MODE_CBC)
\r
104 * \brief XTEA CBC cipher function
\r
106 * \param ctx XTEA context
\r
107 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
\r
108 * \param length the length of input, multiple of 8
\r
109 * \param iv initialization vector for CBC mode
\r
110 * \param input input block
\r
111 * \param output output block
\r
113 * \return 0 if successful,
\r
114 * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
\r
116 int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
\r
119 unsigned char iv[8],
\r
120 const unsigned char *input,
\r
121 unsigned char *output);
\r
122 #endif /* MBEDTLS_CIPHER_MODE_CBC */
\r
124 #if defined(MBEDTLS_SELF_TEST)
\r
127 * \brief Checkup routine
\r
129 * \return 0 if successful, or 1 if the test failed
\r
131 int mbedtls_xtea_self_test( int verbose );
\r
133 #endif /* MBEDTLS_SELF_TEST */
\r
139 #endif /* xtea.h */
\r