2 # Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # ====================================================================
11 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
12 # project. The module is, however, dual licensed under OpenSSL and
13 # CRYPTOGAMS licenses depending on where you obtain it. For further
14 # details see http://www.openssl.org/~appro/cryptogams/.
15 # ====================================================================
21 # RC4 subroutine processes one byte in 7.0 cycles, which is 3x faster
22 # than TI CGT-generated code. Loop is scheduled in such way that
23 # there is only one reference to memory in each cycle. This is done
24 # to avoid L1D memory banking conflicts, see SPRU871 TI publication
25 # for further details. Otherwise it should be possible to schedule
26 # the loop for iteration interval of 6...
28 ($KEY,$LEN,$INP,$OUT)=("A4","B4","A6","B6");
30 ($KEYA,$XX,$TY,$xx,$ONE,$ret)=map("A$_",(5,7,8,9,1,2));
31 ($KEYB,$YY,$TX,$tx,$SUM,$dat)=map("B$_",(5,7,8,9,1,2));
36 .if .ASSEMBLER_VERSION<7000000
42 .asg RC4_set_key,_RC4_set_key
43 .asg RC4_options,_RC4_options
51 [!B0] BNOP B3 ; if (len==0) return;
52 ||[B0] ADD $KEY,2,$KEYA
53 ||[B0] ADD $KEY,2,$KEYB
55 ||[B0] LDBU *${KEYA}[-2],$XX ; key->x
56 [B0] LDBU *${KEYB}[-1],$YY ; key->y
60 LDBU *${KEYA}[$XX],$TX
63 ;;==================================================
67 LDBU *${KEYB}[$YY],$TY
70 LDBU *${KEYA}[$XX],$tx
74 ||[B0] ADD4 $TX,$YY,$YY
76 ||[!B0] ADD4 $tx,$YY,$YY
78 ADD4 $TY,$TX,$SUM ; [0,0] $TX is not replaced by $tx yet!
82 LDBU *${KEYB}[$SUM],$ret
87 ;;==================================================
90 STB $XX,*${KEYA}[-2] ; key->x
93 STB $YY,*${KEYB}[-1] ; key->y
105 || MVKH 0x00010000,B0
110 || MVKH 0x03020000,B0
114 || ADD $INP,$LEN,$ret ; end of input
117 STH $TX,*${KEY}++ ; key->x=key->y=0
121 ;;==================================================
128 ;;==================================================
135 ;;==================================================
140 || CMPEQ $INP,$ret,A0 ; end of input?
141 LDBU *${KEYB}[$YY],$TY
144 LDBU *${KEYA}[$XX],$tx
145 ||[A0] SUB $INP,$LEN,$INP ; rewind
149 STB $TX,*${KEYB}[$YY]
150 ||[B0] ADD4 $TX,$YY,$YY
151 STB $TY,*${KEYA}[$xx]
152 ||[!B0] ADD4 $tx,$YY,$YY
155 ;;==================================================
166 ADDKPC _rc4_options,B4
168 MVKL \$PCR_OFFSET(rc4_options,_rc4_options),A4
169 MVKH \$PCR_OFFSET(rc4_options,_rc4_options),A4
171 MVKL (rc4_options-_rc4_options),A4
172 MVKH (rc4_options-_rc4_options),A4
178 .sect ".text:rc4_options.const"
180 .sect ".const:rc4_options"
184 .cstring "rc4(sploop,char)"
185 .cstring "RC4 for C64+, CRYPTOGAMS by <appro\@openssl.org>"
189 $output = pop and open STDOUT,">$output";
191 close STDOUT or die "error closing STDOUT";