blob: feb1237cc5ebf1fc0ec8c31b7f42f3af01af3ae6 [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 *
Paul Bakker84f12b72010-07-18 10:13:04 +00006 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakker7a7c78f2009-01-04 18:15:48 +000012 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_XTEA_H
28#define POLARSSL_XTEA_H
29
Paul Bakker477fd322009-10-04 13:22:13 +000030#ifdef _MSC_VER
31#include <basetsd.h>
32typedef UINT32 uint32_t;
33#else
34#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000035#endif
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000036
Paul Bakker7a7c78f2009-01-04 18:15:48 +000037#define XTEA_ENCRYPT 1
38#define XTEA_DECRYPT 0
39
Paul Bakkerb6ecaf52011-04-19 14:29:23 +000040#define POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH -0x0820
Paul Bakker7a7c78f2009-01-04 18:15:48 +000041
42/**
43 * \brief XTEA context structure
44 */
45typedef struct
46{
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000047 uint32_t k[4]; /*!< key */
Paul Bakker7a7c78f2009-01-04 18:15:48 +000048}
49xtea_context;
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/**
56 * \brief XTEA key schedule
57 *
58 * \param ctx XTEA context to be initialized
59 * \param key the secret key
60 */
61void xtea_setup( xtea_context *ctx, unsigned char key[16] );
62
63/**
64 * \brief XTEA cipher function
65 *
66 * \param ctx XTEA context
67 * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
68 * \param input 8-byte input block
69 * \param output 8-byte output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +000070 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000071 * \return 0 if successful
Paul Bakker7a7c78f2009-01-04 18:15:48 +000072 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +000073int xtea_crypt_ecb( xtea_context *ctx,
Paul Bakker7a7c78f2009-01-04 18:15:48 +000074 int mode,
75 unsigned char input[8],
76 unsigned char output[8] );
77
Paul Bakkerb6ecaf52011-04-19 14:29:23 +000078/**
79 * \brief XTEA CBC cipher function
80 *
81 * \param ctx XTEA context
82 * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
83 * \param length the length of input, multiple of 8
84 * \param iv initialization vector for CBC mode
85 * \param input input block
86 * \param output output block
87 *
88 * \return 0 if successful,
89 * POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
90 */
91int xtea_crypt_cbc( xtea_context *ctx,
92 int mode,
93 int length,
94 unsigned char iv[8],
95 unsigned char *input,
96 unsigned char *output);
97
Paul Bakker7a7c78f2009-01-04 18:15:48 +000098/*
99 * \brief Checkup routine
100 *
101 * \return 0 if successful, or 1 if the test failed
102 */
103int xtea_self_test( int verbose );
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* xtea.h */