diff --git a/NEWS.md b/NEWS.md index 97c232802..52aa05129 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,9 @@ Default negotiation is unchanged. Select SHA-3 with `--checksum-choice` or include it in both peers' `RSYNC_CHECKSUM_LIST`. +- Added the opt-in SHA-256 transfer checksum `sha256` for builds with OpenSSL + SHA-256 support. Default negotiation is unchanged. + ## Bug fixes - Fixed `-X` transfers of user xattrs on NetBSD by using the native BSD diff --git a/checksum.c b/checksum.c index 64224f48d..40d5c1aa1 100644 --- a/checksum.c +++ b/checksum.c @@ -60,6 +60,9 @@ struct name_num_item valid_checksums_items[] = { { CSUM_SHA3_512, NNI_EVP|NNI_EXPLICIT_ONLY, "sha3-512", NULL }, { CSUM_SHA3_384, NNI_EVP|NNI_EXPLICIT_ONLY, "sha3-384", NULL }, { CSUM_SHA3_256, NNI_EVP|NNI_EXPLICIT_ONLY, "sha3-256", NULL }, +#endif +#ifdef SHA256_DIGEST_LENGTH + { CSUM_SHA256, NNI_EVP|NNI_EXPLICIT_ONLY, "sha256", NULL }, #endif { CSUM_MD5, NNI_BUILTIN|NNI_EVP, "md5", NULL }, { CSUM_MD4, NNI_BUILTIN|NNI_EVP, "md4", NULL }, diff --git a/rsync.1.md b/rsync.1.md index b8e91fa46..3d86ae1c1 100644 --- a/rsync.1.md +++ b/rsync.1.md @@ -2040,15 +2040,16 @@ sign) if you want the local shell to expand it. - `sha3-512` - `sha3-384` - `sha3-256` + - `sha256` - `md5` - `md4` - `sha1` - `none` - The `sha3-*` choices require an rsync built with OpenSSL support and - a libcrypto that provides SHA-3. They are not offered during default - negotiation. Use `--checksum-choice` or include them in both peers' - [`RSYNC_CHECKSUM_LIST`](#). + The `sha3-*` and `sha256` choices require an rsync built with OpenSSL + support and a libcrypto that provides the chosen digest. They are not + offered during default negotiation. Use `--checksum-choice` or include the + chosen digest in both peers' [`RSYNC_CHECKSUM_LIST`](#). Run `rsync --version` to see the checksum choices available in your build. diff --git a/testsuite/tests/transfer/checksum-sha3.py b/testsuite/tests/transfer/checksum-explicit-evp.py old mode 100755 new mode 100644 similarity index 89% rename from testsuite/tests/transfer/checksum-sha3.py rename to testsuite/tests/transfer/checksum-explicit-evp.py index 2ba385cce..8f990ba33 --- a/testsuite/tests/transfer/checksum-sha3.py +++ b/testsuite/tests/transfer/checksum-explicit-evp.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -# SHA-3 checksum support (sha3-256, sha3-384, sha3-512). -# +# Transfer checksums that require an explicit choice. import json import os from random import Random @@ -15,10 +14,13 @@ metadata(transports={'pipe'}, mutates={'environment', 'filesystem'}, tags={'transfer', 'regression'}) -ALGOS = ('sha3-256', 'sha3-384', 'sha3-512') +ALGOS = ('sha3-256', 'sha3-384', 'sha3-512', 'sha256') -choices = json.loads(run_rsync('-VV', capture_output=True).stdout)['checksum_list'] +version = json.loads(run_rsync('-VV', capture_output=True).stdout) +choices = version['checksum_list'] available = [algo for algo in ALGOS if algo in choices] +if ('sha256' in choices) != ('sha256' in version['daemon_auth_list']): + test_fail('SHA-256 transfer availability does not match the linked EVP digest') os.environ.pop('RSYNC_CHECKSUM_LIST', None) protocol = forced_protocol() legacy_checksum = protocol is not None and protocol < 30 @@ -27,7 +29,7 @@ makepath(FROMDIR / 'sub') # Empty, small and chunk-spanning sizes (CHUNK_SIZE is 32k internally). (FROMDIR / 'empty').write_bytes(b'') -(FROMDIR / 'small').write_text('hello sha-3\n') +(FROMDIR / 'small').write_text('hello checksum\n') size = 70 * 1024 (FROMDIR / 'sub' / 'big').write_bytes(Random(0).getrandbits(size * 8).to_bytes(size, 'big')) @@ -73,7 +75,7 @@ def check_checksum_list(algo): if legacy_checksum: # Without negotiation the list may allow MD4 or refuse it, not replace it. if result.returncode != 4 or 'Failed to negotiate a checksum choice.' not in result.stderr: - test_fail(f'protocol {protocol}: expected a SHA-3-only list to be refused: {result}') + test_fail(f'protocol {protocol}: expected a {algo}-only list to be refused: {result}') rmtree(TODIR) result = transfer_with_checksum_list(f'{algo} md4') expected = 'Client checksum: md4' @@ -108,8 +110,7 @@ def check_checksum_list(algo): run_rsync('-ac', f'--checksum-choice={algo},{algo}', src, dst) check_tree(f'{algo},{algo} -c') -if available: - algo = available[0] +for algo in available: check_checksum_list(algo) with (TODIR / 'sub' / 'big').open('r+b') as stream: stream.seek(32 * 1024)