3

I signed the same file producing a separate file for the signatures, and I noticed that every file is signed with a different signature. I don't get it. Shouldn't it always be signed with the same public key in the end?

gpg2 --output FILE1.sig --detach-sig --armor FILE

I made three files (FILE1,2,3). Every file has a different signature - why is that?

2 Answers 2

10

real time

Looking at the signed message, the reason gets very obvious. gpg --list-packets takes the input and lists all packets contained in a somewhat readable fashion:

$ echo "foo" | gpg --sign | gpg --list-packets

[gpg asking for passphrase]

:compressed packet: algo=1    
:onepass_sig packet: keyid 8E78E44DFB1B55E9
    version 3, sigclass 0x00, digest 2, pubkey 1, last=1
:literal data packet:
    mode b (62), created 1421012528, name="",
    raw data: 4 bytes
:signature packet: algo 1, keyid 8E78E44DFB1B55E9
    version 4, created 1421012528, md5len 0, sigclass 0x00
    digest algo 2, begin of digest 96 e3
    hashed subpkt 2 len 4 (sig created 2015-01-11)
    subpkt 16 len 8 (issuer key ID 8E78E44DFB1B55E9)
    data: [4096 bits]

The "literal data packet" and also the "signature packet" contain the creation timestamp, here 1421012528. The actual signature data also takes the literal data packet's creation timestamp into account, thus will also be different for every signature calculated.

faketime

To verify this, use the glorious faketime program and calculate the checksum of the signature (which is always the same, no matter how often you run the command):

faketime 5pm /bin/bash -c "echo "foo" | gpg --sign | sha256sum"
7
  • Thanks! That explains it. I also checked a few e-mails I've signed and they all have different signatures, as I understand now - due to a different time they had been signed.
    – Peter
    Jan 13, 2015 at 16:49
  • If the answer solved your problem, consider marking it as such by selecting the checkmark on the left (also have a look at the FAQ).
    – Jens Erat
    Jan 13, 2015 at 16:51
  • One more thing...why does gpg ask for my secret password whenever I sign the message? Does it use both secret/public key to sign messages? It would follow that someone wouldn't be able to sign messages using my publicly available key?
    – Peter
    Jan 13, 2015 at 16:52
  • This is a completely unrelated question. Please ask a new question. And maybe read up on digital signatures a little bit before doing so (otherwise your question might get too broad) - lots of people already wrote about this, for example on Wikipedia.
    – Jens Erat
    Jan 13, 2015 at 16:57
  • O.K. Jens, I guess you're absolutely right, just thought you might have the expertise to answer this question right on the spot.
    – Peter
    Jan 14, 2015 at 0:32
3

This is to prevent a "Chosen Ciphertext Attack" if your key produced the same output over and over again, there would be no entropy. An attacker can launch attacks against the encrypted message.

2
  • 1
    But I only signed the message, not encrypted it.
    – Peter
    Jan 11, 2015 at 21:37
  • 4
    @Peter It's the same thing. When you sign a message, what happens is that you take a hash of the message, encrypt it with your private key, and then append it to the original message. The recipient verifies it by hashing the original message, using your public key to decrypt the hash you attached, and then comparing the two to make sure they're the same. Jan 12, 2015 at 1:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .