aboutsummaryrefslogtreecommitdiff
path: root/cryptfs
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-04 20:31:06 +0200
committerJakob Unterwurzacher2015-09-04 20:37:37 +0200
commit6f90ec716a0e486628297a8d74e9f4d8d895e744 (patch)
tree66261a242910310edd4db12455de3970ed23e2fb /cryptfs
parent779ad6dda3d7926c1f68e72600a5db3764e6039d (diff)
Rebase to cluefs
https://github.com/airnandez/cluefs
Diffstat (limited to 'cryptfs')
-rw-r--r--cryptfs/file.go12
-rw-r--r--cryptfs/fs.go26
2 files changed, 19 insertions, 19 deletions
diff --git a/cryptfs/file.go b/cryptfs/file.go
index 77262d4..5645f3c 100644
--- a/cryptfs/file.go
+++ b/cryptfs/file.go
@@ -8,7 +8,7 @@ import (
"crypto/cipher"
)
-type File struct {
+type CryptFile struct {
file *os.File
gcm cipher.AEAD
plainBS int64
@@ -17,7 +17,7 @@ type File struct {
// readCipherBlock - Read ciphertext block number "blockNo", decrypt,
// return plaintext
-func (be *File) readCipherBlock(blockNo int64) ([]byte, error) {
+func (be *CryptFile) readCipherBlock(blockNo int64) ([]byte, error) {
off := blockNo * int64(be.cipherBS)
buf := make([]byte, be.cipherBS)
@@ -64,7 +64,7 @@ type intraBlock struct {
}
// Split a plaintext byte range into (possible partial) blocks
-func (be *File) splitRange(offset int64, length int64) []intraBlock {
+func (be *CryptFile) splitRange(offset int64, length int64) []intraBlock {
var b intraBlock
var parts []intraBlock
@@ -79,7 +79,7 @@ func (be *File) splitRange(offset int64, length int64) []intraBlock {
return parts
}
-func (be *File) min64(x int64, y int64) int64 {
+func (be *CryptFile) min64(x int64, y int64) int64 {
if x < y {
return x
}
@@ -87,7 +87,7 @@ func (be *File) min64(x int64, y int64) int64 {
}
// writeCipherBlock - Encrypt plaintext and write it to file block "blockNo"
-func (be *File) writeCipherBlock(blockNo int64, plain []byte) error {
+func (be *CryptFile) writeCipherBlock(blockNo int64, plain []byte) error {
if int64(len(plain)) > be.plainBS {
panic("writeCipherBlock: Cannot write block that is larger than plainBS")
@@ -109,7 +109,7 @@ func (be *File) writeCipherBlock(blockNo int64, plain []byte) error {
// Perform RMW cycle on block
// Write "data" into file location specified in "b"
-func (be *File) rmwWrite(b intraBlock, data []byte, f *os.File) error {
+func (be *CryptFile) rmwWrite(b intraBlock, data []byte, f *os.File) error {
if b.length != int64(len(data)) {
panic("Length mismatch")
}
diff --git a/cryptfs/fs.go b/cryptfs/fs.go
index 9050b30..f5781e2 100644
--- a/cryptfs/fs.go
+++ b/cryptfs/fs.go
@@ -19,14 +19,14 @@ const (
DECRYPT = false
)
-type FS struct {
+type CryptFS struct {
blockCipher cipher.Block
gcm cipher.AEAD
plainBS int64
cipherBS int64
}
-func NewFS(key [16]byte) *FS {
+func NewCryptFS(key [16]byte) *CryptFS {
b, err := aes.NewCipher(key[:])
if err != nil {
@@ -38,7 +38,7 @@ func NewFS(key [16]byte) *FS {
panic(err)
}
- return &FS{
+ return &CryptFS{
blockCipher: b,
gcm: g,
plainBS: DEFAULT_PLAINBS,
@@ -46,8 +46,8 @@ func NewFS(key [16]byte) *FS {
}
}
-func (fs *FS) NewFile(f *os.File) *File {
- return &File {
+func (fs *CryptFS) NewFile(f *os.File) *CryptFile {
+ return &CryptFile {
file: f,
gcm: fs.gcm,
plainBS: fs.plainBS,
@@ -56,7 +56,7 @@ func (fs *FS) NewFile(f *os.File) *File {
}
// DecryptName - decrypt filename
-func (be *FS) decryptName(cipherName string) (string, error) {
+func (be *CryptFS) decryptName(cipherName string) (string, error) {
bin, err := base64.URLEncoding.DecodeString(cipherName)
if err != nil {
@@ -81,7 +81,7 @@ func (be *FS) decryptName(cipherName string) (string, error) {
}
// EncryptName - encrypt filename
-func (be *FS) encryptName(plainName string) string {
+func (be *CryptFS) encryptName(plainName string) string {
bin := []byte(plainName)
bin = be.pad16(bin)
@@ -97,7 +97,7 @@ func (be *FS) encryptName(plainName string) string {
// TranslatePath - encrypt or decrypt path. Just splits the string on "/"
// and hands the parts to EncryptName() / DecryptName()
-func (be *FS) translatePath(path string, op bool) (string, error) {
+func (be *CryptFS) translatePath(path string, op bool) (string, error) {
var err error
// Empty string means root directory
@@ -125,18 +125,18 @@ func (be *FS) translatePath(path string, op bool) (string, error) {
}
// EncryptPath - encrypt filename or path. Just hands it to TranslatePath().
-func (be *FS) EncryptPath(path string) string {
+func (be *CryptFS) EncryptPath(path string) string {
newPath, _ := be.translatePath(path, ENCRYPT)
return newPath
}
// DecryptPath - decrypt filename or path. Just hands it to TranslatePath().
-func (be *FS) DecryptPath(path string) (string, error) {
+func (be *CryptFS) DecryptPath(path string) (string, error) {
return be.translatePath(path, DECRYPT)
}
// plainSize - calculate plaintext size from ciphertext size
-func (be *FS) PlainSize(s int64) int64 {
+func (be *CryptFS) PlainSize(s int64) int64 {
// Zero sized files stay zero-sized
if s > 0 {
// Number of blocks
@@ -149,7 +149,7 @@ func (be *FS) PlainSize(s int64) int64 {
// pad16 - pad filename to 16 byte blocks using standard PKCS#7 padding
// https://tools.ietf.org/html/rfc5652#section-6.3
-func (be *FS) pad16(orig []byte) (padded []byte) {
+func (be *CryptFS) pad16(orig []byte) (padded []byte) {
oldLen := len(orig)
if oldLen == 0 {
panic("Padding zero-length string makes no sense")
@@ -169,7 +169,7 @@ func (be *FS) pad16(orig []byte) (padded []byte) {
}
// unPad16 - remove padding
-func (be *FS) unPad16(orig []byte) ([]byte, error) {
+func (be *CryptFS) unPad16(orig []byte) ([]byte, error) {
oldLen := len(orig)
if oldLen % aes.BlockSize != 0 {
return nil, errors.New("Unaligned size")