summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsg <>2010-06-29 01:46:19 +0000
committerjsg <>2010-06-29 01:46:19 +0000
commitf0f1f4907585831d014bb48ae84cc8655a3570f8 (patch)
tree3b538dab276e2f2bd8e3647fbb4a89379f0eb276 /src
parent6eedf8363affeb8644950c72022c00cbdd22b189 (diff)
downloadopenbsd-f0f1f4907585831d014bb48ae84cc8655a3570f8.tar.gz
openbsd-f0f1f4907585831d014bb48ae84cc8655a3570f8.tar.bz2
openbsd-f0f1f4907585831d014bb48ae84cc8655a3570f8.zip
VIA xcrypt for amd64, simpler version of a diff from deraadt
with suggestions from miod. The codepath doesn't seem to be called yet, this will be investigated later. looks good miod@, ok deraadt@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/engine/hw_cryptodev.c25
-rw-r--r--src/lib/libssl/src/crypto/engine/hw_cryptodev.c25
2 files changed, 38 insertions, 12 deletions
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c
index de2ee1efea..b90f24576c 100644
--- a/src/lib/libcrypto/engine/hw_cryptodev.c
+++ b/src/lib/libcrypto/engine/hw_cryptodev.c
@@ -64,7 +64,7 @@ ENGINE_load_cryptodev(void)
64#include <errno.h> 64#include <errno.h>
65#include <string.h> 65#include <string.h>
66 66
67#ifdef __i386__ 67#if defined(__i386__) || defined(__amd64__)
68#include <sys/sysctl.h> 68#include <sys/sysctl.h>
69#include <machine/cpu.h> 69#include <machine/cpu.h>
70#include <machine/specialreg.h> 70#include <machine/specialreg.h>
@@ -262,9 +262,9 @@ get_cryptodev_ciphers(const int **cnids)
262 } 262 }
263 close(fd); 263 close(fd);
264 264
265#if defined(__i386__) 265#if defined(__i386__) || defined(__amd64__)
266 /* 266 /*
267 * On i386, always check for the VIA C3 AES instructions; 267 * Always check for the VIA C3 AES instructions;
268 * even if /dev/crypto is disabled. 268 * even if /dev/crypto is disabled.
269 */ 269 */
270 if (check_viac3aes() >= 1) { 270 if (check_viac3aes() >= 1) {
@@ -602,17 +602,19 @@ EVP_CIPHER cryptodev_aes_256_cbc = {
602 NULL 602 NULL
603}; 603};
604 604
605#if defined(__i386__) 605#if defined(__i386__) || defined(__amd64__)
606 606
607static inline void 607static inline void
608viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep, 608viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep,
609 void *iv) 609 void *iv)
610{ 610{
611#ifdef notdef 611#ifdef notdef
612 printf("cw %x[%x %x %x %x] src %x dst %x key %x rep %x iv %x\n", 612 printf("cw %p[%x %x %x %x] src %p dst %p key %p rep %x iv %p\n",
613 cw, cw[0], cw[1], cw[2], cw[3], 613 cw, cw[0], cw[1], cw[2], cw[3],
614 src, dst, key, rep, iv); 614 src, dst, key, rep, iv);
615#endif 615#endif
616#if defined(__i386__)
617
616 /* 618 /*
617 * Clear bit 30 of EFLAGS. 619 * Clear bit 30 of EFLAGS.
618 */ 620 */
@@ -625,6 +627,17 @@ viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep,
625 __asm __volatile("pushl %%ebx; movl %0, %%ebx; rep xcrypt-cbc; popl %%ebx" : 627 __asm __volatile("pushl %%ebx; movl %0, %%ebx; rep xcrypt-cbc; popl %%ebx" :
626 : "m" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst) 628 : "m" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst)
627 : "memory", "cc"); 629 : "memory", "cc");
630#else
631
632 /*
633 * Clear bit 30 of EFLAGS.
634 */
635 __asm __volatile("pushfq; popfq");
636 __asm __volatile("rep xcrypt-cbc" :
637 : "b" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst)
638 : "memory", "cc");
639#endif
640
628} 641}
629 642
630#define ISUNALIGNED(x) ((long)(x)) & 15 643#define ISUNALIGNED(x) ((long)(x)) & 15
@@ -778,7 +791,7 @@ check_viac3aes(void)
778 } 791 }
779 return (value); 792 return (value);
780} 793}
781#endif /* __i386__ */ 794#endif /* __i386__ || __amd64__ */
782 795
783/* 796/*
784 * Registered by the ENGINE when used to find out how to deal with 797 * Registered by the ENGINE when used to find out how to deal with
diff --git a/src/lib/libssl/src/crypto/engine/hw_cryptodev.c b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c
index de2ee1efea..b90f24576c 100644
--- a/src/lib/libssl/src/crypto/engine/hw_cryptodev.c
+++ b/src/lib/libssl/src/crypto/engine/hw_cryptodev.c
@@ -64,7 +64,7 @@ ENGINE_load_cryptodev(void)
64#include <errno.h> 64#include <errno.h>
65#include <string.h> 65#include <string.h>
66 66
67#ifdef __i386__ 67#if defined(__i386__) || defined(__amd64__)
68#include <sys/sysctl.h> 68#include <sys/sysctl.h>
69#include <machine/cpu.h> 69#include <machine/cpu.h>
70#include <machine/specialreg.h> 70#include <machine/specialreg.h>
@@ -262,9 +262,9 @@ get_cryptodev_ciphers(const int **cnids)
262 } 262 }
263 close(fd); 263 close(fd);
264 264
265#if defined(__i386__) 265#if defined(__i386__) || defined(__amd64__)
266 /* 266 /*
267 * On i386, always check for the VIA C3 AES instructions; 267 * Always check for the VIA C3 AES instructions;
268 * even if /dev/crypto is disabled. 268 * even if /dev/crypto is disabled.
269 */ 269 */
270 if (check_viac3aes() >= 1) { 270 if (check_viac3aes() >= 1) {
@@ -602,17 +602,19 @@ EVP_CIPHER cryptodev_aes_256_cbc = {
602 NULL 602 NULL
603}; 603};
604 604
605#if defined(__i386__) 605#if defined(__i386__) || defined(__amd64__)
606 606
607static inline void 607static inline void
608viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep, 608viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep,
609 void *iv) 609 void *iv)
610{ 610{
611#ifdef notdef 611#ifdef notdef
612 printf("cw %x[%x %x %x %x] src %x dst %x key %x rep %x iv %x\n", 612 printf("cw %p[%x %x %x %x] src %p dst %p key %p rep %x iv %p\n",
613 cw, cw[0], cw[1], cw[2], cw[3], 613 cw, cw[0], cw[1], cw[2], cw[3],
614 src, dst, key, rep, iv); 614 src, dst, key, rep, iv);
615#endif 615#endif
616#if defined(__i386__)
617
616 /* 618 /*
617 * Clear bit 30 of EFLAGS. 619 * Clear bit 30 of EFLAGS.
618 */ 620 */
@@ -625,6 +627,17 @@ viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep,
625 __asm __volatile("pushl %%ebx; movl %0, %%ebx; rep xcrypt-cbc; popl %%ebx" : 627 __asm __volatile("pushl %%ebx; movl %0, %%ebx; rep xcrypt-cbc; popl %%ebx" :
626 : "m" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst) 628 : "m" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst)
627 : "memory", "cc"); 629 : "memory", "cc");
630#else
631
632 /*
633 * Clear bit 30 of EFLAGS.
634 */
635 __asm __volatile("pushfq; popfq");
636 __asm __volatile("rep xcrypt-cbc" :
637 : "b" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst)
638 : "memory", "cc");
639#endif
640
628} 641}
629 642
630#define ISUNALIGNED(x) ((long)(x)) & 15 643#define ISUNALIGNED(x) ((long)(x)) & 15
@@ -778,7 +791,7 @@ check_viac3aes(void)
778 } 791 }
779 return (value); 792 return (value);
780} 793}
781#endif /* __i386__ */ 794#endif /* __i386__ || __amd64__ */
782 795
783/* 796/*
784 * Registered by the ENGINE when used to find out how to deal with 797 * Registered by the ENGINE when used to find out how to deal with