From 7e92ebe16a7735b29e0fdc62d4b5d49ce0dc2b66 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 16 Jun 2016 19:02:47 +0200 Subject: [PATCH] Rename nametransform, contentenc source files Let's have shorter names, and merge *_api.go into the "main" file. No code changes. --- internal/contentenc/content.go | 33 +++++++++++++++++ internal/contentenc/content_api.go | 35 ------------------- .../{names_diriv.go => diriv.go} | 0 internal/nametransform/name_api.go | 18 ---------- .../nametransform/{names_core.go => names.go} | 27 +++++++++++--- .../nametransform/{names_noiv.go => noiv.go} | 0 6 files changed, 56 insertions(+), 57 deletions(-) delete mode 100644 internal/contentenc/content_api.go rename internal/nametransform/{names_diriv.go => diriv.go} (100%) delete mode 100644 internal/nametransform/name_api.go rename internal/nametransform/{names_core.go => names.go} (71%) rename internal/nametransform/{names_noiv.go => noiv.go} (100%) 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 similarity index 100% rename from internal/nametransform/names_diriv.go rename to 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 similarity index 71% rename from internal/nametransform/names_core.go rename to 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 similarity index 100% rename from internal/nametransform/names_noiv.go rename to internal/nametransform/noiv.go