From 02c9e17a8e3abbb706194b7924501c8976305efe Mon Sep 17 00:00:00 2001 From: JT Olio Date: Wed, 24 Jan 2024 16:16:25 -0500 Subject: [PATCH] satellite/audit/reverify: support blake3 Change-Id: Icc4e5aec1531128404749cd68992808b2a45466f --- satellite/audit/reverifier.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/satellite/audit/reverifier.go b/satellite/audit/reverifier.go index 36c1fbc908b2..60040663a780 100644 --- a/satellite/audit/reverifier.go +++ b/satellite/audit/reverifier.go @@ -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" @@ -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 @@ -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) {