Browse Source

Add more documentation in the form of comments.

Yawning Angel 4 years ago
parent
commit
2930c076e9
2 changed files with 28 additions and 7 deletions
  1. 12 3
      crypto/identity/identity.go
  2. 16 4
      handshake/obfuscation.go

+ 12 - 3
crypto/identity/identity.go

@@ -29,16 +29,24 @@ import (
 )
 
 const (
+	// SharedSecretSize is the side of a ECDH shared secret in bytes.
 	SharedSecretSize = 32
-	PublicKeySize    = ed25519.PublicKeySize
-	PrivateKeySize   = ed25519.PrivateKeySize
-	SignatureSize    = ed25519.SignatureSize
+
+	// PublicKeySize is the side of a PublicKey in bytes.
+	PublicKeySize = ed25519.PublicKeySize
+
+	// PrivateKeySize is the size of a PrivateKey in bytes.
+	PrivateKeySize = ed25519.PrivateKeySize
+
+	// SignatureSize is the size of a Signature in bytes.
+	SignatureSize = ed25519.SignatureSize
 
 	maxKeygenAttempts = 8
 )
 
 var identityRandTweak = []byte("basket2-identity-tweak")
 
+// PrivateKey is a EdDSA private key and it's X25519 counterpart.
 type PrivateKey struct {
 	PublicKey
 	DSAPrivateKey *[PrivateKeySize]byte
@@ -96,6 +104,7 @@ func NewPrivateKey(rand io.Reader) (*PrivateKey, error) {
 	panic("crypto/identity: failed to generate keypair, broken rng?")
 }
 
+// PublicKey is a EdDSA public key and it's X25519 counterpart.
 type PublicKey struct {
 	DSAPublicKey *[PublicKeySize]byte
 	KEXPublicKey [PublicKeySize]byte

+ 16 - 4
handshake/obfuscation.go

@@ -44,11 +44,23 @@ var (
 	obfsKdfTweak   = []byte("basket2-obfs-v0-kdf-tweak")
 	obfsTransTweak = []byte("basket2-obfs-v0-transcript-tweak")
 
+	// ErrInvalidPoint is the error returned when the obfuscation crypto fails.
 	ErrInvalidPoint = errors.New("obfs: invalid point")
-	ErrInvalidCmd   = errors.New("obfs: invalid command")
-	ErrInvalidMark  = errors.New("obfs: client send invalid mark")
-	ErrReplay       = errors.New("obfs: client sent replayed handshake")
-	ErrNoPayload    = errors.New("obfs: no handshake paylaod")
+
+	// ErrInvalidCmd is the error returned on a invalid obfuscated handshake
+	// payload command.
+	ErrInvalidCmd = errors.New("obfs: invalid command")
+
+	// ErrInvalidMark is the error returned when the client mark is invalid.
+	ErrInvalidMark = errors.New("obfs: client send invalid mark")
+
+	// ErrReplay is the error returned when the client appears to be replaying
+	// a previously seen handshake.
+	ErrReplay = errors.New("obfs: client sent replayed handshake")
+
+	// ErrNoPayload is the error returned when the obfuscated handshake
+	// contains no payload.
+	ErrNoPayload = errors.New("obfs: no handshake paylaod")
 )
 
 // clientObfsCtx is the client handshake obfuscator state.