1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/*
* fips180opt.powerpc.S
*
* Assembler optimized SHA-1 routines for PowerPC processors
*
* Warning: this code is incomplete and only contains a rough prototype!
*
* Compile target is GNU Assembler
*
* Copyright (c) 2000, 2001 Virtual Unlimited B.V.
*
* Author: Bob Deblier <bob@virtualunlimited.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "beecrypt.gas.h"
.file "fips180opt.powerpc.S"
.text
#if DARWIN
# define reg0 r0
# define reg3 r3
# define reg4 r4
# define reg5 r5
# define reg6 r6
# define reg7 r7
# define reg8 r8
# define reg9 r9
# define reg26 r26
# define reg27 r27
# define reg28 r28
# define reg29 r29
# define reg30 r30
# define reg31 r31
#else
# define reg0 %r0
# define reg3 %r3
# define reg4 %r4
# define reg5 %r5
# define reg6 %r6
# define reg7 %r7
# define reg8 %r8
# define reg9 %r9
# define reg26 %r26
# define reg27 %r27
# define reg28 %r28
# define reg29 %r29
# define reg30 %r30
# define reg31 %r31
#endif
.equ K00, 0x5a827999
.equ K20, 0x6ed9eba1
.equ K40, 0x8f1bbcdc
.equ K60, 0xca62c1d6
.equ PARAM_H, 0
.equ PARAM_DATA, 20
/* sha1Param: param in reg3 */
.macro subround1 a b c d e w
lwzu reg7,4(\w)
rotlwi reg5,\a,5
dbct r0,\w
xor reg6,\c,\d
add \e,\e,K00
and reg6,reg6,\b
add \e,\e,reg7
xor reg6,reg6,\d
add \e,\e,reg5
rotrwi \b,\b,2
add \e,\e,reg6
.endm
.macro subround2 a b c d e w
lwzu reg7,4(\w)
rotlwi reg5,\a,5
dbct r0,\w
add \e,\e,K20
xor reg6,\b,\c
add \e,\e,reg5
xor reg6,reg6,\d
add \e,\e,reg7
rotrwi \b,\b,2
add \e,\e,reg6
.endm
.macro subround3 a b c d e w
lwzu reg7,4(\w)
rotlwi reg5,\a,5
dbct r0,\w
xor reg6,\b,\c
add \e,\e,reg5
and reg6,reg6,\d
add \e,\e,K40
and reg5,\b,\c
add \e,\e,reg7
or reg6,reg6,reg5
rotrwi \b,\b,2
add \e,\e,reg6
.endm
.macro subround4 a b c d e w
lwzu reg7,4(\w)
rotlwi reg5,\a,5
dbct r0,\w
add \e,\e,K60
xor reg6,\b,\c
add \e,\e,reg5
xor reg6,reg6,\d
add \e,\e,reg7
rotrwi \b,\b,2
add \e,\e,reg6
.endm
C_FUNCTION_BEGIN(sha1Process)
/* zero reg0 for general use */
li reg0,0
/* for a,b,c,d,e use r26,r27,r28,r29,r30, for w use r31 */
/* we need to save registers before loading them */
stmw reg26,-24(reg1)
/* load the frame pointer with parameter data, and hint cache */
addi reg31,reg3,PARAM_DATA
dbct reg31
#if !WORDS_BIGENDIAN /* have to provide for PowerPC little-endian mode
/* loop of 16 entries */
li reg5,60
mtctr reg6
.L00:
lwbrx reg6,reg31,reg5
stwx reg6,reg31,reg5
subi. reg5,reg5,4
bcge cr0,.L00
addi reg31,reg3,PARAM_DATA
#endif
/* do the initial mixing */
li reg8,64
addi reg26,reg3,PARAM_DATA+64-4
addi reg27,reg3,PARAM_DATA+64-3*4-4
addi reg28,reg3,PARAM_DATA+64-8*4-4
addi reg29,reg3,PARAM_DATA+64-14*4-4
addi reg30,reg3,PARAM_DATA+64-16*4-4
mtctr reg8
.L10:
lwzu reg5,4(reg27)
lwzu reg6,4(reg28)
lwzu reg7,4(reg29)
lwzu reg8,4(reg30)
xor reg5,reg5,reg6
xor reg7,reg7,reg8
xor reg5,reg5,reg7
stwu reg5,4(reg26)
bdnz .L10
lwz reg26,PARAM_H (reg3)
lwz reg27,PARAM_H+4 (reg3)
lwz reg28,PARAM_H+8 (reg3)
lwz reg29,PARAM_H+12(reg3)
lwz reg30,PARAM_H+16(reg3)
subround1 reg26,reg27,reg28,reg29,reg30,reg31
subround1 reg30,reg26,reg27,reg28,reg29,reg31
subround1 reg29,reg30,reg26,reg27,reg28,reg31
subround1 reg28,reg29,reg30,reg26,reg27,reg31
subround1 reg27,reg28,reg29,reg30,reg26,reg31
subround1 reg26,reg27,reg28,reg29,reg30,reg31
subround1 reg30,reg26,reg27,reg28,reg29,reg31
subround1 reg29,reg30,reg26,reg27,reg28,reg31
subround1 reg28,reg29,reg30,reg26,reg27,reg31
subround1 reg27,reg28,reg29,reg30,reg26,reg31
subround1 reg26,reg27,reg28,reg29,reg30,reg31
subround1 reg30,reg26,reg27,reg28,reg29,reg31
subround1 reg29,reg30,reg26,reg27,reg28,reg31
subround1 reg28,reg29,reg30,reg26,reg27,reg31
subround1 reg27,reg28,reg29,reg30,reg26,reg31
subround1 reg26,reg27,reg28,reg29,reg30,reg31
subround1 reg30,reg26,reg27,reg28,reg29,reg31
subround1 reg29,reg30,reg26,reg27,reg28,reg31
subround1 reg28,reg29,reg30,reg26,reg27,reg31
subround1 reg27,reg28,reg29,reg30,reg26,reg31
subround2 reg26,reg27,reg28,reg29,reg30,reg31
subround2 reg30,reg26,reg27,reg28,reg29,reg31
subround2 reg29,reg30,reg26,reg27,reg28,reg31
subround2 reg28,reg29,reg30,reg26,reg27,reg31
subround2 reg27,reg28,reg29,reg30,reg26,reg31
subround2 reg26,reg27,reg28,reg29,reg30,reg31
subround2 reg30,reg26,reg27,reg28,reg29,reg31
subround2 reg29,reg30,reg26,reg27,reg28,reg31
subround2 reg28,reg29,reg30,reg26,reg27,reg31
subround2 reg27,reg28,reg29,reg30,reg26,reg31
subround2 reg26,reg27,reg28,reg29,reg30,reg31
subround2 reg30,reg26,reg27,reg28,reg29,reg31
subround2 reg29,reg30,reg26,reg27,reg28,reg31
subround2 reg28,reg29,reg30,reg26,reg27,reg31
subround2 reg27,reg28,reg29,reg30,reg26,reg31
subround2 reg26,reg27,reg28,reg29,reg30,reg31
subround2 reg30,reg26,reg27,reg28,reg29,reg31
subround2 reg29,reg30,reg26,reg27,reg28,reg31
subround2 reg28,reg29,reg30,reg26,reg27,reg31
subround2 reg27,reg28,reg29,reg30,reg26,reg31
subround3 reg26,reg27,reg28,reg29,reg30,reg31
subround3 reg30,reg26,reg27,reg28,reg29,reg31
subround3 reg29,reg30,reg26,reg27,reg28,reg31
subround3 reg28,reg29,reg30,reg26,reg27,reg31
subround3 reg27,reg28,reg29,reg30,reg26,reg31
subround3 reg26,reg27,reg28,reg29,reg30,reg31
subround3 reg30,reg26,reg27,reg28,reg29,reg31
subround3 reg29,reg30,reg26,reg27,reg28,reg31
subround3 reg28,reg29,reg30,reg26,reg27,reg31
subround3 reg27,reg28,reg29,reg30,reg26,reg31
subround3 reg26,reg27,reg28,reg29,reg30,reg31
subround3 reg30,reg26,reg27,reg28,reg29,reg31
subround3 reg29,reg30,reg26,reg27,reg28,reg31
subround3 reg28,reg29,reg30,reg26,reg27,reg31
subround3 reg27,reg28,reg29,reg30,reg26,reg31
subround3 reg26,reg27,reg28,reg29,reg30,reg31
subround3 reg30,reg26,reg27,reg28,reg29,reg31
subround3 reg29,reg30,reg26,reg27,reg28,reg31
subround3 reg28,reg29,reg30,reg26,reg27,reg31
subround3 reg27,reg28,reg29,reg30,reg26,reg31
subround4 reg26,reg27,reg28,reg29,reg30,reg31
subround4 reg30,reg26,reg27,reg28,reg29,reg31
subround4 reg29,reg30,reg26,reg27,reg28,reg31
subround4 reg28,reg29,reg30,reg26,reg27,reg31
subround4 reg27,reg28,reg29,reg30,reg26,reg31
subround4 reg26,reg27,reg28,reg29,reg30,reg31
subround4 reg30,reg26,reg27,reg28,reg29,reg31
subround4 reg29,reg30,reg26,reg27,reg28,reg31
subround4 reg28,reg29,reg30,reg26,reg27,reg31
subround4 reg27,reg28,reg29,reg30,reg26,reg31
subround4 reg26,reg27,reg28,reg29,reg30,reg31
subround4 reg30,reg26,reg27,reg28,reg29,reg31
subround4 reg29,reg30,reg26,reg27,reg28,reg31
subround4 reg28,reg29,reg30,reg26,reg27,reg31
subround4 reg27,reg28,reg29,reg30,reg26,reg31
subround4 reg26,reg27,reg28,reg29,reg30,reg31
subround4 reg30,reg26,reg27,reg28,reg29,reg31
subround4 reg29,reg30,reg26,reg27,reg28,reg31
subround4 reg28,reg29,reg30,reg26,reg27,reg31
subround4 reg27,reg28,reg29,reg30,reg26,reg31
/* then store the five values into registers */
lwz reg5,PARAM_H (reg3)
lwz reg6,PARAM_H+4 (reg3)
lwz reg7,PARAM_H+8 (reg3)
lwz reg8,PARAM_H+12(reg3)
lwz reg9,PARAM_H+16(reg3)
add reg26,reg5,reg26
add reg27,reg5,reg27
add reg28,reg5,reg28
add reg29,reg5,reg29
add reg30,reg5,reg30
stw reg26,PARAM_H (reg3)
stw reg27,PARAM_H+4 (reg3)
stw reg28,PARAM_H+8 (reg3)
stw reg29,PARAM_H+12(reg3)
stw reg30,PARAM_H+16(reg3)
/* finally, restore registers */
lmw reg26,-24(reg1)
/* and return */
blr
C_FUNCION_END(sha1Process, .Lsha1Process_size)
|