Skip to content
Permalink
Browse files

xtea: use correct load and store macros

  • Loading branch information...
sjaeckel committed Jul 2, 2012
1 parent 0f0b182 commit 2526d5df8f9a228cf20ba90982aed4a5e951ac5f
Showing with 12 additions and 12 deletions.
  1. +12 −12 src/ciphers/xtea.c
@@ -48,10 +48,10 @@ int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
}

/* load key */
LOAD32L(K[0], key+0);
LOAD32L(K[1], key+4);
LOAD32L(K[2], key+8);
LOAD32L(K[3], key+12);
LOAD32H(K[0], key+0);
LOAD32H(K[1], key+4);
LOAD32H(K[2], key+8);
LOAD32H(K[3], key+12);

for (x = sum = 0; x < 32; x++) {
skey->xtea.A[x] = (sum + K[sum&3]) & 0xFFFFFFFFUL;
@@ -82,8 +82,8 @@ int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
LTC_ARGCHK(ct != NULL);
LTC_ARGCHK(skey != NULL);

LOAD32L(y, &pt[0]);
LOAD32L(z, &pt[4]);
LOAD32H(y, &pt[0]);
LOAD32H(z, &pt[4]);
for (r = 0; r < 32; r += 4) {
y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL;
z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL;
@@ -97,8 +97,8 @@ int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r+3])) & 0xFFFFFFFFUL;
z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r+3])) & 0xFFFFFFFFUL;
}
STORE32L(y, &ct[0]);
STORE32L(z, &ct[4]);
STORE32H(y, &ct[0]);
STORE32H(z, &ct[4]);
return CRYPT_OK;
}

@@ -118,8 +118,8 @@ int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
LTC_ARGCHK(ct != NULL);
LTC_ARGCHK(skey != NULL);

LOAD32L(y, &ct[0]);
LOAD32L(z, &ct[4]);
LOAD32H(y, &ct[0]);
LOAD32H(z, &ct[4]);
for (r = 31; r >= 0; r -= 4) {
z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL;
y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL;
@@ -133,8 +133,8 @@ int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r-3])) & 0xFFFFFFFFUL;
y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r-3])) & 0xFFFFFFFFUL;
}
STORE32L(y, &pt[0]);
STORE32L(z, &pt[4]);
STORE32H(y, &pt[0]);
STORE32H(z, &pt[4]);
return CRYPT_OK;
}

0 comments on commit 2526d5d

Please sign in to comment.
You can’t perform that action at this time.