Just Enough Cryptography

Digital Signatures, Digital Certificates, and Hashed Message Authentication Codes

Digital Signatures

If you send a message and its hash, all you prove is that you know how to calculate a hash!

Instead, send the message and the result of encrypting its hash with your private key. That result is called a digital signature. The digital signature is:
E( H(message), Kprivate )

Anyone can calculate the hash of the received message. They can also use your public key to decrypt the digital signature. Then they compare those two results. If the two are the same, you are the sender, and the message wasn't altered.

Digitally signing a message:
                                            +---------+
                                          { | Message |
           +----------------------------> { |  body   |
           |                              { |         |
           |   +---+   +---+                +---------+
  Message -+-->| H |-->| E |--> Digital --> |Signature|
               +---+   +---+   signature    +---------+
                         ^
                         |
                         kpriv

Verifying a digitally signed message:

    +---------+      +---+
    | Message | }--->| H |------------+
    |  body   | }    +---+            |
    |         | }                     |
    +---------+      +---+            v
    |Signature| }--->| D |----> Are they the same?
    +---------+      +---+    If so, the message is valid
                       ^      and the sender is legitimate!
                       |
                      kpub

	Firefox users may find that "monospace" isn't really a constant-width
	font, and Courier works much better for ASCII art.

For an application of this technology, see my page explaining how to use this to verify downloaded software and operating systems.

For a less technical explanation of how this can be used with e-mail messages, see my page referenced in my .signature file, explaining it to people puzzled by their clueless mail tool's report of "unknown attachment".

Verifying Digital Signatures With PGP Tools

I use The GNU Privacy Guard, or GnuPG. It can be used from the command line, where the gpg command does pretty much everything. And it can be used as a plug-in for mail tools.

One of four things must happen when you attempt to verify a digitally signed message or data file:

Hashed Message Authentication Code (HMAC)

The sender and receiver share a secret key. HMAC is formed as hash(message+key). Sender transmits message and HMAC. Receiver performs same hash(received+key) to verify message integrity and sender authentication.

Generating HMAC:

    +----------+
    |          | }
    | Message  | }    +---+
    |          | }--->| H |---> HMAC
    +----------+ }    +---+
    |Secret Key| }
    +----------+

Transmit only the message and HMAC to the receiver.

       Sender                  Receiver
    +----------+
    |          |
    | Message  | =================>
    |          |
    +----------+

    +----------+
    |   HMAC   | =================>
    +----------+

Verifying HMAC:
    +----------+
    | Received | }
    | Message  | }    +---+
    |          | }--->| H |---> hash
    +----------+ }    +---+      ^
    |Secret Key| }               |
    +----------+                 |
                                 |
    +----------+                 |
    | Received |  <--------------Compare these.
    |   HMAC   |                 If equal, then this was a valid
    +----------+                 message from the authentic sender.

Note that a digital signature requires a hash of the entire message followed by an encryption of the hash. If you are only sending one large message, the work required for the hash overwhelms that for the encryption, and there is no real computational advantage to an HMAC.

An HMAC requires only a hash. If you are sending a large number of small messages, an HMAC has a computational advantage.

So, digitally sign an electronic mail message, but use HMAC within IPsec to verify all IP datagrams.

X.509v3 Digital Certificates

None of this makes much sense if you cannot be absolutely certain who you are talking to!

A digital certificate is a message that says, "The public key of so-and-so is such-and-such", with that message digitally signed by an entity called a Certificate Authority (CA). Attributes of a CA:

For instance, Verisign, Thawt, and others are CAs whose public keys have been coded into your web browsers by the software developers (and so you must absolutely trust your software providers, too).

When you download a secure page via HTTPS:

  1. The server sends your browser a digital certificate signed by some CA you trust.
  2. Your browser verifies the digital certificate and thus is certain that it really has the public key for some claimed identity.
  3. However, anyone could send you the well-known digital certificate, we must verify that the server really is who it claims....
  4. Your browser generates a random number and encrypts it with that public key. It then sends the result to the server, asking the server to decrypt it with the corresponding private key and send it back. [OK, I have simplified this somewhat for the sake of this explanation, go read the SSL/TLS specifications for the whole story if you care.]

X.509v3 is simply the format of digital certificate that everyone uses.

Also be aware that a digital certificate is proof of identity, but not proof of intent or good will! Anyone could get a digital certificate for the bogus-and-dishonest-bank.com domain, set up a web server, and get you to tell it your credit card numbers over an SSL/TLS connection.

I have a page explaining how to create and install keys and X.509v3 certificates for a secure Apache web server.

Enigma encryption machine.

Back to the Security Index

Click here to inquire about advertising on this or any page on this site.
Home Unix/Linux Networking Cybersecurity Travel Technical Radio Site Map Contact


Use /bin/vi! Manipulate images with ImageMagick! Hosted on OpenBSD
Hosted on Apache This site is viewable with any browser Valid XHTML 1.0! Valid CSS!
© Bob Cromwell Feb 2012. Created with /bin/vi and ImageMagick, hosted on OpenBSD with Apache.    Root password available here, privacy policy here.