Digital signature overview

A digital signature is a widely used security technique for assuring the integrity of data and authentication of its signer.

The first step in creating a digital signature is to use asymmetric cryptography (also known as public-key cryptography) to generate a pair of keys:

These keys are complementary: if data is encrypted with the private key, then the public key is required to decrypt the data. In a similar way, if the public key is used to encrypt the data, the private key should be used in the decryption.

To generate the signature of a document, encrypt it with the private key, which only the signer has. Note that this does not provide any confidentiality: the public key is known to anyone, so anyone can decrypt the document. However, decrypting the signature with the public signer key and obtaining the same document guarantees that:

Since the signature is the same size as the document, the signed document ends up to be twice the document size. To solve this problem, a cryptographic hash is introduced.

A cryptographic hash (also know as digest) is a function that maps data of any size to data of a fixed size and which is designed to be a one-way function. A cryptographic hash is impossible to invert. Several properties of the hash allows the function to be used in this context without introducing weakness in the scheme:

Instead of encrypting the entire document to generate the signature, the signature is generated from just the hash of the document. This keeps the size of the signature relatively small. The image below shows the complete process:

 

Authenticating a signed document

To authenticate a signed document, follow this procedure:

  1. Decrypt the signature to obtain the hash of the original document.
  2. Compute the hash of the document.
  3. Compare the hashes. For them to match, the following conditions must be met: 

If the hashes match, the signature is correct and the document is valid. The following diagram illustrates the authentication process:

 

How can you be sure that the public key is the signer's public key? If an attacker provides a public key as if it was the public key that the signer used, the attacker could use its private key to sign images.  There are several ways to solve this problem.

Validating and booting signed firmware

For firmware validation, the most common approach is to program the public key in the device's secure storage memory during manufacturing. The secure storage guarantees that the public key is valid and was programmed by the signer.  This scheme for validating and booting signed firmware images is shown below: