blob: d1635fc2756bd194ce15ddac00b6b44e305b6d6a [file] [log] [blame]
Paul Bakker7a7c78f2009-01-04 18:15:48 +00001/**
2 * \file xtea.h
3 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
5 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00006 * All rights reserved.
Paul Bakker7a7c78f2009-01-04 18:15:48 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22#ifndef POLARSSL_XTEA_H
23#define POLARSSL_XTEA_H
24
Paul Bakker477fd322009-10-04 13:22:13 +000025#ifdef _MSC_VER
26#include <basetsd.h>
27typedef UINT32 uint32_t;
28#else
29#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000030#endif
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000031
Paul Bakker7a7c78f2009-01-04 18:15:48 +000032#define XTEA_ENCRYPT 1
33#define XTEA_DECRYPT 0
34
35
36/**
37 * \brief XTEA context structure
38 */
39typedef struct
40{
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000041 uint32_t k[4]; /*!< key */
Paul Bakker7a7c78f2009-01-04 18:15:48 +000042}
43xtea_context;
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * \brief XTEA key schedule
51 *
52 * \param ctx XTEA context to be initialized
53 * \param key the secret key
54 */
55void xtea_setup( xtea_context *ctx, unsigned char key[16] );
56
57/**
58 * \brief XTEA cipher function
59 *
60 * \param ctx XTEA context
61 * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
62 * \param input 8-byte input block
63 * \param output 8-byte output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +000064 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000065 * \return 0 if successful
Paul Bakker7a7c78f2009-01-04 18:15:48 +000066 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +000067int xtea_crypt_ecb( xtea_context *ctx,
Paul Bakker7a7c78f2009-01-04 18:15:48 +000068 int mode,
69 unsigned char input[8],
70 unsigned char output[8] );
71
72/*
73 * \brief Checkup routine
74 *
75 * \return 0 if successful, or 1 if the test failed
76 */
77int xtea_self_test( int verbose );
78
79#ifdef __cplusplus
80}
81#endif
82
83#endif /* xtea.h */