github.com/flyinox/gosm@v0.0.0-20171117061539-16768cb62077/src/crypto/rc4/rc4_386.s (about)

     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  #include "textflag.h"
     6  
     7  // func xorKeyStream(dst, src *byte, n int, state *[256]byte, i, j *uint8)
     8  TEXT ·xorKeyStream(SB),NOSPLIT,$0
     9  	MOVL dst+0(FP), DI
    10  	MOVL src+4(FP), SI
    11  	MOVL state+12(FP), BP
    12  
    13  	MOVL i+16(FP), AX
    14  	MOVBLZX (AX), AX
    15  	MOVL j+20(FP), BX
    16  	MOVBLZX (BX), BX
    17  	CMPL n+8(FP), $0
    18  	JEQ done
    19  
    20  loop:
    21  	// i += 1
    22  	INCB AX
    23  
    24  	// j += c.s[i]
    25  	MOVBLZX (BP)(AX*4), DX
    26  	ADDB DX, BX
    27  	MOVBLZX BX, BX
    28  
    29  	// c.s[i], c.s[j] = c.s[j], c.s[i]
    30  	MOVBLZX (BP)(BX*4), CX
    31  	MOVB CX, (BP)(AX*4)
    32  	MOVB DX, (BP)(BX*4)
    33  
    34  	// *dst = *src ^ c.s[c.s[i]+c.s[j]]
    35  	ADDB DX, CX
    36  	MOVBLZX CX, CX
    37  	MOVB (BP)(CX*4), CX
    38  	XORB (SI), CX
    39  	MOVBLZX CX, CX
    40  	MOVB CX, (DI)
    41  
    42  	INCL SI
    43  	INCL DI
    44  	DECL n+8(FP)
    45  	JNE loop
    46  
    47  done:
    48  	MOVL i+16(FP), CX
    49  	MOVB AX, (CX)
    50  	MOVL j+20(FP), CX
    51  	MOVB BX, (CX)
    52  
    53  	RET