optimized cubehash a bit

This commit is contained in:
bg 2010-09-01 00:50:09 +00:00
parent 25ccd391d2
commit f078dc4f51
5 changed files with 89 additions and 14 deletions

View File

@ -28,12 +28,10 @@
#include "memxor.h"
#include "cubehash.h"
#include "cubehash_rotates.h"
#include <string.h>
#include <stdint.h>
static uint32_t rol32(uint32_t a, uint8_t r){
return (a<<r)|(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];

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
.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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef CUBEHASH_ROTATES_H_
#define CUBEHASH_ROTATES_H_
#include <stdint.h>
uint32_t rotate7left(uint32_t a);
uint32_t rotate11left(uint32_t a);
#endif /* CUBEHASH_ROTATES_H_ */

View File

@ -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<<r)|(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) },

View File

@ -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