1! Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. 2! 3! Licensed under the Apache License 2.0 (the "License"). You may not use 4! this file except in compliance with the License. You can obtain a copy 5! in the file LICENSE in the source distribution or at 6! https://www.openssl.org/source/license.html 7! 8! To expand the m4 macros: m4 -B 8192 des_enc.m4 > des_enc.S 9! 10! Global registers 1 to 5 are used. This is the same as done by the 11! cc compiler. The UltraSPARC load/store little endian feature is used. 12! 13! Instruction grouping often refers to one CPU cycle. 14! 15! Assemble through gcc: gcc -c -mcpu=ultrasparc -o des_enc.o des_enc.S 16! 17! Assemble through cc: cc -c -xarch=v8plusa -o des_enc.o des_enc.S 18! 19! Performance improvement according to './apps/openssl speed des' 20! 21! 32-bit build: 22! 23% faster than cc-5.2 -xarch=v8plus -xO5 23! 115% faster than gcc-3.2.1 -m32 -mcpu=ultrasparc -O5 24! 64-bit build: 25! 50% faster than cc-5.2 -xarch=v9 -xO5 26! 100% faster than gcc-3.2.1 -m64 -mcpu=ultrasparc -O5 27! 28 29.ident "des_enc.m4 2.1" 30.file "des_enc-sparc.S" 31 32#if defined(__SUNPRO_C) && defined(__sparcv9) 33# define ABI64 /* They've said -xarch=v9 at command line */ 34#elif defined(__GNUC__) && defined(__arch64__) 35# define ABI64 /* They've said -m64 at command line */ 36#endif 37 38#ifdef ABI64 39 .register %g2,#scratch 40 .register %g3,#scratch 41# define FRAME -192 42# define BIAS 2047 43# define LDPTR ldx 44# define STPTR stx 45# define ARG0 128 46# define ARGSZ 8 47#else 48# define FRAME -96 49# define BIAS 0 50# define LDPTR ld 51# define STPTR st 52# define ARG0 68 53# define ARGSZ 4 54#endif 55 56#define LOOPS 7 57 58#define global0 %g0 59#define global1 %g1 60#define global2 %g2 61#define global3 %g3 62#define global4 %g4 63#define global5 %g5 64 65#define local0 %l0 66#define local1 %l1 67#define local2 %l2 68#define local3 %l3 69#define local4 %l4 70#define local5 %l5 71#define local7 %l6 72#define local6 %l7 73 74#define in0 %i0 75#define in1 %i1 76#define in2 %i2 77#define in3 %i3 78#define in4 %i4 79#define in5 %i5 80#define in6 %i6 81#define in7 %i7 82 83#define out0 %o0 84#define out1 %o1 85#define out2 %o2 86#define out3 %o3 87#define out4 %o4 88#define out5 %o5 89#define out6 %o6 90#define out7 %o7 91 92#define stub stb 93 94 95 96 97! Macro definitions: 98 99 100! ip_macro 101! 102! The logic used in initial and final permutations is the same as in 103! the C code. The permutations are done with a clever , xor, and 104! technique. 105! 106! The macro also loads address sbox 1 to 5 to global 1 to 5, address 107! sbox 6 to local6, and address sbox 8 to out3. 108! 109! Rotates the halves 3 left to bring the sbox bits in convenient positions. 110! 111! Loads key first round from address in parameter 5 to out0, out1. 112! 113! After the original LibDES initial permutation, the resulting left 114! is in the variable initially used for right and vice versa. The macro 115! implements the possibility to keep the halves in the original registers. 116! 117! parameter 1 left 118! parameter 2 right 119! parameter 3 result left (modify in first round) 120! parameter 4 result right (use in first round) 121! parameter 5 key address 122! parameter 6 1/2 for include encryption/decryption 123! parameter 7 1 for move in1 to in3 124! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 125! parameter 9 1 for load ks3 and ks2 to in4 and in3 126 127 128 129 130! rounds_macro 131! 132! The logic used in the DES rounds is the same as in the C code, 133! except that calculations for sbox 1 and sbox 5 begin before 134! the previous round is finished. 135! 136! In each round one half (work) is modified based on key and the 137! other half (use). 138! 139! In this version we do two rounds in a loop repeated 7 times 140! and two rounds separately. 141! 142! One half has the bits for the sboxes in the following positions: 143! 144! 777777xx555555xx333333xx111111xx 145! 146! 88xx666666xx444444xx222222xx8888 147! 148! The bits for each sbox are xor-ed with the key bits for that box. 149! The above xx bits are cleared, and the result used for lookup in 150! the sbox table. Each sbox entry contains the 4 output bits permuted 151! into 32 bits according to the P permutation. 152! 153! In the description of DES, left and right are switched after 154! each round, except after last round. In this code the original 155! left and right are kept in the same register in all rounds, meaning 156! that after the 16 rounds the result for right is in the register 157! originally used for left. 158! 159! parameter 1 first work (left in first round) 160! parameter 2 first use (right in first round) 161! parameter 3 enc/dec 1/-1 162! parameter 4 loop label 163! parameter 5 key address register 164! parameter 6 optional address for key next encryption/decryption 165! parameter 7 not empty for include retl 166! 167! also compares in2 to 8 168 169 170 171 172! fp_macro 173! 174! parameter 1 right (original left) 175! parameter 2 left (original right) 176! parameter 3 1 for optional store to [in0] 177! parameter 4 1 for load input/output address to local5/7 178! 179! The final permutation logic switches the halves, meaning that 180! left and right ends up the registers originally used. 181 182 183 184 185! fp_ip_macro 186! 187! Does initial permutation for next block mixed with 188! final permutation for current block. 189! 190! parameter 1 original left 191! parameter 2 original right 192! parameter 3 left ip 193! parameter 4 right ip 194! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4 195! 2: mov in4 to in3 196! 197! also adds -8 to length in2 and loads loop counter to out4 198 199 200 201 202 203! load_little_endian 204! 205! parameter 1 address 206! parameter 2 destination left 207! parameter 3 destination right 208! parameter 4 temporary 209! parameter 5 label 210 211 212 213 214! load_little_endian_inc 215! 216! parameter 1 address 217! parameter 2 destination left 218! parameter 3 destination right 219! parameter 4 temporary 220! parameter 4 label 221! 222! adds 8 to address 223 224 225 226 227! load_n_bytes 228! 229! Loads 1 to 7 bytes little endian 230! Remaining bytes are zeroed. 231! 232! parameter 1 address 233! parameter 2 length 234! parameter 3 destination register left 235! parameter 4 destination register right 236! parameter 5 temp 237! parameter 6 temp2 238! parameter 7 label 239! parameter 8 return label 240 241 242 243 244! store_little_endian 245! 246! parameter 1 address 247! parameter 2 source left 248! parameter 3 source right 249! parameter 4 temporary 250 251 252 253 254! store_n_bytes 255! 256! Stores 1 to 7 bytes little endian 257! 258! parameter 1 address 259! parameter 2 length 260! parameter 3 source register left 261! parameter 4 source register right 262! parameter 5 temp 263! parameter 6 temp2 264! parameter 7 label 265! parameter 8 return label 266 267 268 269 270 271 272 273 274.section ".text" 275 276 .align 32 277 278.des_enc: 279 280 ! key address in3 281 ! loads key next encryption/decryption first round from [in4] 282 283 284 285! rounds_macro 286! in5 out5 1 .des_enc.1 in3 in4 retl 287 288 xor out5, out0, local1 289 290 ld [out2+284], local5 ! 0x0000FC00 291 ba .des_enc.1 292 and local1, 252, local1 293 294 .align 32 295 296.des_enc.1: 297 ! local6 is address sbox 6 298 ! out3 is address sbox 8 299 ! out4 is loop counter 300 301 ld [global1+local1], local1 302 xor out5, out1, out1 ! 8642 303 xor out5, out0, out0 ! 7531 304 ! fmovs %f0, %f0 ! fxor used for alignment 305 306 srl out1, 4, local0 ! rotate 4 right 307 and out0, local5, local3 ! 3 308 ! fmovs %f0, %f0 309 310 ld [in3+1*8], local7 ! key 7531 next round 311 srl local3, 8, local3 ! 3 312 and local0, 252, local2 ! 2 313 ! fmovs %f0, %f0 314 315 ld [global3+local3],local3 ! 3 316 sll out1, 28, out1 ! rotate 317 xor in5, local1, in5 ! 1 finished, local1 now sbox 7 318 319 ld [global2+local2], local2 ! 2 320 srl out0, 24, local1 ! 7 321 or out1, local0, out1 ! rotate 322 323 ldub [out2+local1], local1 ! 7 (and 0xFC) 324 srl out1, 24, local0 ! 8 325 and out1, local5, local4 ! 4 326 327 ldub [out2+local0], local0 ! 8 (and 0xFC) 328 srl local4, 8, local4 ! 4 329 xor in5, local2, in5 ! 2 finished local2 now sbox 6 330 331 ld [global4+local4],local4 ! 4 332 srl out1, 16, local2 ! 6 333 xor in5, local3, in5 ! 3 finished local3 now sbox 5 334 335 ld [out3+local0],local0 ! 8 336 and local2, 252, local2 ! 6 337 add global1, 1536, local5 ! address sbox 7 338 339 ld [local6+local2], local2 ! 6 340 srl out0, 16, local3 ! 5 341 xor in5, local4, in5 ! 4 finished 342 343 ld [local5+local1],local1 ! 7 344 and local3, 252, local3 ! 5 345 xor in5, local0, in5 ! 8 finished 346 347 ld [global5+local3],local3 ! 5 348 xor in5, local2, in5 ! 6 finished 349 subcc out4, 1, out4 350 351 ld [in3+1*8+4], out0 ! key 8642 next round 352 xor in5, local7, local2 ! sbox 5 next round 353 xor in5, local1, in5 ! 7 finished 354 355 srl local2, 16, local2 ! sbox 5 next round 356 xor in5, local3, in5 ! 5 finished 357 358 ld [in3+1*16+4], out1 ! key 8642 next round again 359 and local2, 252, local2 ! sbox5 next round 360! next round 361 xor in5, local7, local7 ! 7531 362 363 ld [global5+local2], local2 ! 5 364 srl local7, 24, local3 ! 7 365 xor in5, out0, out0 ! 8642 366 367 ldub [out2+local3], local3 ! 7 (and 0xFC) 368 srl out0, 4, local0 ! rotate 4 right 369 and local7, 252, local1 ! 1 370 371 sll out0, 28, out0 ! rotate 372 xor out5, local2, out5 ! 5 finished local2 used 373 374 srl local0, 8, local4 ! 4 375 and local0, 252, local2 ! 2 376 ld [local5+local3], local3 ! 7 377 378 srl local0, 16, local5 ! 6 379 or out0, local0, out0 ! rotate 380 ld [global2+local2], local2 ! 2 381 382 srl out0, 24, local0 383 ld [in3+1*16], out0 ! key 7531 next round 384 and local4, 252, local4 ! 4 385 386 and local5, 252, local5 ! 6 387 ld [global4+local4], local4 ! 4 388 xor out5, local3, out5 ! 7 finished local3 used 389 390 and local0, 252, local0 ! 8 391 ld [local6+local5], local5 ! 6 392 xor out5, local2, out5 ! 2 finished local2 now sbox 3 393 394 srl local7, 8, local2 ! 3 start 395 ld [out3+local0], local0 ! 8 396 xor out5, local4, out5 ! 4 finished 397 398 and local2, 252, local2 ! 3 399 ld [global1+local1], local1 ! 1 400 xor out5, local5, out5 ! 6 finished local5 used 401 402 ld [global3+local2], local2 ! 3 403 xor out5, local0, out5 ! 8 finished 404 add in3, 1*16, in3 ! enc add 8, dec add -8 to key pointer 405 406 ld [out2+284], local5 ! 0x0000FC00 407 xor out5, out0, local4 ! sbox 1 next round 408 xor out5, local1, out5 ! 1 finished 409 410 xor out5, local2, out5 ! 3 finished 411 bne .des_enc.1 412 and local4, 252, local1 ! sbox 1 next round 413 414! two rounds more: 415 416 ld [global1+local1], local1 417 xor out5, out1, out1 418 xor out5, out0, out0 419 420 srl out1, 4, local0 ! rotate 421 and out0, local5, local3 422 423 ld [in3+1*8], local7 ! key 7531 424 srl local3, 8, local3 425 and local0, 252, local2 426 427 ld [global3+local3],local3 428 sll out1, 28, out1 ! rotate 429 xor in5, local1, in5 ! 1 finished, local1 now sbox 7 430 431 ld [global2+local2], local2 432 srl out0, 24, local1 433 or out1, local0, out1 ! rotate 434 435 ldub [out2+local1], local1 436 srl out1, 24, local0 437 and out1, local5, local4 438 439 ldub [out2+local0], local0 440 srl local4, 8, local4 441 xor in5, local2, in5 ! 2 finished local2 now sbox 6 442 443 ld [global4+local4],local4 444 srl out1, 16, local2 445 xor in5, local3, in5 ! 3 finished local3 now sbox 5 446 447 ld [out3+local0],local0 448 and local2, 252, local2 449 add global1, 1536, local5 ! address sbox 7 450 451 ld [local6+local2], local2 452 srl out0, 16, local3 453 xor in5, local4, in5 ! 4 finished 454 455 ld [local5+local1],local1 456 and local3, 252, local3 457 xor in5, local0, in5 458 459 ld [global5+local3],local3 460 xor in5, local2, in5 ! 6 finished 461 cmp in2, 8 462 463 ld [out2+280], out4 ! loop counter 464 xor in5, local7, local2 ! sbox 5 next round 465 xor in5, local1, in5 ! 7 finished 466 467 ld [in3+1*8+4], out0 468 srl local2, 16, local2 ! sbox 5 next round 469 xor in5, local3, in5 ! 5 finished 470 471 and local2, 252, local2 472! next round (two rounds more) 473 xor in5, local7, local7 ! 7531 474 475 ld [global5+local2], local2 476 srl local7, 24, local3 477 xor in5, out0, out0 ! 8642 478 479 ldub [out2+local3], local3 480 srl out0, 4, local0 ! rotate 481 and local7, 252, local1 482 483 sll out0, 28, out0 ! rotate 484 xor out5, local2, out5 ! 5 finished local2 used 485 486 srl local0, 8, local4 487 and local0, 252, local2 488 ld [local5+local3], local3 489 490 srl local0, 16, local5 491 or out0, local0, out0 ! rotate 492 ld [global2+local2], local2 493 494 srl out0, 24, local0 495 ld [in4], out0 ! key next encryption/decryption 496 and local4, 252, local4 497 498 and local5, 252, local5 499 ld [global4+local4], local4 500 xor out5, local3, out5 ! 7 finished local3 used 501 502 and local0, 252, local0 503 ld [local6+local5], local5 504 xor out5, local2, out5 ! 2 finished local2 now sbox 3 505 506 srl local7, 8, local2 ! 3 start 507 ld [out3+local0], local0 508 xor out5, local4, out5 509 510 and local2, 252, local2 511 ld [global1+local1], local1 512 xor out5, local5, out5 ! 6 finished local5 used 513 514 ld [global3+local2], local2 515 srl in5, 3, local3 516 xor out5, local0, out5 517 518 ld [in4+4], out1 ! key next encryption/decryption 519 sll in5, 29, local4 520 xor out5, local1, out5 521 522 retl 523 xor out5, local2, out5 524 525 526 527 .align 32 528 529.des_dec: 530 531 ! implemented with out5 as first parameter to avoid 532 ! register exchange in ede modes 533 534 ! key address in4 535 ! loads key next encryption/decryption first round from [in3] 536 537 538 539! rounds_macro 540! out5 in5 -1 .des_dec.1 in4 in3 retl 541 542 xor in5, out0, local1 543 544 ld [out2+284], local5 ! 0x0000FC00 545 ba .des_dec.1 546 and local1, 252, local1 547 548 .align 32 549 550.des_dec.1: 551 ! local6 is address sbox 6 552 ! out3 is address sbox 8 553 ! out4 is loop counter 554 555 ld [global1+local1], local1 556 xor in5, out1, out1 ! 8642 557 xor in5, out0, out0 ! 7531 558 ! fmovs %f0, %f0 ! fxor used for alignment 559 560 srl out1, 4, local0 ! rotate 4 right 561 and out0, local5, local3 ! 3 562 ! fmovs %f0, %f0 563 564 ld [in4+-1*8], local7 ! key 7531 next round 565 srl local3, 8, local3 ! 3 566 and local0, 252, local2 ! 2 567 ! fmovs %f0, %f0 568 569 ld [global3+local3],local3 ! 3 570 sll out1, 28, out1 ! rotate 571 xor out5, local1, out5 ! 1 finished, local1 now sbox 7 572 573 ld [global2+local2], local2 ! 2 574 srl out0, 24, local1 ! 7 575 or out1, local0, out1 ! rotate 576 577 ldub [out2+local1], local1 ! 7 (and 0xFC) 578 srl out1, 24, local0 ! 8 579 and out1, local5, local4 ! 4 580 581 ldub [out2+local0], local0 ! 8 (and 0xFC) 582 srl local4, 8, local4 ! 4 583 xor out5, local2, out5 ! 2 finished local2 now sbox 6 584 585 ld [global4+local4],local4 ! 4 586 srl out1, 16, local2 ! 6 587 xor out5, local3, out5 ! 3 finished local3 now sbox 5 588 589 ld [out3+local0],local0 ! 8 590 and local2, 252, local2 ! 6 591 add global1, 1536, local5 ! address sbox 7 592 593 ld [local6+local2], local2 ! 6 594 srl out0, 16, local3 ! 5 595 xor out5, local4, out5 ! 4 finished 596 597 ld [local5+local1],local1 ! 7 598 and local3, 252, local3 ! 5 599 xor out5, local0, out5 ! 8 finished 600 601 ld [global5+local3],local3 ! 5 602 xor out5, local2, out5 ! 6 finished 603 subcc out4, 1, out4 604 605 ld [in4+-1*8+4], out0 ! key 8642 next round 606 xor out5, local7, local2 ! sbox 5 next round 607 xor out5, local1, out5 ! 7 finished 608 609 srl local2, 16, local2 ! sbox 5 next round 610 xor out5, local3, out5 ! 5 finished 611 612 ld [in4+-1*16+4], out1 ! key 8642 next round again 613 and local2, 252, local2 ! sbox5 next round 614! next round 615 xor out5, local7, local7 ! 7531 616 617 ld [global5+local2], local2 ! 5 618 srl local7, 24, local3 ! 7 619 xor out5, out0, out0 ! 8642 620 621 ldub [out2+local3], local3 ! 7 (and 0xFC) 622 srl out0, 4, local0 ! rotate 4 right 623 and local7, 252, local1 ! 1 624 625 sll out0, 28, out0 ! rotate 626 xor in5, local2, in5 ! 5 finished local2 used 627 628 srl local0, 8, local4 ! 4 629 and local0, 252, local2 ! 2 630 ld [local5+local3], local3 ! 7 631 632 srl local0, 16, local5 ! 6 633 or out0, local0, out0 ! rotate 634 ld [global2+local2], local2 ! 2 635 636 srl out0, 24, local0 637 ld [in4+-1*16], out0 ! key 7531 next round 638 and local4, 252, local4 ! 4 639 640 and local5, 252, local5 ! 6 641 ld [global4+local4], local4 ! 4 642 xor in5, local3, in5 ! 7 finished local3 used 643 644 and local0, 252, local0 ! 8 645 ld [local6+local5], local5 ! 6 646 xor in5, local2, in5 ! 2 finished local2 now sbox 3 647 648 srl local7, 8, local2 ! 3 start 649 ld [out3+local0], local0 ! 8 650 xor in5, local4, in5 ! 4 finished 651 652 and local2, 252, local2 ! 3 653 ld [global1+local1], local1 ! 1 654 xor in5, local5, in5 ! 6 finished local5 used 655 656 ld [global3+local2], local2 ! 3 657 xor in5, local0, in5 ! 8 finished 658 add in4, -1*16, in4 ! enc add 8, dec add -8 to key pointer 659 660 ld [out2+284], local5 ! 0x0000FC00 661 xor in5, out0, local4 ! sbox 1 next round 662 xor in5, local1, in5 ! 1 finished 663 664 xor in5, local2, in5 ! 3 finished 665 bne .des_dec.1 666 and local4, 252, local1 ! sbox 1 next round 667 668! two rounds more: 669 670 ld [global1+local1], local1 671 xor in5, out1, out1 672 xor in5, out0, out0 673 674 srl out1, 4, local0 ! rotate 675 and out0, local5, local3 676 677 ld [in4+-1*8], local7 ! key 7531 678 srl local3, 8, local3 679 and local0, 252, local2 680 681 ld [global3+local3],local3 682 sll out1, 28, out1 ! rotate 683 xor out5, local1, out5 ! 1 finished, local1 now sbox 7 684 685 ld [global2+local2], local2 686 srl out0, 24, local1 687 or out1, local0, out1 ! rotate 688 689 ldub [out2+local1], local1 690 srl out1, 24, local0 691 and out1, local5, local4 692 693 ldub [out2+local0], local0 694 srl local4, 8, local4 695 xor out5, local2, out5 ! 2 finished local2 now sbox 6 696 697 ld [global4+local4],local4 698 srl out1, 16, local2 699 xor out5, local3, out5 ! 3 finished local3 now sbox 5 700 701 ld [out3+local0],local0 702 and local2, 252, local2 703 add global1, 1536, local5 ! address sbox 7 704 705 ld [local6+local2], local2 706 srl out0, 16, local3 707 xor out5, local4, out5 ! 4 finished 708 709 ld [local5+local1],local1 710 and local3, 252, local3 711 xor out5, local0, out5 712 713 ld [global5+local3],local3 714 xor out5, local2, out5 ! 6 finished 715 cmp in2, 8 716 717 ld [out2+280], out4 ! loop counter 718 xor out5, local7, local2 ! sbox 5 next round 719 xor out5, local1, out5 ! 7 finished 720 721 ld [in4+-1*8+4], out0 722 srl local2, 16, local2 ! sbox 5 next round 723 xor out5, local3, out5 ! 5 finished 724 725 and local2, 252, local2 726! next round (two rounds more) 727 xor out5, local7, local7 ! 7531 728 729 ld [global5+local2], local2 730 srl local7, 24, local3 731 xor out5, out0, out0 ! 8642 732 733 ldub [out2+local3], local3 734 srl out0, 4, local0 ! rotate 735 and local7, 252, local1 736 737 sll out0, 28, out0 ! rotate 738 xor in5, local2, in5 ! 5 finished local2 used 739 740 srl local0, 8, local4 741 and local0, 252, local2 742 ld [local5+local3], local3 743 744 srl local0, 16, local5 745 or out0, local0, out0 ! rotate 746 ld [global2+local2], local2 747 748 srl out0, 24, local0 749 ld [in3], out0 ! key next encryption/decryption 750 and local4, 252, local4 751 752 and local5, 252, local5 753 ld [global4+local4], local4 754 xor in5, local3, in5 ! 7 finished local3 used 755 756 and local0, 252, local0 757 ld [local6+local5], local5 758 xor in5, local2, in5 ! 2 finished local2 now sbox 3 759 760 srl local7, 8, local2 ! 3 start 761 ld [out3+local0], local0 762 xor in5, local4, in5 763 764 and local2, 252, local2 765 ld [global1+local1], local1 766 xor in5, local5, in5 ! 6 finished local5 used 767 768 ld [global3+local2], local2 769 srl out5, 3, local3 770 xor in5, local0, in5 771 772 ld [in3+4], out1 ! key next encryption/decryption 773 sll out5, 29, local4 774 xor in5, local1, in5 775 776 retl 777 xor in5, local2, in5 778 779 780 781 782! void DES_encrypt1(data, ks, enc) 783! ******************************* 784 785 .align 32 786 .global DES_encrypt1 787 .type DES_encrypt1,#function 788 789DES_encrypt1: 790 791 save %sp, FRAME, %sp 792 793 sethi %hi(_PIC_DES_SPtrans-1f),global1 794 or global1,%lo(_PIC_DES_SPtrans-1f),global1 7951: call .+8 796 add %o7,global1,global1 797 sub global1,_PIC_DES_SPtrans-.des_and,out2 798 799 ld [in0], in5 ! left 800 cmp in2, 0 ! enc 801 802 be .encrypt.dec 803 ld [in0+4], out5 ! right 804 805 ! parameter 6 1/2 for include encryption/decryption 806 ! parameter 7 1 for move in1 to in3 807 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 808 809 810 811! ip_macro 812! in5 out5 out5 in5 in3 0 1 1 813 814 ld [out2+256], local1 815 srl out5, 4, local4 816 817 xor local4, in5, local4 818 mov in1, in3 819 820 ld [out2+260], local2 821 and local4, local1, local4 822 mov in3, in4 823 824 825 ld [out2+280], out4 ! loop counter 826 sll local4, 4, local1 827 xor in5, local4, in5 828 829 ld [out2+264], local3 830 srl in5, 16, local4 831 xor out5, local1, out5 832 833 834 xor local4, out5, local4 835 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 836 837 838 and local4, local2, local4 839 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 840 841 sll local4, 16, local1 842 xor out5, local4, out5 843 844 srl out5, 2, local4 845 xor in5, local1, in5 846 847 sethi %hi(16711680), local5 848 xor local4, in5, local4 849 850 and local4, local3, local4 851 or local5, 255, local5 852 853 sll local4, 2, local2 854 xor in5, local4, in5 855 856 srl in5, 8, local4 857 xor out5, local2, out5 858 859 xor local4, out5, local4 860 add global1, 768, global4 861 862 and local4, local5, local4 863 add global1, 1024, global5 864 865 ld [out2+272], local7 866 sll local4, 8, local1 867 xor out5, local4, out5 868 869 srl out5, 1, local4 870 xor in5, local1, in5 871 872 ld [in3], out0 ! key 7531 873 xor local4, in5, local4 874 add global1, 256, global2 875 876 ld [in3+4], out1 ! key 8642 877 and local4, local7, local4 878 add global1, 512, global3 879 880 sll local4, 1, local1 881 xor in5, local4, in5 882 883 sll in5, 3, local3 884 xor out5, local1, out5 885 886 sll out5, 3, local2 887 add global1, 1280, local6 ! address sbox 8 888 889 srl in5, 29, local4 890 add global1, 1792, out3 ! address sbox 8 891 892 srl out5, 29, local1 893 or local4, local3, out5 894 895 or local2, local1, in5 896 897 898 899 900 901 902 903 904! rounds_macro 905! in5 out5 1 .des_encrypt1.1 in3 in4 906 907 xor out5, out0, local1 908 909 ld [out2+284], local5 ! 0x0000FC00 910 ba .des_encrypt1.1 911 and local1, 252, local1 912 913 .align 32 914 915.des_encrypt1.1: 916 ! local6 is address sbox 6 917 ! out3 is address sbox 8 918 ! out4 is loop counter 919 920 ld [global1+local1], local1 921 xor out5, out1, out1 ! 8642 922 xor out5, out0, out0 ! 7531 923 ! fmovs %f0, %f0 ! fxor used for alignment 924 925 srl out1, 4, local0 ! rotate 4 right 926 and out0, local5, local3 ! 3 927 ! fmovs %f0, %f0 928 929 ld [in3+1*8], local7 ! key 7531 next round 930 srl local3, 8, local3 ! 3 931 and local0, 252, local2 ! 2 932 ! fmovs %f0, %f0 933 934 ld [global3+local3],local3 ! 3 935 sll out1, 28, out1 ! rotate 936 xor in5, local1, in5 ! 1 finished, local1 now sbox 7 937 938 ld [global2+local2], local2 ! 2 939 srl out0, 24, local1 ! 7 940 or out1, local0, out1 ! rotate 941 942 ldub [out2+local1], local1 ! 7 (and 0xFC) 943 srl out1, 24, local0 ! 8 944 and out1, local5, local4 ! 4 945 946 ldub [out2+local0], local0 ! 8 (and 0xFC) 947 srl local4, 8, local4 ! 4 948 xor in5, local2, in5 ! 2 finished local2 now sbox 6 949 950 ld [global4+local4],local4 ! 4 951 srl out1, 16, local2 ! 6 952 xor in5, local3, in5 ! 3 finished local3 now sbox 5 953 954 ld [out3+local0],local0 ! 8 955 and local2, 252, local2 ! 6 956 add global1, 1536, local5 ! address sbox 7 957 958 ld [local6+local2], local2 ! 6 959 srl out0, 16, local3 ! 5 960 xor in5, local4, in5 ! 4 finished 961 962 ld [local5+local1],local1 ! 7 963 and local3, 252, local3 ! 5 964 xor in5, local0, in5 ! 8 finished 965 966 ld [global5+local3],local3 ! 5 967 xor in5, local2, in5 ! 6 finished 968 subcc out4, 1, out4 969 970 ld [in3+1*8+4], out0 ! key 8642 next round 971 xor in5, local7, local2 ! sbox 5 next round 972 xor in5, local1, in5 ! 7 finished 973 974 srl local2, 16, local2 ! sbox 5 next round 975 xor in5, local3, in5 ! 5 finished 976 977 ld [in3+1*16+4], out1 ! key 8642 next round again 978 and local2, 252, local2 ! sbox5 next round 979! next round 980 xor in5, local7, local7 ! 7531 981 982 ld [global5+local2], local2 ! 5 983 srl local7, 24, local3 ! 7 984 xor in5, out0, out0 ! 8642 985 986 ldub [out2+local3], local3 ! 7 (and 0xFC) 987 srl out0, 4, local0 ! rotate 4 right 988 and local7, 252, local1 ! 1 989 990 sll out0, 28, out0 ! rotate 991 xor out5, local2, out5 ! 5 finished local2 used 992 993 srl local0, 8, local4 ! 4 994 and local0, 252, local2 ! 2 995 ld [local5+local3], local3 ! 7 996 997 srl local0, 16, local5 ! 6 998 or out0, local0, out0 ! rotate 999 ld [global2+local2], local2 ! 2 1000 1001 srl out0, 24, local0 1002 ld [in3+1*16], out0 ! key 7531 next round 1003 and local4, 252, local4 ! 4 1004 1005 and local5, 252, local5 ! 6 1006 ld [global4+local4], local4 ! 4 1007 xor out5, local3, out5 ! 7 finished local3 used 1008 1009 and local0, 252, local0 ! 8 1010 ld [local6+local5], local5 ! 6 1011 xor out5, local2, out5 ! 2 finished local2 now sbox 3 1012 1013 srl local7, 8, local2 ! 3 start 1014 ld [out3+local0], local0 ! 8 1015 xor out5, local4, out5 ! 4 finished 1016 1017 and local2, 252, local2 ! 3 1018 ld [global1+local1], local1 ! 1 1019 xor out5, local5, out5 ! 6 finished local5 used 1020 1021 ld [global3+local2], local2 ! 3 1022 xor out5, local0, out5 ! 8 finished 1023 add in3, 1*16, in3 ! enc add 8, dec add -8 to key pointer 1024 1025 ld [out2+284], local5 ! 0x0000FC00 1026 xor out5, out0, local4 ! sbox 1 next round 1027 xor out5, local1, out5 ! 1 finished 1028 1029 xor out5, local2, out5 ! 3 finished 1030 bne .des_encrypt1.1 1031 and local4, 252, local1 ! sbox 1 next round 1032 1033! two rounds more: 1034 1035 ld [global1+local1], local1 1036 xor out5, out1, out1 1037 xor out5, out0, out0 1038 1039 srl out1, 4, local0 ! rotate 1040 and out0, local5, local3 1041 1042 ld [in3+1*8], local7 ! key 7531 1043 srl local3, 8, local3 1044 and local0, 252, local2 1045 1046 ld [global3+local3],local3 1047 sll out1, 28, out1 ! rotate 1048 xor in5, local1, in5 ! 1 finished, local1 now sbox 7 1049 1050 ld [global2+local2], local2 1051 srl out0, 24, local1 1052 or out1, local0, out1 ! rotate 1053 1054 ldub [out2+local1], local1 1055 srl out1, 24, local0 1056 and out1, local5, local4 1057 1058 ldub [out2+local0], local0 1059 srl local4, 8, local4 1060 xor in5, local2, in5 ! 2 finished local2 now sbox 6 1061 1062 ld [global4+local4],local4 1063 srl out1, 16, local2 1064 xor in5, local3, in5 ! 3 finished local3 now sbox 5 1065 1066 ld [out3+local0],local0 1067 and local2, 252, local2 1068 add global1, 1536, local5 ! address sbox 7 1069 1070 ld [local6+local2], local2 1071 srl out0, 16, local3 1072 xor in5, local4, in5 ! 4 finished 1073 1074 ld [local5+local1],local1 1075 and local3, 252, local3 1076 xor in5, local0, in5 1077 1078 ld [global5+local3],local3 1079 xor in5, local2, in5 ! 6 finished 1080 cmp in2, 8 1081 1082 ld [out2+280], out4 ! loop counter 1083 xor in5, local7, local2 ! sbox 5 next round 1084 xor in5, local1, in5 ! 7 finished 1085 1086 ld [in3+1*8+4], out0 1087 srl local2, 16, local2 ! sbox 5 next round 1088 xor in5, local3, in5 ! 5 finished 1089 1090 and local2, 252, local2 1091! next round (two rounds more) 1092 xor in5, local7, local7 ! 7531 1093 1094 ld [global5+local2], local2 1095 srl local7, 24, local3 1096 xor in5, out0, out0 ! 8642 1097 1098 ldub [out2+local3], local3 1099 srl out0, 4, local0 ! rotate 1100 and local7, 252, local1 1101 1102 sll out0, 28, out0 ! rotate 1103 xor out5, local2, out5 ! 5 finished local2 used 1104 1105 srl local0, 8, local4 1106 and local0, 252, local2 1107 ld [local5+local3], local3 1108 1109 srl local0, 16, local5 1110 or out0, local0, out0 ! rotate 1111 ld [global2+local2], local2 1112 1113 srl out0, 24, local0 1114 ld [in4], out0 ! key next encryption/decryption 1115 and local4, 252, local4 1116 1117 and local5, 252, local5 1118 ld [global4+local4], local4 1119 xor out5, local3, out5 ! 7 finished local3 used 1120 1121 and local0, 252, local0 1122 ld [local6+local5], local5 1123 xor out5, local2, out5 ! 2 finished local2 now sbox 3 1124 1125 srl local7, 8, local2 ! 3 start 1126 ld [out3+local0], local0 1127 xor out5, local4, out5 1128 1129 and local2, 252, local2 1130 ld [global1+local1], local1 1131 xor out5, local5, out5 ! 6 finished local5 used 1132 1133 ld [global3+local2], local2 1134 srl in5, 3, local3 1135 xor out5, local0, out5 1136 1137 ld [in4+4], out1 ! key next encryption/decryption 1138 sll in5, 29, local4 1139 xor out5, local1, out5 1140 1141 1142 xor out5, local2, out5 1143 ! in4 not used 1144 1145 1146 1147! fp_macro 1148! in5 out5 1 1149 1150 ! initially undo the rotate 3 left done after initial permutation 1151 ! original left is received shifted 3 right and 29 left in local3/4 1152 1153 sll out5, 29, local1 1154 or local3, local4, in5 1155 1156 srl out5, 3, out5 1157 sethi %hi(0x55555555), local2 1158 1159 or out5, local1, out5 1160 or local2, %lo(0x55555555), local2 1161 1162 srl out5, 1, local3 1163 sethi %hi(0x00ff00ff), local1 1164 xor local3, in5, local3 1165 or local1, %lo(0x00ff00ff), local1 1166 and local3, local2, local3 1167 sethi %hi(0x33333333), local4 1168 sll local3, 1, local2 1169 1170 xor in5, local3, in5 1171 1172 srl in5, 8, local3 1173 xor out5, local2, out5 1174 xor local3, out5, local3 1175 or local4, %lo(0x33333333), local4 1176 and local3, local1, local3 1177 sethi %hi(0x0000ffff), local1 1178 sll local3, 8, local2 1179 1180 xor out5, local3, out5 1181 1182 srl out5, 2, local3 1183 xor in5, local2, in5 1184 xor local3, in5, local3 1185 or local1, %lo(0x0000ffff), local1 1186 and local3, local4, local3 1187 sethi %hi(0x0f0f0f0f), local4 1188 sll local3, 2, local2 1189 1190 1191 xor in5, local3, in5 1192 1193 1194 srl in5, 16, local3 1195 xor out5, local2, out5 1196 xor local3, out5, local3 1197 or local4, %lo(0x0f0f0f0f), local4 1198 and local3, local1, local3 1199 sll local3, 16, local2 1200 1201 xor out5, local3, local1 1202 1203 srl local1, 4, local3 1204 xor in5, local2, in5 1205 xor local3, in5, local3 1206 and local3, local4, local3 1207 sll local3, 4, local2 1208 1209 xor in5, local3, in5 1210 1211 ! optional store: 1212 1213 st in5, [in0] 1214 1215 xor local1, local2, out5 1216 1217 st out5, [in0+4] 1218 1219 ! 1 for store to [in0] 1220 1221 ret 1222 restore 1223 1224.encrypt.dec: 1225 1226 add in1, 120, in3 ! use last subkey for first round 1227 1228 ! parameter 6 1/2 for include encryption/decryption 1229 ! parameter 7 1 for move in1 to in3 1230 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 1231 1232 1233 1234! ip_macro 1235! in5 out5 in5 out5 in4 2 0 1 1236 1237 ld [out2+256], local1 1238 srl out5, 4, local4 1239 1240 xor local4, in5, local4 1241 nop 1242 1243 ld [out2+260], local2 1244 and local4, local1, local4 1245 mov in3, in4 1246 1247 1248 ld [out2+280], out4 ! loop counter 1249 sll local4, 4, local1 1250 xor in5, local4, in5 1251 1252 ld [out2+264], local3 1253 srl in5, 16, local4 1254 xor out5, local1, out5 1255 1256 1257 xor local4, out5, local4 1258 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 1259 1260 1261 and local4, local2, local4 1262 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 1263 1264 sll local4, 16, local1 1265 xor out5, local4, out5 1266 1267 srl out5, 2, local4 1268 xor in5, local1, in5 1269 1270 sethi %hi(16711680), local5 1271 xor local4, in5, local4 1272 1273 and local4, local3, local4 1274 or local5, 255, local5 1275 1276 sll local4, 2, local2 1277 xor in5, local4, in5 1278 1279 srl in5, 8, local4 1280 xor out5, local2, out5 1281 1282 xor local4, out5, local4 1283 add global1, 768, global4 1284 1285 and local4, local5, local4 1286 add global1, 1024, global5 1287 1288 ld [out2+272], local7 1289 sll local4, 8, local1 1290 xor out5, local4, out5 1291 1292 srl out5, 1, local4 1293 xor in5, local1, in5 1294 1295 ld [in4], out0 ! key 7531 1296 xor local4, in5, local4 1297 add global1, 256, global2 1298 1299 ld [in4+4], out1 ! key 8642 1300 and local4, local7, local4 1301 add global1, 512, global3 1302 1303 sll local4, 1, local1 1304 xor in5, local4, in5 1305 1306 sll in5, 3, local3 1307 xor out5, local1, out5 1308 1309 sll out5, 3, local2 1310 add global1, 1280, local6 ! address sbox 8 1311 1312 srl in5, 29, local4 1313 add global1, 1792, out3 ! address sbox 8 1314 1315 srl out5, 29, local1 1316 or local4, local3, in5 1317 1318 or local2, local1, out5 1319 1320 1321 1322 1323 1324 ld [out2+284], local5 ! 0x0000FC00 used in the rounds 1325 or local2, local1, out5 1326 xor in5, out0, local1 1327 1328 call .des_dec.1 1329 and local1, 252, local1 1330 1331 1332 ! include dec, ks in4 1333 1334 1335 1336! fp_macro 1337! out5 in5 1 1338 1339 ! initially undo the rotate 3 left done after initial permutation 1340 ! original left is received shifted 3 right and 29 left in local3/4 1341 1342 sll in5, 29, local1 1343 or local3, local4, out5 1344 1345 srl in5, 3, in5 1346 sethi %hi(0x55555555), local2 1347 1348 or in5, local1, in5 1349 or local2, %lo(0x55555555), local2 1350 1351 srl in5, 1, local3 1352 sethi %hi(0x00ff00ff), local1 1353 xor local3, out5, local3 1354 or local1, %lo(0x00ff00ff), local1 1355 and local3, local2, local3 1356 sethi %hi(0x33333333), local4 1357 sll local3, 1, local2 1358 1359 xor out5, local3, out5 1360 1361 srl out5, 8, local3 1362 xor in5, local2, in5 1363 xor local3, in5, local3 1364 or local4, %lo(0x33333333), local4 1365 and local3, local1, local3 1366 sethi %hi(0x0000ffff), local1 1367 sll local3, 8, local2 1368 1369 xor in5, local3, in5 1370 1371 srl in5, 2, local3 1372 xor out5, local2, out5 1373 xor local3, out5, local3 1374 or local1, %lo(0x0000ffff), local1 1375 and local3, local4, local3 1376 sethi %hi(0x0f0f0f0f), local4 1377 sll local3, 2, local2 1378 1379 1380 xor out5, local3, out5 1381 1382 1383 srl out5, 16, local3 1384 xor in5, local2, in5 1385 xor local3, in5, local3 1386 or local4, %lo(0x0f0f0f0f), local4 1387 and local3, local1, local3 1388 sll local3, 16, local2 1389 1390 xor in5, local3, local1 1391 1392 srl local1, 4, local3 1393 xor out5, local2, out5 1394 xor local3, out5, local3 1395 and local3, local4, local3 1396 sll local3, 4, local2 1397 1398 xor out5, local3, out5 1399 1400 ! optional store: 1401 1402 st out5, [in0] 1403 1404 xor local1, local2, in5 1405 1406 st in5, [in0+4] 1407 1408 ! 1 for store to [in0] 1409 1410 ret 1411 restore 1412 1413.DES_encrypt1.end: 1414 .size DES_encrypt1,.DES_encrypt1.end-DES_encrypt1 1415 1416 1417! void DES_encrypt2(data, ks, enc) 1418!********************************* 1419 1420 ! encrypts/decrypts without initial/final permutation 1421 1422 .align 32 1423 .global DES_encrypt2 1424 .type DES_encrypt2,#function 1425 1426DES_encrypt2: 1427 1428 save %sp, FRAME, %sp 1429 1430 sethi %hi(_PIC_DES_SPtrans-1f),global1 1431 or global1,%lo(_PIC_DES_SPtrans-1f),global1 14321: call .+8 1433 add %o7,global1,global1 1434 sub global1,_PIC_DES_SPtrans-.des_and,out2 1435 1436 ! Set sbox address 1 to 6 and rotate halves 3 left 1437 ! Errors caught by destest? Yes. Still? *NO* 1438 1439 !sethi %hi(DES_SPtrans), global1 ! address sbox 1 1440 1441 !or global1, %lo(DES_SPtrans), global1 ! sbox 1 1442 1443 add global1, 256, global2 ! sbox 2 1444 add global1, 512, global3 ! sbox 3 1445 1446 ld [in0], out5 ! right 1447 add global1, 768, global4 ! sbox 4 1448 add global1, 1024, global5 ! sbox 5 1449 1450 ld [in0+4], in5 ! left 1451 add global1, 1280, local6 ! sbox 6 1452 add global1, 1792, out3 ! sbox 8 1453 1454 ! rotate 1455 1456 sll in5, 3, local5 1457 mov in1, in3 ! key address to in3 1458 1459 sll out5, 3, local7 1460 srl in5, 29, in5 1461 1462 srl out5, 29, out5 1463 add in5, local5, in5 1464 1465 add out5, local7, out5 1466 cmp in2, 0 1467 1468 ! we use our own stackframe 1469 1470 be .encrypt2.dec 1471 STPTR in0, [%sp+BIAS+ARG0+0*ARGSZ] 1472 1473 ld [in3], out0 ! key 7531 first round 1474 mov LOOPS, out4 ! loop counter 1475 1476 ld [in3+4], out1 ! key 8642 first round 1477 sethi %hi(0x0000FC00), local5 1478 1479 call .des_enc 1480 mov in3, in4 1481 1482 ! rotate 1483 sll in5, 29, in0 1484 srl in5, 3, in5 1485 sll out5, 29, in1 1486 add in5, in0, in5 1487 srl out5, 3, out5 1488 LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0 1489 add out5, in1, out5 1490 st in5, [in0] 1491 st out5, [in0+4] 1492 1493 ret 1494 restore 1495 1496 1497.encrypt2.dec: 1498 1499 add in3, 120, in4 1500 1501 ld [in4], out0 ! key 7531 first round 1502 mov LOOPS, out4 ! loop counter 1503 1504 ld [in4+4], out1 ! key 8642 first round 1505 sethi %hi(0x0000FC00), local5 1506 1507 mov in5, local1 ! left expected in out5 1508 mov out5, in5 1509 1510 call .des_dec 1511 mov local1, out5 1512 1513.encrypt2.finish: 1514 1515 ! rotate 1516 sll in5, 29, in0 1517 srl in5, 3, in5 1518 sll out5, 29, in1 1519 add in5, in0, in5 1520 srl out5, 3, out5 1521 LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0 1522 add out5, in1, out5 1523 st out5, [in0] 1524 st in5, [in0+4] 1525 1526 ret 1527 restore 1528 1529.DES_encrypt2.end: 1530 .size DES_encrypt2, .DES_encrypt2.end-DES_encrypt2 1531 1532 1533! void DES_encrypt3(data, ks1, ks2, ks3) 1534! ************************************** 1535 1536 .align 32 1537 .global DES_encrypt3 1538 .type DES_encrypt3,#function 1539 1540DES_encrypt3: 1541 1542 save %sp, FRAME, %sp 1543 1544 sethi %hi(_PIC_DES_SPtrans-1f),global1 1545 or global1,%lo(_PIC_DES_SPtrans-1f),global1 15461: call .+8 1547 add %o7,global1,global1 1548 sub global1,_PIC_DES_SPtrans-.des_and,out2 1549 1550 ld [in0], in5 ! left 1551 add in2, 120, in4 ! ks2 1552 1553 ld [in0+4], out5 ! right 1554 mov in3, in2 ! save ks3 1555 1556 ! parameter 6 1/2 for include encryption/decryption 1557 ! parameter 7 1 for mov in1 to in3 1558 ! parameter 8 1 for mov in3 to in4 1559 ! parameter 9 1 for load ks3 and ks2 to in4 and in3 1560 1561 1562 1563! ip_macro 1564! in5 out5 out5 in5 in3 1 1 0 0 1565 1566 ld [out2+256], local1 1567 srl out5, 4, local4 1568 1569 xor local4, in5, local4 1570 mov in1, in3 1571 1572 ld [out2+260], local2 1573 and local4, local1, local4 1574 1575 1576 1577 ld [out2+280], out4 ! loop counter 1578 sll local4, 4, local1 1579 xor in5, local4, in5 1580 1581 ld [out2+264], local3 1582 srl in5, 16, local4 1583 xor out5, local1, out5 1584 1585 1586 xor local4, out5, local4 1587 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 1588 1589 1590 and local4, local2, local4 1591 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 1592 1593 sll local4, 16, local1 1594 xor out5, local4, out5 1595 1596 srl out5, 2, local4 1597 xor in5, local1, in5 1598 1599 sethi %hi(16711680), local5 1600 xor local4, in5, local4 1601 1602 and local4, local3, local4 1603 or local5, 255, local5 1604 1605 sll local4, 2, local2 1606 xor in5, local4, in5 1607 1608 srl in5, 8, local4 1609 xor out5, local2, out5 1610 1611 xor local4, out5, local4 1612 add global1, 768, global4 1613 1614 and local4, local5, local4 1615 add global1, 1024, global5 1616 1617 ld [out2+272], local7 1618 sll local4, 8, local1 1619 xor out5, local4, out5 1620 1621 srl out5, 1, local4 1622 xor in5, local1, in5 1623 1624 ld [in3], out0 ! key 7531 1625 xor local4, in5, local4 1626 add global1, 256, global2 1627 1628 ld [in3+4], out1 ! key 8642 1629 and local4, local7, local4 1630 add global1, 512, global3 1631 1632 sll local4, 1, local1 1633 xor in5, local4, in5 1634 1635 sll in5, 3, local3 1636 xor out5, local1, out5 1637 1638 sll out5, 3, local2 1639 add global1, 1280, local6 ! address sbox 8 1640 1641 srl in5, 29, local4 1642 add global1, 1792, out3 ! address sbox 8 1643 1644 srl out5, 29, local1 1645 or local4, local3, out5 1646 1647 or local2, local1, in5 1648 1649 1650 1651 ld [out2+284], local5 ! 0x0000FC00 used in the rounds 1652 or local2, local1, in5 1653 xor out5, out0, local1 1654 1655 call .des_enc.1 1656 and local1, 252, local1 1657 1658 1659 1660 1661 1662 1663 call .des_dec 1664 mov in2, in3 ! preload ks3 1665 1666 call .des_enc 1667 nop 1668 1669 1670 1671! fp_macro 1672! in5 out5 1 1673 1674 ! initially undo the rotate 3 left done after initial permutation 1675 ! original left is received shifted 3 right and 29 left in local3/4 1676 1677 sll out5, 29, local1 1678 or local3, local4, in5 1679 1680 srl out5, 3, out5 1681 sethi %hi(0x55555555), local2 1682 1683 or out5, local1, out5 1684 or local2, %lo(0x55555555), local2 1685 1686 srl out5, 1, local3 1687 sethi %hi(0x00ff00ff), local1 1688 xor local3, in5, local3 1689 or local1, %lo(0x00ff00ff), local1 1690 and local3, local2, local3 1691 sethi %hi(0x33333333), local4 1692 sll local3, 1, local2 1693 1694 xor in5, local3, in5 1695 1696 srl in5, 8, local3 1697 xor out5, local2, out5 1698 xor local3, out5, local3 1699 or local4, %lo(0x33333333), local4 1700 and local3, local1, local3 1701 sethi %hi(0x0000ffff), local1 1702 sll local3, 8, local2 1703 1704 xor out5, local3, out5 1705 1706 srl out5, 2, local3 1707 xor in5, local2, in5 1708 xor local3, in5, local3 1709 or local1, %lo(0x0000ffff), local1 1710 and local3, local4, local3 1711 sethi %hi(0x0f0f0f0f), local4 1712 sll local3, 2, local2 1713 1714 1715 xor in5, local3, in5 1716 1717 1718 srl in5, 16, local3 1719 xor out5, local2, out5 1720 xor local3, out5, local3 1721 or local4, %lo(0x0f0f0f0f), local4 1722 and local3, local1, local3 1723 sll local3, 16, local2 1724 1725 xor out5, local3, local1 1726 1727 srl local1, 4, local3 1728 xor in5, local2, in5 1729 xor local3, in5, local3 1730 and local3, local4, local3 1731 sll local3, 4, local2 1732 1733 xor in5, local3, in5 1734 1735 ! optional store: 1736 1737 st in5, [in0] 1738 1739 xor local1, local2, out5 1740 1741 st out5, [in0+4] 1742 1743 1744 1745 ret 1746 restore 1747 1748.DES_encrypt3.end: 1749 .size DES_encrypt3,.DES_encrypt3.end-DES_encrypt3 1750 1751 1752! void DES_decrypt3(data, ks1, ks2, ks3) 1753! ************************************** 1754 1755 .align 32 1756 .global DES_decrypt3 1757 .type DES_decrypt3,#function 1758 1759DES_decrypt3: 1760 1761 save %sp, FRAME, %sp 1762 1763 sethi %hi(_PIC_DES_SPtrans-1f),global1 1764 or global1,%lo(_PIC_DES_SPtrans-1f),global1 17651: call .+8 1766 add %o7,global1,global1 1767 sub global1,_PIC_DES_SPtrans-.des_and,out2 1768 1769 ld [in0], in5 ! left 1770 add in3, 120, in4 ! ks3 1771 1772 ld [in0+4], out5 ! right 1773 mov in2, in3 ! ks2 1774 1775 ! parameter 6 1/2 for include encryption/decryption 1776 ! parameter 7 1 for mov in1 to in3 1777 ! parameter 8 1 for mov in3 to in4 1778 ! parameter 9 1 for load ks3 and ks2 to in4 and in3 1779 1780 1781 1782! ip_macro 1783! in5 out5 in5 out5 in4 2 0 0 0 1784 1785 ld [out2+256], local1 1786 srl out5, 4, local4 1787 1788 xor local4, in5, local4 1789 nop 1790 1791 ld [out2+260], local2 1792 and local4, local1, local4 1793 1794 1795 1796 ld [out2+280], out4 ! loop counter 1797 sll local4, 4, local1 1798 xor in5, local4, in5 1799 1800 ld [out2+264], local3 1801 srl in5, 16, local4 1802 xor out5, local1, out5 1803 1804 1805 xor local4, out5, local4 1806 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 1807 1808 1809 and local4, local2, local4 1810 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 1811 1812 sll local4, 16, local1 1813 xor out5, local4, out5 1814 1815 srl out5, 2, local4 1816 xor in5, local1, in5 1817 1818 sethi %hi(16711680), local5 1819 xor local4, in5, local4 1820 1821 and local4, local3, local4 1822 or local5, 255, local5 1823 1824 sll local4, 2, local2 1825 xor in5, local4, in5 1826 1827 srl in5, 8, local4 1828 xor out5, local2, out5 1829 1830 xor local4, out5, local4 1831 add global1, 768, global4 1832 1833 and local4, local5, local4 1834 add global1, 1024, global5 1835 1836 ld [out2+272], local7 1837 sll local4, 8, local1 1838 xor out5, local4, out5 1839 1840 srl out5, 1, local4 1841 xor in5, local1, in5 1842 1843 ld [in4], out0 ! key 7531 1844 xor local4, in5, local4 1845 add global1, 256, global2 1846 1847 ld [in4+4], out1 ! key 8642 1848 and local4, local7, local4 1849 add global1, 512, global3 1850 1851 sll local4, 1, local1 1852 xor in5, local4, in5 1853 1854 sll in5, 3, local3 1855 xor out5, local1, out5 1856 1857 sll out5, 3, local2 1858 add global1, 1280, local6 ! address sbox 8 1859 1860 srl in5, 29, local4 1861 add global1, 1792, out3 ! address sbox 8 1862 1863 srl out5, 29, local1 1864 or local4, local3, in5 1865 1866 or local2, local1, out5 1867 1868 1869 1870 1871 1872 ld [out2+284], local5 ! 0x0000FC00 used in the rounds 1873 or local2, local1, out5 1874 xor in5, out0, local1 1875 1876 call .des_dec.1 1877 and local1, 252, local1 1878 1879 1880 1881 1882 call .des_enc 1883 add in1, 120, in4 ! preload ks1 1884 1885 call .des_dec 1886 nop 1887 1888 1889 1890! fp_macro 1891! out5 in5 1 1892 1893 ! initially undo the rotate 3 left done after initial permutation 1894 ! original left is received shifted 3 right and 29 left in local3/4 1895 1896 sll in5, 29, local1 1897 or local3, local4, out5 1898 1899 srl in5, 3, in5 1900 sethi %hi(0x55555555), local2 1901 1902 or in5, local1, in5 1903 or local2, %lo(0x55555555), local2 1904 1905 srl in5, 1, local3 1906 sethi %hi(0x00ff00ff), local1 1907 xor local3, out5, local3 1908 or local1, %lo(0x00ff00ff), local1 1909 and local3, local2, local3 1910 sethi %hi(0x33333333), local4 1911 sll local3, 1, local2 1912 1913 xor out5, local3, out5 1914 1915 srl out5, 8, local3 1916 xor in5, local2, in5 1917 xor local3, in5, local3 1918 or local4, %lo(0x33333333), local4 1919 and local3, local1, local3 1920 sethi %hi(0x0000ffff), local1 1921 sll local3, 8, local2 1922 1923 xor in5, local3, in5 1924 1925 srl in5, 2, local3 1926 xor out5, local2, out5 1927 xor local3, out5, local3 1928 or local1, %lo(0x0000ffff), local1 1929 and local3, local4, local3 1930 sethi %hi(0x0f0f0f0f), local4 1931 sll local3, 2, local2 1932 1933 1934 xor out5, local3, out5 1935 1936 1937 srl out5, 16, local3 1938 xor in5, local2, in5 1939 xor local3, in5, local3 1940 or local4, %lo(0x0f0f0f0f), local4 1941 and local3, local1, local3 1942 sll local3, 16, local2 1943 1944 xor in5, local3, local1 1945 1946 srl local1, 4, local3 1947 xor out5, local2, out5 1948 xor local3, out5, local3 1949 and local3, local4, local3 1950 sll local3, 4, local2 1951 1952 xor out5, local3, out5 1953 1954 ! optional store: 1955 1956 st out5, [in0] 1957 1958 xor local1, local2, in5 1959 1960 st in5, [in0+4] 1961 1962 1963 1964 ret 1965 restore 1966 1967.DES_decrypt3.end: 1968 .size DES_decrypt3,.DES_decrypt3.end-DES_decrypt3 1969 1970! void DES_ncbc_encrypt(input, output, length, schedule, ivec, enc) 1971! ***************************************************************** 1972 1973 1974 .align 32 1975 .global DES_ncbc_encrypt 1976 .type DES_ncbc_encrypt,#function 1977 1978DES_ncbc_encrypt: 1979 1980 save %sp, FRAME, %sp 1981 1982 1983 1984 1985 1986 sethi %hi(_PIC_DES_SPtrans-1f),global1 1987 or global1,%lo(_PIC_DES_SPtrans-1f),global1 19881: call .+8 1989 add %o7,global1,global1 1990 sub global1,_PIC_DES_SPtrans-.des_and,out2 1991 1992 cmp in5, 0 ! enc 1993 1994 be .ncbc.dec 1995 STPTR in4, [%sp+BIAS+ARG0+4*ARGSZ] 1996 1997 ! addr left right temp label 1998 1999 2000! load_little_endian 2001! in4 in5 out5 local3 .LLE1 2002 2003 ! first in memory to rightmost in register 2004 2005.LLE1: 2006 ldub [in4+3], in5 2007 2008 ldub [in4+2], local3 2009 sll in5, 8, in5 2010 or in5, local3, in5 2011 2012 ldub [in4+1], local3 2013 sll in5, 8, in5 2014 or in5, local3, in5 2015 2016 ldub [in4+0], local3 2017 sll in5, 8, in5 2018 or in5, local3, in5 2019 2020 2021 ldub [in4+3+4], out5 2022 2023 ldub [in4+2+4], local3 2024 sll out5, 8, out5 2025 or out5, local3, out5 2026 2027 ldub [in4+1+4], local3 2028 sll out5, 8, out5 2029 or out5, local3, out5 2030 2031 ldub [in4+0+4], local3 2032 sll out5, 8, out5 2033 or out5, local3, out5 2034.LLE1a: 2035 2036 ! iv 2037 2038 addcc in2, -8, in2 ! bytes missing when first block done 2039 2040 bl .ncbc.enc.seven.or.less 2041 mov in3, in4 ! schedule 2042 2043.ncbc.enc.next.block: 2044 2045 2046 2047! load_little_endian 2048! in0 out4 global4 local3 .LLE2 2049 2050 ! first in memory to rightmost in register 2051 2052.LLE2: 2053 ldub [in0+3], out4 2054 2055 ldub [in0+2], local3 2056 sll out4, 8, out4 2057 or out4, local3, out4 2058 2059 ldub [in0+1], local3 2060 sll out4, 8, out4 2061 or out4, local3, out4 2062 2063 ldub [in0+0], local3 2064 sll out4, 8, out4 2065 or out4, local3, out4 2066 2067 2068 ldub [in0+3+4], global4 2069 2070 ldub [in0+2+4], local3 2071 sll global4, 8, global4 2072 or global4, local3, global4 2073 2074 ldub [in0+1+4], local3 2075 sll global4, 8, global4 2076 or global4, local3, global4 2077 2078 ldub [in0+0+4], local3 2079 sll global4, 8, global4 2080 or global4, local3, global4 2081.LLE2a: 2082 2083 ! block 2084 2085.ncbc.enc.next.block_1: 2086 2087 xor in5, out4, in5 ! iv xor 2088 xor out5, global4, out5 ! iv xor 2089 2090 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 2091 2092 2093! ip_macro 2094! in5 out5 out5 in5 in3 0 0 2 2095 2096 ld [out2+256], local1 2097 srl out5, 4, local4 2098 2099 xor local4, in5, local4 2100 nop 2101 2102 ld [out2+260], local2 2103 and local4, local1, local4 2104 2105 mov in4, in3 2106 2107 ld [out2+280], out4 ! loop counter 2108 sll local4, 4, local1 2109 xor in5, local4, in5 2110 2111 ld [out2+264], local3 2112 srl in5, 16, local4 2113 xor out5, local1, out5 2114 2115 2116 xor local4, out5, local4 2117 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 2118 2119 2120 and local4, local2, local4 2121 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 2122 2123 sll local4, 16, local1 2124 xor out5, local4, out5 2125 2126 srl out5, 2, local4 2127 xor in5, local1, in5 2128 2129 sethi %hi(16711680), local5 2130 xor local4, in5, local4 2131 2132 and local4, local3, local4 2133 or local5, 255, local5 2134 2135 sll local4, 2, local2 2136 xor in5, local4, in5 2137 2138 srl in5, 8, local4 2139 xor out5, local2, out5 2140 2141 xor local4, out5, local4 2142 add global1, 768, global4 2143 2144 and local4, local5, local4 2145 add global1, 1024, global5 2146 2147 ld [out2+272], local7 2148 sll local4, 8, local1 2149 xor out5, local4, out5 2150 2151 srl out5, 1, local4 2152 xor in5, local1, in5 2153 2154 ld [in3], out0 ! key 7531 2155 xor local4, in5, local4 2156 add global1, 256, global2 2157 2158 ld [in3+4], out1 ! key 8642 2159 and local4, local7, local4 2160 add global1, 512, global3 2161 2162 sll local4, 1, local1 2163 xor in5, local4, in5 2164 2165 sll in5, 3, local3 2166 xor out5, local1, out5 2167 2168 sll out5, 3, local2 2169 add global1, 1280, local6 ! address sbox 8 2170 2171 srl in5, 29, local4 2172 add global1, 1792, out3 ! address sbox 8 2173 2174 srl out5, 29, local1 2175 or local4, local3, out5 2176 2177 or local2, local1, in5 2178 2179 2180 2181 2182 2183 2184.ncbc.enc.next.block_2: 2185 2186!// call .des_enc ! compares in2 to 8 2187! rounds inlined for alignment purposes 2188 2189 add global1, 768, global4 ! address sbox 4 since register used below 2190 2191 2192 2193! rounds_macro 2194! in5 out5 1 .ncbc.enc.1 in3 in4 2195 2196 xor out5, out0, local1 2197 2198 ld [out2+284], local5 ! 0x0000FC00 2199 ba .ncbc.enc.1 2200 and local1, 252, local1 2201 2202 .align 32 2203 2204.ncbc.enc.1: 2205 ! local6 is address sbox 6 2206 ! out3 is address sbox 8 2207 ! out4 is loop counter 2208 2209 ld [global1+local1], local1 2210 xor out5, out1, out1 ! 8642 2211 xor out5, out0, out0 ! 7531 2212 ! fmovs %f0, %f0 ! fxor used for alignment 2213 2214 srl out1, 4, local0 ! rotate 4 right 2215 and out0, local5, local3 ! 3 2216 ! fmovs %f0, %f0 2217 2218 ld [in3+1*8], local7 ! key 7531 next round 2219 srl local3, 8, local3 ! 3 2220 and local0, 252, local2 ! 2 2221 ! fmovs %f0, %f0 2222 2223 ld [global3+local3],local3 ! 3 2224 sll out1, 28, out1 ! rotate 2225 xor in5, local1, in5 ! 1 finished, local1 now sbox 7 2226 2227 ld [global2+local2], local2 ! 2 2228 srl out0, 24, local1 ! 7 2229 or out1, local0, out1 ! rotate 2230 2231 ldub [out2+local1], local1 ! 7 (and 0xFC) 2232 srl out1, 24, local0 ! 8 2233 and out1, local5, local4 ! 4 2234 2235 ldub [out2+local0], local0 ! 8 (and 0xFC) 2236 srl local4, 8, local4 ! 4 2237 xor in5, local2, in5 ! 2 finished local2 now sbox 6 2238 2239 ld [global4+local4],local4 ! 4 2240 srl out1, 16, local2 ! 6 2241 xor in5, local3, in5 ! 3 finished local3 now sbox 5 2242 2243 ld [out3+local0],local0 ! 8 2244 and local2, 252, local2 ! 6 2245 add global1, 1536, local5 ! address sbox 7 2246 2247 ld [local6+local2], local2 ! 6 2248 srl out0, 16, local3 ! 5 2249 xor in5, local4, in5 ! 4 finished 2250 2251 ld [local5+local1],local1 ! 7 2252 and local3, 252, local3 ! 5 2253 xor in5, local0, in5 ! 8 finished 2254 2255 ld [global5+local3],local3 ! 5 2256 xor in5, local2, in5 ! 6 finished 2257 subcc out4, 1, out4 2258 2259 ld [in3+1*8+4], out0 ! key 8642 next round 2260 xor in5, local7, local2 ! sbox 5 next round 2261 xor in5, local1, in5 ! 7 finished 2262 2263 srl local2, 16, local2 ! sbox 5 next round 2264 xor in5, local3, in5 ! 5 finished 2265 2266 ld [in3+1*16+4], out1 ! key 8642 next round again 2267 and local2, 252, local2 ! sbox5 next round 2268! next round 2269 xor in5, local7, local7 ! 7531 2270 2271 ld [global5+local2], local2 ! 5 2272 srl local7, 24, local3 ! 7 2273 xor in5, out0, out0 ! 8642 2274 2275 ldub [out2+local3], local3 ! 7 (and 0xFC) 2276 srl out0, 4, local0 ! rotate 4 right 2277 and local7, 252, local1 ! 1 2278 2279 sll out0, 28, out0 ! rotate 2280 xor out5, local2, out5 ! 5 finished local2 used 2281 2282 srl local0, 8, local4 ! 4 2283 and local0, 252, local2 ! 2 2284 ld [local5+local3], local3 ! 7 2285 2286 srl local0, 16, local5 ! 6 2287 or out0, local0, out0 ! rotate 2288 ld [global2+local2], local2 ! 2 2289 2290 srl out0, 24, local0 2291 ld [in3+1*16], out0 ! key 7531 next round 2292 and local4, 252, local4 ! 4 2293 2294 and local5, 252, local5 ! 6 2295 ld [global4+local4], local4 ! 4 2296 xor out5, local3, out5 ! 7 finished local3 used 2297 2298 and local0, 252, local0 ! 8 2299 ld [local6+local5], local5 ! 6 2300 xor out5, local2, out5 ! 2 finished local2 now sbox 3 2301 2302 srl local7, 8, local2 ! 3 start 2303 ld [out3+local0], local0 ! 8 2304 xor out5, local4, out5 ! 4 finished 2305 2306 and local2, 252, local2 ! 3 2307 ld [global1+local1], local1 ! 1 2308 xor out5, local5, out5 ! 6 finished local5 used 2309 2310 ld [global3+local2], local2 ! 3 2311 xor out5, local0, out5 ! 8 finished 2312 add in3, 1*16, in3 ! enc add 8, dec add -8 to key pointer 2313 2314 ld [out2+284], local5 ! 0x0000FC00 2315 xor out5, out0, local4 ! sbox 1 next round 2316 xor out5, local1, out5 ! 1 finished 2317 2318 xor out5, local2, out5 ! 3 finished 2319 bne .ncbc.enc.1 2320 and local4, 252, local1 ! sbox 1 next round 2321 2322! two rounds more: 2323 2324 ld [global1+local1], local1 2325 xor out5, out1, out1 2326 xor out5, out0, out0 2327 2328 srl out1, 4, local0 ! rotate 2329 and out0, local5, local3 2330 2331 ld [in3+1*8], local7 ! key 7531 2332 srl local3, 8, local3 2333 and local0, 252, local2 2334 2335 ld [global3+local3],local3 2336 sll out1, 28, out1 ! rotate 2337 xor in5, local1, in5 ! 1 finished, local1 now sbox 7 2338 2339 ld [global2+local2], local2 2340 srl out0, 24, local1 2341 or out1, local0, out1 ! rotate 2342 2343 ldub [out2+local1], local1 2344 srl out1, 24, local0 2345 and out1, local5, local4 2346 2347 ldub [out2+local0], local0 2348 srl local4, 8, local4 2349 xor in5, local2, in5 ! 2 finished local2 now sbox 6 2350 2351 ld [global4+local4],local4 2352 srl out1, 16, local2 2353 xor in5, local3, in5 ! 3 finished local3 now sbox 5 2354 2355 ld [out3+local0],local0 2356 and local2, 252, local2 2357 add global1, 1536, local5 ! address sbox 7 2358 2359 ld [local6+local2], local2 2360 srl out0, 16, local3 2361 xor in5, local4, in5 ! 4 finished 2362 2363 ld [local5+local1],local1 2364 and local3, 252, local3 2365 xor in5, local0, in5 2366 2367 ld [global5+local3],local3 2368 xor in5, local2, in5 ! 6 finished 2369 cmp in2, 8 2370 2371 ld [out2+280], out4 ! loop counter 2372 xor in5, local7, local2 ! sbox 5 next round 2373 xor in5, local1, in5 ! 7 finished 2374 2375 ld [in3+1*8+4], out0 2376 srl local2, 16, local2 ! sbox 5 next round 2377 xor in5, local3, in5 ! 5 finished 2378 2379 and local2, 252, local2 2380! next round (two rounds more) 2381 xor in5, local7, local7 ! 7531 2382 2383 ld [global5+local2], local2 2384 srl local7, 24, local3 2385 xor in5, out0, out0 ! 8642 2386 2387 ldub [out2+local3], local3 2388 srl out0, 4, local0 ! rotate 2389 and local7, 252, local1 2390 2391 sll out0, 28, out0 ! rotate 2392 xor out5, local2, out5 ! 5 finished local2 used 2393 2394 srl local0, 8, local4 2395 and local0, 252, local2 2396 ld [local5+local3], local3 2397 2398 srl local0, 16, local5 2399 or out0, local0, out0 ! rotate 2400 ld [global2+local2], local2 2401 2402 srl out0, 24, local0 2403 ld [in4], out0 ! key next encryption/decryption 2404 and local4, 252, local4 2405 2406 and local5, 252, local5 2407 ld [global4+local4], local4 2408 xor out5, local3, out5 ! 7 finished local3 used 2409 2410 and local0, 252, local0 2411 ld [local6+local5], local5 2412 xor out5, local2, out5 ! 2 finished local2 now sbox 3 2413 2414 srl local7, 8, local2 ! 3 start 2415 ld [out3+local0], local0 2416 xor out5, local4, out5 2417 2418 and local2, 252, local2 2419 ld [global1+local1], local1 2420 xor out5, local5, out5 ! 6 finished local5 used 2421 2422 ld [global3+local2], local2 2423 srl in5, 3, local3 2424 xor out5, local0, out5 2425 2426 ld [in4+4], out1 ! key next encryption/decryption 2427 sll in5, 29, local4 2428 xor out5, local1, out5 2429 2430 2431 xor out5, local2, out5 2432 ! include encryption ks in3 2433 2434 bl .ncbc.enc.next.block_fp 2435 add in0, 8, in0 ! input address 2436 2437 ! If 8 or more bytes are to be encrypted after this block, 2438 ! we combine final permutation for this block with initial 2439 ! permutation for next block. Load next block: 2440 2441 2442 2443! load_little_endian 2444! in0 global3 global4 local5 .LLE12 2445 2446 ! first in memory to rightmost in register 2447 2448.LLE12: 2449 ldub [in0+3], global3 2450 2451 ldub [in0+2], local5 2452 sll global3, 8, global3 2453 or global3, local5, global3 2454 2455 ldub [in0+1], local5 2456 sll global3, 8, global3 2457 or global3, local5, global3 2458 2459 ldub [in0+0], local5 2460 sll global3, 8, global3 2461 or global3, local5, global3 2462 2463 2464 ldub [in0+3+4], global4 2465 2466 ldub [in0+2+4], local5 2467 sll global4, 8, global4 2468 or global4, local5, global4 2469 2470 ldub [in0+1+4], local5 2471 sll global4, 8, global4 2472 or global4, local5, global4 2473 2474 ldub [in0+0+4], local5 2475 sll global4, 8, global4 2476 or global4, local5, global4 2477.LLE12a: 2478 2479 2480 2481 ! parameter 1 original left 2482 ! parameter 2 original right 2483 ! parameter 3 left ip 2484 ! parameter 4 right ip 2485 ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4 2486 ! 2: mov in4 to in3 2487 ! 2488 ! also adds -8 to length in2 and loads loop counter to out4 2489 2490 2491 2492! fp_ip_macro 2493! out0 out1 global3 global4 2 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 ! out0 in local3, local4 2504 2505 ld [out2+256], local1 2506 sll out5, 29, out4 2507 or local3, local4, out0 2508 2509 srl out5, 3, out1 2510 mov in4, in3 2511 2512 ld [out2+272], local5 2513 srl global4, 4, local0 2514 or out1, out4, out1 2515 2516 srl out1, 1, out4 2517 xor out4, out0, out4 2518 2519 and out4, local5, out4 2520 xor local0, global3, local0 2521 2522 sll out4, 1, local3 2523 xor out0, out4, out0 2524 2525 and local0, local1, local0 2526 add in2, -8, in2 2527 2528 sll local0, 4, local7 2529 xor global3, local0, global3 2530 2531 ld [out2+268], local4 2532 srl out0, 8, out4 2533 xor out1, local3, out1 2534 ld [out2+260], local2 2535 srl global3, 16, local0 2536 xor global4, local7, global4 2537 xor out4, out1, out4 2538 xor local0, global4, local0 2539 and out4, local4, out4 2540 and local0, local2, local0 2541 sll out4, 8, local3 2542 xor out1, out4, out1 2543 sll local0, 16, local7 2544 xor global4, local0, global4 2545 2546 srl out1, 2, out4 2547 xor out0, local3, out0 2548 2549 ld [out2+264], local3 ! ip3 2550 srl global4, 2, local0 2551 xor global3, local7, global3 2552 xor out4, out0, out4 2553 xor local0, global3, local0 2554 and out4, local3, out4 2555 and local0, local3, local0 2556 sll out4, 2, local3 2557 xor out0, out4, out0 2558 sll local0, 2, local7 2559 xor global3, local0, global3 2560 2561 srl out0, 16, out4 2562 xor out1, local3, out1 2563 srl global3, 8, local0 2564 xor global4, local7, global4 2565 xor out4, out1, out4 2566 xor local0, global4, local0 2567 and out4, local2, out4 2568 and local0, local4, local0 2569 sll out4, 16, local3 2570 xor out1, out4, local4 2571 sll local0, 8, local7 2572 xor global4, local0, global4 2573 2574 srl global4, 1, local0 2575 xor global3, local7, global3 2576 2577 srl local4, 4, out4 2578 xor local0, global3, local0 2579 2580 xor out0, local3, out0 2581 and local0, local5, local0 2582 2583 sll local0, 1, local7 2584 xor out4, out0, out4 2585 2586 xor global3, local0, global3 2587 xor global4, local7, global4 2588 2589 sll global3, 3, local5 2590 and out4, local1, out4 2591 2592 sll out4, 4, local3 2593 xor out0, out4, out0 2594 2595 2596 sll global4, 3, local2 2597 xor local4, local3, out1 2598 2599 ! reload since used as temporary: 2600 2601 ld [out2+280], out4 ! loop counter 2602 2603 srl global3, 29, local0 2604 2605 2606 2607 srl global4, 29, local7 2608 2609 or local0, local5, global4 2610 or local2, local7, global3 2611 2612 2613 2614 2615 2616! store_little_endian 2617! in1 out0 out1 local3 .SLE10 2618 2619 ! rightmost in register to first in memory 2620 2621.SLE10: 2622 and out0, 255, local3 2623 stub local3, [in1+0] 2624 2625 srl out0, 8, local3 2626 and local3, 255, local3 2627 stub local3, [in1+1] 2628 2629 srl out0, 16, local3 2630 and local3, 255, local3 2631 stub local3, [in1+2] 2632 2633 srl out0, 24, local3 2634 stub local3, [in1+3] 2635 2636 2637 and out1, 255, local3 2638 stub local3, [in1+0+4] 2639 2640 srl out1, 8, local3 2641 and local3, 255, local3 2642 stub local3, [in1+1+4] 2643 2644 srl out1, 16, local3 2645 and local3, 255, local3 2646 stub local3, [in1+2+4] 2647 2648 srl out1, 24, local3 2649 stub local3, [in1+3+4] 2650 2651.SLE10a: 2652 2653 ! block 2654 2655 ld [in3], out0 ! key 7531 first round next block 2656 mov in5, local1 2657 xor global3, out5, in5 ! iv xor next block 2658 2659 ld [in3+4], out1 ! key 8642 2660 add global1, 512, global3 ! address sbox 3 since register used 2661 xor global4, local1, out5 ! iv xor next block 2662 2663 ba .ncbc.enc.next.block_2 2664 add in1, 8, in1 ! output address 2665 2666.ncbc.enc.next.block_fp: 2667 2668 2669 2670! fp_macro 2671! in5 out5 2672 2673 ! initially undo the rotate 3 left done after initial permutation 2674 ! original left is received shifted 3 right and 29 left in local3/4 2675 2676 sll out5, 29, local1 2677 or local3, local4, in5 2678 2679 srl out5, 3, out5 2680 sethi %hi(0x55555555), local2 2681 2682 or out5, local1, out5 2683 or local2, %lo(0x55555555), local2 2684 2685 srl out5, 1, local3 2686 sethi %hi(0x00ff00ff), local1 2687 xor local3, in5, local3 2688 or local1, %lo(0x00ff00ff), local1 2689 and local3, local2, local3 2690 sethi %hi(0x33333333), local4 2691 sll local3, 1, local2 2692 2693 xor in5, local3, in5 2694 2695 srl in5, 8, local3 2696 xor out5, local2, out5 2697 xor local3, out5, local3 2698 or local4, %lo(0x33333333), local4 2699 and local3, local1, local3 2700 sethi %hi(0x0000ffff), local1 2701 sll local3, 8, local2 2702 2703 xor out5, local3, out5 2704 2705 srl out5, 2, local3 2706 xor in5, local2, in5 2707 xor local3, in5, local3 2708 or local1, %lo(0x0000ffff), local1 2709 and local3, local4, local3 2710 sethi %hi(0x0f0f0f0f), local4 2711 sll local3, 2, local2 2712 2713 2714 xor in5, local3, in5 2715 2716 2717 srl in5, 16, local3 2718 xor out5, local2, out5 2719 xor local3, out5, local3 2720 or local4, %lo(0x0f0f0f0f), local4 2721 and local3, local1, local3 2722 sll local3, 16, local2 2723 2724 xor out5, local3, local1 2725 2726 srl local1, 4, local3 2727 xor in5, local2, in5 2728 xor local3, in5, local3 2729 and local3, local4, local3 2730 sll local3, 4, local2 2731 2732 xor in5, local3, in5 2733 2734 ! optional store: 2735 2736 2737 2738 xor local1, local2, out5 2739 2740 2741 2742 2743 2744 2745 2746! store_little_endian 2747! in1 in5 out5 local3 .SLE1 2748 2749 ! rightmost in register to first in memory 2750 2751.SLE1: 2752 and in5, 255, local3 2753 stub local3, [in1+0] 2754 2755 srl in5, 8, local3 2756 and local3, 255, local3 2757 stub local3, [in1+1] 2758 2759 srl in5, 16, local3 2760 and local3, 255, local3 2761 stub local3, [in1+2] 2762 2763 srl in5, 24, local3 2764 stub local3, [in1+3] 2765 2766 2767 and out5, 255, local3 2768 stub local3, [in1+0+4] 2769 2770 srl out5, 8, local3 2771 and local3, 255, local3 2772 stub local3, [in1+1+4] 2773 2774 srl out5, 16, local3 2775 and local3, 255, local3 2776 stub local3, [in1+2+4] 2777 2778 srl out5, 24, local3 2779 stub local3, [in1+3+4] 2780 2781.SLE1a: 2782 2783 ! block 2784 2785 addcc in2, -8, in2 ! bytes missing when next block done 2786 2787 bpos .ncbc.enc.next.block 2788 add in1, 8, in1 2789 2790.ncbc.enc.seven.or.less: 2791 2792 cmp in2, -8 2793 2794 ble .ncbc.enc.finish 2795 nop 2796 2797 add in2, 8, local1 ! bytes to load 2798 2799 ! addr, length, dest left, dest right, temp, local3, label, ret label 2800 2801 2802! load_n_bytes 2803! in0 local1 local2 local3 .LNB1 .ncbc.enc.next.block_1 .LNB1 .ncbc.enc.next.block_1 2804 2805.LNB1.0: call .+8 2806 sll local1, 2, local3 2807 2808 add %o7,.LNB1.jmp.table-.LNB1.0,local2 2809 2810 add local2, local3, local2 2811 mov 0, out4 2812 2813 ld [local2], local2 2814 2815 jmp %o7+local2 2816 mov 0, global4 2817 2818.LNB1.7: 2819 ldub [in0+6], local2 2820 sll local2, 16, local2 2821 or global4, local2, global4 2822.LNB1.6: 2823 ldub [in0+5], local2 2824 sll local2, 8, local2 2825 or global4, local2, global4 2826.LNB1.5: 2827 ldub [in0+4], local2 2828 or global4, local2, global4 2829.LNB1.4: 2830 ldub [in0+3], local2 2831 sll local2, 24, local2 2832 or out4, local2, out4 2833.LNB1.3: 2834 ldub [in0+2], local2 2835 sll local2, 16, local2 2836 or out4, local2, out4 2837.LNB1.2: 2838 ldub [in0+1], local2 2839 sll local2, 8, local2 2840 or out4, local2, out4 2841.LNB1.1: 2842 ldub [in0+0], local2 2843 ba .ncbc.enc.next.block_1 2844 or out4, local2, out4 2845 2846 .align 4 2847 2848.LNB1.jmp.table: 2849 .word 0 2850 .word .LNB1.1-.LNB1.0 2851 .word .LNB1.2-.LNB1.0 2852 .word .LNB1.3-.LNB1.0 2853 .word .LNB1.4-.LNB1.0 2854 .word .LNB1.5-.LNB1.0 2855 .word .LNB1.6-.LNB1.0 2856 .word .LNB1.7-.LNB1.0 2857 2858 2859 ! Loads 1 to 7 bytes little endian to global4, out4 2860 2861 2862.ncbc.enc.finish: 2863 2864 LDPTR [%sp+BIAS+ARG0+4*ARGSZ] , local4 2865 2866 2867! store_little_endian 2868! local4 in5 out5 local5 .SLE2 2869 2870 ! rightmost in register to first in memory 2871 2872.SLE2: 2873 and in5, 255, local5 2874 stub local5, [local4+0] 2875 2876 srl in5, 8, local5 2877 and local5, 255, local5 2878 stub local5, [local4+1] 2879 2880 srl in5, 16, local5 2881 and local5, 255, local5 2882 stub local5, [local4+2] 2883 2884 srl in5, 24, local5 2885 stub local5, [local4+3] 2886 2887 2888 and out5, 255, local5 2889 stub local5, [local4+0+4] 2890 2891 srl out5, 8, local5 2892 and local5, 255, local5 2893 stub local5, [local4+1+4] 2894 2895 srl out5, 16, local5 2896 and local5, 255, local5 2897 stub local5, [local4+2+4] 2898 2899 srl out5, 24, local5 2900 stub local5, [local4+3+4] 2901 2902.SLE2a: 2903 2904 ! ivec 2905 2906 ret 2907 restore 2908 2909 2910.ncbc.dec: 2911 2912 STPTR in0, [%sp+BIAS+ARG0+0*ARGSZ] 2913 cmp in2, 0 ! length 2914 add in3, 120, in3 2915 2916 LDPTR [%sp+BIAS+ARG0+4*ARGSZ] , local7 ! ivec 2917 ble .ncbc.dec.finish 2918 mov in3, in4 ! schedule 2919 2920 STPTR in1, [%sp+BIAS+ARG0+1*ARGSZ] 2921 mov in0, local5 ! input 2922 2923 2924 2925! load_little_endian 2926! local7 in0 in1 local3 .LLE3 2927 2928 ! first in memory to rightmost in register 2929 2930.LLE3: 2931 ldub [local7+3], in0 2932 2933 ldub [local7+2], local3 2934 sll in0, 8, in0 2935 or in0, local3, in0 2936 2937 ldub [local7+1], local3 2938 sll in0, 8, in0 2939 or in0, local3, in0 2940 2941 ldub [local7+0], local3 2942 sll in0, 8, in0 2943 or in0, local3, in0 2944 2945 2946 ldub [local7+3+4], in1 2947 2948 ldub [local7+2+4], local3 2949 sll in1, 8, in1 2950 or in1, local3, in1 2951 2952 ldub [local7+1+4], local3 2953 sll in1, 8, in1 2954 or in1, local3, in1 2955 2956 ldub [local7+0+4], local3 2957 sll in1, 8, in1 2958 or in1, local3, in1 2959.LLE3a: 2960 2961 ! ivec 2962 2963.ncbc.dec.next.block: 2964 2965 2966 2967! load_little_endian 2968! local5 in5 out5 local3 .LLE4 2969 2970 ! first in memory to rightmost in register 2971 2972.LLE4: 2973 ldub [local5+3], in5 2974 2975 ldub [local5+2], local3 2976 sll in5, 8, in5 2977 or in5, local3, in5 2978 2979 ldub [local5+1], local3 2980 sll in5, 8, in5 2981 or in5, local3, in5 2982 2983 ldub [local5+0], local3 2984 sll in5, 8, in5 2985 or in5, local3, in5 2986 2987 2988 ldub [local5+3+4], out5 2989 2990 ldub [local5+2+4], local3 2991 sll out5, 8, out5 2992 or out5, local3, out5 2993 2994 ldub [local5+1+4], local3 2995 sll out5, 8, out5 2996 or out5, local3, out5 2997 2998 ldub [local5+0+4], local3 2999 sll out5, 8, out5 3000 or out5, local3, out5 3001.LLE4a: 3002 3003 ! block 3004 3005 ! parameter 6 1/2 for include encryption/decryption 3006 ! parameter 7 1 for mov in1 to in3 3007 ! parameter 8 1 for mov in3 to in4 3008 3009 3010 3011! ip_macro 3012! in5 out5 in5 out5 in4 2 0 1 3013 3014 ld [out2+256], local1 3015 srl out5, 4, local4 3016 3017 xor local4, in5, local4 3018 nop 3019 3020 ld [out2+260], local2 3021 and local4, local1, local4 3022 mov in3, in4 3023 3024 3025 ld [out2+280], out4 ! loop counter 3026 sll local4, 4, local1 3027 xor in5, local4, in5 3028 3029 ld [out2+264], local3 3030 srl in5, 16, local4 3031 xor out5, local1, out5 3032 3033 3034 xor local4, out5, local4 3035 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 3036 3037 3038 and local4, local2, local4 3039 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 3040 3041 sll local4, 16, local1 3042 xor out5, local4, out5 3043 3044 srl out5, 2, local4 3045 xor in5, local1, in5 3046 3047 sethi %hi(16711680), local5 3048 xor local4, in5, local4 3049 3050 and local4, local3, local4 3051 or local5, 255, local5 3052 3053 sll local4, 2, local2 3054 xor in5, local4, in5 3055 3056 srl in5, 8, local4 3057 xor out5, local2, out5 3058 3059 xor local4, out5, local4 3060 add global1, 768, global4 3061 3062 and local4, local5, local4 3063 add global1, 1024, global5 3064 3065 ld [out2+272], local7 3066 sll local4, 8, local1 3067 xor out5, local4, out5 3068 3069 srl out5, 1, local4 3070 xor in5, local1, in5 3071 3072 ld [in4], out0 ! key 7531 3073 xor local4, in5, local4 3074 add global1, 256, global2 3075 3076 ld [in4+4], out1 ! key 8642 3077 and local4, local7, local4 3078 add global1, 512, global3 3079 3080 sll local4, 1, local1 3081 xor in5, local4, in5 3082 3083 sll in5, 3, local3 3084 xor out5, local1, out5 3085 3086 sll out5, 3, local2 3087 add global1, 1280, local6 ! address sbox 8 3088 3089 srl in5, 29, local4 3090 add global1, 1792, out3 ! address sbox 8 3091 3092 srl out5, 29, local1 3093 or local4, local3, in5 3094 3095 or local2, local1, out5 3096 3097 3098 3099 3100 3101 ld [out2+284], local5 ! 0x0000FC00 used in the rounds 3102 or local2, local1, out5 3103 xor in5, out0, local1 3104 3105 call .des_dec.1 3106 and local1, 252, local1 3107 3108 3109 ! include decryption ks in4 3110 3111 3112 3113! fp_macro 3114! out5 in5 0 1 3115 3116 ! initially undo the rotate 3 left done after initial permutation 3117 ! original left is received shifted 3 right and 29 left in local3/4 3118 3119 sll in5, 29, local1 3120 or local3, local4, out5 3121 3122 srl in5, 3, in5 3123 sethi %hi(0x55555555), local2 3124 3125 or in5, local1, in5 3126 or local2, %lo(0x55555555), local2 3127 3128 srl in5, 1, local3 3129 sethi %hi(0x00ff00ff), local1 3130 xor local3, out5, local3 3131 or local1, %lo(0x00ff00ff), local1 3132 and local3, local2, local3 3133 sethi %hi(0x33333333), local4 3134 sll local3, 1, local2 3135 3136 xor out5, local3, out5 3137 3138 srl out5, 8, local3 3139 xor in5, local2, in5 3140 xor local3, in5, local3 3141 or local4, %lo(0x33333333), local4 3142 and local3, local1, local3 3143 sethi %hi(0x0000ffff), local1 3144 sll local3, 8, local2 3145 3146 xor in5, local3, in5 3147 3148 srl in5, 2, local3 3149 xor out5, local2, out5 3150 xor local3, out5, local3 3151 or local1, %lo(0x0000ffff), local1 3152 and local3, local4, local3 3153 sethi %hi(0x0f0f0f0f), local4 3154 sll local3, 2, local2 3155 3156 LDPTR [%sp+BIAS+ARG0+0*ARGSZ] , local5 3157 xor out5, local3, out5 3158 3159 LDPTR [%sp+BIAS+ARG0+1*ARGSZ] , local7 3160 srl out5, 16, local3 3161 xor in5, local2, in5 3162 xor local3, in5, local3 3163 or local4, %lo(0x0f0f0f0f), local4 3164 and local3, local1, local3 3165 sll local3, 16, local2 3166 3167 xor in5, local3, local1 3168 3169 srl local1, 4, local3 3170 xor out5, local2, out5 3171 xor local3, out5, local3 3172 and local3, local4, local3 3173 sll local3, 4, local2 3174 3175 xor out5, local3, out5 3176 3177 ! optional store: 3178 3179 3180 3181 xor local1, local2, in5 3182 3183 3184 3185 ! 1 for input and output address to local5/7 3186 3187 ! in2 is bytes left to be stored 3188 ! in2 is compared to 8 in the rounds 3189 3190 xor out5, in0, out4 ! iv xor 3191 bl .ncbc.dec.seven.or.less 3192 xor in5, in1, global4 ! iv xor 3193 3194 ! Load ivec next block now, since input and output address might be the same. 3195 3196 3197 3198! load_little_endian_inc 3199! local5 in0 in1 local3 .LLE5 3200 3201 ! first in memory to rightmost in register 3202 3203.LLE5: 3204 ldub [local5+3], in0 3205 3206 ldub [local5+2], local3 3207 sll in0, 8, in0 3208 or in0, local3, in0 3209 3210 ldub [local5+1], local3 3211 sll in0, 8, in0 3212 or in0, local3, in0 3213 3214 ldub [local5+0], local3 3215 sll in0, 8, in0 3216 or in0, local3, in0 3217 3218 ldub [local5+3+4], in1 3219 add local5, 8, local5 3220 3221 ldub [local5+2+4-8], local3 3222 sll in1, 8, in1 3223 or in1, local3, in1 3224 3225 ldub [local5+1+4-8], local3 3226 sll in1, 8, in1 3227 or in1, local3, in1 3228 3229 ldub [local5+0+4-8], local3 3230 sll in1, 8, in1 3231 or in1, local3, in1 3232.LLE5a: 3233 3234 ! iv 3235 3236 3237 3238! store_little_endian 3239! local7 out4 global4 local3 .SLE3 3240 3241 ! rightmost in register to first in memory 3242 3243.SLE3: 3244 and out4, 255, local3 3245 stub local3, [local7+0] 3246 3247 srl out4, 8, local3 3248 and local3, 255, local3 3249 stub local3, [local7+1] 3250 3251 srl out4, 16, local3 3252 and local3, 255, local3 3253 stub local3, [local7+2] 3254 3255 srl out4, 24, local3 3256 stub local3, [local7+3] 3257 3258 3259 and global4, 255, local3 3260 stub local3, [local7+0+4] 3261 3262 srl global4, 8, local3 3263 and local3, 255, local3 3264 stub local3, [local7+1+4] 3265 3266 srl global4, 16, local3 3267 and local3, 255, local3 3268 stub local3, [local7+2+4] 3269 3270 srl global4, 24, local3 3271 stub local3, [local7+3+4] 3272 3273.SLE3a: 3274 3275 3276 3277 STPTR local5, [%sp+BIAS+ARG0+0*ARGSZ] 3278 add local7, 8, local7 3279 addcc in2, -8, in2 3280 3281 bg .ncbc.dec.next.block 3282 STPTR local7, [%sp+BIAS+ARG0+1*ARGSZ] 3283 3284 3285.ncbc.dec.store.iv: 3286 3287 LDPTR [%sp+BIAS+ARG0+4*ARGSZ] , local4 ! ivec 3288 3289 3290! store_little_endian 3291! local4 in0 in1 local5 .SLE4 3292 3293 ! rightmost in register to first in memory 3294 3295.SLE4: 3296 and in0, 255, local5 3297 stub local5, [local4+0] 3298 3299 srl in0, 8, local5 3300 and local5, 255, local5 3301 stub local5, [local4+1] 3302 3303 srl in0, 16, local5 3304 and local5, 255, local5 3305 stub local5, [local4+2] 3306 3307 srl in0, 24, local5 3308 stub local5, [local4+3] 3309 3310 3311 and in1, 255, local5 3312 stub local5, [local4+0+4] 3313 3314 srl in1, 8, local5 3315 and local5, 255, local5 3316 stub local5, [local4+1+4] 3317 3318 srl in1, 16, local5 3319 and local5, 255, local5 3320 stub local5, [local4+2+4] 3321 3322 srl in1, 24, local5 3323 stub local5, [local4+3+4] 3324 3325.SLE4a: 3326 3327 3328 3329.ncbc.dec.finish: 3330 3331 ret 3332 restore 3333 3334.ncbc.dec.seven.or.less: 3335 3336 3337 3338! load_little_endian_inc 3339! local5 in0 in1 local3 .LLE13 3340 3341 ! first in memory to rightmost in register 3342 3343.LLE13: 3344 ldub [local5+3], in0 3345 3346 ldub [local5+2], local3 3347 sll in0, 8, in0 3348 or in0, local3, in0 3349 3350 ldub [local5+1], local3 3351 sll in0, 8, in0 3352 or in0, local3, in0 3353 3354 ldub [local5+0], local3 3355 sll in0, 8, in0 3356 or in0, local3, in0 3357 3358 ldub [local5+3+4], in1 3359 add local5, 8, local5 3360 3361 ldub [local5+2+4-8], local3 3362 sll in1, 8, in1 3363 or in1, local3, in1 3364 3365 ldub [local5+1+4-8], local3 3366 sll in1, 8, in1 3367 or in1, local3, in1 3368 3369 ldub [local5+0+4-8], local3 3370 sll in1, 8, in1 3371 or in1, local3, in1 3372.LLE13a: 3373 3374 ! ivec 3375 3376 3377 3378! store_n_bytes 3379! local7 in2 local3 local4 .SNB1 .ncbc.dec.store.iv .SNB1 .ncbc.dec.store.iv 3380 3381.SNB1.0: call .+8 3382 sll in2, 2, local4 3383 3384 add %o7,.SNB1.jmp.table-.SNB1.0,local3 3385 3386 add local3, local4, local3 3387 3388 ld [local3], local3 3389 3390 jmp %o7+local3 3391 nop 3392 3393.SNB1.7: 3394 srl global4, 16, local3 3395 and local3, 0xff, local3 3396 stub local3, [local7+6] 3397.SNB1.6: 3398 srl global4, 8, local3 3399 and local3, 0xff, local3 3400 stub local3, [local7+5] 3401.SNB1.5: 3402 and global4, 0xff, local3 3403 stub local3, [local7+4] 3404.SNB1.4: 3405 srl out4, 24, local3 3406 stub local3, [local7+3] 3407.SNB1.3: 3408 srl out4, 16, local3 3409 and local3, 0xff, local3 3410 stub local3, [local7+2] 3411.SNB1.2: 3412 srl out4, 8, local3 3413 and local3, 0xff, local3 3414 stub local3, [local7+1] 3415.SNB1.1: 3416 and out4, 0xff, local3 3417 3418 3419 ba .ncbc.dec.store.iv 3420 stub local3, [local7] 3421 3422 .align 4 3423 3424.SNB1.jmp.table: 3425 3426 .word 0 3427 .word .SNB1.1-.SNB1.0 3428 .word .SNB1.2-.SNB1.0 3429 .word .SNB1.3-.SNB1.0 3430 .word .SNB1.4-.SNB1.0 3431 .word .SNB1.5-.SNB1.0 3432 .word .SNB1.6-.SNB1.0 3433 .word .SNB1.7-.SNB1.0 3434 3435 3436 3437.DES_ncbc_encrypt.end: 3438 .size DES_ncbc_encrypt, .DES_ncbc_encrypt.end-DES_ncbc_encrypt 3439 3440 3441! void DES_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) 3442! ************************************************************************** 3443 3444 3445 .align 32 3446 .global DES_ede3_cbc_encrypt 3447 .type DES_ede3_cbc_encrypt,#function 3448 3449DES_ede3_cbc_encrypt: 3450 3451 save %sp, FRAME, %sp 3452 3453 3454 3455 3456 3457 sethi %hi(_PIC_DES_SPtrans-1f),global1 3458 or global1,%lo(_PIC_DES_SPtrans-1f),global1 34591: call .+8 3460 add %o7,global1,global1 3461 sub global1,_PIC_DES_SPtrans-.des_and,out2 3462 3463 LDPTR [%fp+BIAS+ARG0+7*ARGSZ], local3 ! enc 3464 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec 3465 cmp local3, 0 ! enc 3466 3467 be .ede3.dec 3468 STPTR in4, [%sp+BIAS+ARG0+4*ARGSZ] 3469 3470 STPTR in5, [%sp+BIAS+ARG0+5*ARGSZ] 3471 3472 3473 3474! load_little_endian 3475! local4 in5 out5 local3 .LLE6 3476 3477 ! first in memory to rightmost in register 3478 3479.LLE6: 3480 ldub [local4+3], in5 3481 3482 ldub [local4+2], local3 3483 sll in5, 8, in5 3484 or in5, local3, in5 3485 3486 ldub [local4+1], local3 3487 sll in5, 8, in5 3488 or in5, local3, in5 3489 3490 ldub [local4+0], local3 3491 sll in5, 8, in5 3492 or in5, local3, in5 3493 3494 3495 ldub [local4+3+4], out5 3496 3497 ldub [local4+2+4], local3 3498 sll out5, 8, out5 3499 or out5, local3, out5 3500 3501 ldub [local4+1+4], local3 3502 sll out5, 8, out5 3503 or out5, local3, out5 3504 3505 ldub [local4+0+4], local3 3506 sll out5, 8, out5 3507 or out5, local3, out5 3508.LLE6a: 3509 3510 ! ivec 3511 3512 addcc in2, -8, in2 ! bytes missing after next block 3513 3514 bl .ede3.enc.seven.or.less 3515 STPTR in3, [%sp+BIAS+ARG0+3*ARGSZ] 3516 3517.ede3.enc.next.block: 3518 3519 3520 3521! load_little_endian 3522! in0 out4 global4 local3 .LLE7 3523 3524 ! first in memory to rightmost in register 3525 3526.LLE7: 3527 ldub [in0+3], out4 3528 3529 ldub [in0+2], local3 3530 sll out4, 8, out4 3531 or out4, local3, out4 3532 3533 ldub [in0+1], local3 3534 sll out4, 8, out4 3535 or out4, local3, out4 3536 3537 ldub [in0+0], local3 3538 sll out4, 8, out4 3539 or out4, local3, out4 3540 3541 3542 ldub [in0+3+4], global4 3543 3544 ldub [in0+2+4], local3 3545 sll global4, 8, global4 3546 or global4, local3, global4 3547 3548 ldub [in0+1+4], local3 3549 sll global4, 8, global4 3550 or global4, local3, global4 3551 3552 ldub [in0+0+4], local3 3553 sll global4, 8, global4 3554 or global4, local3, global4 3555.LLE7a: 3556 3557 3558 3559.ede3.enc.next.block_1: 3560 3561 LDPTR [%sp+BIAS+ARG0+4*ARGSZ] , in4 3562 xor in5, out4, in5 ! iv xor 3563 xor out5, global4, out5 ! iv xor 3564 3565 LDPTR [%sp+BIAS+ARG0+3*ARGSZ] , in3 3566 add in4, 120, in4 ! for decryption we use last subkey first 3567 nop 3568 3569 3570 3571! ip_macro 3572! in5 out5 out5 in5 in3 3573 3574 ld [out2+256], local1 3575 srl out5, 4, local4 3576 3577 xor local4, in5, local4 3578 nop 3579 3580 ld [out2+260], local2 3581 and local4, local1, local4 3582 3583 3584 3585 ld [out2+280], out4 ! loop counter 3586 sll local4, 4, local1 3587 xor in5, local4, in5 3588 3589 ld [out2+264], local3 3590 srl in5, 16, local4 3591 xor out5, local1, out5 3592 3593 3594 xor local4, out5, local4 3595 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 3596 3597 3598 and local4, local2, local4 3599 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 3600 3601 sll local4, 16, local1 3602 xor out5, local4, out5 3603 3604 srl out5, 2, local4 3605 xor in5, local1, in5 3606 3607 sethi %hi(16711680), local5 3608 xor local4, in5, local4 3609 3610 and local4, local3, local4 3611 or local5, 255, local5 3612 3613 sll local4, 2, local2 3614 xor in5, local4, in5 3615 3616 srl in5, 8, local4 3617 xor out5, local2, out5 3618 3619 xor local4, out5, local4 3620 add global1, 768, global4 3621 3622 and local4, local5, local4 3623 add global1, 1024, global5 3624 3625 ld [out2+272], local7 3626 sll local4, 8, local1 3627 xor out5, local4, out5 3628 3629 srl out5, 1, local4 3630 xor in5, local1, in5 3631 3632 ld [in3], out0 ! key 7531 3633 xor local4, in5, local4 3634 add global1, 256, global2 3635 3636 ld [in3+4], out1 ! key 8642 3637 and local4, local7, local4 3638 add global1, 512, global3 3639 3640 sll local4, 1, local1 3641 xor in5, local4, in5 3642 3643 sll in5, 3, local3 3644 xor out5, local1, out5 3645 3646 sll out5, 3, local2 3647 add global1, 1280, local6 ! address sbox 8 3648 3649 srl in5, 29, local4 3650 add global1, 1792, out3 ! address sbox 8 3651 3652 srl out5, 29, local1 3653 or local4, local3, out5 3654 3655 or local2, local1, in5 3656 3657 3658 3659 3660 3661 3662.ede3.enc.next.block_2: 3663 3664 call .des_enc ! ks1 in3 3665 nop 3666 3667 call .des_dec ! ks2 in4 3668 LDPTR [%sp+BIAS+ARG0+5*ARGSZ] , in3 3669 3670 call .des_enc ! ks3 in3 compares in2 to 8 3671 nop 3672 3673 bl .ede3.enc.next.block_fp 3674 add in0, 8, in0 3675 3676 ! If 8 or more bytes are to be encrypted after this block, 3677 ! we combine final permutation for this block with initial 3678 ! permutation for next block. Load next block: 3679 3680 3681 3682! load_little_endian 3683! in0 global3 global4 local5 .LLE11 3684 3685 ! first in memory to rightmost in register 3686 3687.LLE11: 3688 ldub [in0+3], global3 3689 3690 ldub [in0+2], local5 3691 sll global3, 8, global3 3692 or global3, local5, global3 3693 3694 ldub [in0+1], local5 3695 sll global3, 8, global3 3696 or global3, local5, global3 3697 3698 ldub [in0+0], local5 3699 sll global3, 8, global3 3700 or global3, local5, global3 3701 3702 3703 ldub [in0+3+4], global4 3704 3705 ldub [in0+2+4], local5 3706 sll global4, 8, global4 3707 or global4, local5, global4 3708 3709 ldub [in0+1+4], local5 3710 sll global4, 8, global4 3711 or global4, local5, global4 3712 3713 ldub [in0+0+4], local5 3714 sll global4, 8, global4 3715 or global4, local5, global4 3716.LLE11a: 3717 3718 3719 3720 ! parameter 1 original left 3721 ! parameter 2 original right 3722 ! parameter 3 left ip 3723 ! parameter 4 right ip 3724 ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4 3725 ! 2: mov in4 to in3 3726 ! 3727 ! also adds -8 to length in2 and loads loop counter to out4 3728 3729 3730 3731! fp_ip_macro 3732! out0 out1 global3 global4 1 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 ! out0 in local3, local4 3743 3744 ld [out2+256], local1 3745 sll out5, 29, out4 3746 or local3, local4, out0 3747 3748 srl out5, 3, out1 3749 3750 3751 ld [out2+272], local5 3752 srl global4, 4, local0 3753 or out1, out4, out1 3754 3755 srl out1, 1, out4 3756 xor out4, out0, out4 3757 3758 and out4, local5, out4 3759 xor local0, global3, local0 3760 3761 sll out4, 1, local3 3762 xor out0, out4, out0 3763 3764 and local0, local1, local0 3765 add in2, -8, in2 3766 3767 sll local0, 4, local7 3768 xor global3, local0, global3 3769 3770 ld [out2+268], local4 3771 srl out0, 8, out4 3772 xor out1, local3, out1 3773 ld [out2+260], local2 3774 srl global3, 16, local0 3775 xor global4, local7, global4 3776 xor out4, out1, out4 3777 xor local0, global4, local0 3778 and out4, local4, out4 3779 and local0, local2, local0 3780 sll out4, 8, local3 3781 xor out1, out4, out1 3782 sll local0, 16, local7 3783 xor global4, local0, global4 3784 3785 srl out1, 2, out4 3786 xor out0, local3, out0 3787 3788 ld [out2+264], local3 ! ip3 3789 srl global4, 2, local0 3790 xor global3, local7, global3 3791 xor out4, out0, out4 3792 xor local0, global3, local0 3793 and out4, local3, out4 3794 and local0, local3, local0 3795 sll out4, 2, local3 3796 xor out0, out4, out0 3797 sll local0, 2, local7 3798 xor global3, local0, global3 3799 3800 srl out0, 16, out4 3801 xor out1, local3, out1 3802 srl global3, 8, local0 3803 xor global4, local7, global4 3804 xor out4, out1, out4 3805 xor local0, global4, local0 3806 and out4, local2, out4 3807 and local0, local4, local0 3808 sll out4, 16, local3 3809 xor out1, out4, local4 3810 sll local0, 8, local7 3811 xor global4, local0, global4 3812 3813 srl global4, 1, local0 3814 xor global3, local7, global3 3815 3816 srl local4, 4, out4 3817 xor local0, global3, local0 3818 3819 xor out0, local3, out0 3820 and local0, local5, local0 3821 3822 sll local0, 1, local7 3823 xor out4, out0, out4 3824 3825 xor global3, local0, global3 3826 xor global4, local7, global4 3827 3828 sll global3, 3, local5 3829 and out4, local1, out4 3830 3831 sll out4, 4, local3 3832 xor out0, out4, out0 3833 3834 LDPTR [%sp+BIAS+ARG0+4*ARGSZ] , in4 3835 sll global4, 3, local2 3836 xor local4, local3, out1 3837 3838 ! reload since used as temporary: 3839 3840 ld [out2+280], out4 ! loop counter 3841 3842 srl global3, 29, local0 3843 add in4, 120, in4 3844 3845 LDPTR [%sp+BIAS+ARG0+3*ARGSZ] , in3 3846 srl global4, 29, local7 3847 3848 or local0, local5, global4 3849 or local2, local7, global3 3850 3851 3852 3853 3854 3855! store_little_endian 3856! in1 out0 out1 local3 .SLE9 3857 3858 ! rightmost in register to first in memory 3859 3860.SLE9: 3861 and out0, 255, local3 3862 stub local3, [in1+0] 3863 3864 srl out0, 8, local3 3865 and local3, 255, local3 3866 stub local3, [in1+1] 3867 3868 srl out0, 16, local3 3869 and local3, 255, local3 3870 stub local3, [in1+2] 3871 3872 srl out0, 24, local3 3873 stub local3, [in1+3] 3874 3875 3876 and out1, 255, local3 3877 stub local3, [in1+0+4] 3878 3879 srl out1, 8, local3 3880 and local3, 255, local3 3881 stub local3, [in1+1+4] 3882 3883 srl out1, 16, local3 3884 and local3, 255, local3 3885 stub local3, [in1+2+4] 3886 3887 srl out1, 24, local3 3888 stub local3, [in1+3+4] 3889 3890.SLE9a: 3891 3892 ! block 3893 3894 mov in5, local1 3895 xor global3, out5, in5 ! iv xor next block 3896 3897 ld [in3], out0 ! key 7531 3898 add global1, 512, global3 ! address sbox 3 3899 xor global4, local1, out5 ! iv xor next block 3900 3901 ld [in3+4], out1 ! key 8642 3902 add global1, 768, global4 ! address sbox 4 3903 ba .ede3.enc.next.block_2 3904 add in1, 8, in1 3905 3906.ede3.enc.next.block_fp: 3907 3908 3909 3910! fp_macro 3911! in5 out5 3912 3913 ! initially undo the rotate 3 left done after initial permutation 3914 ! original left is received shifted 3 right and 29 left in local3/4 3915 3916 sll out5, 29, local1 3917 or local3, local4, in5 3918 3919 srl out5, 3, out5 3920 sethi %hi(0x55555555), local2 3921 3922 or out5, local1, out5 3923 or local2, %lo(0x55555555), local2 3924 3925 srl out5, 1, local3 3926 sethi %hi(0x00ff00ff), local1 3927 xor local3, in5, local3 3928 or local1, %lo(0x00ff00ff), local1 3929 and local3, local2, local3 3930 sethi %hi(0x33333333), local4 3931 sll local3, 1, local2 3932 3933 xor in5, local3, in5 3934 3935 srl in5, 8, local3 3936 xor out5, local2, out5 3937 xor local3, out5, local3 3938 or local4, %lo(0x33333333), local4 3939 and local3, local1, local3 3940 sethi %hi(0x0000ffff), local1 3941 sll local3, 8, local2 3942 3943 xor out5, local3, out5 3944 3945 srl out5, 2, local3 3946 xor in5, local2, in5 3947 xor local3, in5, local3 3948 or local1, %lo(0x0000ffff), local1 3949 and local3, local4, local3 3950 sethi %hi(0x0f0f0f0f), local4 3951 sll local3, 2, local2 3952 3953 3954 xor in5, local3, in5 3955 3956 3957 srl in5, 16, local3 3958 xor out5, local2, out5 3959 xor local3, out5, local3 3960 or local4, %lo(0x0f0f0f0f), local4 3961 and local3, local1, local3 3962 sll local3, 16, local2 3963 3964 xor out5, local3, local1 3965 3966 srl local1, 4, local3 3967 xor in5, local2, in5 3968 xor local3, in5, local3 3969 and local3, local4, local3 3970 sll local3, 4, local2 3971 3972 xor in5, local3, in5 3973 3974 ! optional store: 3975 3976 3977 3978 xor local1, local2, out5 3979 3980 3981 3982 3983 3984 3985 3986! store_little_endian 3987! in1 in5 out5 local3 .SLE5 3988 3989 ! rightmost in register to first in memory 3990 3991.SLE5: 3992 and in5, 255, local3 3993 stub local3, [in1+0] 3994 3995 srl in5, 8, local3 3996 and local3, 255, local3 3997 stub local3, [in1+1] 3998 3999 srl in5, 16, local3 4000 and local3, 255, local3 4001 stub local3, [in1+2] 4002 4003 srl in5, 24, local3 4004 stub local3, [in1+3] 4005 4006 4007 and out5, 255, local3 4008 stub local3, [in1+0+4] 4009 4010 srl out5, 8, local3 4011 and local3, 255, local3 4012 stub local3, [in1+1+4] 4013 4014 srl out5, 16, local3 4015 and local3, 255, local3 4016 stub local3, [in1+2+4] 4017 4018 srl out5, 24, local3 4019 stub local3, [in1+3+4] 4020 4021.SLE5a: 4022 4023 ! block 4024 4025 addcc in2, -8, in2 ! bytes missing when next block done 4026 4027 bpos .ede3.enc.next.block 4028 add in1, 8, in1 4029 4030.ede3.enc.seven.or.less: 4031 4032 cmp in2, -8 4033 4034 ble .ede3.enc.finish 4035 nop 4036 4037 add in2, 8, local1 ! bytes to load 4038 4039 ! addr, length, dest left, dest right, temp, local3, label, ret label 4040 4041 4042! load_n_bytes 4043! in0 local1 local2 local3 .LNB2 .ede3.enc.next.block_1 .LNB2 .ede3.enc.next.block_1 4044 4045.LNB2.0: call .+8 4046 sll local1, 2, local3 4047 4048 add %o7,.LNB2.jmp.table-.LNB2.0,local2 4049 4050 add local2, local3, local2 4051 mov 0, out4 4052 4053 ld [local2], local2 4054 4055 jmp %o7+local2 4056 mov 0, global4 4057 4058.LNB2.7: 4059 ldub [in0+6], local2 4060 sll local2, 16, local2 4061 or global4, local2, global4 4062.LNB2.6: 4063 ldub [in0+5], local2 4064 sll local2, 8, local2 4065 or global4, local2, global4 4066.LNB2.5: 4067 ldub [in0+4], local2 4068 or global4, local2, global4 4069.LNB2.4: 4070 ldub [in0+3], local2 4071 sll local2, 24, local2 4072 or out4, local2, out4 4073.LNB2.3: 4074 ldub [in0+2], local2 4075 sll local2, 16, local2 4076 or out4, local2, out4 4077.LNB2.2: 4078 ldub [in0+1], local2 4079 sll local2, 8, local2 4080 or out4, local2, out4 4081.LNB2.1: 4082 ldub [in0+0], local2 4083 ba .ede3.enc.next.block_1 4084 or out4, local2, out4 4085 4086 .align 4 4087 4088.LNB2.jmp.table: 4089 .word 0 4090 .word .LNB2.1-.LNB2.0 4091 .word .LNB2.2-.LNB2.0 4092 .word .LNB2.3-.LNB2.0 4093 .word .LNB2.4-.LNB2.0 4094 .word .LNB2.5-.LNB2.0 4095 .word .LNB2.6-.LNB2.0 4096 .word .LNB2.7-.LNB2.0 4097 4098 4099.ede3.enc.finish: 4100 4101 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec 4102 4103 4104! store_little_endian 4105! local4 in5 out5 local5 .SLE6 4106 4107 ! rightmost in register to first in memory 4108 4109.SLE6: 4110 and in5, 255, local5 4111 stub local5, [local4+0] 4112 4113 srl in5, 8, local5 4114 and local5, 255, local5 4115 stub local5, [local4+1] 4116 4117 srl in5, 16, local5 4118 and local5, 255, local5 4119 stub local5, [local4+2] 4120 4121 srl in5, 24, local5 4122 stub local5, [local4+3] 4123 4124 4125 and out5, 255, local5 4126 stub local5, [local4+0+4] 4127 4128 srl out5, 8, local5 4129 and local5, 255, local5 4130 stub local5, [local4+1+4] 4131 4132 srl out5, 16, local5 4133 and local5, 255, local5 4134 stub local5, [local4+2+4] 4135 4136 srl out5, 24, local5 4137 stub local5, [local4+3+4] 4138 4139.SLE6a: 4140 4141 ! ivec 4142 4143 ret 4144 restore 4145 4146.ede3.dec: 4147 4148 STPTR in0, [%sp+BIAS+ARG0+0*ARGSZ] 4149 add in5, 120, in5 4150 4151 STPTR in1, [%sp+BIAS+ARG0+1*ARGSZ] 4152 mov in0, local5 4153 add in3, 120, in3 4154 4155 STPTR in3, [%sp+BIAS+ARG0+3*ARGSZ] 4156 cmp in2, 0 4157 4158 ble .ede3.dec.finish 4159 STPTR in5, [%sp+BIAS+ARG0+5*ARGSZ] 4160 4161 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local7 ! iv 4162 4163 4164! load_little_endian 4165! local7 in0 in1 local3 .LLE8 4166 4167 ! first in memory to rightmost in register 4168 4169.LLE8: 4170 ldub [local7+3], in0 4171 4172 ldub [local7+2], local3 4173 sll in0, 8, in0 4174 or in0, local3, in0 4175 4176 ldub [local7+1], local3 4177 sll in0, 8, in0 4178 or in0, local3, in0 4179 4180 ldub [local7+0], local3 4181 sll in0, 8, in0 4182 or in0, local3, in0 4183 4184 4185 ldub [local7+3+4], in1 4186 4187 ldub [local7+2+4], local3 4188 sll in1, 8, in1 4189 or in1, local3, in1 4190 4191 ldub [local7+1+4], local3 4192 sll in1, 8, in1 4193 or in1, local3, in1 4194 4195 ldub [local7+0+4], local3 4196 sll in1, 8, in1 4197 or in1, local3, in1 4198.LLE8a: 4199 4200 4201 4202.ede3.dec.next.block: 4203 4204 4205 4206! load_little_endian 4207! local5 in5 out5 local3 .LLE9 4208 4209 ! first in memory to rightmost in register 4210 4211.LLE9: 4212 ldub [local5+3], in5 4213 4214 ldub [local5+2], local3 4215 sll in5, 8, in5 4216 or in5, local3, in5 4217 4218 ldub [local5+1], local3 4219 sll in5, 8, in5 4220 or in5, local3, in5 4221 4222 ldub [local5+0], local3 4223 sll in5, 8, in5 4224 or in5, local3, in5 4225 4226 4227 ldub [local5+3+4], out5 4228 4229 ldub [local5+2+4], local3 4230 sll out5, 8, out5 4231 or out5, local3, out5 4232 4233 ldub [local5+1+4], local3 4234 sll out5, 8, out5 4235 or out5, local3, out5 4236 4237 ldub [local5+0+4], local3 4238 sll out5, 8, out5 4239 or out5, local3, out5 4240.LLE9a: 4241 4242 4243 4244 ! parameter 6 1/2 for include encryption/decryption 4245 ! parameter 7 1 for mov in1 to in3 4246 ! parameter 8 1 for mov in3 to in4 4247 ! parameter 9 1 for load ks3 and ks2 to in4 and in3 4248 4249 4250 4251! ip_macro 4252! in5 out5 in5 out5 in4 2 0 0 1 4253 4254 ld [out2+256], local1 4255 srl out5, 4, local4 4256 4257 xor local4, in5, local4 4258 nop 4259 4260 ld [out2+260], local2 4261 and local4, local1, local4 4262 4263 4264 4265 ld [out2+280], out4 ! loop counter 4266 sll local4, 4, local1 4267 xor in5, local4, in5 4268 4269 ld [out2+264], local3 4270 srl in5, 16, local4 4271 xor out5, local1, out5 4272 4273 LDPTR [%sp+BIAS+ARG0+5*ARGSZ] , in4 4274 xor local4, out5, local4 4275 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr 4276 4277 LDPTR [%sp+BIAS+ARG0+4*ARGSZ] , in3 4278 and local4, local2, local4 4279 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr 4280 4281 sll local4, 16, local1 4282 xor out5, local4, out5 4283 4284 srl out5, 2, local4 4285 xor in5, local1, in5 4286 4287 sethi %hi(16711680), local5 4288 xor local4, in5, local4 4289 4290 and local4, local3, local4 4291 or local5, 255, local5 4292 4293 sll local4, 2, local2 4294 xor in5, local4, in5 4295 4296 srl in5, 8, local4 4297 xor out5, local2, out5 4298 4299 xor local4, out5, local4 4300 add global1, 768, global4 4301 4302 and local4, local5, local4 4303 add global1, 1024, global5 4304 4305 ld [out2+272], local7 4306 sll local4, 8, local1 4307 xor out5, local4, out5 4308 4309 srl out5, 1, local4 4310 xor in5, local1, in5 4311 4312 ld [in4], out0 ! key 7531 4313 xor local4, in5, local4 4314 add global1, 256, global2 4315 4316 ld [in4+4], out1 ! key 8642 4317 and local4, local7, local4 4318 add global1, 512, global3 4319 4320 sll local4, 1, local1 4321 xor in5, local4, in5 4322 4323 sll in5, 3, local3 4324 xor out5, local1, out5 4325 4326 sll out5, 3, local2 4327 add global1, 1280, local6 ! address sbox 8 4328 4329 srl in5, 29, local4 4330 add global1, 1792, out3 ! address sbox 8 4331 4332 srl out5, 29, local1 4333 or local4, local3, in5 4334 4335 or local2, local1, out5 4336 4337 4338 4339 4340 4341 ld [out2+284], local5 ! 0x0000FC00 used in the rounds 4342 or local2, local1, out5 4343 xor in5, out0, local1 4344 4345 call .des_dec.1 4346 and local1, 252, local1 4347 4348 4349 ! inc .des_dec ks3 in4 4350 4351 call .des_enc ! ks2 in3 4352 LDPTR [%sp+BIAS+ARG0+3*ARGSZ] , in4 4353 4354 call .des_dec ! ks1 in4 4355 nop 4356 4357 4358 4359! fp_macro 4360! out5 in5 0 1 4361 4362 ! initially undo the rotate 3 left done after initial permutation 4363 ! original left is received shifted 3 right and 29 left in local3/4 4364 4365 sll in5, 29, local1 4366 or local3, local4, out5 4367 4368 srl in5, 3, in5 4369 sethi %hi(0x55555555), local2 4370 4371 or in5, local1, in5 4372 or local2, %lo(0x55555555), local2 4373 4374 srl in5, 1, local3 4375 sethi %hi(0x00ff00ff), local1 4376 xor local3, out5, local3 4377 or local1, %lo(0x00ff00ff), local1 4378 and local3, local2, local3 4379 sethi %hi(0x33333333), local4 4380 sll local3, 1, local2 4381 4382 xor out5, local3, out5 4383 4384 srl out5, 8, local3 4385 xor in5, local2, in5 4386 xor local3, in5, local3 4387 or local4, %lo(0x33333333), local4 4388 and local3, local1, local3 4389 sethi %hi(0x0000ffff), local1 4390 sll local3, 8, local2 4391 4392 xor in5, local3, in5 4393 4394 srl in5, 2, local3 4395 xor out5, local2, out5 4396 xor local3, out5, local3 4397 or local1, %lo(0x0000ffff), local1 4398 and local3, local4, local3 4399 sethi %hi(0x0f0f0f0f), local4 4400 sll local3, 2, local2 4401 4402 LDPTR [%sp+BIAS+ARG0+0*ARGSZ] , local5 4403 xor out5, local3, out5 4404 4405 LDPTR [%sp+BIAS+ARG0+1*ARGSZ] , local7 4406 srl out5, 16, local3 4407 xor in5, local2, in5 4408 xor local3, in5, local3 4409 or local4, %lo(0x0f0f0f0f), local4 4410 and local3, local1, local3 4411 sll local3, 16, local2 4412 4413 xor in5, local3, local1 4414 4415 srl local1, 4, local3 4416 xor out5, local2, out5 4417 xor local3, out5, local3 4418 and local3, local4, local3 4419 sll local3, 4, local2 4420 4421 xor out5, local3, out5 4422 4423 ! optional store: 4424 4425 4426 4427 xor local1, local2, in5 4428 4429 4430 4431 ! 1 for input and output address local5/7 4432 4433 ! in2 is bytes left to be stored 4434 ! in2 is compared to 8 in the rounds 4435 4436 xor out5, in0, out4 4437 bl .ede3.dec.seven.or.less 4438 xor in5, in1, global4 4439 4440 4441 4442! load_little_endian_inc 4443! local5 in0 in1 local3 .LLE10 4444 4445 ! first in memory to rightmost in register 4446 4447.LLE10: 4448 ldub [local5+3], in0 4449 4450 ldub [local5+2], local3 4451 sll in0, 8, in0 4452 or in0, local3, in0 4453 4454 ldub [local5+1], local3 4455 sll in0, 8, in0 4456 or in0, local3, in0 4457 4458 ldub [local5+0], local3 4459 sll in0, 8, in0 4460 or in0, local3, in0 4461 4462 ldub [local5+3+4], in1 4463 add local5, 8, local5 4464 4465 ldub [local5+2+4-8], local3 4466 sll in1, 8, in1 4467 or in1, local3, in1 4468 4469 ldub [local5+1+4-8], local3 4470 sll in1, 8, in1 4471 or in1, local3, in1 4472 4473 ldub [local5+0+4-8], local3 4474 sll in1, 8, in1 4475 or in1, local3, in1 4476.LLE10a: 4477 4478 ! iv next block 4479 4480 4481 4482! store_little_endian 4483! local7 out4 global4 local3 .SLE7 4484 4485 ! rightmost in register to first in memory 4486 4487.SLE7: 4488 and out4, 255, local3 4489 stub local3, [local7+0] 4490 4491 srl out4, 8, local3 4492 and local3, 255, local3 4493 stub local3, [local7+1] 4494 4495 srl out4, 16, local3 4496 and local3, 255, local3 4497 stub local3, [local7+2] 4498 4499 srl out4, 24, local3 4500 stub local3, [local7+3] 4501 4502 4503 and global4, 255, local3 4504 stub local3, [local7+0+4] 4505 4506 srl global4, 8, local3 4507 and local3, 255, local3 4508 stub local3, [local7+1+4] 4509 4510 srl global4, 16, local3 4511 and local3, 255, local3 4512 stub local3, [local7+2+4] 4513 4514 srl global4, 24, local3 4515 stub local3, [local7+3+4] 4516 4517.SLE7a: 4518 4519 ! block 4520 4521 STPTR local5, [%sp+BIAS+ARG0+0*ARGSZ] 4522 addcc in2, -8, in2 4523 add local7, 8, local7 4524 4525 bg .ede3.dec.next.block 4526 STPTR local7, [%sp+BIAS+ARG0+1*ARGSZ] 4527 4528.ede3.dec.store.iv: 4529 4530 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec 4531 4532 4533! store_little_endian 4534! local4 in0 in1 local5 .SLE8 4535 4536 ! rightmost in register to first in memory 4537 4538.SLE8: 4539 and in0, 255, local5 4540 stub local5, [local4+0] 4541 4542 srl in0, 8, local5 4543 and local5, 255, local5 4544 stub local5, [local4+1] 4545 4546 srl in0, 16, local5 4547 and local5, 255, local5 4548 stub local5, [local4+2] 4549 4550 srl in0, 24, local5 4551 stub local5, [local4+3] 4552 4553 4554 and in1, 255, local5 4555 stub local5, [local4+0+4] 4556 4557 srl in1, 8, local5 4558 and local5, 255, local5 4559 stub local5, [local4+1+4] 4560 4561 srl in1, 16, local5 4562 and local5, 255, local5 4563 stub local5, [local4+2+4] 4564 4565 srl in1, 24, local5 4566 stub local5, [local4+3+4] 4567 4568.SLE8a: 4569 4570 ! ivec 4571 4572.ede3.dec.finish: 4573 4574 ret 4575 restore 4576 4577.ede3.dec.seven.or.less: 4578 4579 4580 4581! load_little_endian_inc 4582! local5 in0 in1 local3 .LLE14 4583 4584 ! first in memory to rightmost in register 4585 4586.LLE14: 4587 ldub [local5+3], in0 4588 4589 ldub [local5+2], local3 4590 sll in0, 8, in0 4591 or in0, local3, in0 4592 4593 ldub [local5+1], local3 4594 sll in0, 8, in0 4595 or in0, local3, in0 4596 4597 ldub [local5+0], local3 4598 sll in0, 8, in0 4599 or in0, local3, in0 4600 4601 ldub [local5+3+4], in1 4602 add local5, 8, local5 4603 4604 ldub [local5+2+4-8], local3 4605 sll in1, 8, in1 4606 or in1, local3, in1 4607 4608 ldub [local5+1+4-8], local3 4609 sll in1, 8, in1 4610 or in1, local3, in1 4611 4612 ldub [local5+0+4-8], local3 4613 sll in1, 8, in1 4614 or in1, local3, in1 4615.LLE14a: 4616 4617 ! iv 4618 4619 4620 4621! store_n_bytes 4622! local7 in2 local3 local4 .SNB2 .ede3.dec.store.iv .SNB2 .ede3.dec.store.iv 4623 4624.SNB2.0: call .+8 4625 sll in2, 2, local4 4626 4627 add %o7,.SNB2.jmp.table-.SNB2.0,local3 4628 4629 add local3, local4, local3 4630 4631 ld [local3], local3 4632 4633 jmp %o7+local3 4634 nop 4635 4636.SNB2.7: 4637 srl global4, 16, local3 4638 and local3, 0xff, local3 4639 stub local3, [local7+6] 4640.SNB2.6: 4641 srl global4, 8, local3 4642 and local3, 0xff, local3 4643 stub local3, [local7+5] 4644.SNB2.5: 4645 and global4, 0xff, local3 4646 stub local3, [local7+4] 4647.SNB2.4: 4648 srl out4, 24, local3 4649 stub local3, [local7+3] 4650.SNB2.3: 4651 srl out4, 16, local3 4652 and local3, 0xff, local3 4653 stub local3, [local7+2] 4654.SNB2.2: 4655 srl out4, 8, local3 4656 and local3, 0xff, local3 4657 stub local3, [local7+1] 4658.SNB2.1: 4659 and out4, 0xff, local3 4660 4661 4662 ba .ede3.dec.store.iv 4663 stub local3, [local7] 4664 4665 .align 4 4666 4667.SNB2.jmp.table: 4668 4669 .word 0 4670 .word .SNB2.1-.SNB2.0 4671 .word .SNB2.2-.SNB2.0 4672 .word .SNB2.3-.SNB2.0 4673 .word .SNB2.4-.SNB2.0 4674 .word .SNB2.5-.SNB2.0 4675 .word .SNB2.6-.SNB2.0 4676 .word .SNB2.7-.SNB2.0 4677 4678 4679 4680.DES_ede3_cbc_encrypt.end: 4681 .size DES_ede3_cbc_encrypt,.DES_ede3_cbc_encrypt.end-DES_ede3_cbc_encrypt 4682 4683 .align 256 4684 .type .des_and,#object 4685 .size .des_and,284 4686 4687.des_and: 4688 4689! This table is used for AND 0xFC when it is known that register 4690! bits 8-31 are zero. Makes it possible to do three arithmetic 4691! operations in one cycle. 4692 4693 .byte 0, 0, 0, 0, 4, 4, 4, 4 4694 .byte 8, 8, 8, 8, 12, 12, 12, 12 4695 .byte 16, 16, 16, 16, 20, 20, 20, 20 4696 .byte 24, 24, 24, 24, 28, 28, 28, 28 4697 .byte 32, 32, 32, 32, 36, 36, 36, 36 4698 .byte 40, 40, 40, 40, 44, 44, 44, 44 4699 .byte 48, 48, 48, 48, 52, 52, 52, 52 4700 .byte 56, 56, 56, 56, 60, 60, 60, 60 4701 .byte 64, 64, 64, 64, 68, 68, 68, 68 4702 .byte 72, 72, 72, 72, 76, 76, 76, 76 4703 .byte 80, 80, 80, 80, 84, 84, 84, 84 4704 .byte 88, 88, 88, 88, 92, 92, 92, 92 4705 .byte 96, 96, 96, 96, 100, 100, 100, 100 4706 .byte 104, 104, 104, 104, 108, 108, 108, 108 4707 .byte 112, 112, 112, 112, 116, 116, 116, 116 4708 .byte 120, 120, 120, 120, 124, 124, 124, 124 4709 .byte 128, 128, 128, 128, 132, 132, 132, 132 4710 .byte 136, 136, 136, 136, 140, 140, 140, 140 4711 .byte 144, 144, 144, 144, 148, 148, 148, 148 4712 .byte 152, 152, 152, 152, 156, 156, 156, 156 4713 .byte 160, 160, 160, 160, 164, 164, 164, 164 4714 .byte 168, 168, 168, 168, 172, 172, 172, 172 4715 .byte 176, 176, 176, 176, 180, 180, 180, 180 4716 .byte 184, 184, 184, 184, 188, 188, 188, 188 4717 .byte 192, 192, 192, 192, 196, 196, 196, 196 4718 .byte 200, 200, 200, 200, 204, 204, 204, 204 4719 .byte 208, 208, 208, 208, 212, 212, 212, 212 4720 .byte 216, 216, 216, 216, 220, 220, 220, 220 4721 .byte 224, 224, 224, 224, 228, 228, 228, 228 4722 .byte 232, 232, 232, 232, 236, 236, 236, 236 4723 .byte 240, 240, 240, 240, 244, 244, 244, 244 4724 .byte 248, 248, 248, 248, 252, 252, 252, 252 4725 4726 ! 5 numbers for initial/final permutation 4727 4728 .word 0x0f0f0f0f ! offset 256 4729 .word 0x0000ffff ! 260 4730 .word 0x33333333 ! 264 4731 .word 0x00ff00ff ! 268 4732 .word 0x55555555 ! 272 4733 4734 .word 0 ! 276 4735 .word LOOPS ! 280 4736 .word 0x0000FC00 ! 284 4737 4738 .global DES_SPtrans 4739 .type DES_SPtrans,#object 4740 .size DES_SPtrans,2048 4741.align 64 4742DES_SPtrans: 4743_PIC_DES_SPtrans: 4744 ! nibble 0 4745 .word 0x02080800, 0x00080000, 0x02000002, 0x02080802 4746 .word 0x02000000, 0x00080802, 0x00080002, 0x02000002 4747 .word 0x00080802, 0x02080800, 0x02080000, 0x00000802 4748 .word 0x02000802, 0x02000000, 0x00000000, 0x00080002 4749 .word 0x00080000, 0x00000002, 0x02000800, 0x00080800 4750 .word 0x02080802, 0x02080000, 0x00000802, 0x02000800 4751 .word 0x00000002, 0x00000800, 0x00080800, 0x02080002 4752 .word 0x00000800, 0x02000802, 0x02080002, 0x00000000 4753 .word 0x00000000, 0x02080802, 0x02000800, 0x00080002 4754 .word 0x02080800, 0x00080000, 0x00000802, 0x02000800 4755 .word 0x02080002, 0x00000800, 0x00080800, 0x02000002 4756 .word 0x00080802, 0x00000002, 0x02000002, 0x02080000 4757 .word 0x02080802, 0x00080800, 0x02080000, 0x02000802 4758 .word 0x02000000, 0x00000802, 0x00080002, 0x00000000 4759 .word 0x00080000, 0x02000000, 0x02000802, 0x02080800 4760 .word 0x00000002, 0x02080002, 0x00000800, 0x00080802 4761 ! nibble 1 4762 .word 0x40108010, 0x00000000, 0x00108000, 0x40100000 4763 .word 0x40000010, 0x00008010, 0x40008000, 0x00108000 4764 .word 0x00008000, 0x40100010, 0x00000010, 0x40008000 4765 .word 0x00100010, 0x40108000, 0x40100000, 0x00000010 4766 .word 0x00100000, 0x40008010, 0x40100010, 0x00008000 4767 .word 0x00108010, 0x40000000, 0x00000000, 0x00100010 4768 .word 0x40008010, 0x00108010, 0x40108000, 0x40000010 4769 .word 0x40000000, 0x00100000, 0x00008010, 0x40108010 4770 .word 0x00100010, 0x40108000, 0x40008000, 0x00108010 4771 .word 0x40108010, 0x00100010, 0x40000010, 0x00000000 4772 .word 0x40000000, 0x00008010, 0x00100000, 0x40100010 4773 .word 0x00008000, 0x40000000, 0x00108010, 0x40008010 4774 .word 0x40108000, 0x00008000, 0x00000000, 0x40000010 4775 .word 0x00000010, 0x40108010, 0x00108000, 0x40100000 4776 .word 0x40100010, 0x00100000, 0x00008010, 0x40008000 4777 .word 0x40008010, 0x00000010, 0x40100000, 0x00108000 4778 ! nibble 2 4779 .word 0x04000001, 0x04040100, 0x00000100, 0x04000101 4780 .word 0x00040001, 0x04000000, 0x04000101, 0x00040100 4781 .word 0x04000100, 0x00040000, 0x04040000, 0x00000001 4782 .word 0x04040101, 0x00000101, 0x00000001, 0x04040001 4783 .word 0x00000000, 0x00040001, 0x04040100, 0x00000100 4784 .word 0x00000101, 0x04040101, 0x00040000, 0x04000001 4785 .word 0x04040001, 0x04000100, 0x00040101, 0x04040000 4786 .word 0x00040100, 0x00000000, 0x04000000, 0x00040101 4787 .word 0x04040100, 0x00000100, 0x00000001, 0x00040000 4788 .word 0x00000101, 0x00040001, 0x04040000, 0x04000101 4789 .word 0x00000000, 0x04040100, 0x00040100, 0x04040001 4790 .word 0x00040001, 0x04000000, 0x04040101, 0x00000001 4791 .word 0x00040101, 0x04000001, 0x04000000, 0x04040101 4792 .word 0x00040000, 0x04000100, 0x04000101, 0x00040100 4793 .word 0x04000100, 0x00000000, 0x04040001, 0x00000101 4794 .word 0x04000001, 0x00040101, 0x00000100, 0x04040000 4795 ! nibble 3 4796 .word 0x00401008, 0x10001000, 0x00000008, 0x10401008 4797 .word 0x00000000, 0x10400000, 0x10001008, 0x00400008 4798 .word 0x10401000, 0x10000008, 0x10000000, 0x00001008 4799 .word 0x10000008, 0x00401008, 0x00400000, 0x10000000 4800 .word 0x10400008, 0x00401000, 0x00001000, 0x00000008 4801 .word 0x00401000, 0x10001008, 0x10400000, 0x00001000 4802 .word 0x00001008, 0x00000000, 0x00400008, 0x10401000 4803 .word 0x10001000, 0x10400008, 0x10401008, 0x00400000 4804 .word 0x10400008, 0x00001008, 0x00400000, 0x10000008 4805 .word 0x00401000, 0x10001000, 0x00000008, 0x10400000 4806 .word 0x10001008, 0x00000000, 0x00001000, 0x00400008 4807 .word 0x00000000, 0x10400008, 0x10401000, 0x00001000 4808 .word 0x10000000, 0x10401008, 0x00401008, 0x00400000 4809 .word 0x10401008, 0x00000008, 0x10001000, 0x00401008 4810 .word 0x00400008, 0x00401000, 0x10400000, 0x10001008 4811 .word 0x00001008, 0x10000000, 0x10000008, 0x10401000 4812 ! nibble 4 4813 .word 0x08000000, 0x00010000, 0x00000400, 0x08010420 4814 .word 0x08010020, 0x08000400, 0x00010420, 0x08010000 4815 .word 0x00010000, 0x00000020, 0x08000020, 0x00010400 4816 .word 0x08000420, 0x08010020, 0x08010400, 0x00000000 4817 .word 0x00010400, 0x08000000, 0x00010020, 0x00000420 4818 .word 0x08000400, 0x00010420, 0x00000000, 0x08000020 4819 .word 0x00000020, 0x08000420, 0x08010420, 0x00010020 4820 .word 0x08010000, 0x00000400, 0x00000420, 0x08010400 4821 .word 0x08010400, 0x08000420, 0x00010020, 0x08010000 4822 .word 0x00010000, 0x00000020, 0x08000020, 0x08000400 4823 .word 0x08000000, 0x00010400, 0x08010420, 0x00000000 4824 .word 0x00010420, 0x08000000, 0x00000400, 0x00010020 4825 .word 0x08000420, 0x00000400, 0x00000000, 0x08010420 4826 .word 0x08010020, 0x08010400, 0x00000420, 0x00010000 4827 .word 0x00010400, 0x08010020, 0x08000400, 0x00000420 4828 .word 0x00000020, 0x00010420, 0x08010000, 0x08000020 4829 ! nibble 5 4830 .word 0x80000040, 0x00200040, 0x00000000, 0x80202000 4831 .word 0x00200040, 0x00002000, 0x80002040, 0x00200000 4832 .word 0x00002040, 0x80202040, 0x00202000, 0x80000000 4833 .word 0x80002000, 0x80000040, 0x80200000, 0x00202040 4834 .word 0x00200000, 0x80002040, 0x80200040, 0x00000000 4835 .word 0x00002000, 0x00000040, 0x80202000, 0x80200040 4836 .word 0x80202040, 0x80200000, 0x80000000, 0x00002040 4837 .word 0x00000040, 0x00202000, 0x00202040, 0x80002000 4838 .word 0x00002040, 0x80000000, 0x80002000, 0x00202040 4839 .word 0x80202000, 0x00200040, 0x00000000, 0x80002000 4840 .word 0x80000000, 0x00002000, 0x80200040, 0x00200000 4841 .word 0x00200040, 0x80202040, 0x00202000, 0x00000040 4842 .word 0x80202040, 0x00202000, 0x00200000, 0x80002040 4843 .word 0x80000040, 0x80200000, 0x00202040, 0x00000000 4844 .word 0x00002000, 0x80000040, 0x80002040, 0x80202000 4845 .word 0x80200000, 0x00002040, 0x00000040, 0x80200040 4846 ! nibble 6 4847 .word 0x00004000, 0x00000200, 0x01000200, 0x01000004 4848 .word 0x01004204, 0x00004004, 0x00004200, 0x00000000 4849 .word 0x01000000, 0x01000204, 0x00000204, 0x01004000 4850 .word 0x00000004, 0x01004200, 0x01004000, 0x00000204 4851 .word 0x01000204, 0x00004000, 0x00004004, 0x01004204 4852 .word 0x00000000, 0x01000200, 0x01000004, 0x00004200 4853 .word 0x01004004, 0x00004204, 0x01004200, 0x00000004 4854 .word 0x00004204, 0x01004004, 0x00000200, 0x01000000 4855 .word 0x00004204, 0x01004000, 0x01004004, 0x00000204 4856 .word 0x00004000, 0x00000200, 0x01000000, 0x01004004 4857 .word 0x01000204, 0x00004204, 0x00004200, 0x00000000 4858 .word 0x00000200, 0x01000004, 0x00000004, 0x01000200 4859 .word 0x00000000, 0x01000204, 0x01000200, 0x00004200 4860 .word 0x00000204, 0x00004000, 0x01004204, 0x01000000 4861 .word 0x01004200, 0x00000004, 0x00004004, 0x01004204 4862 .word 0x01000004, 0x01004200, 0x01004000, 0x00004004 4863 ! nibble 7 4864 .word 0x20800080, 0x20820000, 0x00020080, 0x00000000 4865 .word 0x20020000, 0x00800080, 0x20800000, 0x20820080 4866 .word 0x00000080, 0x20000000, 0x00820000, 0x00020080 4867 .word 0x00820080, 0x20020080, 0x20000080, 0x20800000 4868 .word 0x00020000, 0x00820080, 0x00800080, 0x20020000 4869 .word 0x20820080, 0x20000080, 0x00000000, 0x00820000 4870 .word 0x20000000, 0x00800000, 0x20020080, 0x20800080 4871 .word 0x00800000, 0x00020000, 0x20820000, 0x00000080 4872 .word 0x00800000, 0x00020000, 0x20000080, 0x20820080 4873 .word 0x00020080, 0x20000000, 0x00000000, 0x00820000 4874 .word 0x20800080, 0x20020080, 0x20020000, 0x00800080 4875 .word 0x20820000, 0x00000080, 0x00800080, 0x20020000 4876 .word 0x20820080, 0x00800000, 0x20800000, 0x20000080 4877 .word 0x00820000, 0x00020080, 0x20020080, 0x20800000 4878 .word 0x00000080, 0x20820000, 0x00820080, 0x00000000 4879 .word 0x20000000, 0x20800080, 0x00020000, 0x00820080 4880 4881