From 776f546828f0b40003237fb13852bb3c3370748b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Tr=C3=B3n?= Date: Fri, 15 Mar 2024 14:42:55 +0100 Subject: [PATCH] fix(seg65) (#4604) Co-authored-by: Acha Bill --- pkg/encryption/chunk_encryption.go | 11 +++++------ pkg/encryption/store/decrypt_store.go | 14 ++------------ pkg/file/splitter/internal/job.go | 13 ++----------- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/pkg/encryption/chunk_encryption.go b/pkg/encryption/chunk_encryption.go index 0cb6a901083..3c697847824 100644 --- a/pkg/encryption/chunk_encryption.go +++ b/pkg/encryption/chunk_encryption.go @@ -20,22 +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 { - refSize := int64(swarm.HashSize + KeyLength) - return New(key, 0, uint32(swarm.ChunkSize/refSize), sha3.NewLegacyKeccak256) +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 7a9f0395e91..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,22 +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 { - refSize := int64(swarm.HashSize + encryption.KeyLength) - return encryption.New(key, 0, uint32(swarm.ChunkSize/refSize), 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..e4b20663058 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 @@ -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) -}