]> git.cryptolib.org Git - arm-crypto-lib.git/blob - bmw/bmw_small-asm.S
b04635e5b56cecacbfabb8a1d3611bf8e4ccb648
[arm-crypto-lib.git] / bmw / bmw_small-asm.S
1 /* bmw_small-asm.S */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  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    bmw_small-asm.S
21  * \author  Daniel Otte
22  * \email   daniel.otte@rub.de
23  * \date    2010-05-23
24  * \license GPLv3 or later
25  *
26  */
27 .syntax unified
28 .text
29 .thumb
30 .align 2
31 .thumb_func
32  /*
33 #define S32_1(x) ( (SHR32((x),   1)) ^ \
34                        (SHL32((x),   2)) ^ \
35                        (ROTL32((x),  8)) ^ \
36                        (ROTR32((x),  9)) )
37
38 #define S32_2(x) ( (SHR32((x),   2)) ^ \
39                        (SHL32((x),   1)) ^ \
40                        (ROTL32((x), 12)) ^ \
41                        (ROTR32((x),  7)) )
42
43 #define S32_3(x) ( (SHR32((x),   2)) ^ \
44                        (SHL32((x),   2)) ^ \
45                        (ROTL32((x), 15)) ^ \
46                        (ROTR32((x),  3)) )
47
48 #define S32_4(x) ( (SHR32((x),   1)) ^ (x))
49
50 #define S32_5(x) ( (SHR32((x),   2)) ^ (x))
51
52 */
53
54 .global bmw_s32_0
55 .text
56 .thumb
57 .align 2
58 .thumb_func
59 .type bmw_s32_0, %function
60 bmw_s32_0:
61         mov r1, r0
62         lsrs r0, r0, #1
63         eor r0, r0, r1, lsl #3
64         eor r0, r0, r1, ror #28
65         eor r0, r0, r1, ror #13
66         bx lr
67
68 .global bmw_s32_1
69 .text
70 .thumb
71 .align 2
72 .thumb_func
73 .type bmw_s32_1, %function
74 bmw_s32_1:
75         mov r1, r0
76         lsrs r0, r0, #1
77         eor r0, r0, r1, lsl #2
78         eor r0, r0, r1, ror #24
79         eor r0, r0, r1, ror #9
80         bx lr
81
82 .global bmw_s32_2
83 .text
84 .thumb
85 .align 2
86 .thumb_func
87 .type bmw_s32_2, %function
88 bmw_s32_2:
89         mov r1, r0
90         lsrs r0, r0, #2
91         eor r0, r0, r1, lsl #1
92         eor r0, r0, r1, ror #20
93         eor r0, r0, r1, ror #7
94         bx lr
95
96 .global bmw_s32_3
97 .text
98 .thumb
99 .align 2
100 .thumb_func
101 .type bmw_s32_3, %function
102 bmw_s32_3:
103         mov r1, r0
104         lsrs r0, r0, #2
105         eor r0, r0, r1, lsl #2
106         eor r0, r0, r1, ror #17
107         eor r0, r0, r1, ror #3
108         bx lr
109
110 .global bmw_s32_4
111 .text
112 .thumb
113 .align 2
114 .thumb_func
115 .type bmw_s32_4, %function
116 bmw_s32_4:
117         eor r0, r0, r0, lsr #1
118         bx lr
119
120 .global bmw_s32_5
121 .text
122 .thumb
123 .align 2
124 .thumb_func
125 .type bmw_s32_5, %function
126 bmw_s32_5:
127         eor r0, r0, r0, lsr #2
128         bx lr
129
130
131
132 .global bmw_small_f0
133 .text
134 .thumb
135 .align 2
136 .thumb_func
137 .type bmw_small_f0, %function
138 /*
139  * param q:  r0
140  * param h:  r1
141  * param m:  r2
142  */
143 bmw_small_f0:
144         push {r4-r11, r14}
145         sub sp, sp, #64
146         mov r3, sp
147         adds r3, r3, #4
148 10:
149         ldmia r1!, {r4,r6,r8,r10}
150         ldmia r2!, {r5,r7,r9,r11}
151         eors r4, r5
152         eors r6, r7
153         eors r8, r9
154         eors r10, r11
155         stmia r3!, {r4,r6,r8,r10}
156
157         ldmia r1!, {r4,r6,r8,r10}
158         ldmia r2!, {r5,r7,r9,r11}
159         eors r4, r5
160         eors r6, r7
161         eors r8, r9
162         eors r10, r11
163         stmia r3!, {r4,r6,r8,r10}
164
165         ldmia r1!, {r4,r6,r8,r10}
166         ldmia r2!, {r5,r7,r9,r11}
167         eors r4, r5
168         eors r6, r7
169         eors r8, r9
170         eors r10, r11
171         stmia r3!, {r4,r6,r8,r10}
172
173         ldmia r1!, {r4,r6,r8,r10}
174         ldmia r2!, {r5,r7,r9,r11}
175         eors r4, r5
176         eors r6, r7
177         eors r8, r9
178         eors r10, r11
179         stmia r3!, {r4,r6,r8,r10}
180 /* --- */
181         subs r1, r1, #64
182         subs r3, r3, #64
183 /*
184         q[ 0] = (+ h[ 5] - h[ 7] + h[10] + h[13] + h[14]);
185         q[ 3] = (+ h[ 8] - h[10] + h[13] + h[ 0] - h[ 1]);
186         q[ 6] = (- h[11] + h[13] - h[ 0] - h[ 3] + h[ 4]);
187         q[ 9] = (+ h[14] + h[ 0] - h[ 3] + h[ 6] - h[ 7]);
188         q[12] = (+ h[ 1] + h[ 3] - h[ 6] - h[ 9] + h[10]);
189         q[15] = (- h[ 4] - h[ 6] - h[ 9] + h[12] + h[13]);
190         q[ 2] = (+ h[ 7] + h[ 9] - h[12] + h[15] + h[ 0]);
191         q[ 5] = (+ h[10] - h[12] + h[15] - h[ 2] + h[ 3]);
192         q[ 8] = (+ h[13] - h[15] + h[ 2] - h[ 5] - h[ 6]);
193         q[11] = (- h[ 0] - h[ 2] - h[ 5] + h[ 8] + h[ 9]);
194         q[14] = (+ h[ 3] - h[ 5] + h[ 8] - h[11] - h[12]);
195         q[ 1] = (+ h[ 6] - h[ 8] + h[11] + h[14] - h[15]);
196         q[ 4] = (+ h[ 9] - h[11] - h[14] + h[ 1] + h[ 2]);
197         q[ 7] = (- h[12] - h[14] + h[ 1] - h[ 4] - h[ 5]);
198         q[10] = (+ h[15] - h[ 1] - h[ 4] - h[ 7] + h[ 8]);
199         q[13] = (+ h[ 2] + h[ 4] + h[ 7] + h[10] + h[11]);
200 */
201         ldr r4,  [r3,  #(5*4)]
202         ldr r5,  [r3,  #(7*4)]
203         ldr r6,  [r3, #(10*4)]
204         ldr r7,  [r3, #(13*4)]
205         ldr r8,  [r3, #(14*4)]
206         ldr r9,  [r3, #(8*4)]
207         ldr r10, [r3, #(11*4)]
208         subs r2, r4, r5
209         adds r2, r2, r6
210         adds r2, r2, r7
211         adds r2, r2, r8
212         str r2, [r0, #0]
213         ldr r4, [r3, #0]
214         ldr r5, [r3, #1]
215         subs r2, r9, r6
216         adds r2, r2, r7
217         adds r2, r2, r4
218         subs r2, r2, r5
219         add sp, sp, #64
220         pop {r4-r11, pc}