From cd4416e7e518d266f0c17e26a4866de8c508264c Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 18 Jun 2016 10:58:21 +0200 Subject: [PATCH] another test case for simple authenticator --- transport/internet/kcp/crypt_test.go | 13 +++++++++++++ transport/internet/kcp/xor_amd64.s | 15 +++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/transport/internet/kcp/crypt_test.go b/transport/internet/kcp/crypt_test.go index 8431dcc9c..174d4e8fa 100644 --- a/transport/internet/kcp/crypt_test.go +++ b/transport/internet/kcp/crypt_test.go @@ -22,6 +22,19 @@ func TestSimpleAuthenticator(t *testing.T) { assert.Bytes(buffer.Value).Equals([]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}) } +func TestSimpleAuthenticator2(t *testing.T) { + assert := assert.On(t) + + buffer := alloc.NewBuffer().Clear() + buffer.AppendBytes('1', '2') + + auth := NewSimpleAuthenticator() + auth.Seal(buffer) + + assert.Bool(auth.Open(buffer)).IsTrue() + assert.Bytes(buffer.Value).Equals([]byte{'1', '2'}) +} + func BenchmarkSimpleAuthenticator(b *testing.B) { buffer := alloc.NewBuffer().Clear() buffer.Slice(0, 1024) diff --git a/transport/internet/kcp/xor_amd64.s b/transport/internet/kcp/xor_amd64.s index f038a1479..f06942660 100644 --- a/transport/internet/kcp/xor_amd64.s +++ b/transport/internet/kcp/xor_amd64.s @@ -8,14 +8,15 @@ TEXT ·xorfwd(SB),NOSPLIT,$0 ADDQ $4, DI // x[i+4] SUBQ $4, CX loop: - CMPL CX, $0 - JE done - MOVL (SI), AX XORL AX, (DI) ADDQ $4, SI ADDQ $4, DI SUBQ $4, CX + + CMPL CX, $0 + JE done + JMP loop done: RET @@ -31,14 +32,16 @@ TEXT ·xorbkd(SB),NOSPLIT,$0 SUBQ $4, DI SUBQ $4, CX loop: - CMPL CX, $0 - JE done - MOVL (SI), AX XORL AX, (DI) SUBQ $4, SI SUBQ $4, DI SUBQ $4, CX + + CMPL CX, $0 + JE done + JMP loop + done: RET