1 C nettle, low-level cryptographics library
3 C Copyright (C) 2004, Niels Möller
5 C The nettle library is free software; you can redistribute it and/or modify
6 C it under the terms of the GNU Lesser General Public License as published by
7 C the Free Software Foundation; either version 2.1 of the License, or (at your
8 C option) any later version.
10 C The nettle library is distributed in the hope that it will be useful, but
11 C WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 C or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 C License for more details.
15 C You should have received a copy of the GNU Lesser General Public License
16 C along with the nettle library; see the file COPYING.LIB. If not, write to
17 C the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 .file "arcfour-crypt.asm"
22 C arcfour_crypt(struct arcfour_ctx *ctx,
23 C unsigned length, uint8_t *dst,
27 PROLOGUE(nettle_arcfour_crypt)
28 C save all registers that need to be saved
49 movl 24(%esp), %edx C length
50 movl 20(%esp), %ebp C ctx
51 movl 28(%esp), %edi C dst
52 movl 32(%esp), %esi C src
54 lea (%edx, %edi), %edi
55 lea (%edx, %esi), %esi
59 movzbl ARCFOUR_I (%ebp), %eax C i
60 movzbl ARCFOUR_J (%ebp), %ebx C j
68 movb (%ebp, %eax), %cl C si.
70 movb (%ebp, %ebx), %ch C sj
71 movb %ch, (%ebp, %eax) C S[i] = sj
74 movb %cl, (%ebp, %ebx) C S[j] = si
76 movzbl %cl, %ecx C Clear, so it can be used
78 movb (%ebp, %ecx), %cl
79 xorb (%esi, %edx, 2), %cl
80 movb %cl, (%edi, %edx, 2)
82 C FIXME: Could exchange cl and ch in the second half
83 C and try to interleave instructions better.
85 movb (%ebp, %eax), %cl C si.
87 movb (%ebp, %ebx), %ch C sj
88 movb %ch, (%ebp, %eax) C S[i] = sj
91 movb %cl, (%ebp, %ebx) C S[j] = si
93 movzbl %cl, %ecx C Clear, so it can be used
95 movb (%ebp, %ecx), %cl
96 xorb 1(%esi, %edx, 2), %cl
98 movb %cl, -1(%edi, %edx, 2)
104 movb %al, ARCFOUR_I (%ebp) C Store the new i and j.
105 movb %bl, ARCFOUR_J (%ebp)
112 EPILOGUE(nettle_arcfour_crypt)