diff options
| author | djm <> | 2008-09-06 12:17:54 +0000 |
|---|---|---|
| committer | djm <> | 2008-09-06 12:17:54 +0000 |
| commit | 6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda (patch) | |
| tree | 7ccc28afe1789ea3dbedf72365f955d5b8e105b5 /src/lib/libcrypto/rc4 | |
| parent | 89181603212b41e95cde36b1be5a146ce8fb2935 (diff) | |
| download | openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.tar.gz openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.tar.bz2 openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.zip | |
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/rc4')
| -rw-r--r-- | src/lib/libcrypto/rc4/asm/rc4-586.pl | 11 | ||||
| -rw-r--r-- | src/lib/libcrypto/rc4/rc4.c | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/rc4/rc4.h | 6 | ||||
| -rw-r--r-- | src/lib/libcrypto/rc4/rc4_enc.c | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/rc4/rc4_skey.c | 55 | ||||
| -rw-r--r-- | src/lib/libcrypto/rc4/rc4speed.c | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/rc4/rc4test.c | 51 |
7 files changed, 99 insertions, 34 deletions
diff --git a/src/lib/libcrypto/rc4/asm/rc4-586.pl b/src/lib/libcrypto/rc4/asm/rc4-586.pl index d6e98f0811..ef7eee766c 100644 --- a/src/lib/libcrypto/rc4/asm/rc4-586.pl +++ b/src/lib/libcrypto/rc4/asm/rc4-586.pl | |||
| @@ -200,22 +200,23 @@ sub RC4 | |||
| 200 | 200 | ||
| 201 | &lea ($ty,&DWP(0,$in,$ty)); | 201 | &lea ($ty,&DWP(0,$in,$ty)); |
| 202 | &mov (&swtmp(2),$ty); | 202 | &mov (&swtmp(2),$ty); |
| 203 | &movz ($tx,&BP(0,$d,$x)); | ||
| 203 | 204 | ||
| 204 | # strangely enough unrolled loop performs over 20% slower... | 205 | # strangely enough unrolled loop performs over 20% slower... |
| 205 | &set_label("RC4_CHAR_loop"); | 206 | &set_label("RC4_CHAR_loop"); |
| 206 | &movz ($tx,&BP(0,$d,$x)); | ||
| 207 | &add (&LB($y),&LB($tx)); | 207 | &add (&LB($y),&LB($tx)); |
| 208 | &movz ($ty,&BP(0,$d,$y)); | 208 | &movz ($ty,&BP(0,$d,$y)); |
| 209 | &movb (&BP(0,$d,$y),&LB($tx)); | 209 | &movb (&BP(0,$d,$y),&LB($tx)); |
| 210 | &movb (&BP(0,$d,$x),&LB($ty)); | 210 | &movb (&BP(0,$d,$x),&LB($ty)); |
| 211 | &add (&LB($ty),&LB($tx)); | 211 | &add (&LB($ty),&LB($tx)); |
| 212 | &movz ($ty,&BP(0,$d,$ty)); | 212 | &movz ($ty,&BP(0,$d,$ty)); |
| 213 | &add (&LB($x),1); | ||
| 213 | &xorb (&LB($ty),&BP(0,$in)); | 214 | &xorb (&LB($ty),&BP(0,$in)); |
| 214 | &movb (&BP(0,$out),&LB($ty)); | 215 | &lea ($in,&DWP(1,$in)); |
| 215 | &inc (&LB($x)); | 216 | &movz ($tx,&BP(0,$d,$x)); |
| 216 | &inc ($in); | ||
| 217 | &inc ($out); | ||
| 218 | &cmp ($in,&swtmp(2)); | 217 | &cmp ($in,&swtmp(2)); |
| 218 | &movb (&BP(0,$out),&LB($ty)); | ||
| 219 | &lea ($out,&DWP(1,$out)); | ||
| 219 | &jb (&label("RC4_CHAR_loop")); | 220 | &jb (&label("RC4_CHAR_loop")); |
| 220 | 221 | ||
| 221 | &set_label("finished"); | 222 | &set_label("finished"); |
diff --git a/src/lib/libcrypto/rc4/rc4.c b/src/lib/libcrypto/rc4/rc4.c index b39c070292..c900b26055 100644 --- a/src/lib/libcrypto/rc4/rc4.c +++ b/src/lib/libcrypto/rc4/rc4.c | |||
| @@ -60,6 +60,7 @@ | |||
| 60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
| 61 | #include <string.h> | 61 | #include <string.h> |
| 62 | #include <openssl/rc4.h> | 62 | #include <openssl/rc4.h> |
| 63 | #include <openssl/evp.h> | ||
| 63 | 64 | ||
| 64 | char *usage[]={ | 65 | char *usage[]={ |
| 65 | "usage: rc4 args\n", | 66 | "usage: rc4 args\n", |
| @@ -162,7 +163,7 @@ bad: | |||
| 162 | keystr=buf; | 163 | keystr=buf; |
| 163 | } | 164 | } |
| 164 | 165 | ||
| 165 | EVP_Digest((unsigned char *)keystr,(unsigned long)strlen(keystr),md,NULL,EVP_md5()); | 166 | EVP_Digest((unsigned char *)keystr,strlen(keystr),md,NULL,EVP_md5(),NULL); |
| 166 | OPENSSL_cleanse(keystr,strlen(keystr)); | 167 | OPENSSL_cleanse(keystr,strlen(keystr)); |
| 167 | RC4_set_key(&key,MD5_DIGEST_LENGTH,md); | 168 | RC4_set_key(&key,MD5_DIGEST_LENGTH,md); |
| 168 | 169 | ||
diff --git a/src/lib/libcrypto/rc4/rc4.h b/src/lib/libcrypto/rc4/rc4.h index ae0cea75b8..7aec04fe93 100644 --- a/src/lib/libcrypto/rc4/rc4.h +++ b/src/lib/libcrypto/rc4/rc4.h | |||
| @@ -59,12 +59,11 @@ | |||
| 59 | #ifndef HEADER_RC4_H | 59 | #ifndef HEADER_RC4_H |
| 60 | #define HEADER_RC4_H | 60 | #define HEADER_RC4_H |
| 61 | 61 | ||
| 62 | #include <openssl/opensslconf.h> /* OPENSSL_NO_RC4, RC4_INT */ | ||
| 62 | #ifdef OPENSSL_NO_RC4 | 63 | #ifdef OPENSSL_NO_RC4 |
| 63 | #error RC4 is disabled. | 64 | #error RC4 is disabled. |
| 64 | #endif | 65 | #endif |
| 65 | 66 | ||
| 66 | #include <openssl/opensslconf.h> /* RC4_INT */ | ||
| 67 | |||
| 68 | #ifdef __cplusplus | 67 | #ifdef __cplusplus |
| 69 | extern "C" { | 68 | extern "C" { |
| 70 | #endif | 69 | #endif |
| @@ -77,9 +76,6 @@ typedef struct rc4_key_st | |||
| 77 | 76 | ||
| 78 | 77 | ||
| 79 | const char *RC4_options(void); | 78 | const char *RC4_options(void); |
| 80 | #ifdef OPENSSL_FIPS | ||
| 81 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); | ||
| 82 | #endif | ||
| 83 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); | 79 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); |
| 84 | void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, | 80 | void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, |
| 85 | unsigned char *outdata); | 81 | unsigned char *outdata); |
diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c index d5f18a3a70..0660ea60a2 100644 --- a/src/lib/libcrypto/rc4/rc4_enc.c +++ b/src/lib/libcrypto/rc4/rc4_enc.c | |||
| @@ -157,7 +157,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, | |||
| 157 | if (!is_endian.little) | 157 | if (!is_endian.little) |
| 158 | { /* BIG-ENDIAN CASE */ | 158 | { /* BIG-ENDIAN CASE */ |
| 159 | # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) | 159 | # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) |
| 160 | for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK)) | 160 | for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK)) |
| 161 | { | 161 | { |
| 162 | ichunk = *(RC4_CHUNK *)indata; | 162 | ichunk = *(RC4_CHUNK *)indata; |
| 163 | otp = RC4_STEP<<BESHFT(0); | 163 | otp = RC4_STEP<<BESHFT(0); |
| @@ -210,7 +210,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, | |||
| 210 | else | 210 | else |
| 211 | { /* LITTLE-ENDIAN CASE */ | 211 | { /* LITTLE-ENDIAN CASE */ |
| 212 | # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) | 212 | # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) |
| 213 | for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK)) | 213 | for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK)) |
| 214 | { | 214 | { |
| 215 | ichunk = *(RC4_CHUNK *)indata; | 215 | ichunk = *(RC4_CHUNK *)indata; |
| 216 | otp = RC4_STEP; | 216 | otp = RC4_STEP; |
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 | ||
diff --git a/src/lib/libcrypto/rc4/rc4speed.c b/src/lib/libcrypto/rc4/rc4speed.c index ced98c52df..0ebd38123d 100644 --- a/src/lib/libcrypto/rc4/rc4speed.c +++ b/src/lib/libcrypto/rc4/rc4speed.c | |||
| @@ -69,7 +69,10 @@ | |||
| 69 | #include OPENSSL_UNISTD_IO | 69 | #include OPENSSL_UNISTD_IO |
| 70 | OPENSSL_DECLARE_EXIT | 70 | OPENSSL_DECLARE_EXIT |
| 71 | 71 | ||
| 72 | #ifndef OPENSSL_SYS_NETWARE | ||
| 72 | #include <signal.h> | 73 | #include <signal.h> |
| 74 | #endif | ||
| 75 | |||
| 73 | #ifndef _IRIX | 76 | #ifndef _IRIX |
| 74 | #include <time.h> | 77 | #include <time.h> |
| 75 | #endif | 78 | #endif |
diff --git a/src/lib/libcrypto/rc4/rc4test.c b/src/lib/libcrypto/rc4/rc4test.c index b9d8f20975..54b597fa26 100644 --- a/src/lib/libcrypto/rc4/rc4test.c +++ b/src/lib/libcrypto/rc4/rc4test.c | |||
| @@ -70,6 +70,7 @@ int main(int argc, char *argv[]) | |||
| 70 | } | 70 | } |
| 71 | #else | 71 | #else |
| 72 | #include <openssl/rc4.h> | 72 | #include <openssl/rc4.h> |
| 73 | #include <openssl/sha.h> | ||
| 73 | 74 | ||
| 74 | static unsigned char keys[7][30]={ | 75 | static unsigned char keys[7][30]={ |
| 75 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, | 76 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, |
| @@ -113,13 +114,11 @@ static unsigned char output[7][30]={ | |||
| 113 | 114 | ||
| 114 | int main(int argc, char *argv[]) | 115 | int main(int argc, char *argv[]) |
| 115 | { | 116 | { |
| 116 | int i,err=0; | 117 | int err=0; |
| 117 | int j; | 118 | unsigned int i, j; |
| 118 | unsigned char *p; | 119 | unsigned char *p; |
| 119 | RC4_KEY key; | 120 | RC4_KEY key; |
| 120 | unsigned char buf[512],obuf[512]; | 121 | unsigned char obuf[512]; |
| 121 | |||
| 122 | for (i=0; i<512; i++) buf[i]=0x01; | ||
| 123 | 122 | ||
| 124 | for (i=0; i<6; i++) | 123 | for (i=0; i<6; i++) |
| 125 | { | 124 | { |
| @@ -130,12 +129,12 @@ int main(int argc, char *argv[]) | |||
| 130 | { | 129 | { |
| 131 | printf("error calculating RC4\n"); | 130 | printf("error calculating RC4\n"); |
| 132 | printf("output:"); | 131 | printf("output:"); |
| 133 | for (j=0; j<data_len[i]+1; j++) | 132 | for (j=0; j<data_len[i]+1U; j++) |
| 134 | printf(" %02x",obuf[j]); | 133 | printf(" %02x",obuf[j]); |
| 135 | printf("\n"); | 134 | printf("\n"); |
| 136 | printf("expect:"); | 135 | printf("expect:"); |
| 137 | p= &(output[i][0]); | 136 | p= &(output[i][0]); |
| 138 | for (j=0; j<data_len[i]+1; j++) | 137 | for (j=0; j<data_len[i]+1U; j++) |
| 139 | printf(" %02x",*(p++)); | 138 | printf(" %02x",*(p++)); |
| 140 | printf("\n"); | 139 | printf("\n"); |
| 141 | err++; | 140 | err++; |
| @@ -181,12 +180,12 @@ int main(int argc, char *argv[]) | |||
| 181 | { | 180 | { |
| 182 | printf("error in RC4 multi-call processing\n"); | 181 | printf("error in RC4 multi-call processing\n"); |
| 183 | printf("output:"); | 182 | printf("output:"); |
| 184 | for (j=0; j<data_len[3]+1; j++) | 183 | for (j=0; j<data_len[3]+1U; j++) |
| 185 | printf(" %02x",obuf[j]); | 184 | printf(" %02x",obuf[j]); |
| 186 | printf("\n"); | 185 | printf("\n"); |
| 187 | printf("expect:"); | 186 | printf("expect:"); |
| 188 | p= &(output[3][0]); | 187 | p= &(output[3][0]); |
| 189 | for (j=0; j<data_len[3]+1; j++) | 188 | for (j=0; j<data_len[3]+1U; j++) |
| 190 | printf(" %02x",*(p++)); | 189 | printf(" %02x",*(p++)); |
| 191 | err++; | 190 | err++; |
| 192 | } | 191 | } |
| @@ -197,6 +196,40 @@ int main(int argc, char *argv[]) | |||
| 197 | } | 196 | } |
| 198 | } | 197 | } |
| 199 | printf("done\n"); | 198 | printf("done\n"); |
| 199 | printf("bulk test "); | ||
| 200 | { unsigned char buf[513]; | ||
| 201 | SHA_CTX c; | ||
| 202 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 203 | static unsigned char expected[]={ | ||
| 204 | 0xa4,0x7b,0xcc,0x00,0x3d,0xd0,0xbd,0xe1,0xac,0x5f, | ||
| 205 | 0x12,0x1e,0x45,0xbc,0xfb,0x1a,0xa1,0xf2,0x7f,0xc5 }; | ||
| 206 | |||
| 207 | RC4_set_key(&key,keys[0][0],&(keys[3][1])); | ||
| 208 | memset(buf,'\0',sizeof(buf)); | ||
| 209 | SHA1_Init(&c); | ||
| 210 | for (i=0;i<2571;i++) { | ||
| 211 | RC4(&key,sizeof(buf),buf,buf); | ||
| 212 | SHA1_Update(&c,buf,sizeof(buf)); | ||
| 213 | } | ||
| 214 | SHA1_Final(md,&c); | ||
| 215 | |||
| 216 | if (memcmp(md,expected,sizeof(md))) { | ||
| 217 | printf("error in RC4 bulk test\n"); | ||
| 218 | printf("output:"); | ||
| 219 | for (j=0; j<sizeof(md); j++) | ||
| 220 | printf(" %02x",md[j]); | ||
| 221 | printf("\n"); | ||
| 222 | printf("expect:"); | ||
| 223 | for (j=0; j<sizeof(md); j++) | ||
| 224 | printf(" %02x",expected[j]); | ||
| 225 | printf("\n"); | ||
| 226 | err++; | ||
| 227 | } | ||
| 228 | else printf("ok\n"); | ||
| 229 | } | ||
| 230 | #ifdef OPENSSL_SYS_NETWARE | ||
| 231 | if (err) printf("ERROR: %d\n", err); | ||
| 232 | #endif | ||
| 200 | EXIT(err); | 233 | EXIT(err); |
| 201 | return(0); | 234 | return(0); |
| 202 | } | 235 | } |
