arcfour-crypt.asm 2.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
C nettle, low-level cryptographics library
C 
C Copyright (C) 2004, Niels Mller
C  
C The nettle library is free software; you can redistribute it and/or modify
C it under the terms of the GNU Lesser General Public License as published by
C the Free Software Foundation; either version 2.1 of the License, or (at your
C option) any later version.
C 
C The nettle library is distributed in the hope that it will be useful, but
C WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
C or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
C License for more details.
C 
C You should have received a copy of the GNU Lesser General Public License
C along with the nettle library; see the file COPYING.LIB.  If not, write to
C the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
C MA 02111-1307, USA.

Niels Möller's avatar
Niels Möller committed
20
	.file "arcfour-crypt.asm"
21
22
23
24
25
26
27
28
29
30

	C arcfour_crypt(struct arcfour_ctx *ctx,
	C               unsigned length, uint8_t *dst,
	C               const uint8_t *src)
	.text
	.align 16
	.globl nettle_arcfour_crypt
	.type  nettle_arcfour_crypt,@function
nettle_arcfour_crypt:
	C save all registers that need to be saved
Niels Möller's avatar
Niels Möller committed
31
32
33
34
	pushl	%ebx		C  12(%esp)
	pushl	%ebp		C  8(%esp)
	pushl	%esi		C  4(%esp)
	pushl	%edi		C  0(%esp)
35

36
C Input arguments:
37
38
39
40
	C ctx = 20(%esp)
	C length = 24(%esp)
	C dst = 28(%esp)
	C src = 32(%esp)
41
42
43
44
45
46
47
48
49
50
C Register usage:
	C %ebp = ctx
	C %esi = src (updated through out loop)
	C %edi = dst (updated through out loop)
	C %edx = src + length (end of source area)
	C %eax = i
	C %ebx = j
	C %cl  = si
	C %ch  = sj
	
51
52
53
54
55
56
57
58
59
60
61
62
	movl	24(%esp), %edx		C  length
	testl	%edx,%edx
	jz	.Lend

	movl	20(%esp), %ebp		C  ctx
	movl	28(%esp), %edi
	movl	32(%esp), %esi
	addl	%esi, %edx		C  Keep src + length
	
	movzbl  256(%ebp), %eax		C  i
	movzbl  257(%ebp), %ebx		C  j
.Lloop:
63
C	incb	%al
64
65
	incl	%eax
	andl	$0xff, %eax
66
	movzbl  (%ebp, %eax), %ecx	C  si. Clears high bytes
67
68
69
C	addb    %cl, %bl
	addl	%ecx, %ebx
	andl	$0xff, %ebx
70
	movb    (%ebp, %ebx), %ch	C  sj
71
	movb    %ch, (%ebp, %eax)	C  S[i] = sj
72
	movb	%cl, (%ebp, %ebx)	C  S[j] = si
73
74
75
76
77
78
79
80
81
82
	addb    %ch, %cl
	xorb    %ch, %ch		C  Clear, so it can be used
					C  for indexing.
	movb    (%ebp, %ecx), %cl
	xorb    (%esi), %cl
	incl    %esi
	movb    %cl, (%edi)
	incl    %edi
	cmpl	%esi, %edx
	jne	.Lloop
83
84
85

	movb	%al, 256(%ebp)		C  Store the new i and j.
	movb	%bl, 257(%ebp)
86
87
88
89
90
91
92
.Lend:
	popl	%edi
	popl	%esi
	popl	%ebp
	popl	%ebx
	ret
.Leord:
93
	.size	nettle_arcfour_crypt,.Leord-nettle_arcfour_crypt