1 1.6 lukem /* $NetBSD: des_cbc.S,v 1.6 2007/12/11 23:31:07 lukem Exp $ */ 2 1.1 tls 3 1.1 tls /* Copyright (C) 1995-1997 Eric Young (eay (at) cryptsoft.com) 4 1.1 tls * All rights reserved. 5 1.1 tls * 6 1.1 tls * This package is an SSL implementation written 7 1.1 tls * by Eric Young (eay (at) cryptsoft.com). 8 1.1 tls * The implementation was written so as to conform with Netscapes SSL. 9 1.4 perry * 10 1.1 tls * This library is free for commercial and non-commercial use as long as 11 1.1 tls * the following conditions are aheared to. The following conditions 12 1.1 tls * apply to all code found in this distribution, be it the RC4, RSA, 13 1.1 tls * lhash, DES, etc., code; not just the SSL code. The SSL documentation 14 1.1 tls * included with this distribution is covered by the same copyright terms 15 1.1 tls * except that the holder is Tim Hudson (tjh (at) cryptsoft.com). 16 1.4 perry * 17 1.1 tls * Copyright remains Eric Young's, and as such any Copyright notices in 18 1.1 tls * the code are not to be removed. 19 1.1 tls * If this package is used in a product, Eric Young should be given attribution 20 1.1 tls * as the author of the parts of the library used. 21 1.1 tls * This can be in the form of a textual message at program startup or 22 1.1 tls * in documentation (online or textual) provided with the package. 23 1.4 perry * 24 1.1 tls * Redistribution and use in source and binary forms, with or without 25 1.1 tls * modification, are permitted provided that the following conditions 26 1.1 tls * are met: 27 1.1 tls * 1. Redistributions of source code must retain the copyright 28 1.1 tls * notice, this list of conditions and the following disclaimer. 29 1.1 tls * 2. Redistributions in binary form must reproduce the above copyright 30 1.1 tls * notice, this list of conditions and the following disclaimer in the 31 1.1 tls * documentation and/or other materials provided with the distribution. 32 1.1 tls * 3. All advertising materials mentioning features or use of this software 33 1.1 tls * must display the following acknowledgement: 34 1.1 tls * "This product includes cryptographic software written by 35 1.1 tls * Eric Young (eay (at) cryptsoft.com)" 36 1.1 tls * The word 'cryptographic' can be left out if the rouines from the library 37 1.1 tls * being used are not cryptographic related :-). 38 1.4 perry * 4. If you include any Windows specific code (or a derivative thereof) from 39 1.1 tls * the apps directory (application code) you must include an acknowledgement: 40 1.1 tls * "This product includes software written by Tim Hudson (tjh (at) cryptsoft.com)" 41 1.4 perry * 42 1.1 tls * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 43 1.1 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 44 1.1 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 45 1.1 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 46 1.1 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 47 1.1 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 48 1.1 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49 1.1 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 50 1.1 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 51 1.1 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 1.1 tls * SUCH DAMAGE. 53 1.4 perry * 54 1.1 tls * The licence and distribution terms for any publically available version or 55 1.1 tls * derivative of this code cannot be changed. i.e. this code cannot simply be 56 1.1 tls * copied and put under another distribution licence 57 1.1 tls * [including the GNU Public Licence.] 58 1.1 tls */ 59 1.1 tls 60 1.1 tls /* 61 1.1 tls * Modified from the output of `perl des686.pl elf' by 62 1.3 keihan * Thor Lancelot Simon <tls (at) NetBSD.org> 63 1.1 tls */ 64 1.1 tls 65 1.1 tls #include <i386/include/asm.h> 66 1.6 lukem __KERNEL_RCSID(0, "$NetBSD: des_cbc.S,v 1.6 2007/12/11 23:31:07 lukem Exp $"); 67 1.1 tls 68 1.1 tls ENTRY(des_ncbc_encrypt) 69 1.1 tls 70 1.1 tls pushl %ebp 71 1.1 tls pushl %ebx 72 1.1 tls pushl %esi 73 1.1 tls pushl %edi 74 1.1 tls movl 28(%esp), %ebp 75 1.4 perry # getting iv ptr from parameter 4 76 1.1 tls movl 36(%esp), %ebx 77 1.1 tls movl (%ebx), %esi 78 1.1 tls movl 4(%ebx), %edi 79 1.1 tls pushl %edi 80 1.1 tls pushl %esi 81 1.1 tls pushl %edi 82 1.1 tls pushl %esi 83 1.1 tls movl %esp, %ebx 84 1.1 tls movl 36(%esp), %esi 85 1.1 tls movl 40(%esp), %edi 86 1.4 perry # getting encrypt flag from parameter 5 87 1.1 tls movl 56(%esp), %ecx 88 1.4 perry # get and push parameter 5 89 1.1 tls pushl %ecx 90 1.4 perry # get and push parameter 3 91 1.1 tls movl 52(%esp), %eax 92 1.1 tls pushl %eax 93 1.1 tls pushl %ebx 94 1.1 tls cmpl $0, %ecx 95 1.1 tls jz .L004decrypt 96 1.1 tls andl $4294967288, %ebp 97 1.1 tls movl 12(%esp), %eax 98 1.1 tls movl 16(%esp), %ebx 99 1.1 tls jz .L005encrypt_finish 100 1.1 tls .L006encrypt_loop: 101 1.1 tls movl (%esi), %ecx 102 1.1 tls movl 4(%esi), %edx 103 1.1 tls xorl %ecx, %eax 104 1.1 tls xorl %edx, %ebx 105 1.1 tls movl %eax, 12(%esp) 106 1.1 tls movl %ebx, 16(%esp) 107 1.1 tls call _C_LABEL(des_encrypt1) 108 1.1 tls movl 12(%esp), %eax 109 1.1 tls movl 16(%esp), %ebx 110 1.1 tls movl %eax, (%edi) 111 1.1 tls movl %ebx, 4(%edi) 112 1.1 tls addl $8, %esi 113 1.1 tls addl $8, %edi 114 1.1 tls subl $8, %ebp 115 1.1 tls jnz .L006encrypt_loop 116 1.1 tls .L005encrypt_finish: 117 1.1 tls movl 56(%esp), %ebp 118 1.1 tls andl $7, %ebp 119 1.1 tls jz .L007finish 120 1.1 tls xorl %ecx, %ecx 121 1.1 tls xorl %edx, %edx 122 1.1 tls movl .L008cbc_enc_jmp_table(,%ebp,4),%ebp 123 1.1 tls jmp *%ebp 124 1.1 tls .L009ej7: 125 1.1 tls movb 6(%esi), %dh 126 1.1 tls sall $8, %edx 127 1.1 tls .L010ej6: 128 1.1 tls movb 5(%esi), %dh 129 1.1 tls .L011ej5: 130 1.1 tls movb 4(%esi), %dl 131 1.1 tls .L012ej4: 132 1.1 tls movl (%esi), %ecx 133 1.1 tls jmp .L013ejend 134 1.1 tls .L014ej3: 135 1.1 tls movb 2(%esi), %ch 136 1.1 tls sall $8, %ecx 137 1.1 tls .L015ej2: 138 1.1 tls movb 1(%esi), %ch 139 1.1 tls .L016ej1: 140 1.1 tls movb (%esi), %cl 141 1.1 tls .L013ejend: 142 1.1 tls xorl %ecx, %eax 143 1.1 tls xorl %edx, %ebx 144 1.1 tls movl %eax, 12(%esp) 145 1.1 tls movl %ebx, 16(%esp) 146 1.1 tls call _C_LABEL(des_encrypt1) 147 1.1 tls movl 12(%esp), %eax 148 1.1 tls movl 16(%esp), %ebx 149 1.1 tls movl %eax, (%edi) 150 1.1 tls movl %ebx, 4(%edi) 151 1.1 tls jmp .L007finish 152 1.2 itohy #ifdef __ELF__ 153 1.1 tls .align 16 154 1.2 itohy #else 155 1.2 itohy .align 4 156 1.2 itohy #endif 157 1.1 tls .L004decrypt: 158 1.1 tls andl $4294967288, %ebp 159 1.1 tls movl 20(%esp), %eax 160 1.1 tls movl 24(%esp), %ebx 161 1.1 tls jz .L017decrypt_finish 162 1.1 tls .L018decrypt_loop: 163 1.1 tls movl (%esi), %eax 164 1.1 tls movl 4(%esi), %ebx 165 1.1 tls movl %eax, 12(%esp) 166 1.1 tls movl %ebx, 16(%esp) 167 1.1 tls call _C_LABEL(des_encrypt1) 168 1.1 tls movl 12(%esp), %eax 169 1.1 tls movl 16(%esp), %ebx 170 1.1 tls movl 20(%esp), %ecx 171 1.1 tls movl 24(%esp), %edx 172 1.1 tls xorl %eax, %ecx 173 1.1 tls xorl %ebx, %edx 174 1.1 tls movl (%esi), %eax 175 1.1 tls movl 4(%esi), %ebx 176 1.1 tls movl %ecx, (%edi) 177 1.1 tls movl %edx, 4(%edi) 178 1.1 tls movl %eax, 20(%esp) 179 1.1 tls movl %ebx, 24(%esp) 180 1.1 tls addl $8, %esi 181 1.1 tls addl $8, %edi 182 1.1 tls subl $8, %ebp 183 1.1 tls jnz .L018decrypt_loop 184 1.1 tls .L017decrypt_finish: 185 1.1 tls movl 56(%esp), %ebp 186 1.1 tls andl $7, %ebp 187 1.1 tls jz .L007finish 188 1.1 tls movl (%esi), %eax 189 1.1 tls movl 4(%esi), %ebx 190 1.1 tls movl %eax, 12(%esp) 191 1.1 tls movl %ebx, 16(%esp) 192 1.1 tls call _C_LABEL(des_encrypt1) 193 1.1 tls movl 12(%esp), %eax 194 1.1 tls movl 16(%esp), %ebx 195 1.1 tls movl 20(%esp), %ecx 196 1.1 tls movl 24(%esp), %edx 197 1.1 tls xorl %eax, %ecx 198 1.1 tls xorl %ebx, %edx 199 1.1 tls movl (%esi), %eax 200 1.1 tls movl 4(%esi), %ebx 201 1.1 tls .L019dj7: 202 1.1 tls rorl $16, %edx 203 1.1 tls movb %dl, 6(%edi) 204 1.1 tls shrl $16, %edx 205 1.1 tls .L020dj6: 206 1.1 tls movb %dh, 5(%edi) 207 1.1 tls .L021dj5: 208 1.1 tls movb %dl, 4(%edi) 209 1.1 tls .L022dj4: 210 1.1 tls movl %ecx, (%edi) 211 1.1 tls jmp .L023djend 212 1.1 tls .L024dj3: 213 1.1 tls rorl $16, %ecx 214 1.1 tls movb %cl, 2(%edi) 215 1.1 tls sall $16, %ecx 216 1.1 tls .L025dj2: 217 1.1 tls movb %ch, 1(%esi) 218 1.1 tls .L026dj1: 219 1.1 tls movb %cl, (%esi) 220 1.1 tls .L023djend: 221 1.1 tls jmp .L007finish 222 1.2 itohy #ifdef __ELF__ 223 1.1 tls .align 16 224 1.2 itohy #else 225 1.2 itohy .align 4 226 1.2 itohy #endif 227 1.1 tls .L007finish: 228 1.1 tls movl 64(%esp), %ecx 229 1.1 tls addl $28, %esp 230 1.1 tls movl %eax, (%ecx) 231 1.1 tls movl %ebx, 4(%ecx) 232 1.1 tls popl %edi 233 1.1 tls popl %esi 234 1.1 tls popl %ebx 235 1.1 tls popl %ebp 236 1.1 tls ret 237 1.2 itohy #ifdef __ELF__ 238 1.1 tls .align 16 239 1.2 itohy #else 240 1.2 itohy .align 4 241 1.2 itohy #endif 242 1.1 tls .L008cbc_enc_jmp_table: 243 1.1 tls .long 0 244 1.1 tls .long .L016ej1 245 1.1 tls .long .L015ej2 246 1.1 tls .long .L014ej3 247 1.1 tls .long .L012ej4 248 1.1 tls .long .L011ej5 249 1.1 tls .long .L010ej6 250 1.1 tls .long .L009ej7 251 1.2 itohy #ifdef __ELF__ 252 1.1 tls .align 16 253 1.2 itohy #else 254 1.2 itohy .align 4 255 1.2 itohy #endif 256 1.1 tls .L027cbc_dec_jmp_table: 257 1.1 tls .long 0 258 1.1 tls .long .L026dj1 259 1.1 tls .long .L025dj2 260 1.1 tls .long .L024dj3 261 1.1 tls .long .L022dj4 262 1.1 tls .long .L021dj5 263 1.1 tls .long .L020dj6 264 1.1 tls .long .L019dj7 265 1.1 tls .L_des_ncbc_encrypt_end: 266 1.1 tls .size _C_LABEL(des_ncbc_encrypt),.L_des_ncbc_encrypt_end-_C_LABEL(des_ncbc_encrypt) 267 1.1 tls 268 1.1 tls ENTRY(des_ede3_cbc_encrypt) 269 1.1 tls 270 1.1 tls pushl %ebp 271 1.1 tls pushl %ebx 272 1.1 tls pushl %esi 273 1.1 tls pushl %edi 274 1.1 tls movl 28(%esp), %ebp 275 1.4 perry # getting iv ptr from parameter 6 276 1.1 tls movl 44(%esp), %ebx 277 1.1 tls movl (%ebx), %esi 278 1.1 tls movl 4(%ebx), %edi 279 1.1 tls pushl %edi 280 1.1 tls pushl %esi 281 1.1 tls pushl %edi 282 1.1 tls pushl %esi 283 1.1 tls movl %esp, %ebx 284 1.1 tls movl 36(%esp), %esi 285 1.1 tls movl 40(%esp), %edi 286 1.4 perry # getting encrypt flag from parameter 7 287 1.1 tls movl 64(%esp), %ecx 288 1.4 perry # get and push parameter 5 289 1.1 tls movl 56(%esp), %eax 290 1.1 tls pushl %eax 291 1.4 perry # get and push parameter 4 292 1.1 tls movl 56(%esp), %eax 293 1.1 tls pushl %eax 294 1.4 perry # get and push parameter 3 295 1.1 tls movl 56(%esp), %eax 296 1.1 tls pushl %eax 297 1.1 tls pushl %ebx 298 1.1 tls cmpl $0, %ecx 299 1.1 tls jz .L028decrypt 300 1.1 tls andl $4294967288, %ebp 301 1.1 tls movl 16(%esp), %eax 302 1.1 tls movl 20(%esp), %ebx 303 1.1 tls jz .L029encrypt_finish 304 1.1 tls .L030encrypt_loop: 305 1.1 tls movl (%esi), %ecx 306 1.1 tls movl 4(%esi), %edx 307 1.1 tls xorl %ecx, %eax 308 1.1 tls xorl %edx, %ebx 309 1.1 tls movl %eax, 16(%esp) 310 1.1 tls movl %ebx, 20(%esp) 311 1.1 tls call _C_LABEL(des_encrypt3) 312 1.1 tls movl 16(%esp), %eax 313 1.1 tls movl 20(%esp), %ebx 314 1.1 tls movl %eax, (%edi) 315 1.1 tls movl %ebx, 4(%edi) 316 1.1 tls addl $8, %esi 317 1.1 tls addl $8, %edi 318 1.1 tls subl $8, %ebp 319 1.1 tls jnz .L030encrypt_loop 320 1.1 tls .L029encrypt_finish: 321 1.1 tls movl 60(%esp), %ebp 322 1.1 tls andl $7, %ebp 323 1.1 tls jz .L031finish 324 1.1 tls xorl %ecx, %ecx 325 1.1 tls xorl %edx, %edx 326 1.1 tls movl .L032cbc_enc_jmp_table(,%ebp,4),%ebp 327 1.1 tls jmp *%ebp 328 1.1 tls .L033ej7: 329 1.1 tls movb 6(%esi), %dh 330 1.1 tls sall $8, %edx 331 1.1 tls .L034ej6: 332 1.1 tls movb 5(%esi), %dh 333 1.1 tls .L035ej5: 334 1.1 tls movb 4(%esi), %dl 335 1.1 tls .L036ej4: 336 1.1 tls movl (%esi), %ecx 337 1.1 tls jmp .L037ejend 338 1.1 tls .L038ej3: 339 1.1 tls movb 2(%esi), %ch 340 1.1 tls sall $8, %ecx 341 1.1 tls .L039ej2: 342 1.1 tls movb 1(%esi), %ch 343 1.1 tls .L040ej1: 344 1.1 tls movb (%esi), %cl 345 1.1 tls .L037ejend: 346 1.1 tls xorl %ecx, %eax 347 1.1 tls xorl %edx, %ebx 348 1.1 tls movl %eax, 16(%esp) 349 1.1 tls movl %ebx, 20(%esp) 350 1.1 tls call _C_LABEL(des_encrypt3) 351 1.1 tls movl 16(%esp), %eax 352 1.1 tls movl 20(%esp), %ebx 353 1.1 tls movl %eax, (%edi) 354 1.1 tls movl %ebx, 4(%edi) 355 1.1 tls jmp .L031finish 356 1.2 itohy #ifdef __ELF__ 357 1.1 tls .align 16 358 1.2 itohy #else 359 1.2 itohy .align 4 360 1.2 itohy #endif 361 1.1 tls .L028decrypt: 362 1.1 tls andl $4294967288, %ebp 363 1.1 tls movl 24(%esp), %eax 364 1.1 tls movl 28(%esp), %ebx 365 1.1 tls jz .L041decrypt_finish 366 1.1 tls .L042decrypt_loop: 367 1.1 tls movl (%esi), %eax 368 1.1 tls movl 4(%esi), %ebx 369 1.1 tls movl %eax, 16(%esp) 370 1.1 tls movl %ebx, 20(%esp) 371 1.1 tls call _C_LABEL(des_decrypt3) 372 1.1 tls movl 16(%esp), %eax 373 1.1 tls movl 20(%esp), %ebx 374 1.1 tls movl 24(%esp), %ecx 375 1.1 tls movl 28(%esp), %edx 376 1.1 tls xorl %eax, %ecx 377 1.1 tls xorl %ebx, %edx 378 1.1 tls movl (%esi), %eax 379 1.1 tls movl 4(%esi), %ebx 380 1.1 tls movl %ecx, (%edi) 381 1.1 tls movl %edx, 4(%edi) 382 1.1 tls movl %eax, 24(%esp) 383 1.1 tls movl %ebx, 28(%esp) 384 1.1 tls addl $8, %esi 385 1.1 tls addl $8, %edi 386 1.1 tls subl $8, %ebp 387 1.1 tls jnz .L042decrypt_loop 388 1.1 tls .L041decrypt_finish: 389 1.1 tls movl 60(%esp), %ebp 390 1.1 tls andl $7, %ebp 391 1.1 tls jz .L031finish 392 1.1 tls movl (%esi), %eax 393 1.1 tls movl 4(%esi), %ebx 394 1.1 tls movl %eax, 16(%esp) 395 1.1 tls movl %ebx, 20(%esp) 396 1.1 tls call _C_LABEL(des_decrypt3) 397 1.1 tls movl 16(%esp), %eax 398 1.1 tls movl 20(%esp), %ebx 399 1.1 tls movl 24(%esp), %ecx 400 1.1 tls movl 28(%esp), %edx 401 1.1 tls xorl %eax, %ecx 402 1.1 tls xorl %ebx, %edx 403 1.1 tls movl (%esi), %eax 404 1.1 tls movl 4(%esi), %ebx 405 1.1 tls .L043dj7: 406 1.1 tls rorl $16, %edx 407 1.1 tls movb %dl, 6(%edi) 408 1.1 tls shrl $16, %edx 409 1.1 tls .L044dj6: 410 1.1 tls movb %dh, 5(%edi) 411 1.1 tls .L045dj5: 412 1.1 tls movb %dl, 4(%edi) 413 1.1 tls .L046dj4: 414 1.1 tls movl %ecx, (%edi) 415 1.1 tls jmp .L047djend 416 1.1 tls .L048dj3: 417 1.1 tls rorl $16, %ecx 418 1.1 tls movb %cl, 2(%edi) 419 1.1 tls sall $16, %ecx 420 1.1 tls .L049dj2: 421 1.1 tls movb %ch, 1(%esi) 422 1.1 tls .L050dj1: 423 1.1 tls movb %cl, (%esi) 424 1.1 tls .L047djend: 425 1.1 tls jmp .L031finish 426 1.2 itohy #ifdef __ELF__ 427 1.1 tls .align 16 428 1.2 itohy #else 429 1.2 itohy .align 4 430 1.2 itohy #endif 431 1.1 tls .L031finish: 432 1.1 tls movl 76(%esp), %ecx 433 1.1 tls addl $32, %esp 434 1.1 tls movl %eax, (%ecx) 435 1.1 tls movl %ebx, 4(%ecx) 436 1.1 tls popl %edi 437 1.1 tls popl %esi 438 1.1 tls popl %ebx 439 1.1 tls popl %ebp 440 1.1 tls ret 441 1.2 itohy #ifdef __ELF__ 442 1.1 tls .align 16 443 1.2 itohy #else 444 1.2 itohy .align 4 445 1.2 itohy #endif 446 1.1 tls .L032cbc_enc_jmp_table: 447 1.1 tls .long 0 448 1.1 tls .long .L040ej1 449 1.1 tls .long .L039ej2 450 1.1 tls .long .L038ej3 451 1.1 tls .long .L036ej4 452 1.1 tls .long .L035ej5 453 1.1 tls .long .L034ej6 454 1.1 tls .long .L033ej7 455 1.2 itohy #ifdef __ELF__ 456 1.1 tls .align 16 457 1.2 itohy #else 458 1.2 itohy .align 4 459 1.2 itohy #endif 460 1.1 tls .L051cbc_dec_jmp_table: 461 1.1 tls .long 0 462 1.1 tls .long .L050dj1 463 1.1 tls .long .L049dj2 464 1.1 tls .long .L048dj3 465 1.1 tls .long .L046dj4 466 1.1 tls .long .L045dj5 467 1.1 tls .long .L044dj6 468 1.1 tls .long .L043dj7 469 1.1 tls .L_des_ede3_cbc_encrypt_end: 470 1.1 tls .size _C_LABEL(des_ede3_cbc_encrypt),.L_des_ede3_cbc_encrypt_end-_C_LABEL(des_ede3_cbc_encrypt) 471