]> git.cryptolib.org Git - avr-crypto-lib.git/blob - shabal/shabal224-asm.S
optimizing norx32
[avr-crypto-lib.git] / shabal / shabal224-asm.S
1 /* shabal224-asm.S */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
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    shabal224-asm.S
21  * \author  Daniel Otte
22  * \email   daniel.otte@rub.de
23  * \date    2009-04-27
24  * \license GPLv3 or later
25  */ 
26
27 #include "avr-asm-macros.S"
28
29 /******************************************************************************/        
30
31 shabal224_iv:
32         /* A */
33 .long   0xA5201467, 0xA9B8D94A, 0xD4CED997, 0x68379D7B 
34 .long   0xA7FC73BA, 0xF1A2546B, 0x606782BF, 0xE0BCFD0F
35 .long   0x2F25374E, 0x069A149F, 0x5E2DFF25, 0xFAECF061
36         /* B */ 
37 .long   0xEC9905D8, 0xF21850CF, 0xC0A746C8, 0x21DAD498
38 .long   0x35156EEB, 0x088C97F2, 0x26303E40, 0x8A2D4FB5
39 .long   0xFEEE44B6, 0x8A1E9573, 0x7B81111A, 0xCBC139F0 
40 .long   0xA3513861, 0x1D2C362E, 0x918C580E, 0xB58E1B9C
41         /* C */
42 .long   0xE4B573A1, 0x4C1A0880, 0x1E907C51, 0x04807EFD 
43 .long   0x3AD8CDE5, 0x16B21302, 0x02512C53, 0x2204CB18
44 .long   0x99405F2D, 0xE5B648A1, 0x70AB1D43, 0xA10C25C2 
45 .long   0x16F1AC05, 0x38BBEB56, 0x9B01DC60, 0xB1096D83
46
47
48 /******************************************************************************/        
49 /*
50  * param ctx: r24,r25
51  */
52 .global shabal224_init
53 shabal224_init:
54         movw r26, r24
55         ldi r24, 1
56         st X+, r24
57         st X+, r1
58         st X+, r1
59         st X+, r1
60         st X+, r1
61         st X+, r1
62         st X+, r1
63         st X+, r1
64         movw r24, r26
65         adiw r24, 12*4+4
66         st X+, r24
67         st X+, r25
68         adiw r24, 4*16-1
69         adiw r24, 1
70         st X+, r24
71         st X+, r25 
72         ldi r24, (12+16+16)
73         ldi r30, lo8(shabal224_iv)
74         ldi r31, hi8(shabal224_iv)
75 1:      lpm r0, Z+
76         st X+, r0
77         lpm r0, Z+
78         st X+, r0
79         lpm r0, Z+
80         st X+, r0
81         lpm r0, Z+
82         st X+, r0
83         dec r24
84         brne 1b
85         ret     
86
87 /******************************************************************************/        
88         
89 .global shabal224_ctx2hash
90 shabal224_ctx2hash:
91         movw r26, r24
92         movw r30, r22
93         ldd r24, Z+(8+2)
94         ldd r25, Z+(8+2+1)
95         movw r30, r24
96         adiw r30, (16-224/32)*4
97         ldi r24, 224/8
98 1:  ld r0, Z+
99         st X+, r0
100         dec r24
101         brne 1b
102         ret             
103         
104 /******************************************************************************/        
105 /*
106  * param dest:      r24:r25
107  * param msg:       r22:r23
108  * param length_b:  r18:r21
109  */
110 DST0 =  8
111 DST1 =  9
112 CTX0 = 10
113 CTX1 = 11
114 MSG0 = 12
115 MSG1 = 13
116 LEN2 = 14
117 LEN3 = 15
118 LEN0 = 16
119 LEN1 = 17
120 .global shabal224
121 shabal224: 
122         push_range 8, 17
123         stack_alloc_large 188
124         adiw r30, 1 /* Z points to stack space (ctx) */
125         movw CTX0, r30
126         movw DST0, r24
127         movw MSG0, r22
128         movw LEN0, r18
129         movw LEN2, r20
130         movw r24, r30
131         rcall shabal224_init
132 2:
133         tst LEN2
134         brne 3f
135         tst LEN3
136         breq 4f
137 3:
138         movw r24, CTX0
139         movw r22, MSG0
140         rcall shabal_nextBlock
141         subi LEN1, 0x02
142         sbc LEN2, r1
143         sbc LEN3, r1
144         ldi r18, 64
145         add MSG0, r18
146         adc MSG1, r1    
147         rjmp 2b
148 4:      
149         movw r24, CTX0
150         movw r22, MSG0
151         movw r20, LEN0
152         rcall shabal_lastBlock
153         movw r24, DST0
154         movw r22, CTX0
155         rcall shabal224_ctx2hash
156         stack_free_large2 188
157         pop_range 8, 17
158         ret
159         
160