text
[RRG-proxmark3.git] / common / mbedtls / xtea.h
blob0b7714e4ff81c065fd7837254d91d32a13e34bef
1 /**
2 * \file xtea.h
4 * \brief XTEA block cipher (32-bit)
5 */
6 /*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
22 #ifndef MBEDTLS_XTEA_H
23 #define MBEDTLS_XTEA_H
25 #if !defined(MBEDTLS_CONFIG_FILE)
26 #include "mbedtls/config.h"
27 #else
28 #include MBEDTLS_CONFIG_FILE
29 #endif
31 #include <stddef.h>
32 #include <stdint.h>
34 #define MBEDTLS_XTEA_ENCRYPT 1
35 #define MBEDTLS_XTEA_DECRYPT 0
37 #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
39 /* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */
40 #define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 #if !defined(MBEDTLS_XTEA_ALT)
47 // Regular implementation
50 /**
51 * \brief XTEA context structure
53 typedef struct mbedtls_xtea_context {
54 uint32_t k[4]; /*!< key */
56 mbedtls_xtea_context;
58 #else /* MBEDTLS_XTEA_ALT */
59 #include "xtea_alt.h"
60 #endif /* MBEDTLS_XTEA_ALT */
62 /**
63 * \brief Initialize XTEA context
65 * \param ctx XTEA context to be initialized
67 void mbedtls_xtea_init(mbedtls_xtea_context *ctx);
69 /**
70 * \brief Clear XTEA context
72 * \param ctx XTEA context to be cleared
74 void mbedtls_xtea_free(mbedtls_xtea_context *ctx);
76 /**
77 * \brief XTEA key schedule
79 * \param ctx XTEA context to be initialized
80 * \param key the secret key
82 void mbedtls_xtea_setup(mbedtls_xtea_context *ctx, const unsigned char key[16]);
84 /**
85 * \brief XTEA cipher function
87 * \param ctx XTEA context
88 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
89 * \param input 8-byte input block
90 * \param output 8-byte output block
92 * \return 0 if successful
94 int mbedtls_xtea_crypt_ecb(mbedtls_xtea_context *ctx,
95 int mode,
96 const unsigned char input[8],
97 unsigned char output[8]);
99 #if defined(MBEDTLS_CIPHER_MODE_CBC)
101 * \brief XTEA CBC cipher function
103 * \param ctx XTEA context
104 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
105 * \param length the length of input, multiple of 8
106 * \param iv initialization vector for CBC mode
107 * \param input input block
108 * \param output output block
110 * \return 0 if successful,
111 * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
113 int mbedtls_xtea_crypt_cbc(mbedtls_xtea_context *ctx,
114 int mode,
115 size_t length,
116 unsigned char iv[8],
117 const unsigned char *input,
118 unsigned char *output);
119 #endif /* MBEDTLS_CIPHER_MODE_CBC */
121 #if defined(MBEDTLS_SELF_TEST)
124 * \brief Checkup routine
126 * \return 0 if successful, or 1 if the test failed
128 int mbedtls_xtea_self_test(int verbose);
130 #endif /* MBEDTLS_SELF_TEST */
132 #ifdef __cplusplus
134 #endif
136 #endif /* xtea.h */