Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(seg65) #4604

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pkg/encryption/chunk_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 2 additions & 12 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,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)
}
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)
}
Loading