blob: f3cb9a15a39ebff3e3646685182fdd7f01f31c47 [file] [log] [blame]
Paul Bakker7a7c78f2009-01-04 18:15:48 +00001/**
2 * \file xtea.h
3 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief XTEA block cipher (32-bit)
5 *
Manuel Pégourié-Gonnard0edee5e2015-01-26 15:29:40 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakker7a7c78f2009-01-04 18:15:48 +00009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24#ifndef POLARSSL_XTEA_H
25#define POLARSSL_XTEA_H
26
Paul Bakker4087c472013-06-12 16:49:10 +020027#include "config.h"
28
Paul Bakker23986e52011-04-24 08:57:21 +000029#include <string.h>
30
Paul Bakker477fd322009-10-04 13:22:13 +000031#ifdef _MSC_VER
32#include <basetsd.h>
33typedef UINT32 uint32_t;
34#else
35#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000036#endif
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000037
Paul Bakker7a7c78f2009-01-04 18:15:48 +000038#define XTEA_ENCRYPT 1
39#define XTEA_DECRYPT 0
40
Paul Bakker9d781402011-05-09 16:17:09 +000041#define POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
Paul Bakker7a7c78f2009-01-04 18:15:48 +000042
Paul Bakker4087c472013-06-12 16:49:10 +020043#if !defined(POLARSSL_XTEA_ALT)
44// Regular implementation
45//
46
Paul Bakker7a7c78f2009-01-04 18:15:48 +000047/**
48 * \brief XTEA context structure
49 */
50typedef struct
51{
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000052 uint32_t k[4]; /*!< key */
Paul Bakker7a7c78f2009-01-04 18:15:48 +000053}
54xtea_context;
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60/**
61 * \brief XTEA key schedule
62 *
63 * \param ctx XTEA context to be initialized
64 * \param key the secret key
65 */
66void xtea_setup( xtea_context *ctx, unsigned char key[16] );
67
68/**
69 * \brief XTEA cipher function
70 *
71 * \param ctx XTEA context
72 * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
73 * \param input 8-byte input block
74 * \param output 8-byte output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +000075 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000076 * \return 0 if successful
Paul Bakker7a7c78f2009-01-04 18:15:48 +000077 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +000078int xtea_crypt_ecb( xtea_context *ctx,
Paul Bakker23986e52011-04-24 08:57:21 +000079 int mode,
80 unsigned char input[8],
81 unsigned char output[8] );
Paul Bakker7a7c78f2009-01-04 18:15:48 +000082
Paul Bakkerb6ecaf52011-04-19 14:29:23 +000083/**
84 * \brief XTEA CBC cipher function
85 *
86 * \param ctx XTEA context
87 * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
88 * \param length the length of input, multiple of 8
89 * \param iv initialization vector for CBC mode
90 * \param input input block
91 * \param output output block
92 *
93 * \return 0 if successful,
94 * POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
95 */
96int xtea_crypt_cbc( xtea_context *ctx,
97 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +000098 size_t length,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +000099 unsigned char iv[8],
100 unsigned char *input,
101 unsigned char *output);
102
Paul Bakker4087c472013-06-12 16:49:10 +0200103#ifdef __cplusplus
104}
105#endif
106
107#else /* POLARSSL_XTEA_ALT */
108#include "xtea_alt.h"
109#endif /* POLARSSL_XTEA_ALT */
110
111#ifdef __cplusplus
112extern "C" {
113#endif
114
Paul Bakker9a736322012-11-14 12:39:52 +0000115/**
Paul Bakker7a7c78f2009-01-04 18:15:48 +0000116 * \brief Checkup routine
117 *
118 * \return 0 if successful, or 1 if the test failed
119 */
120int xtea_self_test( int verbose );
121
122#ifdef __cplusplus
123}
124#endif
125
126#endif /* xtea.h */