adding Noekeon and XTEA
This commit is contained in:
parent
3fdf095440
commit
b6f2bb4e1a
|
@ -1,18 +1,17 @@
|
|||
/* bcal_noekeon.c */
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include <stdlib.h>
|
||||
#include "blockcipher_descriptor.h"
|
||||
#include "noekeon.h"
|
||||
#include "keysize_descriptor.h"
|
||||
|
||||
const char noekeon_direct_str[] PROGMEM = "Noekeon-Direct";
|
||||
const char noekeon_indirect_str[] PROGMEM = "Noekeon-Indirect";
|
||||
const char noekeon_direct_str[] = "Noekeon-Direct";
|
||||
const char noekeon_indirect_str[] = "Noekeon-Indirect";
|
||||
|
||||
const uint8_t noekeon_keysize_desc[] PROGMEM = { KS_TYPE_LIST, 1, KS_INT(128),
|
||||
KS_TYPE_TERMINATOR };
|
||||
const uint8_t noekeon_keysize_desc[] = { KS_TYPE_LIST, 1, KS_INT(128),
|
||||
KS_TYPE_TERMINATOR };
|
||||
|
||||
const bcdesc_t noekeon_direct_desc PROGMEM = {
|
||||
const bcdesc_t noekeon_direct_desc = {
|
||||
BCDESC_TYPE_BLOCKCIPHER,
|
||||
BC_ENC_TYPE_1,
|
||||
noekeon_direct_str,
|
||||
|
@ -25,7 +24,7 @@ const bcdesc_t noekeon_direct_desc PROGMEM = {
|
|||
noekeon_keysize_desc
|
||||
};
|
||||
|
||||
const bcdesc_t noekeon_indirect_desc PROGMEM = {
|
||||
const bcdesc_t noekeon_indirect_desc = {
|
||||
BCDESC_TYPE_BLOCKCIPHER,
|
||||
BC_INIT_TYPE_1 | BC_ENC_TYPE_1,
|
||||
noekeon_indirect_str,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* bcal_noekeon.h */
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include "blockcipher_descriptor.h"
|
||||
#include "noekeon.h"
|
||||
#include "keysize_descriptor.h"
|
||||
|
|
|
@ -25,16 +25,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include <stdlib.h>
|
||||
#include "blockcipher_descriptor.h"
|
||||
#include "xtea.h"
|
||||
#include "keysize_descriptor.h"
|
||||
|
||||
const char xtea_str[] PROGMEM = "XTEA";
|
||||
const char xtea_str[] = "XTEA";
|
||||
|
||||
const uint8_t xtea_keysize_desc[] PROGMEM = { KS_TYPE_LIST, 1, KS_INT(128),
|
||||
KS_TYPE_TERMINATOR };
|
||||
const uint8_t xtea_keysize_desc[] = { KS_TYPE_LIST, 1, KS_INT(128),
|
||||
KS_TYPE_TERMINATOR };
|
||||
|
||||
static
|
||||
void xtea_dummy_enc(void* block, void* key){
|
||||
|
@ -46,7 +45,7 @@ void xtea_dummy_dec(void* block, void* key){
|
|||
xtea_dec(block, block, key);
|
||||
}
|
||||
|
||||
const bcdesc_t xtea_desc PROGMEM = {
|
||||
const bcdesc_t xtea_desc = {
|
||||
BCDESC_TYPE_BLOCKCIPHER,
|
||||
BC_INIT_TYPE_2,
|
||||
xtea_str,
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include "blockcipher_descriptor.h"
|
||||
#include "xtea.h"
|
||||
#include "keysize_descriptor.h"
|
||||
|
|
|
@ -111,7 +111,7 @@ param=(ARGV.size>=7)?ARGV[6]:"";
|
|||
|
||||
puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n");
|
||||
$linewidth = 16
|
||||
$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::SOFT);
|
||||
$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
|
||||
$sp.read_timeout=1000; # 1 secound
|
||||
$extended_wait=100;
|
||||
$sp.write(command);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# Makefile for noekeon
|
||||
ALGO_NAME := NOEKEON_C
|
||||
|
||||
# comment out the following line for removement of noekeon from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_OBJ := noekeon.o
|
||||
$(ALGO_NAME)_DIR := noekeon/
|
||||
$(ALGO_NAME)_INCDIR := bcal/
|
||||
$(ALGO_NAME)_TEST_BIN := main-noekeon-test.o bcal_noekeon.o $(CLI_STD) $(BCAL_STD)
|
||||
$(ALGO_NAME)_NESSIE_TEST := test nessie
|
||||
$(ALGO_NAME)_PERFORMANCE_TEST := performance
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Makefile for XTEA
|
||||
ALGO_NAME := XTEA_C
|
||||
|
||||
# comment out the following line for removement of XTEA from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := xtea/
|
||||
$(ALGO_NAME)_OBJ := xtea.o
|
||||
$(ALGO_NAME)_INCDIR := bcal/
|
||||
$(ALGO_NAME)_TEST_BIN := main-xtea-test.o bcal_xtea.o $(CLI_STD) $(BCAL_STD)
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
#define RC_POS 0
|
||||
|
||||
static
|
||||
void gamma(uint32_t* a){
|
||||
void gamma_x(uint32_t* a){
|
||||
uint32_t tmp;
|
||||
|
||||
a[1] ^= ~((a[3]) | (a[2]));
|
||||
|
@ -94,7 +94,7 @@ void noekeon_round(uint32_t* key, uint32_t* state, uint8_t const1, uint8_t const
|
|||
theta(key, state);
|
||||
((uint8_t*)state)[RC_POS] ^= const2;
|
||||
pi1(state);
|
||||
gamma(state);
|
||||
gamma_x(state);
|
||||
pi2(state);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,232 @@
|
|||
/* main-noekeon-test.c */
|
||||
/*
|
||||
This file is part of the ARM-Crypto-Lib.
|
||||
Copyright (C) 2006-2010 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/>.
|
||||
*/
|
||||
/*
|
||||
* noekeon test-suit
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "cli.h"
|
||||
#include "dump.h"
|
||||
#include "uart_lowlevel.h"
|
||||
#include "sysclock.h"
|
||||
#include "hw_gptm.h"
|
||||
|
||||
#include <noekeon/noekeon.h>
|
||||
#include "nessie_bc_test.h"
|
||||
#include "performance_test.h"
|
||||
#include "bcal-performance.h"
|
||||
#include "bcal_noekeon.h"
|
||||
|
||||
const char* algo_name = "Noekeon";
|
||||
|
||||
void uart0_putc(char byte){
|
||||
uart_putc(UART_0, byte);
|
||||
}
|
||||
|
||||
char uart0_getc(void){
|
||||
return uart_getc(UART_0);
|
||||
}
|
||||
|
||||
const bcdesc_t* algolist[] = {
|
||||
(bcdesc_t*)&noekeon_direct_desc,
|
||||
(bcdesc_t*)&noekeon_indirect_desc,
|
||||
NULL
|
||||
};
|
||||
/*****************************************************************************
|
||||
* additional validation-functions *
|
||||
*****************************************************************************/
|
||||
void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
|
||||
noekeon_init(key, ctx);
|
||||
}
|
||||
|
||||
void testrun_nessie_noekeon_indirect(void){
|
||||
char str[strlen(algo_name)+10];
|
||||
strcpy(str, algo_name);
|
||||
strcat(str, "-indirect");
|
||||
|
||||
nessie_bc_ctx.blocksize_B = 16;
|
||||
nessie_bc_ctx.keysize_b = 128;
|
||||
nessie_bc_ctx.name = str;
|
||||
nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t);
|
||||
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc;
|
||||
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec;
|
||||
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy;
|
||||
|
||||
nessie_bc_run();
|
||||
}
|
||||
|
||||
void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){
|
||||
memcpy(ctx, key, 16);
|
||||
}
|
||||
|
||||
void testrun_nessie_noekeon_direct(void){
|
||||
char str[strlen(algo_name)+10];
|
||||
strcpy(str, algo_name);
|
||||
strcat(str, "-Direct");
|
||||
|
||||
nessie_bc_ctx.blocksize_B = 16;
|
||||
nessie_bc_ctx.keysize_b = 128;
|
||||
nessie_bc_ctx.name = str;
|
||||
nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t);
|
||||
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc;
|
||||
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec;
|
||||
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct;
|
||||
|
||||
nessie_bc_run();
|
||||
}
|
||||
|
||||
void testrun_nessie_noekeon(void){
|
||||
testrun_nessie_noekeon_direct();
|
||||
testrun_nessie_noekeon_indirect();
|
||||
}
|
||||
|
||||
|
||||
void testrun_stdtest_rundirect(void* data, void* key){
|
||||
cli_putstr("\r\n ");
|
||||
cli_putstr("k = ");
|
||||
cli_hexdump(key,16);
|
||||
|
||||
cli_putstr("\r\n ");
|
||||
cli_putstr("a = ");
|
||||
cli_hexdump(data,16);
|
||||
|
||||
noekeon_enc(data, key);
|
||||
cli_putstr("\r\nafter NESSIEencrypt, b = ");
|
||||
cli_hexdump(data,16);
|
||||
|
||||
noekeon_dec(data, key);
|
||||
cli_putstr("\r\nafter NESSIEdecrypt, a?= ");
|
||||
cli_hexdump(data,16);
|
||||
cli_putstr("\r\n");
|
||||
}
|
||||
|
||||
void testrun_stdtest_runindirect(void* data, void* key){
|
||||
noekeon_ctx_t ctx;
|
||||
cli_putstr("\r\n ");
|
||||
cli_putstr("k = ");
|
||||
cli_hexdump(key,16);
|
||||
|
||||
cli_putstr("\r\n ");
|
||||
cli_putstr("a = ");
|
||||
cli_hexdump(data,16);
|
||||
noekeon_init(key, &ctx);
|
||||
noekeon_enc(data, &ctx);
|
||||
cli_putstr("\r\nafter NESSIEencrypt, b = ");
|
||||
cli_hexdump(data,16);
|
||||
|
||||
noekeon_dec(data, &ctx);
|
||||
cli_putstr("\r\nafter NESSIEdecrypt, a?= ");
|
||||
cli_hexdump(data,16);
|
||||
cli_putstr("\r\n");
|
||||
}
|
||||
|
||||
void testrun_stdtest_noekeon(void){
|
||||
uint8_t key[16], data[16];
|
||||
uint8_t key3[16];
|
||||
noekeon_ctx_t ctx;
|
||||
|
||||
cli_putstr("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n");
|
||||
|
||||
memset(key, 0, 16);
|
||||
memset(data, 0, 16);
|
||||
testrun_stdtest_runindirect(data, key);
|
||||
|
||||
memset(key, 0xFF, 16);
|
||||
memset(data, 0xFF, 16);
|
||||
testrun_stdtest_runindirect(data, key);
|
||||
|
||||
memset(key, 0, 16);
|
||||
memset(data, 0, 16);
|
||||
noekeon_init(key, &ctx);
|
||||
noekeon_enc(data, &ctx);
|
||||
memcpy(key3, data, 16);
|
||||
memset(key, 0xFF, 16);
|
||||
memset(data, 0xFF, 16);
|
||||
noekeon_init(key, &ctx);
|
||||
noekeon_enc(data, &ctx);
|
||||
testrun_stdtest_runindirect(data, key3);
|
||||
|
||||
cli_putstr("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n");
|
||||
|
||||
memset(key, 0, 16);
|
||||
memset(data, 0, 16);
|
||||
testrun_stdtest_rundirect(data, key);
|
||||
|
||||
memset(key, 0xFF, 16);
|
||||
memset(data, 0xFF, 16);
|
||||
testrun_stdtest_rundirect(data, key);
|
||||
|
||||
memset(key, 0, 16);
|
||||
memset(data, 0, 16);
|
||||
noekeon_enc(data, key);
|
||||
memcpy(key3, data, 16);
|
||||
memset(key, 0xFF, 16);
|
||||
memset(data, 0xFF, 16);
|
||||
noekeon_enc(data, key);
|
||||
testrun_stdtest_rundirect(data, key3);
|
||||
|
||||
}
|
||||
|
||||
void testrun_performance_noekeon(void){
|
||||
bcal_performance_multiple(algolist);
|
||||
}
|
||||
/*****************************************************************************
|
||||
* main *
|
||||
*****************************************************************************/
|
||||
|
||||
const char nessie_str[] = "nessie";
|
||||
const char test_str[] = "test";
|
||||
const char direct_str[] = "direct";
|
||||
const char indirect_str[] = "indirect";
|
||||
const char performance_str[] = "performance";
|
||||
const char echo_str[] = "echo";
|
||||
|
||||
cmdlist_entry_t cmdlist[] = {
|
||||
{ nessie_str, NULL, testrun_nessie_noekeon},
|
||||
{ test_str, NULL, testrun_stdtest_noekeon},
|
||||
{ direct_str, NULL, testrun_nessie_noekeon_direct},
|
||||
{ indirect_str, NULL, testrun_nessie_noekeon_indirect},
|
||||
{ performance_str, NULL, testrun_performance_noekeon},
|
||||
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
|
||||
{ NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
int main (void){
|
||||
sysclk_set_freq(SYS_FREQ);
|
||||
sysclk_mosc_verify_enable();
|
||||
uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
|
||||
gptm_set_timer_32periodic(TIMER0);
|
||||
|
||||
cli_rx = uart0_getc;
|
||||
cli_tx = uart0_putc;
|
||||
|
||||
for(;;){
|
||||
cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
|
||||
cli_putstr(algo_name);
|
||||
cli_putstr("; ");
|
||||
cli_putstr(__DATE__);
|
||||
cli_putc(' ');
|
||||
cli_putstr(__TIME__);
|
||||
cli_putstr(")\r\nloaded and running\r\n");
|
||||
cmd_interface(cmdlist);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/* main-xtea-test.c */
|
||||
/*
|
||||
This file is part of the ARM-Crypto-Lib.
|
||||
Copyright (C) 2006-2010 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/>.
|
||||
*/
|
||||
/*
|
||||
* XTEA test-suit
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "cli.h"
|
||||
#include "dump.h"
|
||||
#include "uart_lowlevel.h"
|
||||
#include "sysclock.h"
|
||||
#include "hw_gptm.h"
|
||||
|
||||
#include "xtea.h"
|
||||
#include "nessie_bc_test.h"
|
||||
#include "performance_test.h"
|
||||
#include "bcal-performance.h"
|
||||
#include "bcal_xtea.h"
|
||||
|
||||
char* algo_name = "XTEA";
|
||||
|
||||
void uart0_putc(char byte){
|
||||
uart_putc(UART_0, byte);
|
||||
}
|
||||
|
||||
char uart0_getc(void){
|
||||
return uart_getc(UART_0);
|
||||
}
|
||||
|
||||
const bcdesc_t* algolist[] = {
|
||||
(bcdesc_t*)&xtea_desc,
|
||||
NULL
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void xtea_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
|
||||
memcpy(ctx, key, (keysize+7)/8);
|
||||
}
|
||||
|
||||
void xtea_enc_dummy(uint8_t* buffer, void* ctx){
|
||||
xtea_enc((uint32_t*)buffer, (uint32_t*)buffer, ctx);
|
||||
}
|
||||
|
||||
void xtea_dec_dummy(uint8_t* buffer, void* ctx){
|
||||
xtea_dec((uint32_t*)buffer, (uint32_t*)buffer, ctx);
|
||||
}
|
||||
|
||||
void testrun_nessie_xtea(void){
|
||||
nessie_bc_ctx.blocksize_B = 8;
|
||||
nessie_bc_ctx.keysize_b = 128;
|
||||
nessie_bc_ctx.name = algo_name;
|
||||
nessie_bc_ctx.ctx_size_B = 128/8;
|
||||
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)xtea_enc_dummy;
|
||||
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)xtea_dec_dummy;
|
||||
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)xtea_genctx_dummy;
|
||||
|
||||
nessie_bc_run();
|
||||
}
|
||||
|
||||
void testrun_performance_xtea(void){
|
||||
bcal_performance_multiple(algolist);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* main *
|
||||
*****************************************************************************/
|
||||
|
||||
const char nessie_str[] = "nessie";
|
||||
const char test_str[] = "test";
|
||||
const char performance_str[] = "performance";
|
||||
const char echo_str[] = "echo";
|
||||
|
||||
const cmdlist_entry_t cmdlist[] = {
|
||||
{ nessie_str, NULL, testrun_nessie_xtea},
|
||||
{ test_str, NULL, testrun_nessie_xtea},
|
||||
{ performance_str, NULL, testrun_performance_xtea},
|
||||
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
|
||||
{ NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
int main (void){
|
||||
sysclk_set_freq(SYS_FREQ);
|
||||
sysclk_mosc_verify_enable();
|
||||
uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
|
||||
gptm_set_timer_32periodic(TIMER0);
|
||||
|
||||
cli_rx = uart0_getc;
|
||||
cli_tx = uart0_putc;
|
||||
|
||||
for(;;){
|
||||
cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
|
||||
cli_putstr(algo_name);
|
||||
cli_putstr("; ");
|
||||
cli_putstr(__DATE__);
|
||||
cli_putc(' ');
|
||||
cli_putstr(__TIME__);
|
||||
cli_putstr(")\r\nloaded and running\r\n");
|
||||
cmd_interface(cmdlist);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,53 @@
|
|||
/* xtea.c */
|
||||
/*
|
||||
This file is part of the ARM-Crypto-Lib.
|
||||
Copyright (C) 2006-2010 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
|
||||
* copy'n'pasted from http://en.wikipedia.org/wiki/XTEA
|
||||
* and slightly modified
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
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 + ((uint32_t*)k)[sum & 3]);
|
||||
sum += delta;
|
||||
v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + ((uint32_t*)k)[sum>>11 & 3]);
|
||||
}
|
||||
((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;
|
||||
}
|
||||
|
||||
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 + ((uint32_t*)k)[sum>>11 & 3]);
|
||||
sum -= delta;
|
||||
v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((uint32_t*)k)[sum & 3]);
|
||||
}
|
||||
((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/* xtea.h */
|
||||
/*
|
||||
This file is part of the ARM-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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
* Author: Daniel Otte
|
||||
* Date: 06.06.2006
|
||||
* License: GPL
|
||||
*/
|
||||
|
||||
#ifndef XTEA_H_
|
||||
#define XTEA_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* this fits for xtea.c and xtea-asm.S
|
||||
*
|
||||
*/
|
||||
#define XTEA_BLOCKSIZE 64
|
||||
#define XTEA_BLOCKSIZEB ((XTEA_BLOCKSIZE+7)/8)
|
||||
#define XTEA_KEYSIZE 128
|
||||
#define XTEA_KEYSIZEB ((XTEA_KEYSIZE+7)/8)
|
||||
|
||||
|
||||
/*
|
||||
* dest: the destination where result of operation will be placed (64 bit)
|
||||
* v: the block to operate on (64 bit)
|
||||
* k: the key for en/decryption (128 bit)
|
||||
*/
|
||||
void xtea_enc(void* dest, const void* v, const void* k);
|
||||
void xtea_dec(void* dest, const void* v, const void* k);
|
||||
|
||||
|
||||
#endif /*XTEA_H_*/
|
Loading…
Reference in New Issue