From 0fdf3cacf22361e724ee3c2adbcfa026bd7ae561 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Sun, 3 May 2009 12:54:07 +0000
Subject: [PATCH] - Modified XTEA to use uint32_t instead of unsigned long
---
include/polarssl/xtea.h | 4 +++-
library/xtea.c | 33 ++++++++++++++++++++-------------
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/include/polarssl/xtea.h b/include/polarssl/xtea.h
index 770ecc2b58..45f7547665 100644
--- a/include/polarssl/xtea.h
+++ b/include/polarssl/xtea.h
@@ -20,6 +20,8 @@
#ifndef POLARSSL_XTEA_H
#define POLARSSL_XTEA_H
+#include
+
#define XTEA_ENCRYPT 1
#define XTEA_DECRYPT 0
@@ -29,7 +31,7 @@
*/
typedef struct
{
- unsigned long k[4]; /*!< key */
+ uint32_t k[4]; /*!< key */
}
xtea_context;
diff --git a/library/xtea.c b/library/xtea.c
index 9fc4acda23..c610a908ef 100644
--- a/library/xtea.c
+++ b/library/xtea.c
@@ -33,9 +33,9 @@
#define GET_ULONG_BE(n,b,i) \
{ \
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
- | ( (unsigned long) (b)[(i) + 1] << 16 ) \
- | ( (unsigned long) (b)[(i) + 2] << 8 ) \
- | ( (unsigned long) (b)[(i) + 3] ); \
+ | ( (unsigned long) (b)[(i) + 1] << 16 ) \
+ | ( (unsigned long) (b)[(i) + 2] << 8 ) \
+ | ( (unsigned long) (b)[(i) + 3] ); \
}
#endif
@@ -67,9 +67,10 @@ void xtea_setup( xtea_context *ctx, unsigned char key[16] )
/*
* XTEA encrypt function
*/
-void xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8], unsigned char output[8])
+void xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
+ unsigned char output[8])
{
- unsigned long *k, v0, v1, i;
+ uint32_t *k, v0, v1, i;
k = ctx->k;
@@ -78,7 +79,7 @@ void xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8], unsign
if( mode == XTEA_ENCRYPT )
{
- unsigned long sum = 0, delta = 0x9E3779B9;
+ uint32_t sum = 0, delta = 0x9E3779B9;
for( i = 0; i < 32; i++ )
{
@@ -89,7 +90,7 @@ void xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8], unsign
}
else /* XTEA_DECRYPT */
{
- unsigned long delta = 0x9E3779B9, sum = delta * 32;
+ uint32_t delta = 0x9E3779B9, sum = delta * 32;
for( i = 0; i < 32; i++ )
{
@@ -114,12 +115,18 @@ void xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8], unsign
static const unsigned char xtea_test_key[6][16] =
{
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
+ 0x0c, 0x0d, 0x0e, 0x0f },
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
+ 0x0c, 0x0d, 0x0e, 0x0f },
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
+ 0x0c, 0x0d, 0x0e, 0x0f },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00 }
};
static const unsigned char xtea_test_pt[6][8] =