https://www.amazon.com/PGP-Internals-Philip-R-Zimmermann/dp/...
Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
11–20 of 30 posts
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#12It depends a lot on from which angle you want to understand it. There's a difference between "understanding the variety of command line options" vs. "understanding the meaning of the raw data structures". I learned quite a bit by looking up things in the RFC: https://tools.ietf.org/html/rfc4880
This way, knowing the raw data structures makes it easier for me to figure out which command line arguments I want, if you will.
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#13Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#14If you have some pointers to Git internals explanation, similar to what you're looking for PGP/GnuPG, can you provide them? That would be useful and illustrative :) .
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#15If you have some pointers to Git internals explanation, similar to what you're looking for PGP/GnuPG, can you provide them? That would be useful and illustrative :) .
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#16If you have some pointers to Git internals explanation, similar to what you're looking for PGP/GnuPG, can you provide them? That would be useful and illustrative :) .
https://git-scm.com/book/en/v2/ scroll to Chapter 10 "Git Internals"
(Direct link: https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Po... but it only shows you the first page among nine.)
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#17 print(number of recipients, algorithm used, etc.)
for each recipient:
print(RSA_encrypt(symmetric_key, recipient.public_key))
print(AES_encrypt(message + hash(message), symmetric_key))
Typically if you send an email from a@example.com to b@example.com, it will find the two public keys from both parties and encrypt the symmetric key for both. The sender obviously wrote it, but they might want to read it back so the symmetric key is also encrypted with their public key, as well as the recipient's.A random symmetric key is chosen to encrypt the message, since it would be silly to encrypt the whole message for each recipient again and again. And even if there's only one recipient, random key generation plus symmetric key encryption is typically faster than encrypting the whole message with asymmetric crypto (unless the message is just a few bytes, in which case it's fast regardless).
File encryption probably works the same way, except you're typically the sole recipient.
Signatures are done by encrypting a hash of the message with your private key, which everyone can decrypt with your public key to verify the hash. Since you're the only person with the private key, you are the only person who could have encrypted that hash, and since hashes are unique, you must have wanted to sign this text. (N.B. Both keys, public and private, can be used for both encryption and decryption, you just can't use the same key to decrypt if it was already used to encrypt and vice versa.) The hash is used rather than the full message for both speed and because it makes your signature a lot shorter.
Did I miss anything, at least from a crypto standpoint (since I don't know details of the file structure)?
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#18If you have some pointers to Git internals explanation, similar to what you're looking for PGP/GnuPG, can you provide them? That would be useful and illustrative :) .
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#19If you have some pointers to Git internals explanation, similar to what you're looking for PGP/GnuPG, can you provide them? That would be useful and illustrative :) .
Discussion: https://news.ycombinator.com/item?id=12802949
Re: Ask HN: Is there a “ground-up” explanation of PGP/GnuPG?
#20This is something I have done some work on (I wrote a basic implementation in an attempt to understand a while ago [1]), but I don't have a nice writeup.
An OpenPGP file, whether it is a public key or encrypted file, consists of a list of packets. Generally it is a binary file, but an armored file consists of this binary in base64 and then a checksum. You can get these packets with gpg --list-packets
Example output from a signed and encrypted file
gpg: encrypted with 2048-bit RSA key, ID 09FBFEF359DD186F, created 2016-11-30
"asdfas "
# off=0 ctb=85 tag=1 hlen=3 plen=268
:pubkey enc packet: version 3, algo 1, keyid 09FBFEF359DD186F
data: [2047 bits]
# off=271 ctb=d2 tag=18 hlen=3 plen=377 new-ctb
:encrypted data packet:
length: 377
mdc_method: 2
# off=293 ctb=a3 tag=8 hlen=1 plen=0 indeterminate
:compressed packet: algo=2
# off=295 ctb=90 tag=4 hlen=2 plen=13
:onepass_sig packet: keyid 0D3B106118D1EFBE
version 3, sigclass 0x00, digest 8, pubkey 1, last=1
# off=310 ctb=ac tag=11 hlen=2 plen=19
:literal data packet:
mode b (62), created 1480523012, name="file.txt",
raw data: 5 bytes
# off=331 ctb=89 tag=2 hlen=3 plen=284
:signature packet: algo 1, keyid 0D3B106118D1EFBE
version 4, created 1480523012, md5len 0, sigclass 0x00
digest algo 8, begin of digest 05 c4
hashed subpkt 2 len 4 (sig created 2016-11-30)
subpkt 16 len 8 (issuer key ID 0D3B106118D1EFBE)
data: [2046 bits]
The pubkey encrypted packets contain a key used to encrypt the data. The encrypted data packet includes that symmetrically encrypted data.When I have more time, I may do a more useful writeup on my site, but currently I am too busy.
[0] https://www.ietf.org/rfc/rfc4880.txt [1] All I could find was my file parsing code, I dumped it at https://github.com/artemist/mupg