Ver código fonte

another test case for simple authenticator

v2ray 9 anos atrás
pai
commit
cd4416e7e5

+ 13 - 0
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)

+ 9 - 6
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