MD5 now completly in ASM
This commit is contained in:
parent
a397db40b9
commit
d5e2587658
64
md5-asm.S
64
md5-asm.S
|
@ -785,7 +785,7 @@ md5_lastBlock:
|
||||||
movw r16, r20 /* length_b */
|
movw r16, r20 /* length_b */
|
||||||
movw r14, r22 /* block_ptr */
|
movw r14, r22 /* block_ptr */
|
||||||
movw r12, r24 /* state_ptr */
|
movw r12, r24 /* state_ptr */
|
||||||
|
2:
|
||||||
cpi r17, 2 /* hi8(512) */
|
cpi r17, 2 /* hi8(512) */
|
||||||
brlo 2f
|
brlo 2f
|
||||||
1:
|
1:
|
||||||
|
@ -796,7 +796,7 @@ md5_lastBlock:
|
||||||
add r14, r18
|
add r14, r18
|
||||||
adc r15, r1
|
adc r15, r1
|
||||||
subi r17, 2
|
subi r17, 2
|
||||||
brge 1b
|
rjmp 2b
|
||||||
2:
|
2:
|
||||||
pop r31
|
pop r31
|
||||||
pop r30
|
pop r30
|
||||||
|
@ -911,5 +911,65 @@ md5_lastBlock_exit:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
;###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
.global md5_ctx2hash
|
||||||
|
md5_ctx2hash:
|
||||||
|
movw r26, r24
|
||||||
|
movw r30, r22
|
||||||
|
ldi r22, 16
|
||||||
|
1:
|
||||||
|
ld r0, Z+
|
||||||
|
st X+, r0
|
||||||
|
dec r22
|
||||||
|
brne 1b
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
;###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
.global md5
|
||||||
|
md5:
|
||||||
|
stack_alloc 20
|
||||||
|
push_range 8, 17
|
||||||
|
adiw r30, 1
|
||||||
|
movw r8, r30 /* ctx */
|
||||||
|
movw r10, r24 /* dest */
|
||||||
|
movw r12, r22 /* msg */
|
||||||
|
movw r14, r18 /* length (low) */
|
||||||
|
movw r16, r20 /* length (high) */
|
||||||
|
movw r24, r30
|
||||||
|
rcall md5_init
|
||||||
|
1:
|
||||||
|
tst r16
|
||||||
|
brne next_round
|
||||||
|
tst r17
|
||||||
|
breq last_round
|
||||||
|
next_round:
|
||||||
|
movw r24, r8
|
||||||
|
movw r22, r12
|
||||||
|
rcall md5_nextBlock
|
||||||
|
ldi r22, 64
|
||||||
|
add r12, r22
|
||||||
|
adc r13, r1
|
||||||
|
ldi r22, 2
|
||||||
|
sub r15, r22
|
||||||
|
sbci r16, 0
|
||||||
|
sbci r17, 0
|
||||||
|
rjmp 1b
|
||||||
|
last_round:
|
||||||
|
movw r24, r8
|
||||||
|
movw r22, r12
|
||||||
|
movw r20, r14
|
||||||
|
rcall md5_lastBlock
|
||||||
|
movw r24, r10
|
||||||
|
movw r22, r8
|
||||||
|
rcall md5_ctx2hash
|
||||||
|
pop_range 8, 17
|
||||||
|
stack_free 20
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
43
md5-stub.c
43
md5-stub.c
|
@ -1,43 +0,0 @@
|
||||||
/* md5-asm.c */
|
|
||||||
/*
|
|
||||||
This file is part of the Crypto-avr-lib/microcrypt-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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "md5.h"
|
|
||||||
#include "uart.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#undef DEBUG
|
|
||||||
|
|
||||||
|
|
||||||
void md5_ctx2hash(md5_hash_t* dest, const md5_ctx_t* state){
|
|
||||||
memcpy(dest, state->a, MD5_HASH_BYTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
void md5(md5_hash_t* dest, const void* msg, uint32_t length_b){
|
|
||||||
md5_ctx_t ctx;
|
|
||||||
md5_init(&ctx);
|
|
||||||
while(length_b>=MD5_BLOCK_BITS){
|
|
||||||
md5_nextBlock(&ctx, msg);
|
|
||||||
msg = (uint8_t*)msg + MD5_BLOCK_BYTES;
|
|
||||||
length_b -= MD5_BLOCK_BITS;
|
|
||||||
}
|
|
||||||
md5_lastBlock(&ctx, msg, length_b);
|
|
||||||
md5_ctx2hash(dest, &ctx);
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ ALGO_NAME := MD5_ASM
|
||||||
# comment out the following line for removement of MD5 from the build process
|
# comment out the following line for removement of MD5 from the build process
|
||||||
HASHES += $(ALGO_NAME)
|
HASHES += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := md5-asm.o md5-stub.o
|
$(ALGO_NAME)_OBJ := md5-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o \
|
||||||
nessie_hash_test.o nessie_common.o cli.o performance_test.o
|
nessie_hash_test.o nessie_common.o cli.o performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue