diff options
Diffstat (limited to 'src/lib/libcrypto/rc4/rc4_skey.c')
| -rw-r--r-- | src/lib/libcrypto/rc4/rc4_skey.c | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c index 60510624fd..46b77ec321 100644 --- a/src/lib/libcrypto/rc4/rc4_skey.c +++ b/src/lib/libcrypto/rc4/rc4_skey.c | |||
| @@ -57,12 +57,10 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <openssl/rc4.h> | 59 | #include <openssl/rc4.h> |
| 60 | #include <openssl/crypto.h> | ||
| 61 | #include <openssl/fips.h> | ||
| 62 | #include "rc4_locl.h" | 60 | #include "rc4_locl.h" |
| 63 | #include <openssl/opensslv.h> | 61 | #include <openssl/opensslv.h> |
| 64 | 62 | ||
| 65 | const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT; | 63 | const char RC4_version[]="RC4" OPENSSL_VERSION_PTEXT; |
| 66 | 64 | ||
| 67 | const char *RC4_options(void) | 65 | const char *RC4_options(void) |
| 68 | { | 66 | { |
| @@ -87,7 +85,7 @@ const char *RC4_options(void) | |||
| 87 | * Date: Wed, 14 Sep 1994 06:35:31 GMT | 85 | * Date: Wed, 14 Sep 1994 06:35:31 GMT |
| 88 | */ | 86 | */ |
| 89 | 87 | ||
| 90 | FIPS_NON_FIPS_VCIPHER_Init(RC4) | 88 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) |
| 91 | { | 89 | { |
| 92 | register RC4_INT tmp; | 90 | register RC4_INT tmp; |
| 93 | register int id1,id2; | 91 | register int id1,id2; |
| @@ -95,26 +93,59 @@ FIPS_NON_FIPS_VCIPHER_Init(RC4) | |||
| 95 | unsigned int i; | 93 | unsigned int i; |
| 96 | 94 | ||
| 97 | d= &(key->data[0]); | 95 | d= &(key->data[0]); |
| 98 | |||
| 99 | for (i=0; i<256; i++) | ||
| 100 | d[i]=i; | ||
| 101 | key->x = 0; | 96 | key->x = 0; |
| 102 | key->y = 0; | 97 | key->y = 0; |
| 103 | id1=id2=0; | 98 | id1=id2=0; |
| 104 | 99 | ||
| 105 | #define SK_LOOP(n) { \ | 100 | #define SK_LOOP(d,n) { \ |
| 106 | tmp=d[(n)]; \ | 101 | tmp=d[(n)]; \ |
| 107 | id2 = (data[id1] + tmp + id2) & 0xff; \ | 102 | id2 = (data[id1] + tmp + id2) & 0xff; \ |
| 108 | if (++id1 == len) id1=0; \ | 103 | if (++id1 == len) id1=0; \ |
| 109 | d[(n)]=d[id2]; \ | 104 | d[(n)]=d[id2]; \ |
| 110 | d[id2]=tmp; } | 105 | d[id2]=tmp; } |
| 111 | 106 | ||
| 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; | ||
| 112 | for (i=0; i < 256; i+=4) | 143 | for (i=0; i < 256; i+=4) |
| 113 | { | 144 | { |
| 114 | SK_LOOP(i+0); | 145 | SK_LOOP(d,i+0); |
| 115 | SK_LOOP(i+1); | 146 | SK_LOOP(d,i+1); |
| 116 | SK_LOOP(i+2); | 147 | SK_LOOP(d,i+2); |
| 117 | SK_LOOP(i+3); | 148 | SK_LOOP(d,i+3); |
| 118 | } | 149 | } |
| 119 | } | 150 | } |
| 120 | 151 | ||
