Mbed OS Reference
Loading...
Searching...
No Matches
xtea.h
Go to the documentation of this file.
1/**
2 * \file xtea.h
3 *
4 * \brief XTEA block cipher (32-bit)
5 */
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
9 *
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
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
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.
21 */
22#ifndef MBEDTLS_XTEA_H
23#define MBEDTLS_XTEA_H
24
25#if !defined(MBEDTLS_CONFIG_FILE)
26#include "mbedtls/config.h"
27#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
31#include <stddef.h>
32#include <stdint.h>
33
34/**
35 * \addtogroup mbedtls
36 * \{
37 * \defgroup mbedtls_xtea_module XTEA
38 * \{
39 */
40
41#define MBEDTLS_XTEA_ENCRYPT 1
42#define MBEDTLS_XTEA_DECRYPT 0
43
44#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
45
46/* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */
47#define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53#if !defined(MBEDTLS_XTEA_ALT)
54// Regular implementation
55//
56
57/**
58 * \brief XTEA context structure
59 */
61{
62 uint32_t k[4]; /*!< key */
63}
65
66#else /* MBEDTLS_XTEA_ALT */
67#include "xtea_alt.h"
68#endif /* MBEDTLS_XTEA_ALT */
69
70/**
71 * \brief Initialize XTEA context
72 *
73 * \param ctx XTEA context to be initialized
74 */
76
77/**
78 * \brief Clear XTEA context
79 *
80 * \param ctx XTEA context to be cleared
81 */
83
84/**
85 * \brief XTEA key schedule
86 *
87 * \param ctx XTEA context to be initialized
88 * \param key the secret key
89 */
90void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
91
92/**
93 * \brief XTEA cipher function
94 *
95 * \param ctx XTEA context
96 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
97 * \param input 8-byte input block
98 * \param output 8-byte output block
99 *
100 * \return 0 if successful
101 */
103 int mode,
104 const unsigned char input[8],
105 unsigned char output[8] );
106
107#if defined(MBEDTLS_CIPHER_MODE_CBC)
108/**
109 * \brief XTEA CBC cipher function
110 *
111 * \param ctx XTEA context
112 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
113 * \param length the length of input, multiple of 8
114 * \param iv initialization vector for CBC mode
115 * \param input input block
116 * \param output output block
117 *
118 * \return 0 if successful,
119 * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
120 */
121int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
122 int mode,
123 size_t length,
124 unsigned char iv[8],
125 const unsigned char *input,
126 unsigned char *output);
127#endif /* MBEDTLS_CIPHER_MODE_CBC */
128
129#if defined(MBEDTLS_SELF_TEST)
130
131/**
132 * \brief Checkup routine
133 *
134 * \return 0 if successful, or 1 if the test failed
135 */
136int mbedtls_xtea_self_test( int verbose );
137
138#endif /* MBEDTLS_SELF_TEST */
139
140#ifdef __cplusplus
141}
142#endif
143
144/// \}
145/// \}
146
147#endif /* xtea.h */
Configuration options (set of defines)
void mbedtls_xtea_setup(mbedtls_xtea_context *ctx, const unsigned char key[16])
XTEA key schedule.
void mbedtls_xtea_free(mbedtls_xtea_context *ctx)
Clear XTEA context.
int mbedtls_xtea_crypt_ecb(mbedtls_xtea_context *ctx, int mode, const unsigned char input[8], unsigned char output[8])
XTEA cipher function.
void mbedtls_xtea_init(mbedtls_xtea_context *ctx)
Initialize XTEA context.
XTEA context structure.
Definition: xtea.h:61
uint32_t k[4]
Definition: xtea.h:62