File: blowfishopt.i586.S

package info (click to toggle)
beecrypt 2.2.0-pre1-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,820 kB
  • ctags: 1,325
  • sloc: ansic: 12,215; sh: 9,073; asm: 2,715; makefile: 80
file content (178 lines) | stat: -rw-r--r-- 3,798 bytes parent folder | download | duplicates (2)
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
/*
 * blowfishopt.i586.S
 *
 * Assembler optimized blowfish routines for Intel Pentium processors
 *
 * 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 "blowfishopt.i586.S"

	.text

	.macro  etworounds	p # bp in %esi, xl and xr in %ecx and %edx, %eax and %ebx clear
	xorl 0+\p(%esi),%ecx
	roll $16,%ecx
	movb %ch,%al
	movb %cl,%bl
	roll $16,%ecx
	movl 0x000+72(%esi,%eax,4),%edi
	addl 0x400+72(%esi,%ebx,4),%edi
	movb %ch,%al
	movb %cl,%bl
	xorl 0x800+72(%esi,%eax,4),%edi
	addl 0xC00+72(%esi,%ebx,4),%edi
	xorl %edi,%edx
	xorl 4+\p(%esi),%edx
	roll $16,%edx
	movb %dh,%al
	movb %dl,%bl
	roll $16,%edx
	movl 0x000+72(%esi,%eax,4),%edi
	addl 0x400+72(%esi,%ebx,4),%edi
	movb %dh,%al
	movb %dl,%bl
	xorl 0x800+72(%esi,%eax,4),%edi
	addl 0xC00+72(%esi,%ebx,4),%edi
	xorl %edi,%ecx
	.endm

	.macro  dtworounds	p # bp in %esi, xl and xr in %ecx and %edx, %eax and %ebx clear
	xorl 4+\p(%esi),%ecx
	roll $16,%ecx
	movb %ch,%al
	movb %cl,%bl
	roll $16,%ecx
	movl 0x000+72(%esi,%eax,4),%edi
	addl 0x400+72(%esi,%ebx,4),%edi
	movb %ch,%al
	movb %cl,%bl
	xorl 0x800+72(%esi,%eax,4),%edi
	addl 0xC00+72(%esi,%ebx,4),%edi
	xorl %edi,%edx
	xorl 0+\p(%esi),%edx
	roll $16,%edx
	movb %dh,%al
	movb %dl,%bl
	roll $16,%edx
	movl 0x000+72(%esi,%eax,4),%edi
	addl 0x400+72(%esi,%ebx,4),%edi
	movb %dh,%al
	movb %dl,%bl
	xorl 0x800+72(%esi,%eax,4),%edi
	addl 0xC00+72(%esi,%ebx,4),%edi
	xorl %edi,%ecx
	.endm

C_FUNCTION_BEGIN(blowfishEncrypt)
LABEL(blowfishEncrypt)
	/* parameter one is the blowfish parameters; need to extract bp and set it up in esi */
	pushl %edi
	pushl %esi
	pushl %ebx

	movl 16(%esp),%esi # esi now contains bp
	movl 24(%esp),%edi # edi now contains src

	xorl %eax,%eax
	xorl %ebx,%ebx

	movl 0(%edi),%ecx
	movl 4(%edi),%edx

	bswap %ecx
	bswap %edx

	etworounds p= 0
	etworounds p= 8
	etworounds p=16
	etworounds p=24
	etworounds p=32
	etworounds p=40
	etworounds p=48
	etworounds p=56

	movl 20(%esp),%edi	# edi now contains dst
	xorl 64(%esi),%ecx
	xorl 68(%esi),%edx

	bswap %ecx
	bswap %edx

	movl %ecx,4(%edi)
	movl %edx,0(%edi)

	xorl %eax,%eax
	popl %ebx
	popl %esi
	popl %edi
	ret
C_FUNCTION_END(blowfishEncrypt, LOCAL(blowfishEncrypt_size))


C_FUNCTION_BEGIN(blowfishDecrypt)
LABEL(blowfishDecrypt)
	/* parameter one is the blowfish parameters; need to extract bp and set it up in ebp */
	pushl %edi
	pushl %esi
	pushl %ebx

	movl 16(%esp),%esi # esi now contains bp
	movl 24(%esp),%edi # edi now contains dst

	xorl %eax,%eax
	xorl %ebx,%ebx

	movl 0(%edi),%ecx
	movl 4(%edi),%edx

	bswap %ecx
	bswap %edx
	
	dtworounds p=64
	dtworounds p=56
	dtworounds p=48
	dtworounds p=40
	dtworounds p=32
	dtworounds p=24
	dtworounds p=16
	dtworounds p= 8

	movl 20(%esp),%edi	# edi now contains dst
	xorl 4(%esi),%ecx
	xorl 0(%esi),%edx
	
	bswap %ecx
	bswap %edx
	
	movl %ecx,4(%edi)
	movl %edx,0(%edi)

	xorl %eax,%eax

	popl %ebx
	popl %esi
	popl %edi
	ret
C_FUNCTION_END(blowfishDecrypt, LOCAL(blowfishDecrypt_size))