Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file xtea.h |
| 3 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2009, Paul Bakker <polarssl_maintainer at polarssl.org> |
| 5 | * All rights reserved. |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | #ifndef POLARSSL_XTEA_H |
| 22 | #define POLARSSL_XTEA_H |
| 23 | |
Paul Bakker | 53443e4 | 2009-10-04 15:22:11 +0000 | [diff] [blame] | 24 | #ifdef _MSC_VER |
| 25 | #include <basetsd.h> |
| 26 | typedef UINT32 uint32_t; |
| 27 | #else |
| 28 | #include <inttypes.h> |
Paul Bakker | 80ab9f5 | 2009-05-24 14:42:46 +0000 | [diff] [blame] | 29 | #endif |
Paul Bakker | 0fdf3ca | 2009-05-03 12:54:07 +0000 | [diff] [blame] | 30 | |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 31 | #define XTEA_ENCRYPT 1 |
| 32 | #define XTEA_DECRYPT 0 |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * \brief XTEA context structure |
| 37 | */ |
| 38 | typedef struct |
| 39 | { |
Paul Bakker | 0fdf3ca | 2009-05-03 12:54:07 +0000 | [diff] [blame] | 40 | uint32_t k[4]; /*!< key */ |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 41 | } |
| 42 | xtea_context; |
| 43 | |
| 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
| 48 | /** |
| 49 | * \brief XTEA key schedule |
| 50 | * |
| 51 | * \param ctx XTEA context to be initialized |
| 52 | * \param key the secret key |
| 53 | */ |
| 54 | void xtea_setup( xtea_context *ctx, unsigned char key[16] ); |
| 55 | |
| 56 | /** |
| 57 | * \brief XTEA cipher function |
| 58 | * |
| 59 | * \param ctx XTEA context |
| 60 | * \param mode XTEA_ENCRYPT or XTEA_DECRYPT |
| 61 | * \param input 8-byte input block |
| 62 | * \param output 8-byte output block |
| 63 | */ |
Paul Bakker | e5c19aa | 2009-07-08 06:43:40 +0000 | [diff] [blame] | 64 | void xtea_crypt_ecb( xtea_context *ctx, |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 65 | int mode, |
| 66 | unsigned char input[8], |
| 67 | unsigned char output[8] ); |
| 68 | |
| 69 | /* |
| 70 | * \brief Checkup routine |
| 71 | * |
| 72 | * \return 0 if successful, or 1 if the test failed |
| 73 | */ |
| 74 | int xtea_self_test( int verbose ); |
| 75 | |
| 76 | #ifdef __cplusplus |
| 77 | } |
| 78 | #endif |
| 79 | |
| 80 | #endif /* xtea.h */ |