Skip to content

Commit

Permalink
satellite/audit/reverify: support blake3
Browse files Browse the repository at this point in the history
Change-Id: Icc4e5aec1531128404749cd68992808b2a45466f
  • Loading branch information
jtolio authored and Storj Robot committed Jan 25, 2024
1 parent 0269ed3 commit 02c9e17
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions satellite/audit/reverifier.go
Expand Up @@ -14,7 +14,6 @@ import (

"storj.io/common/errs2"
"storj.io/common/pb"
"storj.io/common/pkcrypto"
"storj.io/common/rpc"
"storj.io/common/rpc/rpcstatus"
"storj.io/common/signing"
Expand Down Expand Up @@ -249,7 +248,7 @@ func (reverifier *Reverifier) DoReverifyPiece(ctx context.Context, logger *zap.L
// blaming the node
} else {
// check for a matching hash
downloadedHash := pkcrypto.SHA256Hash(pieceData)
downloadedHash := hashWithAlgo(pieceHash.HashAlgorithm, pieceData)
if !bytes.Equal(downloadedHash, pieceHash.Hash) {
logger.Info("ReverifyPiece: audit failure; downloaded piece does not match hash", zap.ByteString("downloaded", downloadedHash), zap.ByteString("expected", pieceHash.Hash))
outcome = OutcomeFailure
Expand Down Expand Up @@ -280,6 +279,17 @@ func (reverifier *Reverifier) DoReverifyPiece(ctx context.Context, logger *zap.L
return OutcomeSuccess, reputation, nil
}

func hashWithAlgo(algo pb.PieceHashAlgorithm, data []byte) []byte {
h := pb.NewHashFromAlgorithm(algo)
_, err := h.Write(data)
if err != nil {
// sha256 and blake3 hash writers never return errors. we could just ignore
// the error return value (many callers do), but that seems unwise.
panic(err)
}
return h.Sum(nil)
}

// GetPiece uses the piecestore client to download a piece (and the associated
// original OrderLimit and PieceHash) from a node.
func (reverifier *Reverifier) GetPiece(ctx context.Context, limit *pb.AddressedOrderLimit, piecePrivateKey storj.PiecePrivateKey, cachedIPAndPort string, pieceSize int32) (pieceData []byte, hash *pb.PieceHash, origLimit *pb.OrderLimit, err error) {
Expand Down

0 comments on commit 02c9e17

Please sign in to comment.