aboutsummaryrefslogtreecommitdiff
path: root/library/xtea.c
diff options
context:
space:
mode:
authorPaul Bakker <p.j.bakker@polarssl.org>2009-05-03 12:54:07 +0000
committerPaul Bakker <p.j.bakker@polarssl.org>2009-05-03 12:54:07 +0000
commit0fdf3cacf22361e724ee3c2adbcfa026bd7ae561 (patch)
treee3bf69cf69f51a42f602355e65acb0e3912aee3e /library/xtea.c
parentc500bb7c43e0f5cd79270f133eaf3133239dbc98 (diff)
downloadmbedtls-0fdf3cacf22361e724ee3c2adbcfa026bd7ae561.zip
mbedtls-0fdf3cacf22361e724ee3c2adbcfa026bd7ae561.tar.gz
mbedtls-0fdf3cacf22361e724ee3c2adbcfa026bd7ae561.tar.bz2
- Modified XTEA to use uint32_t instead of unsigned long
Diffstat (limited to 'library/xtea.c')
-rw-r--r--library/xtea.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/library/xtea.c b/library/xtea.c
index 9fc4acd..c610a90 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] =