I'm trying to understand what happens when verifying a detached gpg signature.Here's an example from the gnupg manual:blake% gpg --verify doc.sig docgpg: Signature made Fri Jun  4 12:38:46 1999 CDT using DSA key ID BB7576ACgpg: Good signature from Alice (Judge) <alice@cyb.org>How does gpg determine that the signature is a good one? Does the signature contain a hash of the file which was signed? If so, how do you extract that hash from the signature itself?I tried gpg --list-packets <signature> but it doesn't seem to show full information.
What happens when you verify a detached signature?
gpg
You can use the --list-packets option to get a dump of what's in a gpg file. The description of the file format is RFC 4880 (OpenPGP standard).The signature does not directly contain a hash. It contains information that allows verifying both the hash and the sender: there is a signature verification algorithm, which takes a hash value and a public key as input, and returns yes or no; the algorithm returns yes if the signature was made by the private key corresponding to the given public key from a message with the given private key, and returns no in all other circumstances (signature of a different hash, signature made by a different key, or a bunch of bytes that can't be a signature at all). Under the DSA algorithm, I think it's infeasible to extract the hash from a signature if you don't have the private key.The signature file contains the identity of the signer as well as the signature value. To verify the signature, gpg reads the signer's public key from your keyring, calculates the hash of the data, and applies the signature verification algorithm.