1 C x86/arcfour-crypt.asm
4 Copyright (C) 2004, Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free
18 Software Foundation; either version 2 of the License, or (at your
19 option) any later version.
21 or both in parallel, as here.
23 GNU Nettle is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received copies of the GNU General Public License and
29 the GNU Lesser General Public License along with this program. If
30 not, see http://www.gnu.org/licenses/.
33 .file "arcfour-crypt.asm"
35 C arcfour_crypt(struct arcfour_ctx *ctx,
36 C size_t length, uint8_t *dst,
40 PROLOGUE(nettle_arcfour_crypt)
41 C save all registers that need to be saved
62 movl 24(%esp), %edx C length
63 movl 20(%esp), %ebp C ctx
64 movl 28(%esp), %edi C dst
65 movl 32(%esp), %esi C src
67 lea (%edx, %edi), %edi
68 lea (%edx, %esi), %esi
72 movzbl ARCFOUR_I (%ebp), %eax C i
73 movzbl ARCFOUR_J (%ebp), %ebx C j
81 movb (%ebp, %eax), %cl C si.
83 movb (%ebp, %ebx), %ch C sj
84 movb %ch, (%ebp, %eax) C S[i] = sj
87 movb %cl, (%ebp, %ebx) C S[j] = si
89 movzbl %cl, %ecx C Clear, so it can be used
91 movb (%ebp, %ecx), %cl
92 xorb (%esi, %edx, 2), %cl
93 movb %cl, (%edi, %edx, 2)
95 C FIXME: Could exchange cl and ch in the second half
96 C and try to interleave instructions better.
98 movb (%ebp, %eax), %cl C si.
100 movb (%ebp, %ebx), %ch C sj
101 movb %ch, (%ebp, %eax) C S[i] = sj
104 movb %cl, (%ebp, %ebx) C S[j] = si
106 movzbl %cl, %ecx C Clear, so it can be used
108 movb (%ebp, %ecx), %cl
109 xorb 1(%esi, %edx, 2), %cl
111 movb %cl, -1(%edi, %edx, 2)
117 movb %al, ARCFOUR_I (%ebp) C Store the new i and j.
118 movb %bl, ARCFOUR_J (%ebp)
125 EPILOGUE(nettle_arcfour_crypt)