diff options
Diffstat (limited to 'src/lib/libcrypto/engine/eng_padlock.c')
| -rw-r--r-- | src/lib/libcrypto/engine/eng_padlock.c | 133 |
1 files changed, 1 insertions, 132 deletions
diff --git a/src/lib/libcrypto/engine/eng_padlock.c b/src/lib/libcrypto/engine/eng_padlock.c index d1fc8d9315..d5d9a16bf2 100644 --- a/src/lib/libcrypto/engine/eng_padlock.c +++ b/src/lib/libcrypto/engine/eng_padlock.c | |||
| @@ -101,8 +101,7 @@ | |||
| 101 | compiler choice is limited to GCC and Microsoft C. */ | 101 | compiler choice is limited to GCC and Microsoft C. */ |
| 102 | #undef COMPILE_HW_PADLOCK | 102 | #undef COMPILE_HW_PADLOCK |
| 103 | #if !defined(I386_ONLY) && !defined(OPENSSL_NO_INLINE_ASM) | 103 | #if !defined(I386_ONLY) && !defined(OPENSSL_NO_INLINE_ASM) |
| 104 | # if (defined(__GNUC__) && (defined(__i386__) || defined(__i386))) || \ | 104 | # if (defined(__GNUC__) && (defined(__i386__) || defined(__i386))) |
| 105 | (defined(_MSC_VER) && defined(_M_IX86)) | ||
| 106 | # define COMPILE_HW_PADLOCK | 105 | # define COMPILE_HW_PADLOCK |
| 107 | # endif | 106 | # endif |
| 108 | #endif | 107 | #endif |
| @@ -499,136 +498,6 @@ padlock_memcpy(void *dst,const void *src,size_t n) | |||
| 499 | 498 | ||
| 500 | return dst; | 499 | return dst; |
| 501 | } | 500 | } |
| 502 | |||
| 503 | #elif defined(_MSC_VER) | ||
| 504 | /* | ||
| 505 | * Unlike GCC these are real functions. In order to minimize impact | ||
| 506 | * on performance we adhere to __fastcall calling convention in | ||
| 507 | * order to get two first arguments passed through %ecx and %edx. | ||
| 508 | * Which kind of suits very well, as instructions in question use | ||
| 509 | * both %ecx and %edx as input:-) | ||
| 510 | */ | ||
| 511 | #define REP_XCRYPT(code) \ | ||
| 512 | _asm _emit 0xf3 \ | ||
| 513 | _asm _emit 0x0f _asm _emit 0xa7 \ | ||
| 514 | _asm _emit code | ||
| 515 | |||
| 516 | /* BIG FAT WARNING: | ||
| 517 | * The offsets used with 'lea' instructions | ||
| 518 | * describe items of the 'padlock_cipher_data' | ||
| 519 | * structure. | ||
| 520 | */ | ||
| 521 | #define PADLOCK_XCRYPT_ASM(name,code) \ | ||
| 522 | static void * __fastcall \ | ||
| 523 | name (size_t cnt, void *cdata, \ | ||
| 524 | void *outp, const void *inp) \ | ||
| 525 | { _asm mov eax,edx \ | ||
| 526 | _asm lea edx,[eax+16] \ | ||
| 527 | _asm lea ebx,[eax+32] \ | ||
| 528 | _asm mov edi,outp \ | ||
| 529 | _asm mov esi,inp \ | ||
| 530 | REP_XCRYPT(code) \ | ||
| 531 | } | ||
| 532 | |||
| 533 | PADLOCK_XCRYPT_ASM(padlock_xcrypt_ecb,0xc8) | ||
| 534 | PADLOCK_XCRYPT_ASM(padlock_xcrypt_cbc,0xd0) | ||
| 535 | PADLOCK_XCRYPT_ASM(padlock_xcrypt_cfb,0xe0) | ||
| 536 | PADLOCK_XCRYPT_ASM(padlock_xcrypt_ofb,0xe8) | ||
| 537 | |||
| 538 | static int __fastcall | ||
| 539 | padlock_xstore(void *outp,unsigned int code) | ||
| 540 | { _asm mov edi,ecx | ||
| 541 | _asm _emit 0x0f _asm _emit 0xa7 _asm _emit 0xc0 | ||
| 542 | } | ||
| 543 | |||
| 544 | static void __fastcall | ||
| 545 | padlock_reload_key(void) | ||
| 546 | { _asm pushfd _asm popfd } | ||
| 547 | |||
| 548 | static void __fastcall | ||
| 549 | padlock_verify_context(void *cdata) | ||
| 550 | { _asm { | ||
| 551 | pushfd | ||
| 552 | bt DWORD PTR[esp],30 | ||
| 553 | jnc skip | ||
| 554 | cmp ecx,padlock_saved_context | ||
| 555 | je skip | ||
| 556 | popfd | ||
| 557 | sub esp,4 | ||
| 558 | skip: add esp,4 | ||
| 559 | mov padlock_saved_context,ecx | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | static int | ||
| 564 | padlock_available(void) | ||
| 565 | { _asm { | ||
| 566 | pushfd | ||
| 567 | pop eax | ||
| 568 | mov ecx,eax | ||
| 569 | xor eax,1<<21 | ||
| 570 | push eax | ||
| 571 | popfd | ||
| 572 | pushfd | ||
| 573 | pop eax | ||
| 574 | xor eax,ecx | ||
| 575 | bt eax,21 | ||
| 576 | jnc noluck | ||
| 577 | mov eax,0 | ||
| 578 | cpuid | ||
| 579 | xor eax,eax | ||
| 580 | cmp ebx,'tneC' | ||
| 581 | jne noluck | ||
| 582 | cmp edx,'Hrua' | ||
| 583 | jne noluck | ||
| 584 | cmp ecx,'slua' | ||
| 585 | jne noluck | ||
| 586 | mov eax,0xC0000000 | ||
| 587 | cpuid | ||
| 588 | mov edx,eax | ||
| 589 | xor eax,eax | ||
| 590 | cmp edx,0xC0000001 | ||
| 591 | jb noluck | ||
| 592 | mov eax,0xC0000001 | ||
| 593 | cpuid | ||
| 594 | xor eax,eax | ||
| 595 | bt edx,6 | ||
| 596 | jnc skip_a | ||
| 597 | bt edx,7 | ||
| 598 | jnc skip_a | ||
| 599 | mov padlock_use_ace,1 | ||
| 600 | inc eax | ||
| 601 | skip_a: bt edx,2 | ||
| 602 | jnc skip_r | ||
| 603 | bt edx,3 | ||
| 604 | jnc skip_r | ||
| 605 | mov padlock_use_rng,1 | ||
| 606 | inc eax | ||
| 607 | skip_r: | ||
| 608 | noluck: | ||
| 609 | } | ||
| 610 | } | ||
| 611 | |||
| 612 | static void __fastcall | ||
| 613 | padlock_bswapl(void *key) | ||
| 614 | { _asm { | ||
| 615 | pushfd | ||
| 616 | cld | ||
| 617 | mov esi,ecx | ||
| 618 | mov edi,ecx | ||
| 619 | mov ecx,60 | ||
| 620 | up: lodsd | ||
| 621 | bswap eax | ||
| 622 | stosd | ||
| 623 | loop up | ||
| 624 | popfd | ||
| 625 | } | ||
| 626 | } | ||
| 627 | |||
| 628 | /* MS actually specifies status of Direction Flag and compiler even | ||
| 629 | * manages to compile following as 'rep movsd' all by itself... | ||
| 630 | */ | ||
| 631 | #define padlock_memcpy(o,i,n) ((unsigned char *)memcpy((o),(i),(n)&~3U)) | ||
| 632 | #endif | 501 | #endif |
| 633 | 502 | ||
| 634 | /* ===== AES encryption/decryption ===== */ | 503 | /* ===== AES encryption/decryption ===== */ |
