- Modified XTEA to use uint32_t instead of unsigned long

This commit is contained in:
Paul Bakker 2009-05-03 12:54:07 +00:00
parent c500bb7c43
commit 0fdf3cacf2
2 changed files with 23 additions and 14 deletions

View file

@ -20,6 +20,8 @@
#ifndef POLARSSL_XTEA_H
#define POLARSSL_XTEA_H
#include <inttypes.h>
#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;

View file

@ -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] =