diff options
| author | deraadt <> | 2004-02-03 20:18:45 +0000 |
|---|---|---|
| committer | deraadt <> | 2004-02-03 20:18:45 +0000 |
| commit | 0c66a6c2b7500acc336803ba43c73d3cc11d5939 (patch) | |
| tree | 4393fc72f3ebc15991a64752caf4a722f4d74d2a /src/lib/libcrypto/engine/hw_cryptodev.c | |
| parent | d83d4f980474f941920023fbb7def86305630927 (diff) | |
| download | openbsd-0c66a6c2b7500acc336803ba43c73d3cc11d5939.tar.gz openbsd-0c66a6c2b7500acc336803ba43c73d3cc11d5939.tar.bz2 openbsd-0c66a6c2b7500acc336803ba43c73d3cc11d5939.zip | |
Switch to using software generated extended keys (because the cpu cannot
yet generate 192 & 256 bit keys). Ensure that 192 and 256 are in the
nids table. This also accelerates performance for 128 a tiny bit:
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
aes-128-cbc 34921.48k 129617.82k 362059.93k 623649.81k 790397.77k
aes-192-cbc 26227.43k 99215.33k 283242.84k 509881.15k 665323.22k
aes-256-cbc 26133.22k 97458.06k 265990.84k 457824.69k 579835.09k
Diffstat (limited to 'src/lib/libcrypto/engine/hw_cryptodev.c')
| -rw-r--r-- | src/lib/libcrypto/engine/hw_cryptodev.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c index 4959c67e92..06671a51bf 100644 --- a/src/lib/libcrypto/engine/hw_cryptodev.c +++ b/src/lib/libcrypto/engine/hw_cryptodev.c | |||
| @@ -55,6 +55,8 @@ ENGINE_load_cryptodev(void) | |||
| 55 | #include <crypto/cryptodev.h> | 55 | #include <crypto/cryptodev.h> |
| 56 | #include <sys/ioctl.h> | 56 | #include <sys/ioctl.h> |
| 57 | 57 | ||
| 58 | #include <ssl/aes.h> | ||
| 59 | |||
| 58 | #include <errno.h> | 60 | #include <errno.h> |
| 59 | #include <stdio.h> | 61 | #include <stdio.h> |
| 60 | #include <unistd.h> | 62 | #include <unistd.h> |
| @@ -68,7 +70,7 @@ ENGINE_load_cryptodev(void) | |||
| 68 | #include <sys/sysctl.h> | 70 | #include <sys/sysctl.h> |
| 69 | #include <machine/cpu.h> | 71 | #include <machine/cpu.h> |
| 70 | #include <machine/specialreg.h> | 72 | #include <machine/specialreg.h> |
| 71 | static void check_viac3aes(void); | 73 | static int check_viac3aes(void); |
| 72 | #endif | 74 | #endif |
| 73 | 75 | ||
| 74 | struct dev_crypto_state { | 76 | struct dev_crypto_state { |
| @@ -259,7 +261,26 @@ get_cryptodev_ciphers(const int **cnids) | |||
| 259 | * On i386, always check for the VIA C3 AES instructions; | 261 | * On i386, always check for the VIA C3 AES instructions; |
| 260 | * even if /dev/crypto is disabled. | 262 | * even if /dev/crypto is disabled. |
| 261 | */ | 263 | */ |
| 262 | check_viac3aes(); | 264 | if (check_viac3aes() == 1) { |
| 265 | int have_NID_aes_128_cbc = 0; | ||
| 266 | int have_NID_aes_192_cbc = 0; | ||
| 267 | int have_NID_aes_256_cbc = 0; | ||
| 268 | |||
| 269 | for (i = 0; i < count; i++) { | ||
| 270 | if (nids[i] == NID_aes_128_cbc) | ||
| 271 | have_NID_aes_128_cbc = 1; | ||
| 272 | if (nids[i] == NID_aes_192_cbc) | ||
| 273 | have_NID_aes_192_cbc = 1; | ||
| 274 | if (nids[i] == NID_aes_256_cbc) | ||
| 275 | have_NID_aes_256_cbc = 1; | ||
| 276 | } | ||
| 277 | if (!have_NID_aes_128_cbc) | ||
| 278 | nids[count++] = NID_aes_128_cbc; | ||
| 279 | if (!have_NID_aes_192_cbc) | ||
| 280 | nids[count++] = NID_aes_192_cbc; | ||
| 281 | if (!have_NID_aes_256_cbc) | ||
| 282 | nids[count++] = NID_aes_256_cbc; | ||
| 283 | } | ||
| 263 | #endif | 284 | #endif |
| 264 | 285 | ||
| 265 | if (count > 0) | 286 | if (count > 0) |
| @@ -632,7 +653,7 @@ xcrypt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
| 632 | useout = spare; | 653 | useout = spare; |
| 633 | } | 654 | } |
| 634 | 655 | ||
| 635 | cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_HW | | 656 | cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_SW | |
| 636 | C3_CRYPT_CWLO_NORMAL | | 657 | C3_CRYPT_CWLO_NORMAL | |
| 637 | ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT; | 658 | ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT; |
| 638 | cw[1] = cw[2] = cw[3] = 0; | 659 | cw[1] = cw[2] = cw[3] = 0; |
| @@ -687,7 +708,10 @@ static int | |||
| 687 | xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 708 | xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
| 688 | const unsigned char *iv, int enc) | 709 | const unsigned char *iv, int enc) |
| 689 | { | 710 | { |
| 690 | bcopy(key, ctx->cipher_data, ctx->key_len); | 711 | if (enc) |
| 712 | AES_set_encrypt_key(key, 128, ctx->cipher_data); | ||
| 713 | else | ||
| 714 | AES_set_decrypt_key(key, 128, ctx->cipher_data); | ||
| 691 | return (1); | 715 | return (1); |
| 692 | } | 716 | } |
| 693 | 717 | ||
| @@ -698,7 +722,7 @@ xcrypt_cleanup(EVP_CIPHER_CTX *ctx) | |||
| 698 | return (1); | 722 | return (1); |
| 699 | } | 723 | } |
| 700 | 724 | ||
| 701 | static void | 725 | static int |
| 702 | check_viac3aes(void) | 726 | check_viac3aes(void) |
| 703 | { | 727 | { |
| 704 | int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value; | 728 | int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value; |
| @@ -706,24 +730,25 @@ check_viac3aes(void) | |||
| 706 | 730 | ||
| 707 | if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, | 731 | if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, |
| 708 | NULL, 0) < 0) | 732 | NULL, 0) < 0) |
| 709 | return; | 733 | return (0); |
| 710 | if (value == 0) | 734 | if (value == 0) |
| 711 | return; | 735 | return (0); |
| 712 | 736 | ||
| 713 | cryptodev_aes_128_cbc.init = xcrypt_init_key; | 737 | cryptodev_aes_128_cbc.init = xcrypt_init_key; |
| 714 | cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher; | 738 | cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher; |
| 715 | cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup; | 739 | cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup; |
| 716 | cryptodev_aes_128_cbc.ctx_size = 128; | 740 | cryptodev_aes_128_cbc.ctx_size = sizeof(AES_KEY); |
| 717 | 741 | ||
| 718 | cryptodev_aes_192_cbc.init = xcrypt_init_key; | 742 | cryptodev_aes_192_cbc.init = xcrypt_init_key; |
| 719 | cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher; | 743 | cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher; |
| 720 | cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup; | 744 | cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup; |
| 721 | cryptodev_aes_192_cbc.ctx_size = 128; | 745 | cryptodev_aes_192_cbc.ctx_size = sizeof(AES_KEY); |
| 722 | 746 | ||
| 723 | cryptodev_aes_256_cbc.init = xcrypt_init_key; | 747 | cryptodev_aes_256_cbc.init = xcrypt_init_key; |
| 724 | cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher; | 748 | cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher; |
| 725 | cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup; | 749 | cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup; |
| 726 | cryptodev_aes_256_cbc.ctx_size = 128; | 750 | cryptodev_aes_256_cbc.ctx_size = sizeof(AES_KEY); |
| 751 | return (1); | ||
| 727 | } | 752 | } |
| 728 | #endif /* __i386__ */ | 753 | #endif /* __i386__ */ |
| 729 | 754 | ||
