diff --git a/pkg/encryption/chunk_encryption.go b/pkg/encryption/chunk_encryption.go index da982bc139b..3c697847824 100644 --- a/pkg/encryption/chunk_encryption.go +++ b/pkg/encryption/chunk_encryption.go @@ -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) } diff --git a/pkg/encryption/store/decrypt_store.go b/pkg/encryption/store/decrypt_store.go index 97bfa439d64..c4a5ef4b319 100644 --- a/pkg/encryption/store/decrypt_store.go +++ b/pkg/encryption/store/decrypt_store.go @@ -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 { @@ -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) -} diff --git a/pkg/file/splitter/internal/job.go b/pkg/file/splitter/internal/job.go index 90599defbf7..c19e6101916 100644 --- a/pkg/file/splitter/internal/job.go +++ b/pkg/file/splitter/internal/job.go @@ -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 @@ -199,7 +198,7 @@ func (s *SimpleSplitterJob) hashUnfinished() error { // F F // F F F // -// F F F F S +// # F F F F S // // The result will be: // @@ -207,7 +206,7 @@ func (s *SimpleSplitterJob) hashUnfinished() error { // F F // F F F // -// F F F F +// # F F F F // // After which the SS will be hashed to obtain the final root hash func (s *SimpleSplitterJob) moveDanglingChunk() error { @@ -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) -}