PCP public and secret key functions. More...

Classes

struct  _pcp_key_t
 PCP private key structure. More...
 
struct  _pcp_pubkey_t
 PCP public key structure. More...
 
struct  _pcp_rec_t
 Encrypted recipient list. More...
 

Typedefs

typedef struct _pcp_key_t pcp_key_t
 Typedef for secret keys. More...
 
typedef struct _pcp_pubkey_t pcp_pubkey_t
 Typedef for public keys. More...
 
typedef struct _pcp_rec_t pcp_rec_t
 Typedef for public keys. More...
 

Enumerations

enum  _PCP_KEY_TYPES {
  PCP_KEY_TYPE_MAINSECRET = 1, PCP_KEY_TYPE_SECRET = 2, PCP_KEY_TYPE_PUBLIC = 3, PCP_KEYSIG_NATIVE = 4,
  PCP_KEYSIG_PBP = 5
}
 Internal key types. More...
 

Functions

pcp_key_tpcpkey_new ()
 Generate a new key structure. More...
 
char * pcppubkey_get_art (pcp_pubkey_t *k)
 Generate an ASCII art image of the public key. More...
 
char * pcpkey_get_art (pcp_key_t *k)
 Generate an ASCII art image of the public key part of a secret key. More...
 
pcp_key_tpcpkey_encrypt (PCPCTX *ptx, pcp_key_t *key, char *passphrase)
 Encrypt a secret key structure. More...
 
pcp_key_tpcpkey_decrypt (PCPCTX *ptx, pcp_key_t *key, char *passphrase)
 Decrypt a secret key structure. More...
 
pcp_pubkey_tpcpkey_pub_from_secret (pcp_key_t *key)
 Generate a public key structure from a given secret key structure. More...
 
char * pcp_getkeyid (pcp_key_t *k)
 Calculate a key-id from public key fields. More...
 
char * pcp_getpubkeyid (pcp_pubkey_t *k)
 Calculate a key-id from public key fields. More...
 
byte * pcppubkey_getchecksum (pcp_pubkey_t *k)
 Calculate a checksum of a public key. More...
 
byte * pcpkey_getchecksum (pcp_key_t *k)
 Calculate a checksum of a public key part of the given secret key. More...
 
byte * pcp_gennonce ()
 Generate a nonce. More...
 
int pcp_sanitycheck_pub (PCPCTX *ptx, pcp_pubkey_t *key)
 Make a sanity check of the given public key structure. More...
 
int pcp_sanitycheck_key (PCPCTX *ptx, pcp_key_t *key)
 Make a sanity check of the given secret key structure. More...
 
void pcp_dumpkey (pcp_key_t *k)
 Dump a secret key structure to stderr. More...
 
void pcp_dumppubkey (pcp_pubkey_t *k)
 Dump a public key structure to stderr. More...
 
void pcpkey_setowner (pcp_key_t *key, char *owner, char *mail)
 Set Owner and Mail. More...
 

Detailed Description

PCP public and secret key functions.

Functions to generate PCP keypairs, de- and encrypt them and various related helpers.

Typedef Documentation

typedef struct _pcp_key_t pcp_key_t

Typedef for secret keys.

Definition at line 92 of file structs.h.

typedef struct _pcp_pubkey_t pcp_pubkey_t

Typedef for public keys.

Definition at line 119 of file structs.h.

typedef struct _pcp_rec_t pcp_rec_t

Typedef for public keys.

Definition at line 153 of file structs.h.

Enumeration Type Documentation

Internal key types.

Enumerator
PCP_KEY_TYPE_MAINSECRET 

1 - Primary secret

PCP_KEY_TYPE_SECRET 

2 - Other secret

PCP_KEY_TYPE_PUBLIC 

3 - Public

PCP_KEYSIG_NATIVE 

4 - PCP native key signature

PCP_KEYSIG_PBP 

5 - PBP key signature

Definition at line 95 of file defines.h.

Function Documentation

void pcp_dumpkey ( pcp_key_t k)

Dump a secret key structure to stderr.

Parameters
[in]kSecret key to dump.
void pcp_dumppubkey ( pcp_pubkey_t k)

Dump a public key structure to stderr.

Parameters
[in]kPublic key to dump.
byte* pcp_gennonce ( )

Generate a nonce.

This function generates a 24 byte nonce used for cryptographic functions. It allocates the memory and the caller is responsible to clear and free() it after use.

Returns
Returns a pointer to a 24 byte byte array.
char* pcp_getkeyid ( pcp_key_t k)

Calculate a key-id from public key fields.

This function calculates 2 JEN Hashes: one from the 'pub' field and one from the 'edpub' field. It the puts them together into a newly allocated char pointer of 17 bytes length as hex, terminated with a 0.

The key-id is supposed to be collision save, but there's no guarantee. However, it's used locally only, it wont be transmitted over the network and it's not part of any exported packet.

Parameters
[in]kThe secret key structure.
Returns
Returns a char pointer containing the key-id string.
char* pcp_getpubkeyid ( pcp_pubkey_t k)

Calculate a key-id from public key fields.

This does the same as pcp_getkeyid() but uses a pcp_pubkey_t as input.

Parameters
[in]kThe public key structure.
Returns
Returns a char pointer containing the key-id string.
int pcp_sanitycheck_key ( PCPCTX ptx,
pcp_key_t key 
)

Make a sanity check of the given secret key structure.

Parameters
[in]ptxpcp context.
[in]keyThe secret key structure.
Returns
Returns 1 if the sanity check succeeds, 0 otherwise. Use fatals_ifany() to check why.
int pcp_sanitycheck_pub ( PCPCTX ptx,
pcp_pubkey_t key 
)

Make a sanity check of the given public key structure.

Parameters
[in]ptxpcp context.
[in]keyThe public key structure.
Returns
Returns 1 if the sanity check succeeds, 0 otherwise. Use fatals_ifany() to check why.
pcp_key_t* pcpkey_decrypt ( PCPCTX ptx,
pcp_key_t key,
char *  passphrase 
)

Decrypt a secret key structure.

The given passphrase will be used to calculate an encryption key using the scrypt() function.

The encryption key will be used to decrypt the 'encrypted' field of the structure. If it works, the result will be dissected and put into the correspondig secret key fields.

The data structure will be modified directly, no new memory will be allocated.

The caller is responsible to clear the passphrase right after use and free() it as soon as possible.

Parameters
[in]ptxpcp context.
[in,out]keyThe secret key structure.
[in]passphraseThe passphrase used to decrypt the key.
Returns
Returns a pointer to the decrypted key structure or NULL in case of an error. Use fatals_ifany() to catch them.
pcp_key_t* pcpkey_encrypt ( PCPCTX ptx,
pcp_key_t key,
char *  passphrase 
)

Encrypt a secret key structure.

The given passphrase will be used to calculate an encryption key using the scrypt() function.

The secret keys will be concatenated and encrypted, the result will be put into the 'encrypted' field. The first byte of each secret key field will be set to 0 to indicate the key is encrypted.

The data structure will be modified directly, no new memory will be allocated.

The caller is responsible to clear the passphrase right after use and free() it as soon as possible.

Parameters
[in]ptxpcp context.
[in,out]keyThe secret key structure.
[in]passphraseThe passphrase used to encrypt the key.
Returns
Returns a pointer to the encrypted key structure or NULL in case of an error. Use fatals_ifany() to catch them.
char* pcpkey_get_art ( pcp_key_t k)

Generate an ASCII art image of the public key part of a secret key.

see pcppubkey_get_art() for details.

Parameters
[in]kThe secret key structure.
Returns
Returns an allocated char pointer containing the ASCII art image. The caller is responsible to free() it.
byte* pcpkey_getchecksum ( pcp_key_t k)

Calculate a checksum of a public key part of the given secret key.

See pcppubkey_getchecksum().

Parameters
[in]kThe secret key structure.
Returns
Returns a pointer to an 32 byte byte.
pcp_key_t* pcpkey_new ( )

Generate a new key structure.

Owner and mail field must be filled by the caller. Memory for the returned pointer will be allocated by the function.

Returns
Returns pointer to new pcp_key_t structure.
pcp_pubkey_t* pcpkey_pub_from_secret ( pcp_key_t key)

Generate a public key structure from a given secret key structure.

This function extracts all required fields and fills a newly allocated pcp_pubkey_t structure.

The caller is responsible to clear and free() it after use.

Parameters
[in]keyThe secret key structure.
Returns
Returns a new pcp_pubkey_t structure.
void pcpkey_setowner ( pcp_key_t key,
char *  owner,
char *  mail 
)

Set Owner and Mail.

Parameters
[in]keyThe secret key structure.
[in]ownerOwner string.
[in]mailEmail string.
char* pcppubkey_get_art ( pcp_pubkey_t k)

Generate an ASCII art image of the public key.

This functions originally appeared in OpenSSH rev 1.70, comitted by Alexander von Gernler, published under the BSD license.

Human beings are bad at memorizing numbers, especially large numbers, but we are very good at recognizing images. This function calculates an ascii art image of a public key, which the user shall always see, when used. If the image changes, the user would immediately recognize the change, even unconsciously.

Sample random art image from the following public key:

c308455ed4cf0c140bf48bfb0d87c4999c66e823bbe74ff16e2a9adc8e770747
+----------------+
| .o.ooo. |
| o . o |
| . . = |
| . o + |
| . + |
| . |
| |
| |
+----------------+
Parameters
[in]kThe public key structure.
Returns
Returns an allocated char pointer containing the ASCII art image. The caller is responsible to free() it.
byte* pcppubkey_getchecksum ( pcp_pubkey_t k)

Calculate a checksum of a public key.

This function calculates a 32 byte checksum of the encryption public key part of the given pcp_pubkey_t structure using crypto_hash_sha256.

The returned pointer will be allocated and it is the responsibility of the caller to free() ist after use.

Parameters
[in]kThe public key structure.
Returns
Returns a pointer to an 32 byte byte.