Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers xtea.h Source File

xtea.h

Go to the documentation of this file.
00001 /**
00002  * \file xtea.h
00003  *
00004  * \brief XTEA block cipher (32-bit)
00005  *
00006  *  Copyright (C) 2006-2013, Brainspark B.V.
00007  *
00008  *  This file is part of PolarSSL (http://www.polarssl.org)
00009  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
00010  *
00011  *  All rights reserved.
00012  *
00013  *  This program is free software; you can redistribute it and/or modify
00014  *  it under the terms of the GNU General Public License as published by
00015  *  the Free Software Foundation; either version 2 of the License, or
00016  *  (at your option) any later version.
00017  *
00018  *  This program is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *  GNU General Public License for more details.
00022  *
00023  *  You should have received a copy of the GNU General Public License along
00024  *  with this program; if not, write to the Free Software Foundation, Inc.,
00025  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00026  */
00027 #ifndef POLARSSL_XTEA_H
00028 #define POLARSSL_XTEA_H
00029 
00030 #if !defined(POLARSSL_CONFIG_FILE)
00031 #include "config.h"
00032 #else
00033 #include POLARSSL_CONFIG_FILE
00034 #endif
00035 
00036 #include <string.h>
00037 
00038 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
00039 #include <basetsd.h>
00040 typedef UINT32 uint32_t;
00041 #else
00042 #include <inttypes.h>
00043 #endif
00044 
00045 #define XTEA_ENCRYPT     1
00046 #define XTEA_DECRYPT     0
00047 
00048 #define POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH             -0x0028  /**< The data input has an invalid length. */
00049 
00050 #if !defined(POLARSSL_XTEA_ALT)
00051 // Regular implementation
00052 //
00053 
00054 #ifdef __cplusplus
00055 extern "C" {
00056 #endif
00057 
00058 /**
00059  * \brief          XTEA context structure
00060  */
00061 typedef struct
00062 {
00063     uint32_t k[4];       /*!< key */
00064 }
00065 xtea_context;
00066 
00067 /**
00068  * \brief          XTEA key schedule
00069  *
00070  * \param ctx      XTEA context to be initialized
00071  * \param key      the secret key
00072  */
00073 void xtea_setup( xtea_context *ctx, const unsigned char key[16] );
00074 
00075 /**
00076  * \brief          XTEA cipher function
00077  *
00078  * \param ctx      XTEA context
00079  * \param mode     XTEA_ENCRYPT or XTEA_DECRYPT
00080  * \param input    8-byte input block
00081  * \param output   8-byte output block
00082  *
00083  * \return         0 if successful
00084  */
00085 int xtea_crypt_ecb( xtea_context *ctx,
00086                     int mode,
00087                     const unsigned char input[8],
00088                     unsigned char output[8] );
00089 
00090 #if defined(POLARSSL_CIPHER_MODE_CBC)
00091 /**
00092  * \brief          XTEA CBC cipher function
00093  *
00094  * \param ctx      XTEA context
00095  * \param mode     XTEA_ENCRYPT or XTEA_DECRYPT
00096  * \param length   the length of input, multiple of 8
00097  * \param iv       initialization vector for CBC mode
00098  * \param input    input block
00099  * \param output   output block
00100  *
00101  * \return         0 if successful,
00102  *                 POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
00103  */
00104 int xtea_crypt_cbc( xtea_context *ctx,
00105                     int mode,
00106                     size_t length,
00107                     unsigned char iv[8],
00108                     const unsigned char *input,
00109                     unsigned char *output);
00110 #endif /* POLARSSL_CIPHER_MODE_CBC */
00111 
00112 #ifdef __cplusplus
00113 }
00114 #endif
00115 
00116 #else  /* POLARSSL_XTEA_ALT */
00117 #include "xtea_alt.h"
00118 #endif /* POLARSSL_XTEA_ALT */
00119 
00120 #ifdef __cplusplus
00121 extern "C" {
00122 #endif
00123 
00124 /**
00125  * \brief          Checkup routine
00126  *
00127  * \return         0 if successful, or 1 if the test failed
00128  */
00129 int xtea_self_test( int verbose );
00130 
00131 #ifdef __cplusplus
00132 }
00133 #endif
00134 
00135 #endif /* xtea.h */
00136 
00137