Skip to content

Commit

Permalink
chore: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Mar 13, 2024
1 parent 2e266d6 commit ae293d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
8 changes: 4 additions & 4 deletions pkg/encryption/chunk_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ func NewChunkEncrypter() ChunkEncrypter { return &chunkEncrypter{} }

func (c *chunkEncrypter) EncryptChunk(chunkData []byte) (Key, []byte, []byte, error) {
key := GenerateRandomKey(KeyLength)
encryptedSpan, err := newSpanEncryption(key).Encrypt(chunkData[:8])
encryptedSpan, err := NewSpanEncryption(key).Encrypt(chunkData[:8])
if err != nil {
return nil, nil, nil, err
}
encryptedData, err := newDataEncryption(key).Encrypt(chunkData[8:])
encryptedData, err := NewDataEncryption(key).Encrypt(chunkData[8:])
if err != nil {
return nil, nil, nil, err
}
return key, encryptedSpan, encryptedData, nil
}

func newSpanEncryption(key Key) Interface {
func NewSpanEncryption(key Key) Interface {
return New(key, 0, uint32(swarm.ChunkSize/KeyLength), sha3.NewLegacyKeccak256)
}

func newDataEncryption(key Key) Interface {
func NewDataEncryption(key Key) Interface {
return New(key, int(swarm.ChunkSize), 0, sha3.NewLegacyKeccak256)
}
13 changes: 2 additions & 11 deletions pkg/encryption/store/decrypt_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ethersphere/bee/pkg/file/redundancy"
storage "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
"golang.org/x/crypto/sha3"
)

type decryptingStore struct {
Expand Down Expand Up @@ -73,21 +72,13 @@ func DecryptChunkData(chunkData []byte, encryptionKey encryption.Key) ([]byte, e
}

func decrypt(chunkData []byte, key encryption.Key) ([]byte, []byte, error) {
decryptedSpan, err := newSpanEncryption(key).Decrypt(chunkData[:swarm.SpanSize])
decryptedSpan, err := encryption.NewSpanEncryption(key).Decrypt(chunkData[:swarm.SpanSize])
if err != nil {
return nil, nil, err
}
decryptedData, err := newDataEncryption(key).Decrypt(chunkData[swarm.SpanSize:])
decryptedData, err := encryption.NewDataEncryption(key).Decrypt(chunkData[swarm.SpanSize:])
if err != nil {
return nil, nil, err
}
return decryptedSpan, decryptedData, nil
}

func newSpanEncryption(key encryption.Key) encryption.Interface {
return encryption.New(key, 0, uint32(swarm.ChunkSize/encryption.KeyLength), sha3.NewLegacyKeccak256)
}

func newDataEncryption(key encryption.Key) encryption.Interface {
return encryption.New(key, int(swarm.ChunkSize), 0, sha3.NewLegacyKeccak256)
}
13 changes: 2 additions & 11 deletions pkg/file/splitter/internal/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ethersphere/bee/pkg/file"
storage "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
"golang.org/x/crypto/sha3"
)

// maximum amount of file tree levels this file hasher component can handle
Expand Down Expand Up @@ -256,21 +255,13 @@ func (s *SimpleSplitterJob) encryptChunkData(chunkData []byte) ([]byte, encrypti

func (s *SimpleSplitterJob) encrypt(chunkData []byte) (encryption.Key, []byte, []byte, error) {
key := encryption.GenerateRandomKey(encryption.KeyLength)
encryptedSpan, err := s.newSpanEncryption(key).Encrypt(chunkData[:8])
encryptedSpan, err := encryption.NewSpanEncryption(key).Encrypt(chunkData[:8])
if err != nil {
return nil, nil, nil, err
}
encryptedData, err := s.newDataEncryption(key).Encrypt(chunkData[8:])
encryptedData, err := encryption.NewDataEncryption(key).Encrypt(chunkData[8:])
if err != nil {
return nil, nil, nil, err
}
return key, encryptedSpan, encryptedData, nil
}

func (s *SimpleSplitterJob) newSpanEncryption(key encryption.Key) encryption.Interface {
return encryption.New(key, 0, uint32(swarm.ChunkSize/s.refSize), sha3.NewLegacyKeccak256)
}

func (s *SimpleSplitterJob) newDataEncryption(key encryption.Key) encryption.Interface {
return encryption.New(key, int(swarm.ChunkSize), 0, sha3.NewLegacyKeccak256)
}

0 comments on commit ae293d1

Please sign in to comment.