1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 23:06:14 -04:00
This commit is contained in:
Darien Raymond 2016-12-08 16:32:53 +01:00
parent 0917866f38
commit 1431e32d01
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 15 additions and 4 deletions

View File

@ -2,9 +2,9 @@ package kcp
import (
"crypto/cipher"
"errors"
"hash/fnv"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/serial"
)
@ -12,20 +12,25 @@ var (
errInvalidAuth = errors.New("Invalid auth.")
)
// SimpleAuthenticator is a legacy AEAD used for KCP encryption.
type SimpleAuthenticator struct{}
// NewSimpleAuthenticator creates a new SimpleAuthenticator
func NewSimpleAuthenticator() cipher.AEAD {
return &SimpleAuthenticator{}
}
// NonceSize implements cipher.AEAD.NonceSize().
func (v *SimpleAuthenticator) NonceSize() int {
return 0
}
// Overhead implements cipher.AEAD.NonceSize().
func (v *SimpleAuthenticator) Overhead() int {
return 6
}
// Seal implements cipher.AEAD.Seal().
func (v *SimpleAuthenticator) Seal(dst, nonce, plain, extra []byte) []byte {
dst = append(dst, 0, 0, 0, 0)
dst = serial.Uint16ToBytes(uint16(len(plain)), dst)
@ -47,6 +52,7 @@ func (v *SimpleAuthenticator) Seal(dst, nonce, plain, extra []byte) []byte {
return dst
}
// Open implements cipher.AEAD.Open().
func (v *SimpleAuthenticator) Open(dst, nonce, cipherText, extra []byte) ([]byte, error) {
dst = append(dst, cipherText...)
dstLen := len(dst)

View File

@ -6,13 +6,18 @@ import (
"v2ray.com/core/common/serial"
)
// Command is a KCP command that indicate the purpose of a Segment.
type Command byte
const (
CommandACK Command = 0
CommandData Command = 1
// CommandACK indicates a AckSegment.
CommandACK Command = 0
// CommandData indicates a DataSegment.
CommandData Command = 1
// CommandTerminate indicates that peer terminates the connection.
CommandTerminate Command = 2
CommandPing Command = 3
// CommandPing indicates a ping.
CommandPing Command = 3
)
type SegmentOption byte