r/cryptography • • 7d ago

Difference between using a pgp signature and a simple hash to verify authenticity?

Been trynna understand pgp keys and their purpose but i dont understand the difference here. Lets say your distributing a binary on your website, u can either put a simple hash or your public key along side it. Whats the differnece here? If the site got compromised enough to change the binary and hash they can change the public to theirs too cant they? I tried searching it up but its mostly just vague its more or deep into download mirror chain stuff or smth that i dont understand lol. Appriciate any help :3 also keep in mind that i only started learning bout this like an hour ago lol dunno much.

4 Upvotes

12 comments sorted by

5

u/ToTheBatmobileGuy 7d ago

In practice you're correct.

However, the original point of PGP was to use a "web of trust" to ensure that public keys were widely known and not fake-able.


Let's look at HTTPS for a second.

With HTTPS certificates we use "Trusted root certificates" that sign "Certificate Authorities" which in turn sign "domain certificates" for individual domains.

So as long as the root certs and intermediate certs are not compromised or using "4" as their private key (lol) then we KNOW that "google.com" HTTPS cert contains the correct public key.


With PGP, as it was originally intended. PGP users would sign each other's keys, then upload those signatures to "key servers" and share them with other PGP users on those key servers.

Eventually you'd get a world where everyone signs their friends' keys, and so you could trust keys because a bunch of people YOU trust also signed keys that signed keys that signed keys.

The theory would be some faker who makes fake keys won't have a lot of REAL people signing their key, and the chain of signatures between you and a REAL developer will be short and filled with more trusted links than that of a bot farm that signs fake PGP keys.


That said. PGP web of trust is broken for 99% of normal users, because none of your friends use PGP web of trust. (It DOES exist though)

So for YOU SPECIFICALLY, it makes no difference.

"I only learn of the hash from their website" vs "I only learn of their PGP pubkey from their website" is essentially the same risk.

Side note: Usually you can reduce risk if you find the same hash or same pubkey from multiple sources. The more trusted each source is, the better.

1

u/flowicks 7d ago

Thanks a lot, this is the best explanation so far. Think I get now

1

u/AsYouAnswered 7d ago

This is the way.

19

u/daidoji70 7d ago

If I have a payload P and a cryptographic hash H(P). If an attacker comes along and gains control of my website he can make a fake P (say P') and then compute a hash H(P') that are different and place them on the website. Later on someone who reads that digest is unaware of what happened.

A cryptographic signature S over a payload P (or even better a signature over a Hash which is functionally equivalent) S(H(P)) and put that and my public key K_p. Now the attacker has to compromise my website AND compromise the keypair I used to sign if they want to do shenanigans with a different payload. Now you're going to ask "why don't they just replace the public key too?" and that's a whole other can of worms which is why you need a tool like PGP and ideas like Webs of Trust and out-of-band communication that doesn't just lean on your website etc...

These are the basics and generalize over the specifics of PGP and whatever strong cryptographic hash you might want and then things get really really deep because we need things like identities, non-repudiation, encryption keys and other stuff depending on what we want to use the hashes and signatures for but this is the basic motivation.

7

u/nullptr777 7d ago

This is a very clear and correct explanation, without delving into the technical details.

Nicely done.

9

u/flatfinger 7d ago

If one has a secure means of conveying a secure hash, it will verify the authenticity of content sent over an insecure channel just as effectively as would a signature.

If one has a secure means of conveying a public key, it will verify the authenticity of content which has been signed with the corresponding private key even when both the content and signature are sent over an insecure channel.

The primary advantage of a signature over a hash is that public key that is conveyed via secure means can be used in future to validate information that didn't exist at the time the key was conveyed.

1

u/doggydestroyer 7d ago

Think of this as Linux systems ... U install Linux with a lot of pgp keys... Like for example Google chrome... But if u receive an update, how do you know its from Google or not... U need a digital signature... Yes the first time u receive a key or data you need to verify it... But all subsequent packages can be verified...

2

u/bfreis 7d ago

It seems like your "." key is stuck.

1

u/andrewcooke 7d ago

you try to distribute the pgp keys separately, and then your attack does not work.

1

u/Natanael_L 7d ago

SSH uses "trust on first use" so the client keeps the public key it has seen and expects that one again later.

If the first connection happens as the presented key is legit, and the key doesn't get leaked, then future connections will be secure, or else the client can detect it and disconnect.

If the first connection happens to coincidence with a website breach, that user may get compromised, but hopefully they'll eventually learn and flush their system and restore to a good configuration. You might try to get them to learn it it via things like transparency logs.

1

u/paulstelian97 7d ago

Hash can be calculated by anyone. If you can replace the stored hash, you have no protection against intentional change.

Signature can only be calculated by someone who holds the private key. You need to hack that key to be able to forge signatures.

1

u/platinummyr 5d ago

There is no difference if you get the public key from the same source as the file/download/etc. you must verify that the public key is for the person you expect through another system. Most popularly is certificate authorities where you already have pre installed certificates on your system which validate the chain of trust by requiring that all keys are signed by someone who is signed by one of your authorities.

However, if you trust the public key and that the person has kept their private key secret, then you can trust that an attacker can't generate the signature if they change the file. This isn't true of a hash, since they can always generate the new hash and submit that instead. This is the key difference between signature and hash in this case.