blob: 026a800ac279b2c3040dba7b0323d69e248f76cd [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.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakker7a7c78f2009-01-04 18:15:48 +000010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25#ifndef POLARSSL_XTEA_H
26#define POLARSSL_XTEA_H
27
Paul Bakker477fd322009-10-04 13:22:13 +000028#ifdef _MSC_VER
29#include <basetsd.h>
30typedef UINT32 uint32_t;
31#else
32#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000033#endif
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000034
Paul Bakker7a7c78f2009-01-04 18:15:48 +000035#define XTEA_ENCRYPT 1
36#define XTEA_DECRYPT 0
37
38
39/**
40 * \brief XTEA context structure
41 */
42typedef struct
43{
Paul Bakker0fdf3ca2009-05-03 12:54:07 +000044 uint32_t k[4]; /*!< key */
Paul Bakker7a7c78f2009-01-04 18:15:48 +000045}
46xtea_context;
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * \brief XTEA key schedule
54 *
55 * \param ctx XTEA context to be initialized
56 * \param key the secret key
57 */
58void xtea_setup( xtea_context *ctx, unsigned char key[16] );
59
60/**
61 * \brief XTEA cipher function
62 *
63 * \param ctx XTEA context
64 * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
65 * \param input 8-byte input block
66 * \param output 8-byte output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +000067 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000068 * \return 0 if successful
Paul Bakker7a7c78f2009-01-04 18:15:48 +000069 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +000070int xtea_crypt_ecb( xtea_context *ctx,
Paul Bakker7a7c78f2009-01-04 18:15:48 +000071 int mode,
72 unsigned char input[8],
73 unsigned char output[8] );
74
75/*
76 * \brief Checkup routine
77 *
78 * \return 0 if successful, or 1 if the test failed
79 */
80int xtea_self_test( int verbose );
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* xtea.h */