Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
xtea.h
00001 /** 00002 * \file xtea.h 00003 * 00004 * \brief XTEA block cipher (32-bit) 00005 */ 00006 /* 00007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00008 * SPDX-License-Identifier: Apache-2.0 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00011 * not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00018 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 * 00022 * This file is part of mbed TLS (https://tls.mbed.org) 00023 */ 00024 #ifndef MBEDTLS_XTEA_H 00025 #define MBEDTLS_XTEA_H 00026 00027 #if !defined(MBEDTLS_CONFIG_FILE) 00028 #include "config.h" 00029 #else 00030 #include MBEDTLS_CONFIG_FILE 00031 #endif 00032 00033 #include <stddef.h> 00034 #include <stdint.h> 00035 00036 #define MBEDTLS_XTEA_ENCRYPT 1 00037 #define MBEDTLS_XTEA_DECRYPT 0 00038 00039 #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */ 00040 #define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */ 00041 00042 #if !defined(MBEDTLS_XTEA_ALT) 00043 // Regular implementation 00044 // 00045 00046 #ifdef __cplusplus 00047 extern "C" { 00048 #endif 00049 00050 /** 00051 * \brief XTEA context structure 00052 */ 00053 typedef struct 00054 { 00055 uint32_t k[4]; /*!< key */ 00056 } 00057 mbedtls_xtea_context; 00058 00059 /** 00060 * \brief Initialize XTEA context 00061 * 00062 * \param ctx XTEA context to be initialized 00063 */ 00064 void mbedtls_xtea_init( mbedtls_xtea_context *ctx ); 00065 00066 /** 00067 * \brief Clear XTEA context 00068 * 00069 * \param ctx XTEA context to be cleared 00070 */ 00071 void mbedtls_xtea_free( mbedtls_xtea_context *ctx ); 00072 00073 /** 00074 * \brief XTEA key schedule 00075 * 00076 * \param ctx XTEA context to be initialized 00077 * \param key the secret key 00078 */ 00079 void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] ); 00080 00081 /** 00082 * \brief XTEA cipher function 00083 * 00084 * \param ctx XTEA context 00085 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT 00086 * \param input 8-byte input block 00087 * \param output 8-byte output block 00088 * 00089 * \return 0 if successful 00090 */ 00091 int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx, 00092 int mode, 00093 const unsigned char input[8], 00094 unsigned char output[8] ); 00095 00096 #if defined(MBEDTLS_CIPHER_MODE_CBC) 00097 /** 00098 * \brief XTEA CBC cipher function 00099 * 00100 * \param ctx XTEA context 00101 * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT 00102 * \param length the length of input, multiple of 8 00103 * \param iv initialization vector for CBC mode 00104 * \param input input block 00105 * \param output output block 00106 * 00107 * \return 0 if successful, 00108 * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0 00109 */ 00110 int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx, 00111 int mode, 00112 size_t length, 00113 unsigned char iv[8], 00114 const unsigned char *input, 00115 unsigned char *output); 00116 #endif /* MBEDTLS_CIPHER_MODE_CBC */ 00117 00118 #ifdef __cplusplus 00119 } 00120 #endif 00121 00122 #else /* MBEDTLS_XTEA_ALT */ 00123 #include "xtea_alt.h" 00124 #endif /* MBEDTLS_XTEA_ALT */ 00125 00126 #ifdef __cplusplus 00127 extern "C" { 00128 #endif 00129 00130 /** 00131 * \brief Checkup routine 00132 * 00133 * \return 0 if successful, or 1 if the test failed 00134 */ 00135 int mbedtls_xtea_self_test( int verbose ); 00136 00137 #ifdef __cplusplus 00138 } 00139 #endif 00140 00141 #endif /* xtea.h */
Generated on Tue Jul 12 2022 18:18:56 by
