diff options
-rw-r--r-- | src/lib/libcrypto/engine/hw_cryptodev.c | 45 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/hw_cryptodev.c | 45 |
2 files changed, 20 insertions, 70 deletions
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c index 06671a51bf..4959c67e92 100644 --- a/src/lib/libcrypto/engine/hw_cryptodev.c +++ b/src/lib/libcrypto/engine/hw_cryptodev.c | |||
@@ -55,8 +55,6 @@ 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 | |||
60 | #include <errno.h> | 58 | #include <errno.h> |
61 | #include <stdio.h> | 59 | #include <stdio.h> |
62 | #include <unistd.h> | 60 | #include <unistd.h> |
@@ -70,7 +68,7 @@ ENGINE_load_cryptodev(void) | |||
70 | #include <sys/sysctl.h> | 68 | #include <sys/sysctl.h> |
71 | #include <machine/cpu.h> | 69 | #include <machine/cpu.h> |
72 | #include <machine/specialreg.h> | 70 | #include <machine/specialreg.h> |
73 | static int check_viac3aes(void); | 71 | static void check_viac3aes(void); |
74 | #endif | 72 | #endif |
75 | 73 | ||
76 | struct dev_crypto_state { | 74 | struct dev_crypto_state { |
@@ -261,26 +259,7 @@ get_cryptodev_ciphers(const int **cnids) | |||
261 | * On i386, always check for the VIA C3 AES instructions; | 259 | * On i386, always check for the VIA C3 AES instructions; |
262 | * even if /dev/crypto is disabled. | 260 | * even if /dev/crypto is disabled. |
263 | */ | 261 | */ |
264 | if (check_viac3aes() == 1) { | 262 | check_viac3aes(); |
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 | } | ||
284 | #endif | 263 | #endif |
285 | 264 | ||
286 | if (count > 0) | 265 | if (count > 0) |
@@ -653,7 +632,7 @@ xcrypt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
653 | useout = spare; | 632 | useout = spare; |
654 | } | 633 | } |
655 | 634 | ||
656 | cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_SW | | 635 | cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_HW | |
657 | C3_CRYPT_CWLO_NORMAL | | 636 | C3_CRYPT_CWLO_NORMAL | |
658 | ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT; | 637 | ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT; |
659 | cw[1] = cw[2] = cw[3] = 0; | 638 | cw[1] = cw[2] = cw[3] = 0; |
@@ -708,10 +687,7 @@ static int | |||
708 | xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 687 | xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
709 | const unsigned char *iv, int enc) | 688 | const unsigned char *iv, int enc) |
710 | { | 689 | { |
711 | if (enc) | 690 | bcopy(key, ctx->cipher_data, ctx->key_len); |
712 | AES_set_encrypt_key(key, 128, ctx->cipher_data); | ||
713 | else | ||
714 | AES_set_decrypt_key(key, 128, ctx->cipher_data); | ||
715 | return (1); | 691 | return (1); |
716 | } | 692 | } |
717 | 693 | ||
@@ -722,7 +698,7 @@ xcrypt_cleanup(EVP_CIPHER_CTX *ctx) | |||
722 | return (1); | 698 | return (1); |
723 | } | 699 | } |
724 | 700 | ||
725 | static int | 701 | static void |
726 | check_viac3aes(void) | 702 | check_viac3aes(void) |
727 | { | 703 | { |
728 | int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value; | 704 | int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value; |
@@ -730,25 +706,24 @@ check_viac3aes(void) | |||
730 | 706 | ||
731 | if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, | 707 | if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, |
732 | NULL, 0) < 0) | 708 | NULL, 0) < 0) |
733 | return (0); | 709 | return; |
734 | if (value == 0) | 710 | if (value == 0) |
735 | return (0); | 711 | return; |
736 | 712 | ||
737 | cryptodev_aes_128_cbc.init = xcrypt_init_key; | 713 | cryptodev_aes_128_cbc.init = xcrypt_init_key; |
738 | cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher; | 714 | cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher; |
739 | cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup; | 715 | cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup; |
740 | cryptodev_aes_128_cbc.ctx_size = sizeof(AES_KEY); | 716 | cryptodev_aes_128_cbc.ctx_size = 128; |
741 | 717 | ||
742 | cryptodev_aes_192_cbc.init = xcrypt_init_key; | 718 | cryptodev_aes_192_cbc.init = xcrypt_init_key; |
743 | cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher; | 719 | cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher; |
744 | cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup; | 720 | cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup; |
745 | cryptodev_aes_192_cbc.ctx_size = sizeof(AES_KEY); | 721 | cryptodev_aes_192_cbc.ctx_size = 128; |
746 | 722 | ||
747 | cryptodev_aes_256_cbc.init = xcrypt_init_key; | 723 | cryptodev_aes_256_cbc.init = xcrypt_init_key; |
748 | cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher; | 724 | cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher; |
749 | cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup; | 725 | cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup; |
750 | cryptodev_aes_256_cbc.ctx_size = sizeof(AES_KEY); | 726 | cryptodev_aes_256_cbc.ctx_size = 128; |
751 | return (1); | ||
752 | } | 727 | } |
753 | #endif /* __i386__ */ | 728 | #endif /* __i386__ */ |
754 | 729 | ||
diff --git a/src/lib/libssl/src/crypto/engine/hw_cryptodev.c b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c index 06671a51bf..4959c67e92 100644 --- a/src/lib/libssl/src/crypto/engine/hw_cryptodev.c +++ b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c | |||
@@ -55,8 +55,6 @@ 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 | |||
60 | #include <errno.h> | 58 | #include <errno.h> |
61 | #include <stdio.h> | 59 | #include <stdio.h> |
62 | #include <unistd.h> | 60 | #include <unistd.h> |
@@ -70,7 +68,7 @@ ENGINE_load_cryptodev(void) | |||
70 | #include <sys/sysctl.h> | 68 | #include <sys/sysctl.h> |
71 | #include <machine/cpu.h> | 69 | #include <machine/cpu.h> |
72 | #include <machine/specialreg.h> | 70 | #include <machine/specialreg.h> |
73 | static int check_viac3aes(void); | 71 | static void check_viac3aes(void); |
74 | #endif | 72 | #endif |
75 | 73 | ||
76 | struct dev_crypto_state { | 74 | struct dev_crypto_state { |
@@ -261,26 +259,7 @@ get_cryptodev_ciphers(const int **cnids) | |||
261 | * On i386, always check for the VIA C3 AES instructions; | 259 | * On i386, always check for the VIA C3 AES instructions; |
262 | * even if /dev/crypto is disabled. | 260 | * even if /dev/crypto is disabled. |
263 | */ | 261 | */ |
264 | if (check_viac3aes() == 1) { | 262 | check_viac3aes(); |
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 | } | ||
284 | #endif | 263 | #endif |
285 | 264 | ||
286 | if (count > 0) | 265 | if (count > 0) |
@@ -653,7 +632,7 @@ xcrypt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
653 | useout = spare; | 632 | useout = spare; |
654 | } | 633 | } |
655 | 634 | ||
656 | cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_SW | | 635 | cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_HW | |
657 | C3_CRYPT_CWLO_NORMAL | | 636 | C3_CRYPT_CWLO_NORMAL | |
658 | ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT; | 637 | ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT; |
659 | cw[1] = cw[2] = cw[3] = 0; | 638 | cw[1] = cw[2] = cw[3] = 0; |
@@ -708,10 +687,7 @@ static int | |||
708 | xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 687 | xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
709 | const unsigned char *iv, int enc) | 688 | const unsigned char *iv, int enc) |
710 | { | 689 | { |
711 | if (enc) | 690 | bcopy(key, ctx->cipher_data, ctx->key_len); |
712 | AES_set_encrypt_key(key, 128, ctx->cipher_data); | ||
713 | else | ||
714 | AES_set_decrypt_key(key, 128, ctx->cipher_data); | ||
715 | return (1); | 691 | return (1); |
716 | } | 692 | } |
717 | 693 | ||
@@ -722,7 +698,7 @@ xcrypt_cleanup(EVP_CIPHER_CTX *ctx) | |||
722 | return (1); | 698 | return (1); |
723 | } | 699 | } |
724 | 700 | ||
725 | static int | 701 | static void |
726 | check_viac3aes(void) | 702 | check_viac3aes(void) |
727 | { | 703 | { |
728 | int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value; | 704 | int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value; |
@@ -730,25 +706,24 @@ check_viac3aes(void) | |||
730 | 706 | ||
731 | if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, | 707 | if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, |
732 | NULL, 0) < 0) | 708 | NULL, 0) < 0) |
733 | return (0); | 709 | return; |
734 | if (value == 0) | 710 | if (value == 0) |
735 | return (0); | 711 | return; |
736 | 712 | ||
737 | cryptodev_aes_128_cbc.init = xcrypt_init_key; | 713 | cryptodev_aes_128_cbc.init = xcrypt_init_key; |
738 | cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher; | 714 | cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher; |
739 | cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup; | 715 | cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup; |
740 | cryptodev_aes_128_cbc.ctx_size = sizeof(AES_KEY); | 716 | cryptodev_aes_128_cbc.ctx_size = 128; |
741 | 717 | ||
742 | cryptodev_aes_192_cbc.init = xcrypt_init_key; | 718 | cryptodev_aes_192_cbc.init = xcrypt_init_key; |
743 | cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher; | 719 | cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher; |
744 | cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup; | 720 | cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup; |
745 | cryptodev_aes_192_cbc.ctx_size = sizeof(AES_KEY); | 721 | cryptodev_aes_192_cbc.ctx_size = 128; |
746 | 722 | ||
747 | cryptodev_aes_256_cbc.init = xcrypt_init_key; | 723 | cryptodev_aes_256_cbc.init = xcrypt_init_key; |
748 | cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher; | 724 | cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher; |
749 | cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup; | 725 | cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup; |
750 | cryptodev_aes_256_cbc.ctx_size = sizeof(AES_KEY); | 726 | cryptodev_aes_256_cbc.ctx_size = 128; |
751 | return (1); | ||
752 | } | 727 | } |
753 | #endif /* __i386__ */ | 728 | #endif /* __i386__ */ |
754 | 729 | ||