From f078dc4f51afdd67e888869fa5d9e93571ea354f Mon Sep 17 00:00:00 2001 From: bg Date: Wed, 1 Sep 2010 00:50:09 +0000 Subject: [PATCH] optimized cubehash a bit --- cubehash/cubehash.c | 12 ++------ cubehash/cubehash_rotates.S | 57 +++++++++++++++++++++++++++++++++++++ cubehash/cubehash_rotates.h | 28 ++++++++++++++++++ keccak/keccak.c | 4 --- mkfiles/cubehash_c.mk | 2 +- 5 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 cubehash/cubehash_rotates.S create mode 100644 cubehash/cubehash_rotates.h diff --git a/cubehash/cubehash.c b/cubehash/cubehash.c index 997378f..bb5852c 100644 --- a/cubehash/cubehash.c +++ b/cubehash/cubehash.c @@ -28,12 +28,10 @@ #include "memxor.h" #include "cubehash.h" +#include "cubehash_rotates.h" #include #include -static uint32_t rol32(uint32_t a, uint8_t r){ - return (a<>(32-r)); -} /* • Add x_0jklm into x_1jklm modulo 232 , for each (j, k, l, m). • Rotate x_0jklm upwards by 7 bits, for each (j, k, l, m). @@ -52,9 +50,7 @@ static void cubehash_round(cubehash_ctx_t* ctx){ uint32_t t; for(i=0; i<16; ++i){ ctx->a[i+16] += ctx->a[i]; - } - for(i=0; i<16; ++i){ - ctx->a[i] = rol32(ctx->a[i], 7); + ctx->a[i] = rotate7left(ctx->a[i]); } for(i=0; i<8; ++i){ t = ctx->a[i]; @@ -74,9 +70,7 @@ static void cubehash_round(cubehash_ctx_t* ctx){ } for(i=0; i<16; ++i){ ctx->a[i+16] += ctx->a[i]; - } - for(i=0; i<16; ++i){ - ctx->a[i] = rol32(ctx->a[i], 11); + ctx->a[i] = rotate11left(ctx->a[i]); } for(i=0; i<4; ++i){ t = ctx->a[i]; diff --git a/cubehash/cubehash_rotates.S b/cubehash/cubehash_rotates.S new file mode 100644 index 0000000..2e4ca16 --- /dev/null +++ b/cubehash/cubehash_rotates.S @@ -0,0 +1,57 @@ +/* cubehash_rotates.S */ +/* + 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 . +*/ + +.global rotate7left +rotate7left: + mov r0, r25 + mov r25, r24 + mov r24, r23 + mov r23, r22 + mov r22, r0 + ror r0 + ror r25 + ror r24 + ror r23 + ror r22 + ret + +.global rotate11left +rotate11left: + mov r0, r25 + mov r25, r24 + mov r24, r23 + mov r23, r22 + mov r22, r0 + rol r0 + rol r23 + rol r24 + rol r25 + rol r22 + rol r0 + rol r23 + rol r24 + rol r25 + rol r22 + rol r0 + rol r23 + rol r24 + rol r25 + rol r22 + ret + diff --git a/cubehash/cubehash_rotates.h b/cubehash/cubehash_rotates.h new file mode 100644 index 0000000..7e7834a --- /dev/null +++ b/cubehash/cubehash_rotates.h @@ -0,0 +1,28 @@ +/* cubehash_rotates.h */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 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 . +*/ + +#ifndef CUBEHASH_ROTATES_H_ +#define CUBEHASH_ROTATES_H_ + +#include + +uint32_t rotate7left(uint32_t a); +uint32_t rotate11left(uint32_t a); + +#endif /* CUBEHASH_ROTATES_H_ */ diff --git a/keccak/keccak.c b/keccak/keccak.c index 809f219..e7d5279 100644 --- a/keccak/keccak.c +++ b/keccak/keccak.c @@ -87,10 +87,6 @@ static uint8_t rc_comp[] PROGMEM = { 0xf1, 0xd0, 0x21, 0x78, }; -uint64_t rotl64(uint64_t a, uint8_t r){ - return (a<>(64-r)); -} - static uint8_t r[5][5] PROGMEM = { { ROT_CODE( 0), ROT_CODE(36), ROT_CODE( 3), ROT_CODE(41), ROT_CODE(18) }, { ROT_CODE( 1), ROT_CODE(44), ROT_CODE(10), ROT_CODE(45), ROT_CODE( 2) }, diff --git a/mkfiles/cubehash_c.mk b/mkfiles/cubehash_c.mk index 7ed0169..73c227e 100644 --- a/mkfiles/cubehash_c.mk +++ b/mkfiles/cubehash_c.mk @@ -5,7 +5,7 @@ ALGO_NAME := CUBEHASH_C HASHES += $(ALGO_NAME) $(ALGO_NAME)_DIR := cubehash/ -$(ALGO_NAME)_OBJ := cubehash.o memxor.o +$(ALGO_NAME)_OBJ := cubehash.o cubehash_rotates.o memxor.o $(ALGO_NAME)_TEST_BIN := main-cubehash-test.o hfal_cubehash.o $(CLI_STD) $(HFAL_STD) $(ALGO_NAME)_NESSIE_TEST := test nessie $(ALGO_NAME)_PERFORMANCE_TEST := performance -- 2.39.5