From: bg Date: Wed, 26 Dec 2012 20:41:51 +0000 (+0100) Subject: [keccak-asm] removing rotate64 from asm build X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;ds=sidebyside;h=ddc66bc0543c50a0f36a3c26abf90dfef36dc3d9;hp=e7925dc3d2f76b73f54df0e22f69f789715eff8a;p=avr-crypto-lib.git [keccak-asm] removing rotate64 from asm build --- diff --git a/keccak/keccak-asm.S b/keccak/keccak-asm.S index 357c8bd..9d613f9 100644 --- a/keccak/keccak-asm.S +++ b/keccak/keccak-asm.S @@ -40,6 +40,156 @@ rho_pi_idx_table: .endr .align 2 + +.global rotate64_1bit_left +rotate64_1bit_left: + bst r25, 7 + rol r18 + rol r19 + rol r20 + rol r21 + rol r22 + rol r23 + rol r24 + rol r25 + bld r18, 0 + ret + +.global rotate64_1bit_right +rotate64_1bit_right: + bst r18, 0 + ror r25 + ror r24 + ror r23 + ror r22 + ror r21 + ror r20 + ror r19 + ror r18 + bld r25, 7 + ret + +.global rotate64_nbit_autodir +rotate64_nbit_autodir: + lsr r16 + brcc rotate64_nbit_left +.global rotate64_nbit_right +rotate64_nbit_right: + ldi r30, pm_lo8(rotate64_1bit_right) + ldi r31, pm_hi8(rotate64_1bit_right) + rjmp icall_r16_times +.global rotate64_nbit_left +rotate64_nbit_left: + ldi r30, pm_lo8(rotate64_1bit_left) + ldi r31, pm_hi8(rotate64_1bit_left) +icall_r16_times: +1: dec r16 + brmi 2f + icall + rjmp 1b +2: + ret + +rotate64_1byte_left: + mov r0, r25 + mov r25, r24 + mov r24, r23 + mov r23, r22 + mov r22, r21 + mov r21, r20 + mov r20, r19 + mov r19, r18 + mov r18, r0 + ret + +rotate64_2byte_left: + movw r0, r24 + movw r24, r22 + movw r22, r20 + movw r20, r18 + movw r18, r0 + ret + +rotate64_3byte_left: + mov r0, r25 + mov r25, r22 + mov r22, r19 + mov r19, r24 + mov r24, r21 + mov r21, r18 + mov r18, r23 + mov r23, r20 + mov r20, r0 + ret + +rotate64_4byte_left: + movw r0, r24 + movw r24, r20 + movw r20, r0 + movw r0, r22 + movw r22, r18 + movw r18, r0 + ret + +rotate64_5byte_left: + mov r0, r25 + mov r25, r20 + mov r20, r23 + mov r23, r18 + mov r18, r21 + mov r21, r24 + mov r24, r19 + mov r19, r22 + mov r22, r0 + ret + +rotate64_6byte_left: + movw r0, r18 + movw r18, r20 + movw r20, r22 + movw r22, r24 + movw r24, r0 + ret + +rotate64_7byte_left: + mov r0, r18 + mov r18, r19 + mov r19, r20 + mov r20, r21 + mov r21, r22 + mov r22, r23 + mov r23, r24 + mov r24, r25 + mov r25, r0 + ret + + +byte_rot_jmp_table: + ret + rjmp rotate64_1byte_left + rjmp rotate64_2byte_left + rjmp rotate64_3byte_left + rjmp rotate64_4byte_left + rjmp rotate64_5byte_left + rjmp rotate64_6byte_left + rjmp rotate64_7byte_left + +.global rotate64left_code +rotate64left_code: + ldi r30, pm_lo8(byte_rot_jmp_table) + ldi r31, pm_hi8(byte_rot_jmp_table) + mov r0, r16 + andi r16, 0x70 + swap r16 + add r30, r16 + adc r31, r1 + mov r16, r0 + andi r16, 0x0f + icall + clr r1 + rjmp rotate64_nbit_autodir + + /* void keccak_theta (uint64_t *a, uint64_t *b){ // uint64_t b[5][5]; @@ -309,7 +459,7 @@ keccak_f1600: movw ZL, r2 lpm r16, Z+ movw r2, ZL - call rotate64left_code + rcall rotate64left_code movw ZL, r4 lpm r16, Z+ movw r4, ZL diff --git a/keccak/keccak-stub.c b/keccak/keccak-stub.c index 4e5a58a..ff198e7 100644 --- a/keccak/keccak-stub.c +++ b/keccak/keccak-stub.c @@ -62,22 +62,6 @@ void keccak_dump_ctx(keccak_ctx_t* ctx){ #endif -/* -const uint64_t rc[] PROGMEM = { - 0x0000000000000001LL, 0x0000000000008082LL, - 0x800000000000808ALL, 0x8000000080008000LL, - 0x000000000000808BLL, 0x0000000080000001LL, - 0x8000000080008081LL, 0x8000000000008009LL, - 0x000000000000008ALL, 0x0000000000000088LL, - 0x0000000080008009LL, 0x000000008000000ALL, - 0x000000008000808BLL, 0x800000000000008BLL, - 0x8000000000008089LL, 0x8000000000008003LL, - 0x8000000000008002LL, 0x8000000000000080LL, - 0x000000000000800ALL, 0x800000008000000ALL, - 0x8000000080008081LL, 0x8000000000008080LL, - 0x0000000080000001LL, 0x8000000080008008LL -}; -*/ const uint8_t keccak_rc_comp[] PROGMEM = { 0x01, 0x92, 0xda, 0x70, @@ -87,15 +71,7 @@ const uint8_t keccak_rc_comp[] PROGMEM = { 0x52, 0xc0, 0x1a, 0x6a, 0xf1, 0xd0, 0x21, 0x78, }; -/* -const uint8_t keccak_rotate_codes[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) }, - { ROT_CODE(62), ROT_CODE( 6), ROT_CODE(43), ROT_CODE(15), ROT_CODE(61) }, - { ROT_CODE(28), ROT_CODE(55), ROT_CODE(25), ROT_CODE(21), ROT_CODE(56) }, - { ROT_CODE(27), ROT_CODE(20), ROT_CODE(39), ROT_CODE( 8), ROT_CODE(14) } -}; -*/ + const uint8_t keccak_rotate_codes[5][5] PROGMEM = { { ROT_CODE( 0), ROT_CODE( 1), ROT_CODE(62), ROT_CODE(28), ROT_CODE(27) }, { ROT_CODE(36), ROT_CODE(44), ROT_CODE( 6), ROT_CODE(55), ROT_CODE(20) }, diff --git a/mkfiles/keccak_asm.mk b/mkfiles/keccak_asm.mk index 10f7635..f79d114 100644 --- a/mkfiles/keccak_asm.mk +++ b/mkfiles/keccak_asm.mk @@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME) $(ALGO_NAME)_DIR := keccak/ $(ALGO_NAME)_INCDIR := memxor/ hfal/ -$(ALGO_NAME)_OBJ := keccak-stub.o keccak-asm.o memxor.o rotate64.o +$(ALGO_NAME)_OBJ := keccak-stub.o keccak-asm.o memxor.o $(ALGO_NAME)_TESTBIN := main-keccak-test.o hfal_keccak.o $(CLI_STD) $(HFAL_STD) $(ALGO_NAME)_NESSIE_TEST := test nessie $(ALGO_NAME)_PERFORMANCE_TEST := performance