# Digital signature

This chapter is dedicated to the digital signature functions and objects, a subpart of the standard security module.

## Signature objects

A digital signature is a unique representation, supposedly non forgeable, designed to authenticate a document, in whatever form it is represented. For example, a signature is used to sign a certificate which is used during the process of establish a secured connection over the Internet. A signature can also be used to sign a courrier or keys as it is in the Openssh protocol.

Digital signatures come into several flavors eventually associated with the signed document. Sometimes, the signature acts as a container and permits to retrieve the document itself. Whatever the method, the principle remains the same. As of today technology, there are two standards used to sign document as indicated below.

### Digital signature standard

Standard | Name
--- | ---
DSS | Digital Signature Standard
RSA | RSA based signature

### Signer and signature objects

The process of generating a signature is done with the help of a `Signer` object. A signer object is a generic object, similar in functionality to the hasher object. The result produced by a signer object is a `Signature` object which holds the generated signature.

### Signature key

The process of generating a signature often requires the use of a key. Such key can be generated with the help of the `Key` object. The nature of the key will depend on the target signature. The following table is a resume of the supported keys.

### Digital signature key

Standard | Key | Signer
--- | --- | ---
DSS | KDSA | Dsa

In the case of DSS, a key can be generated automatically, although this process is time consuming. The default key size is 1024 bits.

const key (afnix:sec:Key afnix:sec:Key:KDSA) assert 1024 (key:get-bits)

### Creating a signer

A `Signer` object is created with a particular signature object such like DSA. The `Dsa` object is a signer object that implements the Digital Signature Algorithm as specified by the Digital Signature Standard (DSS) in FIPS-PUB 186-3.

# create a dsa signer const dsa (afnix:sec:Dsa key) assert true (afnix:sec:dsa-p dsa)

### Creating a signature

A signature is created with the help of the `compute` method. The `Signature` object is similar to the `Hasher` and operates with string or streams.

# create a signature object const sgn (dsa:compute "afnix") assert true (afnix:sec:signature-p sgn)

Once the signature is created, each data can be accessed directly with the associated component mapper. In the case of DSS, there are two components as show below.

# get the DSS S component sgn:get-relatif-component afnix:sec:Signature:DSA-S-COMPONENT) # get the DSS R component sgn:get-relatif-component afnix:sec:Signature:DSA-R-COMPONENT)