]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - xtea.c
insereated GPLv3 stub
[avr-crypto-lib.git] / xtea.c
diff --git a/xtea.c b/xtea.c
index 70ad914a12519e91f674e8a16604cfda6c42110a..0412754d5785db3ace46f634b042fa0e32adb8f1 100644 (file)
--- a/xtea.c
+++ b/xtea.c
@@ -1,3 +1,21 @@
+/* xtea.c */
+/*
+    This file is part of the Crypto-avr-lib/microcrypt-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 <http://www.gnu.org/licenses/>.
+*/
 /** 
  * \file       xtea.c
  * \brief      XTEA implemantation 
 #include <stdint.h> 
  
 
-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;
 }