summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/contentenc/content.go33
-rw-r--r--internal/contentenc/content_api.go35
-rw-r--r--internal/nametransform/diriv.go (renamed from internal/nametransform/names_diriv.go)0
-rw-r--r--internal/nametransform/name_api.go18
-rw-r--r--internal/nametransform/names.go (renamed from internal/nametransform/names_core.go)27
-rw-r--r--internal/nametransform/noiv.go (renamed from internal/nametransform/names_noiv.go)0
6 files changed, 56 insertions, 57 deletions
diff --git a/internal/contentenc/content.go b/internal/contentenc/content.go
index 5bac2a2..2298c5e 100644
--- a/internal/contentenc/content.go
+++ b/internal/contentenc/content.go
@@ -8,9 +8,42 @@ import (
"encoding/hex"
"errors"
+ "github.com/rfjakob/gocryptfs/internal/cryptocore"
"github.com/rfjakob/gocryptfs/internal/tlog"
)
+const (
+ // Default plaintext block size
+ DefaultBS = 4096
+)
+
+type ContentEnc struct {
+ // Cryptographic primitives
+ cryptoCore *cryptocore.CryptoCore
+ // Plaintext block size
+ plainBS uint64
+ // Ciphertext block size
+ cipherBS uint64
+ // All-zero block of size cipherBS, for fast compares
+ allZeroBlock []byte
+}
+
+func New(cc *cryptocore.CryptoCore, plainBS uint64) *ContentEnc {
+
+ cipherBS := plainBS + uint64(cc.IVLen) + cryptocore.AuthTagLen
+
+ return &ContentEnc{
+ cryptoCore: cc,
+ plainBS: plainBS,
+ cipherBS: cipherBS,
+ allZeroBlock: make([]byte, cipherBS),
+ }
+}
+
+func (be *ContentEnc) PlainBS() uint64 {
+ return be.plainBS
+}
+
// DecryptBlocks - Decrypt a number of blocks
func (be *ContentEnc) DecryptBlocks(ciphertext []byte, firstBlockNo uint64, fileId []byte) ([]byte, error) {
cBuf := bytes.NewBuffer(ciphertext)
diff --git a/internal/contentenc/content_api.go b/internal/contentenc/content_api.go
deleted file mode 100644
index cf482b6..0000000
--- a/internal/contentenc/content_api.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package contentenc
-
-import "github.com/rfjakob/gocryptfs/internal/cryptocore"
-
-const (
- // Default plaintext block size
- DefaultBS = 4096
-)
-
-type ContentEnc struct {
- // Cryptographic primitives
- cryptoCore *cryptocore.CryptoCore
- // Plaintext block size
- plainBS uint64
- // Ciphertext block size
- cipherBS uint64
- // All-zero block of size cipherBS, for fast compares
- allZeroBlock []byte
-}
-
-func New(cc *cryptocore.CryptoCore, plainBS uint64) *ContentEnc {
-
- cipherBS := plainBS + uint64(cc.IVLen) + cryptocore.AuthTagLen
-
- return &ContentEnc{
- cryptoCore: cc,
- plainBS: plainBS,
- cipherBS: cipherBS,
- allZeroBlock: make([]byte, cipherBS),
- }
-}
-
-func (be *ContentEnc) PlainBS() uint64 {
- return be.plainBS
-}
diff --git a/internal/nametransform/names_diriv.go b/internal/nametransform/diriv.go
index b9473aa..b9473aa 100644
--- a/internal/nametransform/names_diriv.go
+++ b/internal/nametransform/diriv.go
diff --git a/internal/nametransform/name_api.go b/internal/nametransform/name_api.go
deleted file mode 100644
index 7ac7d26..0000000
--- a/internal/nametransform/name_api.go
+++ /dev/null
@@ -1,18 +0,0 @@
-package nametransform
-
-import "github.com/rfjakob/gocryptfs/internal/cryptocore"
-
-type NameTransform struct {
- cryptoCore *cryptocore.CryptoCore
- useEME bool
- longNames bool
- DirIVCache dirIVCache
-}
-
-func New(c *cryptocore.CryptoCore, useEME bool, longNames bool) *NameTransform {
- return &NameTransform{
- cryptoCore: c,
- longNames: longNames,
- useEME: useEME,
- }
-}
diff --git a/internal/nametransform/names_core.go b/internal/nametransform/names.go
index 779b885..8a7e260 100644
--- a/internal/nametransform/names_core.go
+++ b/internal/nametransform/names.go
@@ -9,10 +9,28 @@ import (
"fmt"
"github.com/rfjakob/eme"
+
+ "github.com/rfjakob/gocryptfs/internal/cryptocore"
)
+type NameTransform struct {
+ cryptoCore *cryptocore.CryptoCore
+ useEME bool
+ longNames bool
+ DirIVCache dirIVCache
+}
+
+func New(c *cryptocore.CryptoCore, useEME bool, longNames bool) *NameTransform {
+ return &NameTransform{
+ cryptoCore: c,
+ longNames: longNames,
+ useEME: useEME,
+ }
+}
+
// DecryptName - decrypt base64-encoded encrypted filename "cipherName"
-// The used encryption is either CBC or EME, depending on "useEME".
+// Used by DecryptPathDirIV().
+// The encryption is either CBC or EME, depending on "useEME".
//
// This function is exported because it allows for a very efficient readdir
// implementation (read IV once, decrypt all names using this function).
@@ -43,11 +61,12 @@ func (n *NameTransform) DecryptName(cipherName string, iv []byte) (string, error
return plain, err
}
-// encryptName - encrypt "plainName", return base64-encoded "cipherName64"
-// The used encryption is either CBC or EME, depending on "useEME".
+// encryptName - encrypt "plainName", return base64-encoded "cipherName64".
+// Used internally by EncryptPathDirIV().
+// The encryption is either CBC or EME, depending on "useEME".
//
// This function is exported because fusefrontend needs access to the full (not hashed)
-// name if longname is used
+// name if longname is used. Otherwise you should use EncryptPathDirIV()
func (n *NameTransform) EncryptName(plainName string, iv []byte) (cipherName64 string) {
bin := []byte(plainName)
diff --git a/internal/nametransform/names_noiv.go b/internal/nametransform/noiv.go
index f1009e4..f1009e4 100644
--- a/internal/nametransform/names_noiv.go
+++ b/internal/nametransform/noiv.go