root/openpgpsdk/trunk/include/openpgpsdk/packet.h

Revision 334 (checked in by ben, 7 years ago)

Add passphrase callbacks.

  • Property svn:keywords set to Id
Line 
1 /** \file
2  * packet related headers.
3  */
4
5 #ifndef OPS_PACKET_H
6 #define OPS_PACKET_H
7
8 #include "configure.h"
9
10 #include <time.h>
11 #include <openssl/bn.h>
12 #include "types.h"
13 #include "errors.h"
14
15 /** General-use structure for variable-length data
16  */
17
18 typedef struct
19     {
20     size_t len;
21     unsigned char *contents;
22     } ops_data_t;
23
24 /************************************/
25 /* Packet Tags - RFC2440bis-12, 4.2 */
26 /************************************/
27
28 /** Packet Tag - Bit 7 Mask (this bit is always set).
29  * The first byte of a packet is the "Packet Tag".  It always
30  * has bit 7 set.  This is the mask for it.
31  *
32  * \see RFC2440bis-12 4.2
33  */
34 #define OPS_PTAG_ALWAYS_SET             0x80
35
36 /** Packet Tag - New Format Flag.
37  * Bit 6 of the Packet Tag is the packet format indicator.
38  * If it is set, the new format is used, if cleared the
39  * old format is used.
40  *
41  * \see RFC2440bis-12 4.2
42  */
43 #define OPS_PTAG_NEW_FORMAT             0x40
44
45
46 /** Old Packet Format: Mask for content tag.
47  * In the old packet format bits 5 to 2 (including)
48  * are the content tag.  This is the mask to apply
49  * to the packet tag.  Note that you need to
50  * shift by #OPS_PTAG_OF_CONTENT_TAG_SHIFT bits.
51  *
52  * \see RFC2440bis-12 4.2
53  */
54 #define OPS_PTAG_OF_CONTENT_TAG_MASK    0x3c
55 /** Old Packet Format: Offset for the content tag.
56  * As described at #OPS_PTAG_OF_CONTENT_TAG_MASK the
57  * content tag needs to be shifted after being masked
58  * out from the Packet Tag.
59  *
60  * \see RFC2440bis-12 4.2
61  */
62 #define OPS_PTAG_OF_CONTENT_TAG_SHIFT   2
63 /** Old Packet Format: Mask for length type.
64  * Bits 1 and 0 of the packet tag are the length type
65  * in the old packet format.
66  *
67  * See #ops_ptag_of_lt_t for the meaning of the values.
68  *
69  * \see RFC2440bis-12 4.2
70  */
71 #define OPS_PTAG_OF_LENGTH_TYPE_MASK    0x03
72
73
74 /** Old Packet Format Lengths.
75  * Defines the meanings of the 2 bits for length type in the
76  * old packet format.
77  *
78  * \see RFC2440bis-12 4.2.1
79  */
80 typedef enum
81     {
82     OPS_PTAG_OF_LT_ONE_BYTE             =0x00, /*!< Packet has a 1 byte length - header is 2 bytes long. */
83     OPS_PTAG_OF_LT_TWO_BYTE             =0x01, /*!< Packet has a 2 byte length - header is 3 bytes long. */
84     OPS_PTAG_OF_LT_FOUR_BYTE            =0x02, /*!< Packet has a 4 byte length - header is 5 bytes long. */
85     OPS_PTAG_OF_LT_INDETERMINATE        =0x03  /*!< Packet has a indeterminate length. */
86     } ops_ptag_of_lt_t;
87
88
89 /** New Packet Format: Mask for content tag.
90  * In the new packet format the 6 rightmost bits
91  * are the content tag.  This is the mask to apply
92  * to the packet tag.  Note that you need to
93  * shift by #OPS_PTAG_NF_CONTENT_TAG_SHIFT bits.
94  *
95  * \see RFC2440bis-12 4.2
96  */
97 #define OPS_PTAG_NF_CONTENT_TAG_MASK    0x3f
98 /** New Packet Format: Offset for the content tag.
99  * As described at #OPS_PTAG_NF_CONTENT_TAG_MASK the
100  * content tag needs to be shifted after being masked
101  * out from the Packet Tag.
102  *
103  * \see RFC2440bis-12 4.2
104  */
105 #define OPS_PTAG_NF_CONTENT_TAG_SHIFT   0
106
107
108
109 /* PTag Content Tags */
110 /***************************/
111
112 /** Package Tags (aka Content Tags) and signature subpacket types.
113  * This enumerates all rfc-defined packet tag values and the
114  * signature subpacket type values that we understand.
115  *
116  * \see RFC2440bis-12 4.3
117  * \see RFC2440bis-12 5.2.3.1
118  */
119 enum ops_content_tag_t
120     {
121     OPS_PTAG_CT_RESERVED                = 0,    /*!< Reserved - a packet tag must not have this value */
122     OPS_PTAG_CT_PK_SESSION_KEY          = 1,    /*!< Public-Key Encrypted Session Key Packet */
123     OPS_PTAG_CT_SIGNATURE               = 2,    /*!< Signature Packet */
124     OPS_PTAG_CT_SK_SESSION_KEY          = 3,    /*!< Symmetric-Key Encrypted Session Key Packet */
125     OPS_PTAG_CT_ONE_PASS_SIGNATURE      = 4,    /*!< One-Pass Signature Packet */
126     OPS_PTAG_CT_SECRET_KEY              = 5,    /*!< Secret Key Packet */
127     OPS_PTAG_CT_PUBLIC_KEY              = 6,    /*!< Public Key Packet */
128     OPS_PTAG_CT_SECRET_SUBKEY           = 7,    /*!< Secret Subkey Packet */
129     OPS_PTAG_CT_COMPRESSED              = 8,    /*!< Compressed Data Packet */
130     OPS_PTAG_CT_SK_DATA                 = 9,    /*!< Symmetrically Encrypted Data Packet */
131     OPS_PTAG_CT_MARKER                  =10,    /*!< Marker Packet */
132     OPS_PTAG_CT_LITERAL_DATA            =11,    /*!< Literal Data Packet */
133     OPS_PTAG_CT_TRUST                   =12,    /*!< Trust Packet */
134     OPS_PTAG_CT_USER_ID                 =13,    /*!< User ID Packet */
135     OPS_PTAG_CT_PUBLIC_SUBKEY           =14,    /*!< Public Subkey Packet */
136     OPS_PTAG_CT_RESERVED2               =15,    /*!< reserved */
137     OPS_PTAG_CT_RESERVED3               =16,    /*!< reserved */
138     OPS_PTAG_CT_USER_ATTRIBUTE          =17,    /*!< User Attribute Packet */
139     OPS_PTAG_CT_SK_IP_DATA              =18,    /*!< Sym. Encrypted and Integrity Protected Data Packet */
140     OPS_PTAG_CT_MDC                     =19,    /*!< Modification Detection Code Packet */
141
142     OPS_PARSER_ERROR                    =0x100, /*!< Internal Use: Parser Error */
143     OPS_PARSER_PTAG                     =0x101, /*!< Internal Use: The packet is the "Packet Tag" itself - used when
144                                                      callback sends back the PTag. */
145     OPS_PTAG_RAW_SS                     =0x102, /*!< Internal Use: content is raw sig subtag */
146     OPS_PTAG_SS_ALL                     =0x103, /*!< Internal Use: select all subtags */
147     OPS_PARSER_PACKET_END               =0x104,
148     OPS_PARSER_ERRCODE                  =0x105, /*! < Internal Use: Parser Error with errcode returned */
149
150     /* signature subpackets (0x200-2ff) (type+0x200) */
151     /* only those we can parse are listed here */
152     OPS_PTAG_SIGNATURE_SUBPACKET_BASE   =0x200,         /*!< Base for signature subpacket types - All signature type
153                                                              values are relative to this value. */
154     OPS_PTAG_SS_CREATION_TIME           =0x200+2,       /*!< signature creation time */
155     OPS_PTAG_SS_EXPIRATION_TIME         =0x200+3,       /*!< signature expiration time */
156
157     OPS_PTAG_SS_TRUST                   =0x200+5,       /*!< trust signature */
158     OPS_PTAG_SS_REGEXP                  =0x200+6,       /*!< regular expression */
159     OPS_PTAG_SS_REVOCABLE               =0x200+7,       /*!< revocable */
160     OPS_PTAG_SS_KEY_EXPIRATION_TIME     =0x200+9,       /*!< key expiration time */
161     OPS_PTAG_SS_RESERVED                =0x200+10,      /*!< reserved */
162     OPS_PTAG_SS_PREFERRED_SKA           =0x200+11,      /*!< preferred symmetric algorithms */
163     OPS_PTAG_SS_REVOCATION_KEY          =0x200+12,      /*!< revocation key */
164     OPS_PTAG_SS_ISSUER_KEY_ID           =0x200+16, /*!< issuer key ID */
165     OPS_PTAG_SS_NOTATION_DATA           =0x200+20, /*!< notation data */
166     OPS_PTAG_SS_PREFERRED_HASH          =0x200+21, /*!< preferred hash algorithms */
167     OPS_PTAG_SS_PREFERRED_COMPRESSION   =0x200+22, /*!< preferred compression algorithms */
168     OPS_PTAG_SS_KEY_SERVER_PREFS        =0x200+23, /*!< key server preferences */
169     OPS_PTAG_SS_PREFERRED_KEY_SERVER    =0x200+24, /*!< Preferred Key Server */
170     OPS_PTAG_SS_PRIMARY_USER_ID         =0x200+25, /*!< primary User ID */
171     OPS_PTAG_SS_POLICY_URL              =0x200+26, /*!< Policy URL */
172     OPS_PTAG_SS_KEY_FLAGS               =0x200+27, /*!< key flags */
173     OPS_PTAG_SS_SIGNERS_USER_ID         =0x200+28, /*!< Signer's User ID */
174     OPS_PTAG_SS_REVOCATION_REASON       =0x200+29, /*!< reason for revocation */
175     OPS_PTAG_SS_FEATURES                =0x200+30, /*!< features */
176
177     OPS_PTAG_SS_USERDEFINED00   =0x200+100, /*!< internal or user-defined */
178     OPS_PTAG_SS_USERDEFINED01   =0x200+101,
179     OPS_PTAG_SS_USERDEFINED02   =0x200+102,
180     OPS_PTAG_SS_USERDEFINED03   =0x200+103,
181     OPS_PTAG_SS_USERDEFINED04   =0x200+104,
182     OPS_PTAG_SS_USERDEFINED05   =0x200+105,
183     OPS_PTAG_SS_USERDEFINED06   =0x200+106,
184     OPS_PTAG_SS_USERDEFINED07   =0x200+107,
185     OPS_PTAG_SS_USERDEFINED08   =0x200+108,
186     OPS_PTAG_SS_USERDEFINED09   =0x200+109,
187     OPS_PTAG_SS_USERDEFINED10   =0x200+110,
188
189        
190     /* pseudo content types */
191     OPS_PTAG_CT_LITERAL_DATA_HEADER     =0x300,
192     OPS_PTAG_CT_LITERAL_DATA_BODY       =0x300+1,
193     OPS_PTAG_CT_SIGNATURE_HEADER        =0x300+2,
194     OPS_PTAG_CT_SIGNATURE_FOOTER        =0x300+3,
195     OPS_PTAG_CT_ARMOUR_HEADER           =0x300+4,
196     OPS_PTAG_CT_ARMOUR_TRAILER          =0x300+5,
197     OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER =0x300+6,
198     OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY   =0x300+7,
199     OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER=0x300+8,
200     OPS_PTAG_CT_UNARMOURED_TEXT         =0x300+9,
201
202     /* commands to the callback */
203     OPS_PTAG_CMD_GET_PASSPHRASE         =0x400,
204     };
205
206 /** Structure to hold one parse error string. */
207 typedef struct
208     {
209     const char *error; /*!< error message. */
210     } ops_parser_error_t;
211
212 /** Structure to hold one error code */
213 typedef struct
214     {
215     ops_errcode_t errcode;
216     } ops_parser_errcode_t;
217
218 /** Structure to hold one packet tag.
219  * \see RFC2440bis-12 4.2
220  */
221 typedef struct
222     {
223     unsigned            new_format;     /*!< Whether this packet tag is new (true) or old format (false) */
224     unsigned            content_tag;    /*!< content_tag value - See #ops_content_tag_t for meanings */
225     ops_ptag_of_lt_t    length_type;    /*!< Length type (#ops_ptag_of_lt_t) - only if this packet tag is old format.  Set to 0 if new format. */
226     unsigned            length;         /*!< The length of the packet.  This value is set when we read and compute the
227                                           length information, not at the same moment we create the packet tag structure.
228                                           Only defined if #length_read is set. */  /* XXX: Ben, is this correct? */
229     unsigned            position;       /*!< The position (within the current reader) of the packet */
230     } ops_ptag_t;
231
232 /** Public Key Algorithm Numbers.
233  * OpenPGP assigns a unique Algorithm Number to each algorithm that is part of OpenPGP.
234  *
235  * This lists algorithm numbers for public key algorithms.
236  *
237  * \see RFC2440bis-12 9.1
238  */
239 typedef enum
240     {
241     OPS_PKA_RSA                 =1,     /*!< RSA (Encrypt or Sign) */
242     OPS_PKA_RSA_ENCRYPT_ONLY    =2,     /*!< RSA Encrypt-Only (deprecated - \see RFC2440bis-12 12.4) */
243     OPS_PKA_RSA_SIGN_ONLY       =3,     /*!< RSA Sign-Only (deprecated - \see RFC2440bis-12 12.4) */
244     OPS_PKA_ELGAMAL             =16,    /*!< Elgamal (Encrypt-Only) */
245     OPS_PKA_DSA                 =17,    /*!< DSA (Digital Signature Algorithm) */
246     OPS_PKA_RESERVED_ELLIPTIC_CURVE     =18,    /*!< Reserved for Elliptic Curve */
247     OPS_PKA_RESERVED_ECDSA              =19,    /*!< Reserved for ECDSA */
248     OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN     =20,    /*!< Deprecated. */
249     OPS_PKA_RESERVED_DH                 =21,    /*!< Reserved for Diffie-Hellman (X9.42, as defined for IETF-S/MIME) */
250     OPS_PKA_PRIVATE00           =100,   /*!< Private/Experimental Algorithm */
251     OPS_PKA_PRIVATE01           =101,   /*!< Private/Experimental Algorithm */
252     OPS_PKA_PRIVATE02           =102,   /*!< Private/Experimental Algorithm */
253     OPS_PKA_PRIVATE03           =103,   /*!< Private/Experimental Algorithm */
254     OPS_PKA_PRIVATE04           =104,   /*!< Private/Experimental Algorithm */
255     OPS_PKA_PRIVATE05           =105,   /*!< Private/Experimental Algorithm */
256     OPS_PKA_PRIVATE06           =106,   /*!< Private/Experimental Algorithm */
257     OPS_PKA_PRIVATE07           =107,   /*!< Private/Experimental Algorithm */
258     OPS_PKA_PRIVATE08           =108,   /*!< Private/Experimental Algorithm */
259     OPS_PKA_PRIVATE09           =109,   /*!< Private/Experimental Algorithm */
260     OPS_PKA_PRIVATE10           =110,   /*!< Private/Experimental Algorithm */
261     } ops_public_key_algorithm_t;
262
263 /** Structure to hold one DSA public key parameters.
264  *
265  * \see RFC2440bis-12 5.5.2
266  */
267 typedef struct
268     {
269     BIGNUM *p;  /*!< DSA prime p */
270     BIGNUM *q;  /*!< DSA group order q */
271     BIGNUM *g;  /*!< DSA group generator g */
272     BIGNUM *y;  /*!< DSA public key value y (= g^x mod p with x being the secret) */
273     } ops_dsa_public_key_t;
274
275 /** Structure to hold on RSA public key.
276  *
277  * \see RFC2440bis-12 5.5.2
278  */
279 typedef struct
280     {
281     BIGNUM *n;  /*!< RSA public modulus n */
282     BIGNUM *e;  /*!< RSA public encryptiong exponent e */
283     } ops_rsa_public_key_t;
284
285 /** Structure to hold on ElGamal public key parameters.
286  *
287  * \see RFC2440bis-12 5.5.2
288  */
289 typedef struct
290     {
291     BIGNUM *p;  /*!< ElGamal prime p */
292     BIGNUM *g;  /*!< ElGamal group generator g */
293     BIGNUM *y;  /*!< ElGamal public key value y (= g^x mod p with x being the secret) */
294     } ops_elgamal_public_key_t;
295
296 /** Union to hold public key parameters of any algorithm */
297 typedef union
298     {
299     ops_dsa_public_key_t        dsa;            /*!< A DSA public key */
300     ops_rsa_public_key_t        rsa;            /*!< An RSA public key */
301     ops_elgamal_public_key_t    elgamal;        /*!< An ElGamal public key */
302     } ops_public_key_union_t;
303
304 /** Version.
305  * OpenPGP has two different protocol versions: version 3 and version 4.
306  *
307  * \see RFC2440bis-12 5.2
308  */
309 typedef enum
310     {
311     OPS_V3=3,   /*<! Version 3 */
312     OPS_V4=4,   /*<! Version 4 */
313     } ops_version_t;
314
315 /** Structure to hold one pgp public key */
316 typedef struct
317     {
318     ops_version_t               version;        /*!< version of the key (v3, v4...) */
319     time_t                      creation_time;  /*!< when the key was created.  Note that interpretation varies with key
320                                                   version. */
321     unsigned                    days_valid;     /*!< validity period of the key in days since creation.  A value of 0
322                                                   has a special meaning indicating this key does not expire.  Only
323                                                   used with v3 keys. */
324     ops_public_key_algorithm_t  algorithm;      /*!< Public Key Algorithm type */
325     ops_public_key_union_t      key;            /*!< Public Key Parameters */
326     } ops_public_key_t;
327
328 /** Structure to hold data for one RSA secret key
329  */
330 typedef struct
331     {
332     BIGNUM *d;
333     BIGNUM *p;
334     BIGNUM *q;
335     BIGNUM *u;
336     } ops_rsa_secret_key_t;
337
338 /** ops_secret_key_union_t
339  */
340 typedef struct
341     {
342     ops_rsa_secret_key_t rsa;
343     } ops_secret_key_union_t;
344
345 /** s2k_usage_t
346  */
347 typedef enum
348     {
349     OPS_S2KU_NONE=0,
350     OPS_S2KU_ENCRYPTED_AND_HASHED=254,
351     OPS_S2KU_ENCRYPTED=255
352     } ops_s2k_usage_t;
353
354 /** s2k_specifier_t
355  */
356 typedef enum
357     {
358     OPS_S2KS_SIMPLE=0,
359     OPS_S2KS_SALTED=1,
360     OPS_S2KS_ITERATED_AND_SALTED=3
361     } ops_s2k_specifier_t;
362
363 /** Symmetric Key Algorithm Numbers.
364  * OpenPGP assigns a unique Algorithm Number to each algorithm that is part of OpenPGP.
365  *
366  * This lists algorithm numbers for symmetric key algorithms.
367  *
368  * \see RFC2440bis-12 9.2
369  */
370 typedef enum
371     {
372     OPS_SA_PLAINTEXT    =0, /*!< Plaintext or unencrypted data */
373     OPS_SA_IDEA         =1, /*!< IDEA */
374     OPS_SA_TRIPLEDES    =2, /*!< TripleDES */
375     OPS_SA_CAST5        =3, /*!< CAST5 */
376     OPS_SA_BLOWFISH     =4, /*!< Blowfish */
377     OPS_SA_AES_128      =7, /*!< AES with 128-bit key (AES) */
378     OPS_SA_AES_192      =8, /*!< AES with 192-bit key */
379     OPS_SA_AES_256      =9, /*!< AES with 256-bit key */
380     OPS_SA_TWOFISH      =10, /*!< Twofish with 256-bit key (TWOFISH) */
381     } ops_symmetric_algorithm_t;
382
383 // Maximum block size for symmetric crypto
384 #define OPS_MAX_BLOCK_SIZE      16
385
386 /** ops_secret_key_t
387  */
388 typedef struct
389     {
390     ops_public_key_t            public_key;
391     ops_s2k_usage_t             s2k_usage;
392     ops_s2k_specifier_t         s2k_specifier;
393     ops_symmetric_algorithm_t   algorithm;
394     unsigned char               iv[OPS_MAX_BLOCK_SIZE];
395     unsigned                    checksum;
396     ops_secret_key_union_t      key;
397     } ops_secret_key_t;
398
399 /** Structure to hold one trust packet's data */
400
401 typedef struct
402     {
403     ops_data_t data; /*<! Trust Packet */
404     } ops_trust_t;
405        
406 /** Structure to hold one user id */
407 typedef struct
408     {
409     unsigned char *user_id;     /*!< User ID - UTF-8 string */
410     } ops_user_id_t;
411
412 /** Structure to hold one user attribute */
413 typedef struct
414     {
415     ops_data_t data; /*!< User Attribute */
416     } ops_user_attribute_t;
417
418 /** Signature Type.
419  * OpenPGP defines different signature types that allow giving different meanings to signatures.  Signature types
420  * include 0x10 for generitc User ID certifications (used when Ben signs Weasel's key), Subkey binding signatures,
421  * document signatures, key revocations, etc.
422  *
423  * Different types are used in different places, and most make only sense in their intended location (for instance a
424  * subkey binding has no place on a UserID).
425  *
426  * \see RFC2440bis-12 5.2.1
427  */
428 typedef enum
429     {
430     OPS_SIG_BINARY      =0x00,  /*<! Signature of a binary document */
431     OPS_SIG_TEXT        =0x01,  /*<! Signature of a canonical text document */
432     OPS_SIG_STANDALONE  =0x02,  /*<! Standalone signature */
433
434     OPS_CERT_GENERIC    =0x10,  /*<! Generic certification of a User ID and Public Key packet */
435     OPS_CERT_PERSONA    =0x11,  /*<! Persona certification of a User ID and Public Key packet */
436     OPS_CERT_CASUAL     =0x12,  /*<! Casual certification of a User ID and Public Key packet */
437     OPS_CERT_POSITIVE   =0x13,  /*<! Positive certification of a User ID and Public Key packet */
438
439     OPS_SIG_SUBKEY      =0x18,  /*<! Subkey Binding Signature */
440     OPS_SIG_PRIMARY     =0x19,  /*<! Primary Key Binding Signature */
441     OPS_SIG_DIRECT      =0x1f,  /*<! Signature directly on a key */
442
443     OPS_SIG_REV_KEY     =0x20,  /*<! Key revocation signature */
444     OPS_SIG_REV_SUBKEY  =0x28,  /*<! Subkey revocation signature */
445     OPS_SIG_REV_CERT    =0x30,  /*<! Certification revocation signature */
446
447     OPS_SIG_TIMESTAMP   =0x40,  /*<! Timestamp signature */
448
449     OPS_SIG_3RD_PARTY   =0x50,  /*<! Third-Party Confirmation signature */
450     } ops_sig_type_t;
451
452 /** Hashing Algorithm Numbers.
453  * OpenPGP assigns a unique Algorithm Number to each algorithm that is part of OpenPGP.
454  *
455  * This lists algorithm numbers for hash algorithms.
456  *
457  * \see RFC2440bis-12 9.4
458  */
459 typedef enum
460     {
461     OPS_HASH_UNKNOWN    =-1,    /*!< used to indicate errors */
462     OPS_HASH_MD5        = 1,    /*!< MD5 */
463     OPS_HASH_SHA1       = 2,    /*!< SHA-1 */
464     OPS_HASH_RIPEMD     = 3,    /*!< RIPEMD160 */
465
466     OPS_HASH_SHA256     = 8,    /*!< SHA256 */
467     OPS_HASH_SHA384     = 9,    /*!< SHA384 */
468     OPS_HASH_SHA512     =10,    /*!< SHA512 */
469     } ops_hash_algorithm_t;
470
471 /** Struct to hold parameters of an RSA signature */
472 typedef struct
473     {
474     BIGNUM                      *sig;   /*!< the signature value (m^d % n) */
475     } ops_rsa_signature_t;
476
477 /** Struct to hold parameters of a DSA signature */
478 typedef struct
479     {
480     BIGNUM                      *r;     /*!< DSA value r */
481     BIGNUM                      *s;     /*!< DSA value s */
482     } ops_dsa_signature_t;
483
484 /** ops_elgamal_signature_t */
485 typedef struct
486     {
487     BIGNUM                      *r;
488     BIGNUM                      *s;
489     } ops_elgamal_signature_t;
490
491 /** Struct to hold data for a private/experimental signature */
492 typedef struct
493     {
494     ops_data_t  data;
495     } ops_unknown_signature_t;
496
497 /** Union to hold signature parameters of any algorithm */
498 typedef union
499     {
500     ops_rsa_signature_t         rsa;    /*!< An RSA Signature */
501     ops_dsa_signature_t         dsa;    /*!< A DSA Signature */
502     ops_elgamal_signature_t     elgamal; /* deprecated */
503     ops_unknown_signature_t     unknown; /* private or experimental */
504     } ops_signature_union_t;
505
506 #define OPS_KEY_ID_SIZE         8
507
508 /** Struct to hold a signature packet.
509  *
510  * \see RFC2440bis-12 5.2.2
511  * \see RFC2440bis-12 5.2.3
512  */
513 typedef struct
514     {
515     ops_version_t               version;        /*!< signature version number */
516     ops_sig_type_t              type;           /*!< signature type value */
517     time_t                      creation_time;  /*!< creation time of the signature */
518     unsigned char               signer_id[OPS_KEY_ID_SIZE];     /*!< Eight-octet key ID of signer*/
519     ops_public_key_algorithm_t  key_algorithm;  /*!< public key algorithm number */
520     ops_hash_algorithm_t        hash_algorithm; /*!< hashing algorithm number */
521     unsigned char               hash2[2];       /*!< high 2 bytes of hashed value - for quick test */
522     ops_signature_union_t       signature;      /*!< signature parameters */
523     size_t                      v4_hashed_data_start; /* only valid if accumulate is set */
524     size_t                      v4_hashed_data_length;
525     ops_boolean_t               creation_time_set:1;
526     ops_boolean_t               signer_id_set:1;
527     } ops_signature_t;
528
529 /** The raw bytes of a signature subpacket */
530
531 typedef struct
532     {
533     ops_content_tag_t           tag;
534     size_t                      length;
535     unsigned char               *raw;
536     } ops_ss_raw_t;
537
538 /** Signature Subpacket : Trust Level */
539
540 typedef struct
541     {
542     unsigned char               level;  /*<! Trust Level */
543     unsigned char               amount; /*<! Amount */
544     } ops_ss_trust_t;
545
546 /** Signature Subpacket : Revocable */
547 typedef struct
548         {
549         ops_boolean_t   revocable;
550         } ops_ss_revocable_t;
551        
552 /** Signature Subpacket : Time */
553 typedef struct
554     {
555     time_t                      time;
556     } ops_ss_time_t;
557
558 /** Signature Subpacket : Key ID */
559 typedef struct
560     {
561     unsigned char               key_id[OPS_KEY_ID_SIZE];
562     } ops_ss_key_id_t;
563
564 /** Signature Subpacket : Notation Data */
565 typedef struct
566     {
567     ops_data_t flags;
568     ops_data_t name;
569     ops_data_t value;
570     } ops_ss_notation_data_t;
571
572 /** Signature Subpacket : User Defined */
573 typedef struct
574     {
575     ops_data_t data;
576     } ops_ss_userdefined_t;
577
578 /** Signature Subpacket : Unknown */
579 typedef struct
580     {
581     ops_data_t data;
582     } ops_ss_unknown_t;
583
584 /** Signature Subpacket : Preferred Symmetric Key Algorithm */
585 typedef struct
586     {
587     ops_data_t data;
588     /* Note that value 0 may represent the plaintext algorithm
589        so we cannot expect data->contents to be a null-terminated list */
590     } ops_ss_preferred_ska_t;
591
592 /** Signature Subpacket : Preferrred Hash Algorithm */
593 typedef struct
594     {
595     ops_data_t data;
596     } ops_ss_preferred_hash_t;
597
598 /** Signature Subpacket : Preferred Compression */
599 typedef struct
600     {
601     ops_data_t data;
602     } ops_ss_preferred_compression_t;
603
604 /** Signature Subpacket : Key Flags */
605 typedef struct
606     {
607     ops_data_t data;
608     } ops_ss_key_flags_t;
609
610 /** Signature Subpacket : Key Server Preferences */
611 typedef struct
612     {
613     ops_data_t data;
614     } ops_ss_key_server_prefs_t;
615
616 /** Signature Subpacket : Features */
617 typedef struct
618     {
619     ops_data_t data;
620     } ops_ss_features_t;
621
622 /** ops_packet_t */
623
624 typedef struct
625     {
626     size_t                      length;
627     unsigned char               *raw;
628     } ops_packet_t;
629
630 /** Types of Compression */
631 typedef enum
632     {
633     OPS_C_NONE=0,
634     OPS_C_ZIP=1,
635     OPS_C_ZLIB=2,
636     OPS_C_BZIP2=3,
637     } ops_compression_type_t;
638
639 /* unlike most structures, this will feed its data as a stream
640  * to the application instead of directly including it */
641 /** ops_compressed_t */
642 typedef struct
643     {
644     ops_compression_type_t      type;
645     } ops_compressed_t;
646
647 /** ops_one_pass_signature_t */
648 typedef struct
649     {
650     unsigned char               version;
651     ops_sig_type_t              sig_type;
652     ops_hash_algorithm_t        hash_algorithm;
653     ops_public_key_algorithm_t  key_algorithm;
654     unsigned char               keyid[OPS_KEY_ID_SIZE];
655     ops_boolean_t               nested;
656     } ops_one_pass_signature_t;
657
658 /** Signature Subpacket : Primary User ID */
659 typedef struct
660     {
661     ops_boolean_t       primary_user_id;
662     } ops_ss_primary_user_id_t;
663
664 /** Signature Subpacket : Regexp */
665 typedef struct
666     {
667     char *text;
668     } ops_ss_regexp_t;
669
670 /** Signature Subpacket : Policy URL */
671 typedef struct
672     {
673     char *text;
674     } ops_ss_policy_url_t;
675
676 /** Signature Subpacket : Preferred Key Server */
677 typedef struct
678     {
679     char *text;
680     } ops_ss_preferred_key_server_t;
681
682 /** Signature Subpacket : Revocation Key */
683 typedef struct
684     {
685     unsigned char       class;
686     unsigned char       algid;
687     unsigned char fingerprint[20];
688     } ops_ss_revocation_key_t;
689
690 /** Signature Subpacket : Revocation Reason */
691 typedef struct
692     {
693     unsigned char code;
694     char *text;
695     } ops_ss_revocation_reason_t;
696
697 /** literal_data_type_t */
698 typedef enum
699     {
700     OPS_LDT_BINARY='b',
701     OPS_LDT_TEXT='t',
702     OPS_LDT_UTF8='u',
703     OPS_LDT_LOCAL='l',
704     OPS_LDT_LOCAL2='1'
705     } literal_data_type_t;
706
707 /** ops_literal_data_header_t */
708 typedef struct
709     {
710     literal_data_type_t         format;
711     char                        filename[256];
712     time_t                      modification_time;
713     } ops_literal_data_header_t;
714
715 /** ops_literal_data_body_t */
716 typedef struct
717     {
718     unsigned                    length;
719     unsigned char               data[8192];
720     } ops_literal_data_body_t;
721
722 /** ops_armoured_header_value_t */
723 typedef struct
724     {
725     char *key;
726     char *value;
727     } ops_armoured_header_value_t;
728
729 /** ops_headers_t */
730 typedef struct
731     {
732     ops_armoured_header_value_t *headers;
733     unsigned nheaders;
734     } ops_headers_t;
735
736 /** ops_armour_header_t */
737 typedef struct
738     {
739     const char *type;
740     ops_headers_t headers;
741     } ops_armour_header_t;
742
743 /** ops_armour_trailer_t */
744 typedef struct
745     {
746     const char *type;
747     } ops_armour_trailer_t;
748
749 /** ops_signed_cleartext_header_t */
750 typedef struct
751     {
752     ops_headers_t headers;
753     } ops_signed_cleartext_header_t;
754
755 /** ops_signed_cleartext_body_t */
756 typedef struct
757     {
758     unsigned                    length;
759     unsigned char               data[8192];
760     } ops_signed_cleartext_body_t;
761
762 /** ops_signed_cleartext_trailer_t */
763 typedef struct
764     {
765     struct _ops_hash_t          *hash;  /*!< This will not have been finalised, but will have seen all the cleartext data in canonical form */
766     } ops_signed_cleartext_trailer_t;
767
768 /** ops_unarmoured_text_t */
769 typedef struct
770     {
771     unsigned                    length;
772     unsigned char               *data;
773     } ops_unarmoured_text_t;
774
775 typedef enum
776     {
777     OPS_PKSK_V3=3
778     } ops_pk_session_key_version_t;
779
780 typedef struct
781     {
782     BIGNUM                      *encrypted_m;
783     } ops_pk_session_key_parameters_rsa_t;
784
785 typedef struct
786     {
787     BIGNUM                      *g_to_k;
788     BIGNUM                      *encrypted_m;
789     } ops_pk_session_key_parameters_elgamal_t;
790
791 typedef union
792     {
793     ops_pk_session_key_parameters_rsa_t         rsa;
794     ops_pk_session_key_parameters_elgamal_t     elgamal;
795     } ops_pk_session_key_parameters_t;
796
797 typedef struct
798     {
799     ops_pk_session_key_version_t version;
800     unsigned char               key_id[OPS_KEY_ID_SIZE];
801     ops_public_key_algorithm_t  algorithm;
802     ops_pk_session_key_parameters_t parameters;
803     } ops_pk_session_key_t;
804
805 /** ops_parser_union_content_t */
806 typedef union
807     {
808     ops_parser_error_t          error;
809     ops_parser_errcode_t        errcode;
810     ops_ptag_t                  ptag;
811     ops_public_key_t            public_key;
812     ops_trust_t                 trust;
813     ops_user_id_t               user_id;
814     ops_user_attribute_t        user_attribute;
815     ops_signature_t             signature;
816     ops_ss_raw_t                ss_raw;
817     ops_ss_trust_t              ss_trust;
818     ops_ss_revocable_t          ss_revocable;
819     ops_ss_time_t               ss_time;
820     ops_ss_key_id_t             ss_issuer_key_id;
821     ops_ss_notation_data_t      ss_notation_data;
822     ops_packet_t                packet;
823     ops_compressed_t            compressed;
824     ops_one_pass_signature_t    one_pass_signature;
825     ops_ss_preferred_ska_t      ss_preferred_ska;
826     ops_ss_preferred_hash_t     ss_preferred_hash;
827     ops_ss_preferred_compression_t     ss_preferred_compression;
828     ops_ss_key_flags_t          ss_key_flags;
829     ops_ss_key_server_prefs_t   ss_key_server_prefs;
830     ops_ss_primary_user_id_t    ss_primary_user_id;
831     ops_ss_regexp_t             ss_regexp;
832     ops_ss_policy_url_t         ss_policy_url;
833     ops_ss_preferred_key_server_t       ss_preferred_key_server;
834     ops_ss_revocation_key_t     ss_revocation_key;
835     ops_ss_userdefined_t        ss_userdefined;
836     ops_ss_unknown_t            ss_unknown;
837     ops_literal_data_header_t   literal_data_header;
838     ops_literal_data_body_t     literal_data_body;
839     ops_ss_features_t           ss_features;
840     ops_ss_revocation_reason_t  ss_revocation_reason;
841     ops_secret_key_t            secret_key;
842     ops_user_id_t               ss_signers_user_id;
843     ops_armour_header_t         armour_header;
844     ops_armour_trailer_t        armour_trailer;
845     ops_signed_cleartext_header_t signed_cleartext_header;
846     ops_signed_cleartext_body_t signed_cleartext_body;
847     ops_signed_cleartext_trailer_t signed_cleartext_trailer;
848     ops_unarmoured_text_t       unarmoured_text;
849     ops_pk_session_key_t        pk_session_key;
850     char                      **passphrase; /*< point to a char * to be filled in - this is to work around the constness of content */
851     } ops_parser_content_union_t;
852
853 /** ops_parser_content_t */
854 struct ops_parser_content_t
855     {
856     ops_content_tag_t           tag;
857     unsigned char               critical; /* for signature subpackets */
858     ops_parser_content_union_t  content;
859     };
860
861 /** ops_fingerprint_t */
862 typedef struct
863     {
864     unsigned char               fingerprint[20];
865     unsigned                    length;
866     } ops_fingerprint_t;
867
868 void ops_init(void);
869 void ops_finish(void);
870 void ops_keyid(unsigned char keyid[OPS_KEY_ID_SIZE],
871                const ops_public_key_t *key);
872 void ops_fingerprint(ops_fingerprint_t *fp,const ops_public_key_t *key);
873 void ops_public_key_free(ops_public_key_t *key);
874 void ops_user_id_free(ops_user_id_t *id);
875 void ops_user_attribute_free(ops_user_attribute_t *att);
876 void ops_signature_free(ops_signature_t *sig);
877 void ops_trust_free(ops_trust_t *trust);
878 void ops_ss_preferred_ska_free(ops_ss_preferred_ska_t *ss_preferred_ska);
879 void ops_ss_preferred_hash_free(ops_ss_preferred_hash_t *ss_preferred_hash);
880 void ops_ss_preferred_compression_free(ops_ss_preferred_compression_t *ss_preferred_compression);
881 void ops_ss_key_flags_free(ops_ss_key_flags_t *ss_key_flags);
882 void ops_ss_key_server_prefs_free(ops_ss_key_server_prefs_t *ss_key_server_prefs);
883 void ops_ss_features_free(ops_ss_features_t *ss_features);
884 void ops_ss_notation_data_free(ops_ss_notation_data_t *ss_notation_data);
885 void ops_ss_policy_url_free(ops_ss_policy_url_t *ss_policy_url);
886 void ops_ss_preferred_key_server_free(ops_ss_preferred_key_server_t *ss_preferred_key_server);
887 void ops_ss_regexp_free(ops_ss_regexp_t *ss_regexp);
888 void ops_ss_userdefined_free(ops_ss_userdefined_t *ss_userdefined);
889 void ops_ss_reserved_free(ops_ss_unknown_t *ss_unknown);
890 void ops_ss_revocation_reason_free(ops_ss_revocation_reason_t *ss_revocation_reason);
891 void ops_packet_free(ops_packet_t *packet);
892 void ops_parser_content_free(ops_parser_content_t *c);
893 void ops_secret_key_free(ops_secret_key_t *key);
894 void ops_pk_session_key_free(ops_pk_session_key_t *sk);
895
896 /* vim:set textwidth=120: */
897 /* vim:set ts=8: */
898
899 #endif
900
Note: See TracBrowser for help on using the browser.