]> git.cryptolib.org Git - avr-crypto-lib.git/blob - shabal/shabal256-asm.S
optimizing norx32
[avr-crypto-lib.git] / shabal / shabal256-asm.S
1 /* shabal256-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    shabal256-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 shabal256_iv:
32         /* A */ 
33 .long   0x52F84552, 0xE54B7999, 0x2D8EE3EC, 0xB9645191 
34 .long   0xE0078B86, 0xBB7C44C9, 0xD2B5C1CA, 0xB0D2EB8C
35 .long   0x14CE5A45, 0x22AF50DC, 0xEFFDBC6B, 0xEB21B74A
36         /* B */ 
37 .long   0xB555C6EE, 0x3E710596, 0xA72A652F, 0x9301515F 
38 .long   0xDA28C1FA, 0x696FD868, 0x9CB6BF72, 0x0AFE4002
39 .long   0xA6E03615, 0x5138C1D4, 0xBE216306, 0xB38B8890 
40 .long   0x3EA8B96B, 0x3299ACE4, 0x30924DD4, 0x55CB34A5
41         /* C */ 
42 .long   0xB405F031, 0xC4233EBA, 0xB3733979, 0xC0DD9D55
43 .long   0xC51C28AE, 0xA327B8E1, 0x56C56167, 0xED614433
44 .long   0x88B59D60, 0x60E2CEBA, 0x758B4B8B, 0x83E82A7F 
45 .long   0xBC968828, 0xE6E00BF7, 0xBA839E55, 0x9B491C60
46
47 /******************************************************************************/        
48 /*
49  * param ctx: r24,r25
50  */
51 .global shabal256_init
52 shabal256_init:
53         movw r26, r24
54         ldi r24, 1
55         st X+, r24
56         st X+, r1
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         movw r24, r26
64         adiw r24, 12*4+4
65         st X+, r24
66         st X+, r25
67         adiw r24, 4*16-1
68         adiw r24, 1
69         st X+, r24
70         st X+, r25 
71         ldi r24, (12+16+16)
72         ldi r30, lo8(shabal256_iv)
73         ldi r31, hi8(shabal256_iv)
74 1:      lpm r0, Z+
75         st X+, r0
76         lpm r0, Z+
77         st X+, r0
78         lpm r0, Z+
79         st X+, r0
80         lpm r0, Z+
81         st X+, r0
82         dec r24
83         brne 1b
84         ret     
85
86 /******************************************************************************/        
87
88 .global shabal256_ctx2hash
89 shabal256_ctx2hash:
90         movw r26, r24
91         movw r30, r22
92         ldd r24, Z+(8+2)
93         ldd r25, Z+(8+2+1)
94         movw r30, r24
95         adiw r30, (16-256/32)*4
96         ldi r24, 256/8
97 1:  ld r0, Z+
98         st X+, r0
99         dec r24
100         brne 1b
101         ret             
102         
103 /******************************************************************************/        
104 /*
105  * param dest:      r24:r25
106  * param msg:       r22:r23
107  * param length_b:  r18:r21
108  */
109 DST0 =  8
110 DST1 =  9
111 CTX0 = 10
112 CTX1 = 11
113 MSG0 = 12
114 MSG1 = 13
115 LEN2 = 14
116 LEN3 = 15
117 LEN0 = 16
118 LEN1 = 17
119 .global shabal256
120 shabal256: 
121         push_range 8, 17
122         stack_alloc_large 188
123         adiw r30, 1 /* Z points to stack space (ctx) */
124         movw CTX0, r30
125         movw DST0, r24
126         movw MSG0, r22
127         movw LEN0, r18
128         movw LEN2, r20
129         movw r24, r30
130         rcall shabal256_init
131 2:
132         tst LEN2
133         brne 3f
134         tst LEN3
135         breq 4f
136 3:
137         movw r24, CTX0
138         movw r22, MSG0
139         rcall shabal_nextBlock
140         subi LEN1, 0x02
141         sbc LEN2, r1
142         sbc LEN3, r1
143         ldi r18, 64
144         add MSG0, r18
145         adc MSG1, r1    
146         rjmp 2b
147 4:      
148         movw r24, CTX0
149         movw r22, MSG0
150         movw r20, LEN0
151         rcall shabal_lastBlock
152         movw r24, DST0
153         movw r22, CTX0
154         rcall shabal256_ctx2hash
155         stack_free_large2 188
156         pop_range 8, 17
157         ret
158         
159