X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/052b36d05a622a93733b735acce2de865b14627b..ada5514153f5d2935fc82e8c787a12cffa5953d9:/key-data.h diff --git a/key-data.h b/key-data.h index 6cf2439..40b8b4b 100644 --- a/key-data.h +++ b/key-data.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: key-data.h,v 1.1 2000/02/12 18:21:23 mdw Exp $ + * $Id: key-data.h,v 1.4 2004/04/08 01:36:15 mdw Exp $ * * Manipulating key data * @@ -27,14 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: key-data.h,v $ - * Revision 1.1 2000/02/12 18:21:23 mdw - * Overhaul of key management (again). - * - */ - #ifndef CATACOMB_KEY_DATA_H #define CATACOMB_KEY_DATA_H @@ -54,6 +46,10 @@ # include "mp.h" #endif +#ifndef CATACOMB_EC_H +# include "ec.h" +#endif + /*----- Data structures ---------------------------------------------------*/ /* --- Key binary data --- */ @@ -71,6 +67,8 @@ typedef struct key_data { key_bin k; /* Binary key data */ mp *m; /* Multiprecision integer */ sym_table s; /* Structured key data */ + char *p; /* String pointer */ + ec e; /* Elliptic curve point */ } u; } key_data; @@ -79,6 +77,18 @@ typedef struct key_struct { key_data k; } key_struct; +/* --- Packing and unpacking --- */ + +typedef struct key_packdef { + void *p; /* Pointer to the destination */ + key_data kd; /* Key data block */ +} key_packdef; + +typedef struct key_packstruct { + char *name; /* Pointer to name string */ + key_packdef kp; /* Packing structure */ +} key_packstruct; + /* --- Key binary encoding --- * * * The binary encoding consists of a header containing a 16-bit encoding type @@ -103,11 +113,13 @@ enum { /* --- Bottom two bits are the encoding type --- */ - KF_ENCMASK = 0x03, /* Encoding mask */ + KF_ENCMASK = 0x83, /* Encoding mask */ KENC_BINARY = 0x00, /* Plain binary key (@k@) */ KENC_MP = 0x01, /* Multiprecision integer (@i@) */ KENC_STRUCT = 0x02, /* Structured key data (@s@) */ KENC_ENCRYPT = 0x03, /* Encrypted key type (@k@) */ + KENC_STRING = 0x80, /* ASCII string (@p@) */ + KENC_EC = 0x81, /* Elliptic curve point (@e@) */ /* --- Key category bits --- */ @@ -122,6 +134,7 @@ enum { KF_BURN = 0x10, /* Burn key after use */ KF_TEMP = 0x20, /* Temporary copy flag */ + KF_OPT = 0x40, /* Optional key (for @key_unpack@) */ /* --- Tag end --- */ @@ -223,6 +236,30 @@ extern void key_encrypted(key_data */*k*/, const void */*p*/, size_t /*sz*/); extern void key_mp(key_data */*k*/, mp */*m*/); +/* --- @key_string@ --- * + * + * Arguments: @key_data *k@ = pointer to key data block + * @const char *p@ = pointer to the value to set + * + * Returns: --- + * + * Use: Sets a plain string in a key block. + */ + +extern void key_string(key_data */*k*/, const char */*p*/); + +/* --- @key_ec@ --- * + * + * Arguments: @key_data *k@ = pointer to key data block + * @const ec *e@ = pointer to the value to set + * + * Returns: --- + * + * Use: Sets an elliptic curve point in a key block. + */ + +extern void key_ec(key_data */*k*/, const ec */*e*/); + /* --- @key_structure@ --- * * * Arguments: @key_data *k@ = pointer to key data block @@ -361,6 +398,46 @@ extern int key_decode(const void */*p*/, size_t /*sz*/, key_data */*k*/); extern int key_encode(key_data */*k*/, dstr */*d*/, const key_filter */*kf*/); +/*----- Packing and unpacking keys ----------------------------------------*/ + +/* --- @key_pack@ --- * + * + * Arguments: @key_packdef *kp@ = pointer to packing structure + * @key_data *kd@ = pointer to destination key data + * @dstr *d@ = pointer to tag string for the key data + * + * Returns: Error code, or zero. + * + * Use: Packs a key from a data structure. + */ + +extern int key_pack(key_packdef */*kp*/, key_data */*kd*/, dstr */*d*/); + +/* --- @key_unpack@ --- * + * + * Arguments: @key_packdef *kp@ = pointer to packing structure + * @key_data *kd@ = pointer to source key data + * @dstr *d@ = pointer to tag string for the key data + * + * Returns: Error code, or zero. + * + * Use: Unpacks a key into an appropriate data structure. + */ + +extern int key_unpack(key_packdef */*kp*/, key_data */*kd*/, dstr */*d*/); + +/* --- @key_unpackdone@ --- * + * + * Arguments: @key_packdef *kp@ = pointer to packing definition + * + * Returns: --- + * + * Use: Frees the key components contained within a packing + * definition, created during key unpacking. + */ + +extern void key_unpackdone(key_packdef */*kp*/); + /*----- Passphrase encryption ---------------------------------------------*/ /* --- @key_plock@ --- *