X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=xtea.c;h=36050f61f5d7488ba9201c768ff9af66ead9e8e2;hb=e9d58dce0a1eca2c78aec260406e1605ae29fff7;hp=70ad914a12519e91f674e8a16604cfda6c42110a;hpb=9b1bf59ca8d49db1a7495d95119c68d62b036c59;p=avr-crypto-lib.git
diff --git a/xtea.c b/xtea.c
index 70ad914..36050f6 100644
--- a/xtea.c
+++ b/xtea.c
@@ -1,3 +1,21 @@
+/* xtea.c */
+/*
+ This file is part of the This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
/**
* \file xtea.c
* \brief XTEA implemantation
@@ -8,26 +26,28 @@
#include
-void xtea_enc(uint32_t* dest, uint32_t* v, uint32_t* k) {
- uint32_t v0=v[0], v1=v[1], i;
+void xtea_enc(void* dest, const void* v, const void* k) {
+ uint8_t i;
+ uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
uint32_t sum=0, delta=0x9E3779B9;
for(i=0; i<32; i++) {
- v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
+ v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((uint32_t*)k)[sum & 3]);
sum += delta;
- v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
+ v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + ((uint32_t*)k)[sum>>11 & 3]);
}
- dest[0]=v0; dest[1]=v1;
+ ((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;
}
-void xtea_dec(uint32_t* dest, uint32_t* v, uint32_t* k) {
- uint32_t v0=v[0], v1=v[1], i;
+void xtea_dec(void* dest, const void* v, const void* k) {
+ uint8_t i;
+ uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
uint32_t sum=0xC6EF3720, delta=0x9E3779B9;
for(i=0; i<32; i++) {
- v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
+ v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + ((uint32_t*)k)[sum>>11 & 3]);
sum -= delta;
- v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
+ v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((uint32_t*)k)[sum & 3]);
}
- dest[0]=v0; dest[1]=v1;
+ ((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;
}