]> git.cryptolib.org Git - avr-crypto-lib.git/blob - twister/twister-small-asm.S
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / twister / twister-small-asm.S
1 /* twister-small-asm.S */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /**
20  * \file     twister-small-asm.S
21  * \email    bg@nerilex.org
22  * \author   Daniel Otte 
23  * \date     2008-12-26
24  * \license  GPLv3 or later
25  * 
26  */
27
28 #include "avr-asm-macros.S"
29
30 /* void twister_small_init(twister_state_t *ctx, uint16_t hashsize_b)*/
31 /*
32  * param ctx:        r24:r25
33  * param hashsize_b: r22:r23
34  */
35 .global twister224_init
36 twister224_init:
37         ldi r22, lo8(224)
38         ldi r23, hi8(224)
39         rjmp 1f
40
41 .global twister256_init
42 twister256_init:
43         ldi r22, lo8(256)
44         ldi r23, hi8(256)
45         
46 .global twister_small_init
47 twister_small_init:
48         movw r30, r24
49         ldi r24, 64
50 1:
51         st Z+, r1
52         dec r24
53         brne 1b
54
55         dec r1          
56         ldi r24, 8
57 1:
58         st Z+, r1
59         dec r24
60         brne 1b
61
62         inc r1          
63         ldi r24, 8
64 1:
65         st Z+, r1
66         dec r24
67         brne 1b
68
69         sbiw r30, 1+8+8
70         sbiw r30, 8*7
71         st Z, r23
72         std Z+8, r22
73         ret
74 #if 1 
75 /*********************************************************************/
76 /* void twister_small_lastBlock(twister_state_t *ctx, void *msg, uint16_t length_b) */   
77 /*
78  * param ctx:      r24:r25
79  * param msg:      r22:r23
80  * param length_b: r20:r21
81  */
82 TMP_SAVE0 = 12
83 TMP_SAVE1 = 13
84 CTX_SAVE0 = 14
85 CTX_SAVE1 = 15
86 LEN_SAVE0 = 16
87 LEN_SAVE1 = 17
88 MSG_SAVE0 = 28
89 MSG_SAVE1 = 29
90 .global twister_small_lastBlock
91 .global twister224_lastBlock
92 .global twister256_lastBlock
93
94 twister224_lastBlock:
95 twister256_lastBlock:
96 twister_small_lastBlock:
97         push_range 12, 17
98         push r28
99         push r29
100         stack_alloc_large 64
101         adiw r30, 1
102         movw TMP_SAVE0, r30
103         movw CTX_SAVE0, r24
104         movw MSG_SAVE0, r22
105         movw LEN_SAVE0, r20
106 1:      
107         cpi LEN_SAVE1, 2
108         brmi 2f
109         movw r24, CTX_SAVE0
110         movw r22, MSG_SAVE0
111         rcall twister_small_nextBlock
112         adiw MSG_SAVE0, 8
113         subi LEN_SAVE1, 2
114         rjmp 1b
115 2:
116         movw r18, LEN_SAVE0
117         lsr r19
118         ror r18
119         lsr r18
120         lsr r18
121         ldi r19, 63
122         movw r26, MSG_SAVE0
123         movw r30, TMP_SAVE0     
124         ldi r20, 0x80
125         sub r19, r18 /* r18: bytes to copy, r19: bytes to clear */
126
127         ld r0, X+       
128 3:      tst r18
129         breq 4f
130 31:
131         st Z+, r0
132         ld r0, X+
133         dec r18
134         brne 31b
135 4:      
136         mov r18, LEN_SAVE0
137         andi r18, 0x07
138         ldi r20, 0x80
139         breq 5f
140 4:
141         lsr r20
142         dec r18
143         brne 4b
144         or r20, r0
145         rjmp 5f
146
147 5:
148         st Z+, r20      
149
150         tst r19
151         breq 7f
152 6:      
153         st Z+, r1
154         dec r19
155         brne 6b
156 7:      
157         movw r24, CTX_SAVE0
158         movw r22, TMP_SAVE0
159         rcall twister_small_nextBlock
160         
161         ldi r19, 2
162         clr r18
163         
164         sub r18, LEN_SAVE0
165         sbc r19, LEN_SAVE1
166         movw r26, CTX_SAVE0
167         adiw r26, 63
168         adiw r26, 1+8
169         
170         ld r0, X
171         sub r0, r18
172         st X+, r0
173         ld r0, X
174         sbc r0, r19
175         st X+, r0
176         ld r0, X
177         sbc r0, r1
178         st X+, r0
179         ld r0, X
180         sbc r0, r1
181         st X+, r0
182         ld r0, X
183         sbc r0, r1
184         st X+, r0
185         ld r0, X
186         sbc r0, r1
187         st X+, r0
188         ld r0, X
189         sbc r0, r1
190         st X+, r0
191         ld r0, X
192         sbc r0, r1
193         st X+, r0
194         
195         sbiw r26, 8
196         movw r24, CTX_SAVE0
197         movw r22, r26
198         rcall twister_mini_round        
199
200         movw r24, CTX_SAVE0
201         rcall twister_blank_round       
202         
203         stack_free_large 64
204         pop r29
205         pop r28
206         pop_range 12, 17
207         ret
208
209 #endif