Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file xtea.h |
| 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame^] | 4 | * \brief XTEA block cipher (32-bit) |
| 5 | * |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2010, Brainspark B.V. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
| 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 10 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 11 | * All rights reserved. |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 12 | * |
| 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 Bakker | 477fd32 | 2009-10-04 13:22:13 +0000 | [diff] [blame] | 30 | #ifdef _MSC_VER |
| 31 | #include <basetsd.h> |
| 32 | typedef UINT32 uint32_t; |
| 33 | #else |
| 34 | #include <inttypes.h> |
Paul Bakker | 80ab9f5 | 2009-05-24 14:42:46 +0000 | [diff] [blame] | 35 | #endif |
Paul Bakker | 0fdf3ca | 2009-05-03 12:54:07 +0000 | [diff] [blame] | 36 | |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 37 | #define XTEA_ENCRYPT 1 |
| 38 | #define XTEA_DECRYPT 0 |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * \brief XTEA context structure |
| 43 | */ |
| 44 | typedef struct |
| 45 | { |
Paul Bakker | 0fdf3ca | 2009-05-03 12:54:07 +0000 | [diff] [blame] | 46 | uint32_t k[4]; /*!< key */ |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 47 | } |
| 48 | xtea_context; |
| 49 | |
| 50 | #ifdef __cplusplus |
| 51 | extern "C" { |
| 52 | #endif |
| 53 | |
| 54 | /** |
| 55 | * \brief XTEA key schedule |
| 56 | * |
| 57 | * \param ctx XTEA context to be initialized |
| 58 | * \param key the secret key |
| 59 | */ |
| 60 | void xtea_setup( xtea_context *ctx, unsigned char key[16] ); |
| 61 | |
| 62 | /** |
| 63 | * \brief XTEA cipher function |
| 64 | * |
| 65 | * \param ctx XTEA context |
| 66 | * \param mode XTEA_ENCRYPT or XTEA_DECRYPT |
| 67 | * \param input 8-byte input block |
| 68 | * \param output 8-byte output block |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 69 | * |
Paul Bakker | 27caa8a | 2010-03-21 15:43:59 +0000 | [diff] [blame] | 70 | * \return 0 if successful |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 71 | */ |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 72 | int xtea_crypt_ecb( xtea_context *ctx, |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 73 | int mode, |
| 74 | unsigned char input[8], |
| 75 | unsigned char output[8] ); |
| 76 | |
| 77 | /* |
| 78 | * \brief Checkup routine |
| 79 | * |
| 80 | * \return 0 if successful, or 1 if the test failed |
| 81 | */ |
| 82 | int xtea_self_test( int verbose ); |
| 83 | |
| 84 | #ifdef __cplusplus |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | #endif /* xtea.h */ |