summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rc4/asm
diff options
context:
space:
mode:
authorjsing <>2024-03-28 01:49:29 +0000
committerjsing <>2024-03-28 01:49:29 +0000
commitefdc2fdd7e31b41f518a70445b050722a765ff02 (patch)
treeca5f083b55057a8157b330fc459a97936af57f81 /src/lib/libcrypto/rc4/asm
parent852ce4f4fa6a26ebd4801907061f85fb0c1f4e99 (diff)
downloadopenbsd-efdc2fdd7e31b41f518a70445b050722a765ff02.tar.gz
openbsd-efdc2fdd7e31b41f518a70445b050722a765ff02.tar.bz2
openbsd-efdc2fdd7e31b41f518a70445b050722a765ff02.zip
Use C functions for RC4 public API.
Rather than having public API switch between C and assembly, always use C functions as entry points, which then call an assembly implementation (if available). This makes it significantly easier to deal with symbol aliasing/namespaces and it also means we benefit from vulnerability prevention provided by the C compiler. Rename the assembly generated functions from RC4() to rc4_internal() and RC4_set_key() to rc4_set_key_internal(). Always include rc4.c and change it to use defines that are similar to those used in BN. ok beck@ joshua@ tb@
Diffstat (limited to 'src/lib/libcrypto/rc4/asm')
-rw-r--r--src/lib/libcrypto/rc4/asm/rc4-586.pl13
-rwxr-xr-xsrc/lib/libcrypto/rc4/asm/rc4-x86_64.pl16
2 files changed, 15 insertions, 14 deletions
diff --git a/src/lib/libcrypto/rc4/asm/rc4-586.pl b/src/lib/libcrypto/rc4/asm/rc4-586.pl
index bb30f9b88f..8fffe91e74 100644
--- a/src/lib/libcrypto/rc4/asm/rc4-586.pl
+++ b/src/lib/libcrypto/rc4/asm/rc4-586.pl
@@ -152,8 +152,9 @@ if ($alt=0) {
152 152
153&external_label("OPENSSL_ia32cap_P"); 153&external_label("OPENSSL_ia32cap_P");
154 154
155# void RC4(RC4_KEY *key,size_t len,const unsigned char *inp,unsigned char *out); 155# void rc4_internal(RC4_KEY *key, size_t len, const unsigned char *inp,
156&function_begin("RC4"); 156# unsigned char *out);
157&function_begin("rc4_internal");
157 &mov ($dat,&wparam(0)); # load key schedule pointer 158 &mov ($dat,&wparam(0)); # load key schedule pointer
158 &mov ($ty, &wparam(1)); # load len 159 &mov ($ty, &wparam(1)); # load len
159 &mov ($inp,&wparam(2)); # load inp 160 &mov ($inp,&wparam(2)); # load inp
@@ -291,7 +292,7 @@ if ($alt=0) {
291 &mov (&DWP(-4,$dat),$yy); # save key->y 292 &mov (&DWP(-4,$dat),$yy); # save key->y
292 &mov (&BP(-8,$dat),&LB($xx)); # save key->x 293 &mov (&BP(-8,$dat),&LB($xx)); # save key->x
293&set_label("abort"); 294&set_label("abort");
294&function_end("RC4"); 295&function_end("rc4_internal");
295 296
296######################################################################## 297########################################################################
297 298
@@ -301,8 +302,8 @@ $idi="ebp";
301$ido="ecx"; 302$ido="ecx";
302$idx="edx"; 303$idx="edx";
303 304
304# void RC4_set_key(RC4_KEY *key,int len,const unsigned char *data); 305# void rc4_set_key_internal(RC4_KEY *key,int len,const unsigned char *data);
305&function_begin("RC4_set_key"); 306&function_begin("rc4_set_key_internal");
306 &mov ($out,&wparam(0)); # load key 307 &mov ($out,&wparam(0)); # load key
307 &mov ($idi,&wparam(1)); # load len 308 &mov ($idi,&wparam(1)); # load len
308 &mov ($inp,&wparam(2)); # load data 309 &mov ($inp,&wparam(2)); # load data
@@ -382,6 +383,6 @@ $idx="edx";
382 &xor ("eax","eax"); 383 &xor ("eax","eax");
383 &mov (&DWP(-8,$out),"eax"); # key->x=0; 384 &mov (&DWP(-8,$out),"eax"); # key->x=0;
384 &mov (&DWP(-4,$out),"eax"); # key->y=0; 385 &mov (&DWP(-4,$out),"eax"); # key->y=0;
385&function_end("RC4_set_key"); 386&function_end("rc4_set_key_internal");
386 387
387&asm_finish(); 388&asm_finish();
diff --git a/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl b/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl
index a9cf9d1bdf..4dfce6a9ad 100755
--- a/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl
+++ b/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl
@@ -124,10 +124,10 @@ $code=<<___;
124.extern OPENSSL_ia32cap_P 124.extern OPENSSL_ia32cap_P
125.hidden OPENSSL_ia32cap_P 125.hidden OPENSSL_ia32cap_P
126 126
127.globl RC4 127.globl rc4_internal
128.type RC4,\@function,4 128.type rc4_internal,\@function,4
129.align 16 129.align 16
130RC4: 130rc4_internal:
131 _CET_ENDBR 131 _CET_ENDBR
132 or $len,$len 132 or $len,$len
133 jne .Lentry 133 jne .Lentry
@@ -423,7 +423,7 @@ $code.=<<___;
423 add \$24,%rsp 423 add \$24,%rsp
424.Lepilogue: 424.Lepilogue:
425 ret 425 ret
426.size RC4,.-RC4 426.size rc4_internal,.-rc4_internal
427___ 427___
428} 428}
429 429
@@ -431,10 +431,10 @@ $idx="%r8";
431$ido="%r9"; 431$ido="%r9";
432 432
433$code.=<<___; 433$code.=<<___;
434.globl RC4_set_key 434.globl rc4_set_key_internal
435.type RC4_set_key,\@function,3 435.type rc4_set_key_internal,\@function,3
436.align 16 436.align 16
437RC4_set_key: 437rc4_set_key_internal:
438 _CET_ENDBR 438 _CET_ENDBR
439 lea 8($dat),$dat 439 lea 8($dat),$dat
440 lea ($inp,$len),$inp 440 lea ($inp,$len),$inp
@@ -502,7 +502,7 @@ RC4_set_key:
502 mov %eax,-8($dat) 502 mov %eax,-8($dat)
503 mov %eax,-4($dat) 503 mov %eax,-4($dat)
504 ret 504 ret
505.size RC4_set_key,.-RC4_set_key 505.size rc4_set_key_internal,.-rc4_set_key_internal
506___ 506___
507 507
508sub reg_part { 508sub reg_part {