Print this page
6652716 Need an ARCFOUR implementation optimized for Intel EM64T
@@ -21,22 +21,25 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "@(#)arcfour_crypt.c 1.6 08/01/02 SMI"
+#pragma ident "@(#)arcfour_crypt.c 1.7 08/03/20 SMI"
#include "arcfour.h"
#if defined(__amd64)
-/*
- * Use hand-tuned, processor-specific assembly version of arcfour_crypt()
- * for 64-bit x86:
- */
-#define USE_PSR_VERSION_OF_ARCFOUR_CRYPT
+#ifdef _KERNEL
+#include <sys/x86_archext.h>
+#include <sys/cpuvar.h>
+
+#else
+#include <sys/auxv.h>
+#endif /* _KERNEL */
#endif /* __amd64 */
+#if !defined(__amd64)
/* Initialize the key stream 'key' using the key value */
void
arcfour_key_init(ARCFour_key *key, uchar_t *keyval, int keyvallen)
{
/* EXPORT DELETE START */
@@ -43,16 +46,17 @@
uchar_t ext_keyval[256];
uchar_t tmp;
int i, j;
+ /* Normalize key length to 256 */
for (i = j = 0; i < 256; i++, j++) {
if (j == keyvallen)
j = 0;
-
ext_keyval[i] = keyval[j];
}
+
for (i = 0; i < 256; i++)
key->arr[i] = (uchar_t)i;
j = 0;
for (i = 0; i < 256; i++) {
@@ -66,11 +70,10 @@
/* EXPORT DELETE END */
}
-#if !defined(USE_PSR_VERSION_OF_ARCFOUR_CRYPT)
/*
* Encipher 'in' using 'key'.
* in and out can point to the same location
*/
void
@@ -136,6 +139,23 @@
}
#endif /* sun4u */
/* EXPORT DELETE END */
}
-#endif /* !USE_PSR_VERSION_OF_ARCFOUR_CRYPT */
+
+#else
+
+/*
+ * Return 1 if executing on Intel, otherwise 0 (e.g., AMD64).
+ */
+int
+arcfour_crypt_on_intel(void)
+{
+#ifdef _KERNEL
+ return (cpuid_getvendor(CPU) == X86_VENDOR_Intel);
+#else
+ uint_t ui;
+ (void) getisax(&ui, 1);
+ return ((ui & AV_386_AMD_MMX) == 0);
+#endif /* _KERNEL */
+}
+#endif /* !__amd64 */