[MBEDTLS]
[reactos.git] / reactos / sdk / include / reactos / libs / mbedtls / xtea.h
1 /**
2 * \file xtea.h
3 *
4 * \brief XTEA block cipher (32-bit)
5 *
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: GPL-2.0
8 *
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.
13 *
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.
18 *
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.
22 *
23 * This file is part of mbed TLS (https://tls.mbed.org)
24 */
25 #ifndef MBEDTLS_XTEA_H
26 #define MBEDTLS_XTEA_H
27
28 #if !defined(MBEDTLS_CONFIG_FILE)
29 #include "config.h"
30 #else
31 #include MBEDTLS_CONFIG_FILE
32 #endif
33
34 #include <stddef.h>
35 #include <stdint.h>
36
37 #define MBEDTLS_XTEA_ENCRYPT 1
38 #define MBEDTLS_XTEA_DECRYPT 0
39
40 #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
41
42 #if !defined(MBEDTLS_XTEA_ALT)
43 // Regular implementation
44 //
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /**
51 * \brief XTEA context structure
52 */
53 typedef struct
54 {
55 uint32_t k[4]; /*!< key */
56 }
57 mbedtls_xtea_context;
58
59 /**
60 * \brief Initialize XTEA context
61 *
62 * \param ctx XTEA context to be initialized
63 */
64 void mbedtls_xtea_init( mbedtls_xtea_context *ctx );
65
66 /**
67 * \brief Clear XTEA context
68 *
69 * \param ctx XTEA context to be cleared
70 */
71 void mbedtls_xtea_free( mbedtls_xtea_context *ctx );
72
73 /**
74 * \brief XTEA key schedule
75 *
76 * \param ctx XTEA context to be initialized
77 * \param key the secret key
78 */
79 void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
80
81 /**
82 * \brief XTEA cipher function
83 *
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
88 *
89 * \return 0 if successful
90 */
91 int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,
92 int mode,
93 const unsigned char input[8],
94 unsigned char output[8] );
95
96 #if defined(MBEDTLS_CIPHER_MODE_CBC)
97 /**
98 * \brief XTEA CBC cipher function
99 *
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
106 *
107 * \return 0 if successful,
108 * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
109 */
110 int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
111 int mode,
112 size_t length,
113 unsigned char iv[8],
114 const unsigned char *input,
115 unsigned char *output);
116 #endif /* MBEDTLS_CIPHER_MODE_CBC */
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122 #else /* MBEDTLS_XTEA_ALT */
123 #include "xtea_alt.h"
124 #endif /* MBEDTLS_XTEA_ALT */
125
126 #ifdef __cplusplus
127 extern "C" {
128 #endif
129
130 /**
131 * \brief Checkup routine
132 *
133 * \return 0 if successful, or 1 if the test failed
134 */
135 int mbedtls_xtea_self_test( int verbose );
136
137 #ifdef __cplusplus
138 }
139 #endif
140
141 #endif /* xtea.h */