1221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#!/usr/bin/env perl 2221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 3221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# ==================================================================== 4221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# [Re]written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL 5221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# project. The module is, however, dual licensed under OpenSSL and 6221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# CRYPTOGAMS licenses depending on where you obtain it. For further 7221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# details see http://www.openssl.org/~appro/cryptogams/. 8221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# ==================================================================== 9656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 10656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# At some point it became apparent that the original SSLeay RC4 11221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# assembler implementation performs suboptimally on latest IA-32 12656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# microarchitectures. After re-tuning performance has changed as 13656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# following: 14656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# 15221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# Pentium -10% 16221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# Pentium III +12% 17221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# AMD +50%(*) 18221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# P4 +250%(**) 19656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# 20656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# (*) This number is actually a trade-off:-) It's possible to 21656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# achieve +72%, but at the cost of -48% off PIII performance. 22656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# In other words code performing further 13% faster on AMD 23656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# would perform almost 2 times slower on Intel PIII... 24656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# For reference! This code delivers ~80% of rc4-amd64.pl 25656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# performance on the same Opteron machine. 26656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# (**) This number requires compressed key schedule set up by 27221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# RC4_set_key [see commentary below for further details]. 28656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# 29656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# <appro@fy.chalmers.se> 30656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 31392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# May 2011 32392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# 33392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Optimize for Core2 and Westmere [and incidentally Opteron]. Current 34392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# performance in cycles per processed byte (less is better) and 35392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# improvement relative to previous version of this module is: 36392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# 37392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Pentium 10.2 # original numbers 38392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Pentium III 7.8(*) 39392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Intel P4 7.5 40392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# 41392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Opteron 6.1/+20% # new MMX numbers 42392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Core2 5.3/+67%(**) 43392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Westmere 5.1/+94%(**) 44392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Sandy Bridge 5.0/+8% 45392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# Atom 12.6/+6% 46392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# 47392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# (*) PIII can actually deliver 6.6 cycles per byte with MMX code, 48392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# but this specific code performs poorly on Core2. And vice 49392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# versa, below MMX/SSE code delivering 5.8/7.1 on Core2 performs 50392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# poorly on PIII, at 8.0/14.5:-( As PIII is not a "hot" CPU 51392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# [anymore], I chose to discard PIII-specific code path and opt 52392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# for original IALU-only code, which is why MMX/SSE code path 53392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# is guarded by SSE2 bit (see below), not MMX/SSE. 54392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# (**) Performance vs. block size on Core2 and Westmere had a maximum 55392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# at ... 64 bytes block size. And it was quite a maximum, 40-60% 56392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# in comparison to largest 8KB block size. Above improvement 57392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom# coefficients are for the largest block size. 58392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 59221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; 60221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrompush(@INC,"${dir}","${dir}../../perlasm"); 61656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectrequire "x86asm.pl"; 62656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 63656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project&asm_init($ARGV[0],"rc4-586.pl"); 64656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 65221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$xx="eax"; 66221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$yy="ebx"; 67656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$tx="ecx"; 68656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$ty="edx"; 69221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$inp="esi"; 70221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$out="ebp"; 71221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$dat="edi"; 72221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 73221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromsub RC4_loop { 74221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom my $i=shift; 75221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom my $func = ($i==0)?*mov:*or; 76221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 77221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($yy),&LB($tx)); 78221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($ty,&DWP(0,$dat,$yy,4)); 79221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$dat,$yy,4),$tx); 80221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$dat,$xx,4),$ty); 81221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add ($ty,$tx); 82221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &inc (&LB($xx)); 83221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &and ($ty,0xff); 84221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &ror ($out,8) if ($i!=0); 85221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom if ($i<3) { 86221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($tx,&DWP(0,$dat,$xx,4)); 87221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom } else { 88221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($tx,&wparam(3)); # reload [re-biased] out 89656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 90221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &$func ($out,&DWP(0,$dat,$ty,4)); 91221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom} 92221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 93392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstromif ($alt=0) { 94392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # >20% faster on Atom and Sandy Bridge[!], 8% faster on Opteron, 95392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # but ~40% slower on Core2 and Westmere... Attempt to add movz 96392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # brings down Opteron by 25%, Atom and Sandy Bridge by 15%, yet 97392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # on Core2 with movz it's almost 20% slower than below alternative 98392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # code... Yes, it's a total mess... 99392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom my @XX=($xx,$out); 100392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $RC4_loop_mmx = sub { # SSE actually... 101392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom my $i=shift; 102392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom my $j=$i<=0?0:$i>>1; 103392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom my $mm=$i<=0?"mm0":"mm".($i&1); 104392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 105392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &add (&LB($yy),&LB($tx)); 106392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &lea (@XX[1],&DWP(1,@XX[0])); 107392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm2","mm0") if ($i==0); 108392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &psllq ("mm1",8) if ($i==0); 109392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &and (@XX[1],0xff); 110392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm0","mm0") if ($i<=0); 111392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov ($ty,&DWP(0,$dat,$yy,4)); 112392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&DWP(0,$dat,$yy,4),$tx); 113392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm1","mm2") if ($i==0); 114392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&DWP(0,$dat,$XX[0],4),$ty); 115392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &add (&LB($ty),&LB($tx)); 116392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movd (@XX[0],"mm7") if ($i==0); 117392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov ($tx,&DWP(0,$dat,@XX[1],4)); 118392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm1","mm1") if ($i==1); 119392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movq ("mm2",&QWP(0,$inp)) if ($i==1); 120392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movq (&QWP(-8,(@XX[0],$inp)),"mm1") if ($i==0); 121392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pinsrw ($mm,&DWP(0,$dat,$ty,4),$j); 122392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 123392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom push (@XX,shift(@XX)) if ($i>=0); 124392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom } 125392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom} else { 126392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # Using pinsrw here improves performane on Intel CPUs by 2-3%, but 127392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # brings down AMD by 7%... 128392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom $RC4_loop_mmx = sub { 129392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom my $i=shift; 130392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 131392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &add (&LB($yy),&LB($tx)); 132392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &psllq ("mm1",8*(($i-1)&7)) if (abs($i)!=1); 133392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov ($ty,&DWP(0,$dat,$yy,4)); 134392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&DWP(0,$dat,$yy,4),$tx); 135392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&DWP(0,$dat,$xx,4),$ty); 136392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &inc ($xx); 137392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &add ($ty,$tx); 138392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movz ($xx,&LB($xx)); # (*) 139392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movz ($ty,&LB($ty)); # (*) 140392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm2",$i==1?"mm0":"mm1") if ($i>=0); 141392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movq ("mm0",&QWP(0,$inp)) if ($i<=0); 142392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movq (&QWP(-8,($out,$inp)),"mm2") if ($i==0); 143392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov ($tx,&DWP(0,$dat,$xx,4)); 144392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movd ($i>0?"mm1":"mm2",&DWP(0,$dat,$ty,4)); 145392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 146392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # (*) This is the key to Core2 and Westmere performance. 147392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # Whithout movz out-of-order execution logic confuses 148392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # itself and fails to reorder loads and stores. Problem 149392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom # appears to be fixed in Sandy Bridge... 150392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom } 151392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom} 152392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 153392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom&external_label("OPENSSL_ia32cap_P"); 154392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 155221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# void RC4(RC4_KEY *key,size_t len,const unsigned char *inp,unsigned char *out); 156221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&function_begin("RC4"); 157221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($dat,&wparam(0)); # load key schedule pointer 158221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($ty, &wparam(1)); # load len 159221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($inp,&wparam(2)); # load inp 160221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($out,&wparam(3)); # load out 161221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 162221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ($xx,$xx); # avoid partial register stalls 163221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ($yy,$yy); 164221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 165221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &cmp ($ty,0); # safety net 166221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &je (&label("abort")); 167221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 168221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&LB($xx),&BP(0,$dat)); # load key->x 169221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&LB($yy),&BP(4,$dat)); # load key->y 170221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add ($dat,8); 171221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 172221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ($tx,&DWP(0,$inp,$ty)); 173221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &sub ($out,$inp); # re-bias out 174221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&wparam(1),$tx); # save input+len 175221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 176221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &inc (&LB($xx)); 177221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 178221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom # detect compressed key schedule... 179221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &cmp (&DWP(256,$dat),-1); 180221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &je (&label("RC4_CHAR")); 181221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 182221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($tx,&DWP(0,$dat,$xx,4)); 183221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 184221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &and ($ty,-4); # how many 4-byte chunks? 185221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jz (&label("loop1")); 186221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 187392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &test ($ty,-8); 188392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&wparam(3),$out); # $out as accumulator in these loops 189392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &jz (&label("go4loop4")); 190392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 191392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &picmeup($out,"OPENSSL_ia32cap_P"); 192392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &bt (&DWP(0,$out),26); # check SSE2 bit [could have been MMX] 193392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &jnc (&label("go4loop4")); 194392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 195392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov ($out,&wparam(3)) if (!$alt); 196392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movd ("mm7",&wparam(3)) if ($alt); 197392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &and ($ty,-8); 198392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &lea ($ty,&DWP(-8,$inp,$ty)); 199392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&DWP(-4,$dat),$ty); # save input+(len/8)*8-8 200392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 201392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &$RC4_loop_mmx(-1); 202392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &jmp(&label("loop_mmx_enter")); 203392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 204392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &set_label("loop_mmx",16); 205392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &$RC4_loop_mmx(0); 206392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &set_label("loop_mmx_enter"); 207392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom for ($i=1;$i<8;$i++) { &$RC4_loop_mmx($i); } 208392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov ($ty,$yy); 209392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &xor ($yy,$yy); # this is second key to Core2 210392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&LB($yy),&LB($ty)); # and Westmere performance... 211392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &cmp ($inp,&DWP(-4,$dat)); 212392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &lea ($inp,&DWP(8,$inp)); 213392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &jb (&label("loop_mmx")); 214392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 215392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom if ($alt) { 216392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movd ($out,"mm7"); 217392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm2","mm0"); 218392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &psllq ("mm1",8); 219392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm1","mm2"); 220392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movq (&QWP(-8,$out,$inp),"mm1"); 221392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom } else { 222392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &psllq ("mm1",56); 223392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &pxor ("mm2","mm1"); 224392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &movq (&QWP(-8,$out,$inp),"mm2"); 225392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom } 226392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &emms (); 227392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 228392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &cmp ($inp,&wparam(1)); # compare to input+len 229392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &je (&label("done")); 230392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &jmp (&label("loop1")); 231392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 232392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom&set_label("go4loop4",16); 233221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ($ty,&DWP(-4,$inp,$ty)); 234221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&wparam(2),$ty); # save input+(len/4)*4-4 235221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 236392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &set_label("loop4"); 237221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom for ($i=0;$i<4;$i++) { RC4_loop($i); } 238221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &ror ($out,8); 239221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ($out,&DWP(0,$inp)); 240221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &cmp ($inp,&wparam(2)); # compare to input+(len/4)*4-4 241221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$tx,$inp),$out);# $tx holds re-biased out here 242221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ($inp,&DWP(4,$inp)); 243221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($tx,&DWP(0,$dat,$xx,4)); 244221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jb (&label("loop4")); 245221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 246221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &cmp ($inp,&wparam(1)); # compare to input+len 247221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &je (&label("done")); 248221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($out,&wparam(3)); # restore $out 249221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 250221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &set_label("loop1",16); 251221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($yy),&LB($tx)); 252221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($ty,&DWP(0,$dat,$yy,4)); 253221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$dat,$yy,4),$tx); 254221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$dat,$xx,4),$ty); 255221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add ($ty,$tx); 256221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &inc (&LB($xx)); 257221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &and ($ty,0xff); 258221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($ty,&DWP(0,$dat,$ty,4)); 259221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor (&LB($ty),&BP(0,$inp)); 260221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ($inp,&DWP(1,$inp)); 261221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($tx,&DWP(0,$dat,$xx,4)); 262221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &cmp ($inp,&wparam(1)); # compare to input+len 263221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(-1,$out,$inp),&LB($ty)); 264221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jb (&label("loop1")); 265221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 266221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jmp (&label("done")); 267221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 268221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# this is essentially Intel P4 specific codepath... 269221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("RC4_CHAR",16); 270221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &movz ($tx,&BP(0,$dat,$xx)); 271656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project # strangely enough unrolled loop performs over 20% slower... 272221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &set_label("cloop1"); 273221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($yy),&LB($tx)); 274221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &movz ($ty,&BP(0,$dat,$yy)); 275221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(0,$dat,$yy),&LB($tx)); 276221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(0,$dat,$xx),&LB($ty)); 277656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project &add (&LB($ty),&LB($tx)); 278221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &movz ($ty,&BP(0,$dat,$ty)); 279221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($xx),1); 280221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor (&LB($ty),&BP(0,$inp)); 281221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ($inp,&DWP(1,$inp)); 282221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &movz ($tx,&BP(0,$dat,$xx)); 283221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &cmp ($inp,&wparam(1)); 284221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(-1,$out,$inp),&LB($ty)); 285221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jb (&label("cloop1")); 286221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 287221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("done"); 288221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &dec (&LB($xx)); 289392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov (&DWP(-4,$dat),$yy); # save key->y 290221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(-8,$dat),&LB($xx)); # save key->x 291221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("abort"); 292221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&function_end("RC4"); 293221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 294221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom######################################################################## 295221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 296221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$inp="esi"; 297221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$out="edi"; 298221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$idi="ebp"; 299221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$ido="ecx"; 300221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom$idx="edx"; 301221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 302221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# void RC4_set_key(RC4_KEY *key,int len,const unsigned char *data); 303392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom&function_begin("private_RC4_set_key"); 304221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($out,&wparam(0)); # load key 305221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($idi,&wparam(1)); # load len 306221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($inp,&wparam(2)); # load data 307221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &picmeup($idx,"OPENSSL_ia32cap_P"); 308221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 309221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ($out,&DWP(2*4,$out)); # &key->data 310221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ($inp,&DWP(0,$inp,$idi)); # $inp to point at the end 311221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &neg ($idi); 312221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ("eax","eax"); 313221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(-4,$out),$idi); # borrow key->y 314221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 315221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &bt (&DWP(0,$idx),20); # check for bit#20 316221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jc (&label("c1stloop")); 317221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 318221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("w1stloop",16); 319221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$out,"eax",4),"eax"); # key->data[i]=i; 320221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB("eax"),1); # i++; 321221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jnc (&label("w1stloop")); 322221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 323221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ($ido,$ido); 324221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ($idx,$idx); 325221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 326221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("w2ndloop",16); 327221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ("eax",&DWP(0,$out,$ido,4)); 328221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($idx),&BP(0,$inp,$idi)); 329221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($idx),&LB("eax")); 330221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add ($idi,1); 331221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ("ebx",&DWP(0,$out,$idx,4)); 332221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jnz (&label("wnowrap")); 333221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($idi,&DWP(-4,$out)); 334221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &set_label("wnowrap"); 335221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$out,$idx,4),"eax"); 336221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(0,$out,$ido,4),"ebx"); 337221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($ido),1); 338221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jnc (&label("w2ndloop")); 339221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&jmp (&label("exit")); 340221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 341221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# Unlike all other x86 [and x86_64] implementations, Intel P4 core 342221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# [including EM64T] was found to perform poorly with above "32-bit" key 343221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# schedule, a.k.a. RC4_INT. Performance improvement for IA-32 hand-coded 344221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# assembler turned out to be 3.5x if re-coded for compressed 8-bit one, 345221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# a.k.a. RC4_CHAR! It's however inappropriate to just switch to 8-bit 346221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# schedule for x86[_64], because non-P4 implementations suffer from 347221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# significant performance losses then, e.g. PIII exhibits >2x 348221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# deterioration, and so does Opteron. In order to assure optimal 349221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# all-round performance, we detect P4 at run-time and set up compressed 350221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# key schedule, which is recognized by RC4 procedure. 351221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 352221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("c1stloop",16); 353221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(0,$out,"eax"),&LB("eax")); # key->data[i]=i; 354221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB("eax"),1); # i++; 355221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jnc (&label("c1stloop")); 356221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 357221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ($ido,$ido); 358221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ($idx,$idx); 359221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ("ebx","ebx"); 360221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 361221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("c2ndloop",16); 362221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&LB("eax"),&BP(0,$out,$ido)); 363221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($idx),&BP(0,$inp,$idi)); 364221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($idx),&LB("eax")); 365221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add ($idi,1); 366221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&LB("ebx"),&BP(0,$out,$idx)); 367221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jnz (&label("cnowrap")); 368221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov ($idi,&DWP(-4,$out)); 369221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &set_label("cnowrap"); 370221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(0,$out,$idx),&LB("eax")); 371221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&BP(0,$out,$ido),&LB("ebx")); 372221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &add (&LB($ido),1); 373221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &jnc (&label("c2ndloop")); 374221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 375221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(256,$out),-1); # mark schedule as compressed 376221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 377221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("exit"); 378221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &xor ("eax","eax"); 379221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(-8,$out),"eax"); # key->x=0; 380221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &mov (&DWP(-4,$out),"eax"); # key->y=0; 381392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom&function_end("private_RC4_set_key"); 382221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 383221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom# const char *RC4_options(void); 384221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&function_begin_B("RC4_options"); 385221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &call (&label("pic_point")); 386221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("pic_point"); 387221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &blindpop("eax"); 388221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &lea ("eax",&DWP(&label("opts")."-".&label("pic_point"),"eax")); 389221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &picmeup("edx","OPENSSL_ia32cap_P"); 390392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &mov ("edx",&DWP(0,"edx")); 391392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &bt ("edx",20); 392392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &jc (&label("1xchar")); 393392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &bt ("edx",26); 394392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &jnc (&label("ret")); 395392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &add ("eax",25); 396392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &ret (); 397392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom&set_label("1xchar"); 398392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom &add ("eax",12); 399392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom&set_label("ret"); 400221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom &ret (); 401221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&set_label("opts",64); 402221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&asciz ("rc4(4x,int)"); 403221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&asciz ("rc4(1x,char)"); 404392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom&asciz ("rc4(8x,mmx)"); 405221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&asciz ("RC4 for x86, CRYPTOGAMS by <appro\@openssl.org>"); 406221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&align (64); 407221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&function_end_B("RC4_options"); 408221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom 409221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom&asm_finish(); 410656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 411