1/* $NetBSD: bf_cbc.S,v 1.5 2005/12/11 12:20:51 christos Exp $ */ 2 3/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 4 * All rights reserved. 5 * 6 * This package is an SSL implementation written 7 * by Eric Young (eay@cryptsoft.com). 8 * The implementation was written so as to conform with Netscapes SSL. 9 * 10 * This library is free for commercial and non-commercial use as long as 11 * the following conditions are aheared to. The following conditions 12 * apply to all code found in this distribution, be it the RC4, RSA, 13 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 14 * included with this distribution is covered by the same copyright terms 15 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 16 * 17 * Copyright remains Eric Young's, and as such any Copyright notices in 18 * the code are not to be removed. 19 * If this package is used in a product, Eric Young should be given attribution 20 * as the author of the parts of the library used. 21 * This can be in the form of a textual message at program startup or 22 * in documentation (online or textual) provided with the package. 23 * 24 * Redistribution and use in source and binary forms, with or without 25 * modification, are permitted provided that the following conditions 26 * are met: 27 * 1. Redistributions of source code must retain the copyright 28 * notice, this list of conditions and the following disclaimer. 29 * 2. Redistributions in binary form must reproduce the above copyright 30 * notice, this list of conditions and the following disclaimer in the 31 * documentation and/or other materials provided with the distribution. 32 * 3. All advertising materials mentioning features or use of this software 33 * must display the following acknowledgement: 34 * "This product includes cryptographic software written by 35 * Eric Young (eay@cryptsoft.com)" 36 * The word 'cryptographic' can be left out if the rouines from the library 37 * being used are not cryptographic related :-). 38 * 4. If you include any Windows specific code (or a derivative thereof) from 39 * the apps directory (application code) you must include an acknowledgement: 40 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 41 * 42 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 * SUCH DAMAGE. 53 * 54 * The licence and distribution terms for any publically available version or 55 * derivative of this code cannot be changed. i.e. this code cannot simply be 56 * copied and put under another distribution licence 57 * [including the GNU Public Licence.] 58 */ 59 60/* 61 * Modified from the output of `perl bf-686.pl elf' by 62 * Thor Lancelot Simon <tls@NetBSD.org> 63 */ 64 65#include <i386/include/asm.h> 66__KERNEL_RCSID(0, "$NetBSD$"); 67 68ENTRY(BF_cbc_encrypt) 69 70 pushl %ebp 71 pushl %ebx 72 pushl %esi 73 pushl %edi 74 movl 28(%esp), %ebp 75 # getting iv ptr from parameter 4 76 movl 36(%esp), %ebx 77 movl (%ebx), %esi 78 movl 4(%ebx), %edi 79 pushl %edi 80 pushl %esi 81 pushl %edi 82 pushl %esi 83 movl %esp, %ebx 84 movl 36(%esp), %esi 85 movl 40(%esp), %edi 86 # getting encrypt flag from parameter 5 87 movl 56(%esp), %ecx 88 # get and push parameter 3 89 movl 48(%esp), %eax 90 pushl %eax 91 pushl %ebx 92 cmpl $0, %ecx 93 jz .L000decrypt 94 andl $4294967288, %ebp 95 movl 8(%esp), %eax 96 movl 12(%esp), %ebx 97 jz .L001encrypt_finish 98.L002encrypt_loop: 99 movl (%esi), %ecx 100 movl 4(%esi), %edx 101 xorl %ecx, %eax 102 xorl %edx, %ebx 103.byte 15 104.byte 200 # bswapl %eax 105.byte 15 106.byte 203 # bswapl %ebx 107 movl %eax, 8(%esp) 108 movl %ebx, 12(%esp) 109 call _C_LABEL(BF_encrypt) 110 movl 8(%esp), %eax 111 movl 12(%esp), %ebx 112.byte 15 113.byte 200 # bswapl %eax 114.byte 15 115.byte 203 # bswapl %ebx 116 movl %eax, (%edi) 117 movl %ebx, 4(%edi) 118 addl $8, %esi 119 addl $8, %edi 120 subl $8, %ebp 121 jnz .L002encrypt_loop 122.L001encrypt_finish: 123 movl 52(%esp), %ebp 124 andl $7, %ebp 125 jz .L003finish 126 xorl %ecx, %ecx 127 xorl %edx, %edx 128 movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp 129 jmp *%ebp 130.L005ej7: 131 movb 6(%esi), %dh 132 sall $8, %edx 133.L006ej6: 134 movb 5(%esi), %dh 135.L007ej5: 136 movb 4(%esi), %dl 137.L008ej4: 138 movl (%esi), %ecx 139 jmp .L009ejend 140.L010ej3: 141 movb 2(%esi), %ch 142 sall $8, %ecx 143.L011ej2: 144 movb 1(%esi), %ch 145.L012ej1: 146 movb (%esi), %cl 147.L009ejend: 148 xorl %ecx, %eax 149 xorl %edx, %ebx 150.byte 15 151.byte 200 # bswapl %eax 152.byte 15 153.byte 203 # bswapl %ebx 154 movl %eax, 8(%esp) 155 movl %ebx, 12(%esp) 156 call _C_LABEL(BF_encrypt) 157 movl 8(%esp), %eax 158 movl 12(%esp), %ebx 159.byte 15 160.byte 200 # bswapl %eax 161.byte 15 162.byte 203 # bswapl %ebx 163 movl %eax, (%edi) 164 movl %ebx, 4(%edi) 165 jmp .L003finish 166#ifdef __ELF__ 167.align 16 168#else 169.align 4 170#endif 171.L000decrypt: 172 andl $4294967288, %ebp 173 movl 16(%esp), %eax 174 movl 20(%esp), %ebx 175 jz .L013decrypt_finish 176.L014decrypt_loop: 177 movl (%esi), %eax 178 movl 4(%esi), %ebx 179.byte 15 180.byte 200 # bswapl %eax 181.byte 15 182.byte 203 # bswapl %ebx 183 movl %eax, 8(%esp) 184 movl %ebx, 12(%esp) 185 call _C_LABEL(BF_decrypt) 186 movl 8(%esp), %eax 187 movl 12(%esp), %ebx 188.byte 15 189.byte 200 # bswapl %eax 190.byte 15 191.byte 203 # bswapl %ebx 192 movl 16(%esp), %ecx 193 movl 20(%esp), %edx 194 xorl %eax, %ecx 195 xorl %ebx, %edx 196 movl (%esi), %eax 197 movl 4(%esi), %ebx 198 movl %ecx, (%edi) 199 movl %edx, 4(%edi) 200 movl %eax, 16(%esp) 201 movl %ebx, 20(%esp) 202 addl $8, %esi 203 addl $8, %edi 204 subl $8, %ebp 205 jnz .L014decrypt_loop 206.L013decrypt_finish: 207 movl 52(%esp), %ebp 208 andl $7, %ebp 209 jz .L003finish 210 movl (%esi), %eax 211 movl 4(%esi), %ebx 212.byte 15 213.byte 200 # bswapl %eax 214.byte 15 215.byte 203 # bswapl %ebx 216 movl %eax, 8(%esp) 217 movl %ebx, 12(%esp) 218 call _C_LABEL(BF_decrypt) 219 movl 8(%esp), %eax 220 movl 12(%esp), %ebx 221.byte 15 222.byte 200 # bswapl %eax 223.byte 15 224.byte 203 # bswapl %ebx 225 movl 16(%esp), %ecx 226 movl 20(%esp), %edx 227 xorl %eax, %ecx 228 xorl %ebx, %edx 229 movl (%esi), %eax 230 movl 4(%esi), %ebx 231.L015dj7: 232 rorl $16, %edx 233 movb %dl, 6(%edi) 234 shrl $16, %edx 235.L016dj6: 236 movb %dh, 5(%edi) 237.L017dj5: 238 movb %dl, 4(%edi) 239.L018dj4: 240 movl %ecx, (%edi) 241 jmp .L019djend 242.L020dj3: 243 rorl $16, %ecx 244 movb %cl, 2(%edi) 245 sall $16, %ecx 246.L021dj2: 247 movb %ch, 1(%esi) 248.L022dj1: 249 movb %cl, (%esi) 250.L019djend: 251 jmp .L003finish 252#ifdef __ELF__ 253.align 16 254#else 255.align 4 256#endif 257.L003finish: 258 movl 60(%esp), %ecx 259 addl $24, %esp 260 movl %eax, (%ecx) 261 movl %ebx, 4(%ecx) 262 popl %edi 263 popl %esi 264 popl %ebx 265 popl %ebp 266 ret 267#ifdef __ELF__ 268.align 16 269#else 270.align 4 271#endif 272.L004cbc_enc_jmp_table: 273 .long 0 274 .long .L012ej1 275 .long .L011ej2 276 .long .L010ej3 277 .long .L008ej4 278 .long .L007ej5 279 .long .L006ej6 280 .long .L005ej7 281#ifdef __ELF__ 282.align 16 283#else 284.align 4 285#endif 286.L023cbc_dec_jmp_table: 287 .long 0 288 .long .L022dj1 289 .long .L021dj2 290 .long .L020dj3 291 .long .L018dj4 292 .long .L017dj5 293 .long .L016dj6 294 .long .L015dj7 295.L_BF_cbc_encrypt_end: 296 .size _C_LABEL(BF_cbc_encrypt),.L_BF_cbc_encrypt_end-_C_LABEL(BF_cbc_encrypt) 297