1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build !nacl 6 7 #include "textflag.h" 8 9 // Registers 10 #define Rdst R0 11 #define Rsrc R1 12 #define Rn R2 13 #define Rstate R3 14 #define Rpi R4 15 #define Rpj R5 16 #define Ri R6 17 #define Rj R7 18 #define Rk R8 19 #define Rt R11 20 #define Rt2 R12 21 22 // func xorKeyStream(dst, src *byte, n int, state *[256]byte, i, j *uint8) 23 TEXT xorKeyStream(SB),NOSPLIT,$0 24 MOVW dst+0(FP), Rdst 25 MOVW src+4(FP), Rsrc 26 MOVW n+8(FP), Rn 27 MOVW state+12(FP), Rstate 28 MOVW pi+16(FP), Rpi 29 MOVW pj+20(FP), Rpj 30 MOVBU (Rpi), Ri 31 MOVBU (Rpj), Rj 32 MOVW $0, Rk 33 34 loop: 35 // i += 1; j += state[i] 36 ADD $1, Ri 37 AND $0xff, Ri 38 MOVBU Ri<<2(Rstate), Rt 39 ADD Rt, Rj 40 AND $0xff, Rj 41 42 // swap state[i] <-> state[j] 43 MOVBU Rj<<2(Rstate), Rt2 44 MOVB Rt2, Ri<<2(Rstate) 45 MOVB Rt, Rj<<2(Rstate) 46 47 // dst[k] = src[k] ^ state[state[i] + state[j]] 48 ADD Rt2, Rt 49 AND $0xff, Rt 50 MOVBU Rt<<2(Rstate), Rt 51 MOVBU Rk<<0(Rsrc), Rt2 52 EOR Rt, Rt2 53 MOVB Rt2, Rk<<0(Rdst) 54 55 ADD $1, Rk 56 CMP Rk, Rn 57 BNE loop 58 59 done: 60 MOVB Ri, (Rpi) 61 MOVB Rj, (Rpj) 62 RET 63