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_t * | pcpkey_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_t * | pcpkey_encrypt (PCPCTX *ptx, pcp_key_t *key, char *passphrase) |
Encrypt a secret key structure. More... | |
pcp_key_t * | pcpkey_decrypt (PCPCTX *ptx, pcp_key_t *key, char *passphrase) |
Decrypt a secret key structure. More... | |
pcp_pubkey_t * | pcpkey_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... | |
PCP public and secret key functions.
Functions to generate PCP keypairs, de- and encrypt them and various related helpers.
typedef struct _pcp_key_t pcp_key_t |
typedef struct _pcp_pubkey_t pcp_pubkey_t |
typedef struct _pcp_rec_t pcp_rec_t |
enum _PCP_KEY_TYPES |
void pcp_dumpkey | ( | pcp_key_t * | k | ) |
Dump a secret key structure to stderr.
[in] | k | Secret key to dump. |
void pcp_dumppubkey | ( | pcp_pubkey_t * | k | ) |
Dump a public key structure to stderr.
[in] | k | Public 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.
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.
[in] | k | The secret key structure. |
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.
[in] | k | The public key structure. |
Make a sanity check of the given secret key structure.
[in] | ptx | pcp context. |
[in] | key | The secret key structure. |
int pcp_sanitycheck_pub | ( | PCPCTX * | ptx, |
pcp_pubkey_t * | key | ||
) |
Make a sanity check of the given public key structure.
[in] | ptx | pcp context. |
[in] | key | The public key structure. |
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.
[in] | ptx | pcp context. |
[in,out] | key | The secret key structure. |
[in] | passphrase | The passphrase used to decrypt the key. |
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.
[in] | ptx | pcp context. |
[in,out] | key | The secret key structure. |
[in] | passphrase | The passphrase used to encrypt the key. |
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.
[in] | k | The secret key structure. |
byte* pcpkey_getchecksum | ( | pcp_key_t * | k | ) |
Calculate a checksum of a public key part of the given secret key.
[in] | k | The secret key structure. |
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.
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.
[in] | key | The secret key structure. |
void pcpkey_setowner | ( | pcp_key_t * | key, |
char * | owner, | ||
char * | |||
) |
Set Owner and Mail.
[in] | key | The secret key structure. |
[in] | owner | Owner string. |
[in] | Email 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:
[in] | k | The public key structure. |
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.
[in] | k | The public key structure. |