X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=md5-asm.S;h=e48c28d4391408c10e4748661214deeb54cde5a1;hb=17332291e15183d71d88ed868275e3cb53917180;hp=2928fe370b6463ab3ad244f3b296feb6cf641ee3;hpb=a397db40b94b01a3ed72f9367961cf68d82593d1;p=avr-crypto-lib.git diff --git a/md5-asm.S b/md5-asm.S index 2928fe3..e48c28d 100644 --- a/md5-asm.S +++ b/md5-asm.S @@ -1,6 +1,6 @@ /* md5-asm.S */ /* - This file is part of the Crypto-avr-lib/microcrypt-lib. + This file is part of the This file is part of the AVR-Crypto-Lib. Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) This program is free software: you can redistribute it and/or modify @@ -785,7 +785,7 @@ md5_lastBlock: movw r16, r20 /* length_b */ movw r14, r22 /* block_ptr */ movw r12, r24 /* state_ptr */ - +2: cpi r17, 2 /* hi8(512) */ brlo 2f 1: @@ -796,7 +796,7 @@ md5_lastBlock: add r14, r18 adc r15, r1 subi r17, 2 - brge 1b + rjmp 2b 2: pop r31 pop r30 @@ -911,5 +911,65 @@ md5_lastBlock_exit: 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 +