]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Source/mbedtls/include/mbedtls/xtea.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Source / mbedtls / include / mbedtls / xtea.h
1 /**\r
2  * \file xtea.h\r
3  *\r
4  * \brief XTEA block cipher (32-bit)\r
5  */\r
6 /*\r
7  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved\r
8  *  SPDX-License-Identifier: Apache-2.0\r
9  *\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
13  *\r
14  *  http://www.apache.org/licenses/LICENSE-2.0\r
15  *\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
21  *\r
22  *  This file is part of mbed TLS (https://tls.mbed.org)\r
23  */\r
24 #ifndef MBEDTLS_XTEA_H\r
25 #define MBEDTLS_XTEA_H\r
26 \r
27 #if !defined(MBEDTLS_CONFIG_FILE)\r
28 #include "config.h"\r
29 #else\r
30 #include MBEDTLS_CONFIG_FILE\r
31 #endif\r
32 \r
33 #include <stddef.h>\r
34 #include <stdint.h>\r
35 \r
36 #define MBEDTLS_XTEA_ENCRYPT     1\r
37 #define MBEDTLS_XTEA_DECRYPT     0\r
38 \r
39 #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH             -0x0028  /**< The data input has an invalid length. */\r
40 \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
43 \r
44 #ifdef __cplusplus\r
45 extern "C" {\r
46 #endif\r
47 \r
48 #if !defined(MBEDTLS_XTEA_ALT)\r
49 // Regular implementation\r
50 //\r
51 \r
52 /**\r
53  * \brief          XTEA context structure\r
54  */\r
55 typedef struct mbedtls_xtea_context\r
56 {\r
57     uint32_t k[4];       /*!< key */\r
58 }\r
59 mbedtls_xtea_context;\r
60 \r
61 #else  /* MBEDTLS_XTEA_ALT */\r
62 #include "xtea_alt.h"\r
63 #endif /* MBEDTLS_XTEA_ALT */\r
64 \r
65 /**\r
66  * \brief          Initialize XTEA context\r
67  *\r
68  * \param ctx      XTEA context to be initialized\r
69  */\r
70 void mbedtls_xtea_init( mbedtls_xtea_context *ctx );\r
71 \r
72 /**\r
73  * \brief          Clear XTEA context\r
74  *\r
75  * \param ctx      XTEA context to be cleared\r
76  */\r
77 void mbedtls_xtea_free( mbedtls_xtea_context *ctx );\r
78 \r
79 /**\r
80  * \brief          XTEA key schedule\r
81  *\r
82  * \param ctx      XTEA context to be initialized\r
83  * \param key      the secret key\r
84  */\r
85 void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );\r
86 \r
87 /**\r
88  * \brief          XTEA cipher function\r
89  *\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
94  *\r
95  * \return         0 if successful\r
96  */\r
97 int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,\r
98                     int mode,\r
99                     const unsigned char input[8],\r
100                     unsigned char output[8] );\r
101 \r
102 #if defined(MBEDTLS_CIPHER_MODE_CBC)\r
103 /**\r
104  * \brief          XTEA CBC cipher function\r
105  *\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
112  *\r
113  * \return         0 if successful,\r
114  *                 MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0\r
115  */\r
116 int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,\r
117                     int mode,\r
118                     size_t length,\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
123 \r
124 #if defined(MBEDTLS_SELF_TEST)\r
125 \r
126 /**\r
127  * \brief          Checkup routine\r
128  *\r
129  * \return         0 if successful, or 1 if the test failed\r
130  */\r
131 int mbedtls_xtea_self_test( int verbose );\r
132 \r
133 #endif /* MBEDTLS_SELF_TEST */\r
134 \r
135 #ifdef __cplusplus\r
136 }\r
137 #endif\r
138 \r
139 #endif /* xtea.h */\r