3 This file is part of the Crypto-avr-lib/microcrypt-lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * \brief XTEA implemantation
22 * copy'n'pasted from http://en.wikipedia.org/wiki/XTEA
23 * and slightly modified
29 void xtea_enc(void* dest, const void* v, const void* k) {
31 uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
32 uint32_t sum=0, delta=0x9E3779B9;
34 v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((uint32_t*)k)[sum & 3]);
36 v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + ((uint32_t*)k)[sum>>11 & 3]);
38 ((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;
41 void xtea_dec(void* dest, const void* v, const void* k) {
43 uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
44 uint32_t sum=0xC6EF3720, delta=0x9E3779B9;
46 v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + ((uint32_t*)k)[sum>>11 & 3]);
48 v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((uint32_t*)k)[sum & 3]);
50 ((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;