Browse Source

Move the obfs4 padding param generation code around a bit.

Yawning Angel 3 years ago
parent
commit
faf4ddb5b1
2 changed files with 15 additions and 8 deletions
  1. 2 8
      common.go
  2. 13 0
      padding_obfs4.go

+ 2 - 8
common.go

@@ -542,16 +542,10 @@ func paddingOk(needle PaddingMethod, haystack []PaddingMethod) bool {
 // padding method that requires parameterization.
 func DefaultPaddingParams(method PaddingMethod) ([]byte, error) {
 	switch method {
-	case PaddingNull:
+	case PaddingNull, PaddingTamaraw:
 		return nil, nil
 	case PaddingObfs4Burst, PaddingObfs4BurstIAT:
-		// This should be parameterized from persistent state, but allow
-		// random parametrization.
-		seed := make([]byte, Obfs4SeedLength)
-		if _, err := io.ReadFull(rand.Reader, seed); err != nil {
-			return nil, err
-		}
-		return seed, nil
+		return obfs4PaddingDefaultParams(method)
 	}
 	return nil, ErrInvalidPadding
 }

+ 13 - 0
padding_obfs4.go

@@ -18,6 +18,7 @@ package basket2
 
 import (
 	"bytes"
+	"io"
 	"time"
 
 	"git.schwanenlied.me/yawning/basket2.git/crypto/rand"
@@ -206,3 +207,15 @@ func newObfs4Padding(conn *commonConn, m PaddingMethod, seed []byte) (paddingImp
 
 	return p, nil
 }
+
+func obfs4PaddingDefaultParams(method PaddingMethod) ([]byte, error) {
+	switch method {
+	case PaddingObfs4Burst, PaddingObfs4BurstIAT:
+		seed := make([]byte, Obfs4SeedLength)
+		if _, err := io.ReadFull(rand.Reader, seed); err != nil {
+			return nil, err
+		}
+		return seed, nil
+	}
+	return nil, ErrInvalidPadding
+}