From 53b48f09405e1e3f754a2ad52a3669a020a2d4ad Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 28 May 2026 18:51:01 +0200 Subject: [PATCH] FileHashingWrapper: support and use sha256 Cryptographically strong and often hw accelerated nowadays. Also support by borgstore hash method. --- src/borg/crypto/file_integrity.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/borg/crypto/file_integrity.py b/src/borg/crypto/file_integrity.py index e5310a136..701c7f9a2 100644 --- a/src/borg/crypto/file_integrity.py +++ b/src/borg/crypto/file_integrity.py @@ -5,8 +5,6 @@ from hmac import compare_digest from collections.abc import Callable from pathlib import Path -from xxhash import xxh64 - from ..helpers import IntegrityError from ..logger import create_logger @@ -106,20 +104,12 @@ class FileHashingWrapper(FileLikeWrapper): self.hash.update(str(self.tell()).encode()) -class SHA512FileHashingWrapper(FileHashingWrapper): - ALGORITHM = "SHA512" - FACTORY = hashlib.sha512 +class SHA256FileHashingWrapper(FileHashingWrapper): + ALGORITHM = "SHA256" + FACTORY = hashlib.sha256 -class XXH64FileHashingWrapper(FileHashingWrapper): - ALGORITHM = "XXH64" - FACTORY = xxh64 - - -SUPPORTED_ALGORITHMS = { - SHA512FileHashingWrapper.ALGORITHM: SHA512FileHashingWrapper, - XXH64FileHashingWrapper.ALGORITHM: XXH64FileHashingWrapper, -} +SUPPORTED_ALGORITHMS = {SHA256FileHashingWrapper.ALGORITHM: SHA256FileHashingWrapper} class FileIntegrityError(IntegrityError): @@ -137,7 +127,7 @@ class IntegrityCheckedFile(FileLikeWrapper): self.file_opened = override_fd is None self.digests = {} - hash_cls = XXH64FileHashingWrapper + hash_cls = SHA256FileHashingWrapper if not write: algorithm_and_digests = self.load_integrity_data(path, integrity_data)