3 # define for pentium pro friendly version
5 push(@INC,"perlasm","../../perlasm");
8 &asm_init($ARGV[0],"rc4-586.pl");
24 local($n,$p,$char)=@_;
34 &jbe(&label("finished"));
42 &jb(&label("finished"));
47 # &mov( $tx, &DWP(0,$d,$x,4)) if $p < 0;
51 &inc( $x); # NEXT ROUND
52 &mov( $ty, &DWP(0,$d,$y,4));
54 &mov( &DWP(-4,$d,$x,4),$ty); # AGI
56 &and( $x, 0xff); # NEXT ROUND
58 &mov( &DWP(0,$d,$y,4),$tx);
60 &mov( $ty, &DWP(0,$d,$ty,4));
61 &mov( $tx, &DWP(0,$d,$x,4)) if $p < 1; # NEXT ROUND
66 #moved up into last round
71 &movb( &BP($n,"esp","",0), &LB($ty));
75 # Note in+=8 has occured
76 &movb( &HB($ty), &BP(-1,$in,"",0));
78 &xorb(&LB($ty), &HB($ty));
80 &movb(&BP($n,$out,"",0),&LB($ty));
89 &function_begin_B($name,"");
91 &mov($ty,&wparam(1)); # len
93 &jne(&label("proceed"));
95 &set_label("proceed");
103 &mov( $d, &wparam(0)); # key
104 &mov( $in, &wparam(2));
106 &mov( $x, &DWP(0,$d,"",1));
107 &mov( $y, &DWP(4,$d,"",1));
109 &mov( $out, &wparam(3));
112 &stack_push(3); # 3 temp variables
116 # detect compressed schedule, see commentary section in rc4_skey.c...
117 &cmp(&DWP(256,$d),-1);
118 &je(&label("RC4_CHAR"));
120 &lea( $ty, &DWP(-8,$ty,$in));
122 # check for 0 length input
124 &mov( &swtmp(2), $ty); # this is now address to exit at
125 &mov( $tx, &DWP(0,$d,$x,4));
128 &jb( &label("end")); # less than 8 bytes
144 &comment("apply the cipher text");
145 # xor the cipher data with input
147 #&add( $out, 8); #moved up into last round
149 &mov( $tx, &swtmp(0));
150 &mov( $ty, &DWP(-8,$in,"",0));
152 &mov( $ty, &DWP(-4,$in,"",0));
153 &mov( &DWP(-8,$out,"",0), $tx);
154 &mov( $tx, &swtmp(1));
156 &mov( $ty, &swtmp(2)); # load end ptr;
157 &mov( &DWP(-4,$out,"",0), $tx);
158 &mov( $tx, &DWP(0,$d,$x,4));
160 &jbe(&label("start"));
164 # There is quite a bit of extra crap in RC4_loop() for this
174 &jmp(&label("finished"));
177 # this is essentially Intel P4 specific codepath, see rc4_skey.c...
178 &set_label("RC4_CHAR");
180 &lea ($ty,&DWP(0,$in,$ty));
181 &mov (&swtmp(2),$ty);
183 # strangely enough unrolled loop performs over 20% slower...
184 &set_label("RC4_CHAR_loop");
185 &movz ($tx,&BP(0,$d,$x));
186 &add (&LB($y),&LB($tx));
187 &movz ($ty,&BP(0,$d,$y));
188 &movb (&BP(0,$d,$y),&LB($tx));
189 &movb (&BP(0,$d,$x),&LB($ty));
190 &add (&LB($ty),&LB($tx));
191 &movz ($ty,&BP(0,$d,$ty));
192 &xorb (&LB($ty),&BP(0,$in));
193 &movb (&BP(0,$out),&LB($ty));
197 &cmp ($in,&swtmp(2));
198 &jb (&label("RC4_CHAR_loop"));
200 &set_label("finished");
203 &mov( &DWP(-4,$d,"",0),$y);
204 &movb( &BP(-8,$d,"",0),&LB($x));
206 &function_end($name);