Another point worth mentioning is that the checksums can be supplied in a separate file signed with digital signature of the author/maintainer of the content.
In this case even if the attacker gets full control of the server on which the content resides and replaces the payload and checksums, they will be unable to sign the checksums file with the developer's signature (unless they also obtain the private key of the developer).
Then, end users will be able to detect that something is wrong, because signature verification process will fail.
The procedure of download then should include these steps:
- Download the payload.
- Download the checksum file.
- Verify the signature of the checksum file.
- Verify the checksum of the payload against checksum file.
With this, a user can decide to discard the payload should step 3 or 4 fail.
This makes it possible to distribute content via 3rd party infrastructure which is not controlled by original author of the content, without being afraid of unauthorized changes. For example, many Linux distribution's install files are hosted on public mirrors that belong to universities or enthusiasts.
Example: Gentoo Linux mirrors list and list of their public keys so that users can verify downloads.