3 # ====================================================================
4 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
5 # project. The module is, however, dual licensed under OpenSSL and
6 # CRYPTOGAMS licenses depending on where you obtain it. For further
7 # details see http://www.openssl.org/~appro/cryptogams/.
8 # ====================================================================
14 # RC4 subroutine processes one byte in 7.0 cycles, which is 3x faster
15 # than TI CGT-generated code. Loop is scheduled in such way that
16 # there is only one reference to memory in each cycle. This is done
17 # to avoid L1D memory banking conflicts, see SPRU871 TI publication
18 # for further details. Otherwise it should be possible to schedule
19 # the loop for iteration interval of 6...
21 ($KEY,$LEN,$INP,$OUT)=("A4","B4","A6","B6");
23 ($KEYA,$XX,$TY,$xx,$ONE,$ret)=map("A$_",(5,7,8,9,1,2));
24 ($KEYB,$YY,$TX,$tx,$SUM,$dat)=map("B$_",(5,7,8,9,1,2));
29 .if .ASSEMBLER_VERSION<7000000
35 .asg RC4_set_key,_RC4_set_key
36 .asg RC4_options,_RC4_options
44 [!B0] BNOP B3 ; if (len==0) return;
45 ||[B0] ADD $KEY,2,$KEYA
46 ||[B0] ADD $KEY,2,$KEYB
48 ||[B0] LDBU *${KEYA}[-2],$XX ; key->x
49 [B0] LDBU *${KEYB}[-1],$YY ; key->y
53 LDBU *${KEYA}[$XX],$TX
56 ;;==================================================
60 LDBU *${KEYB}[$YY],$TY
63 LDBU *${KEYA}[$XX],$tx
67 ||[B0] ADD4 $TX,$YY,$YY
69 ||[!B0] ADD4 $tx,$YY,$YY
71 ADD4 $TY,$TX,$SUM ; [0,0] $TX is not replaced by $tx yet!
75 LDBU *${KEYB}[$SUM],$ret
80 ;;==================================================
83 STB $XX,*${KEYA}[-2] ; key->x
86 STB $YY,*${KEYB}[-1] ; key->y
103 || MVKH 0x03020000,B0
107 || ADD $INP,$LEN,$ret ; end of input
110 STH $TX,*${KEY}++ ; key->x=key->y=0
114 ;;==================================================
121 ;;==================================================
128 ;;==================================================
133 || CMPEQ $INP,$ret,A0 ; end of input?
134 LDBU *${KEYB}[$YY],$TY
137 LDBU *${KEYA}[$XX],$tx
138 ||[A0] SUB $INP,$LEN,$INP ; rewind
142 STB $TX,*${KEYB}[$YY]
143 ||[B0] ADD4 $TX,$YY,$YY
144 STB $TY,*${KEYA}[$xx]
145 ||[!B0] ADD4 $tx,$YY,$YY
148 ;;==================================================
159 ADDKPC _rc4_options,B4
161 MVKL \$PCR_OFFSET(rc4_options,_rc4_options),A4
162 MVKH \$PCR_OFFSET(rc4_options,_rc4_options),A4
164 MVKL (rc4_options-_rc4_options),A4
165 MVKH (rc4_options-_rc4_options),A4
171 .sect ".text:rc4_options.const"
173 .sect ".const:rc4_options"
177 .cstring "rc4(sploop,char)"
178 .cstring "RC4 for C64+, CRYPTOGAMS by <appro\@openssl.org>"