summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rc4/rc4_skey.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rc4/rc4_skey.c')
-rw-r--r--src/lib/libcrypto/rc4/rc4_skey.c55
1 files changed, 12 insertions, 43 deletions
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c
index 46b77ec321..60510624fd 100644
--- a/src/lib/libcrypto/rc4/rc4_skey.c
+++ b/src/lib/libcrypto/rc4/rc4_skey.c
@@ -57,10 +57,12 @@
57 */ 57 */
58 58
59#include <openssl/rc4.h> 59#include <openssl/rc4.h>
60#include <openssl/crypto.h>
61#include <openssl/fips.h>
60#include "rc4_locl.h" 62#include "rc4_locl.h"
61#include <openssl/opensslv.h> 63#include <openssl/opensslv.h>
62 64
63const char RC4_version[]="RC4" OPENSSL_VERSION_PTEXT; 65const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT;
64 66
65const char *RC4_options(void) 67const char *RC4_options(void)
66 { 68 {
@@ -85,7 +87,7 @@ const char *RC4_options(void)
85 * Date: Wed, 14 Sep 1994 06:35:31 GMT 87 * Date: Wed, 14 Sep 1994 06:35:31 GMT
86 */ 88 */
87 89
88void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) 90FIPS_NON_FIPS_VCIPHER_Init(RC4)
89 { 91 {
90 register RC4_INT tmp; 92 register RC4_INT tmp;
91 register int id1,id2; 93 register int id1,id2;
@@ -93,59 +95,26 @@ void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
93 unsigned int i; 95 unsigned int i;
94 96
95 d= &(key->data[0]); 97 d= &(key->data[0]);
98
99 for (i=0; i<256; i++)
100 d[i]=i;
96 key->x = 0; 101 key->x = 0;
97 key->y = 0; 102 key->y = 0;
98 id1=id2=0; 103 id1=id2=0;
99 104
100#define SK_LOOP(d,n) { \ 105#define SK_LOOP(n) { \
101 tmp=d[(n)]; \ 106 tmp=d[(n)]; \
102 id2 = (data[id1] + tmp + id2) & 0xff; \ 107 id2 = (data[id1] + tmp + id2) & 0xff; \
103 if (++id1 == len) id1=0; \ 108 if (++id1 == len) id1=0; \
104 d[(n)]=d[id2]; \ 109 d[(n)]=d[id2]; \
105 d[id2]=tmp; } 110 d[id2]=tmp; }
106 111
107#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM)
108# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
109 defined(__INTEL__) || \
110 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64)
111 if (sizeof(RC4_INT) > 1) {
112 /*
113 * Unlike all other x86 [and x86_64] implementations,
114 * Intel P4 core [including EM64T] was found to perform
115 * poorly with wider RC4_INT. Performance improvement
116 * for IA-32 hand-coded assembler turned out to be 2.8x
117 * if re-coded for RC4_CHAR! It's however inappropriate
118 * to just switch to RC4_CHAR for x86[_64], as non-P4
119 * implementations suffer from significant performance
120 * losses then, e.g. PIII exhibits >2x deterioration,
121 * and so does Opteron. In order to assure optimal
122 * all-round performance, we detect P4 at run-time by
123 * checking upon reserved bit 20 in CPU capability
124 * vector and set up compressed key schedule, which is
125 * recognized by correspondingly updated assembler
126 * module... Bit 20 is set up by OPENSSL_ia32_cpuid.
127 *
128 * <appro@fy.chalmers.se>
129 */
130 if (OPENSSL_ia32cap_P & (1<<20)) {
131 unsigned char *cp=(unsigned char *)d;
132
133 for (i=0;i<256;i++) cp[i]=i;
134 for (i=0;i<256;i++) SK_LOOP(cp,i);
135 /* mark schedule as compressed! */
136 d[256/sizeof(RC4_INT)]=-1;
137 return;
138 }
139 }
140# endif
141#endif
142 for (i=0; i < 256; i++) d[i]=i;
143 for (i=0; i < 256; i+=4) 112 for (i=0; i < 256; i+=4)
144 { 113 {
145 SK_LOOP(d,i+0); 114 SK_LOOP(i+0);
146 SK_LOOP(d,i+1); 115 SK_LOOP(i+1);
147 SK_LOOP(d,i+2); 116 SK_LOOP(i+2);
148 SK_LOOP(d,i+3); 117 SK_LOOP(i+3);
149 } 118 }
150 } 119 }
151 120