42
43
#define OPENCDK_VERSION_PATCH 6
48
50
/* General contexts */
50
52
/* 'Session' handle to support the various options and run-time
53
typedef struct cdk_ctx_s *cdk_ctx_t;
55
typedef struct cdk_ctx_s *cdk_ctx_t;
55
57
/* A generic context to store list of strings. */
57
typedef struct cdk_strlist_s *cdk_strlist_t;
59
typedef struct cdk_strlist_s *cdk_strlist_t;
59
61
/* Context used to list keys of a keyring. */
61
typedef struct cdk_listkey_s *cdk_listkey_t;
63
typedef struct cdk_listkey_s *cdk_listkey_t;
63
65
/* Opaque String to Key (S2K) handle. */
65
typedef struct cdk_s2k_s *cdk_s2k_t;
67
typedef struct cdk_s2k_s *cdk_s2k_t;
67
69
/* Abstract I/O object, a stream, which is used for most operations. */
69
typedef struct cdk_stream_s *cdk_stream_t;
71
typedef struct cdk_stream_s *cdk_stream_t;
71
73
/* Opaque handle for the user ID preferences. */
72
struct cdk_prefitem_s;
73
typedef struct cdk_prefitem_s *cdk_prefitem_t;
74
struct cdk_prefitem_s;
75
typedef struct cdk_prefitem_s *cdk_prefitem_t;
75
77
/* Node to store a single key node packet. */
77
typedef struct cdk_kbnode_s *cdk_kbnode_t;
79
typedef struct cdk_kbnode_s *cdk_kbnode_t;
79
81
/* Key database handle. */
80
struct cdk_keydb_hd_s;
81
typedef struct cdk_keydb_hd_s *cdk_keydb_hd_t;
82
struct cdk_keydb_hd_s;
83
typedef struct cdk_keydb_hd_s *cdk_keydb_hd_t;
83
struct cdk_keydb_search_s;
84
typedef struct cdk_keydb_search_s *cdk_keydb_search_t;
85
struct cdk_keydb_search_s;
86
typedef struct cdk_keydb_search_s *cdk_keydb_search_t;
86
88
/* Context to store a list of recipient keys. */
88
typedef struct cdk_keylist_s *cdk_keylist_t;
90
typedef struct cdk_keylist_s *cdk_keylist_t;
90
92
/* Context to encapsulate a single sub packet of a signature. */
92
typedef struct cdk_subpkt_s *cdk_subpkt_t;
94
typedef struct cdk_subpkt_s *cdk_subpkt_t;
94
96
/* Context used to generate key pairs. */
95
struct cdk_keygen_ctx_s;
96
typedef struct cdk_keygen_ctx_s *cdk_keygen_ctx_t;
97
struct cdk_keygen_ctx_s;
98
typedef struct cdk_keygen_ctx_s *cdk_keygen_ctx_t;
98
100
/* Handle for a single designated revoker. */
99
struct cdk_desig_revoker_s;
100
typedef struct cdk_desig_revoker_s *cdk_desig_revoker_t;
101
struct cdk_desig_revoker_s;
102
typedef struct cdk_desig_revoker_s *cdk_desig_revoker_t;
102
104
/* Alias for backward compatibility. */
103
typedef bigint_t cdk_mpi_t;
105
typedef bigint_t cdk_mpi_t;
106
108
/* All valid error constants. */
111
CDK_General_Error = 1,
116
CDK_Not_Implemented = 6,
118
CDK_Armor_CRC_Error = 9,
121
CDK_Error_No_Key = 12,
122
CDK_Chksum_Error = 13,
123
CDK_Time_Conflict = 14,
126
CDK_Out_Of_Core = 17,
127
CDK_Wrong_Seckey = 18,
130
CDK_Error_No_Keyring = 21,
131
CDK_Wrong_Format = 22,
132
CDK_Inv_Packet_Ver = 23,
134
CDK_Unusable_Key = 25,
136
CDK_No_Passphrase = 27,
137
CDK_Network_Error = 28
141
enum cdk_control_flags
143
CDK_CTLF_SET = 0, /* Value to set an option */
144
CDK_CTLF_GET = 1, /* Value to get an option */
145
CDK_CTL_DIGEST = 10, /* Option to set the digest algorithm. */
146
CDK_CTL_ARMOR = 12, /* Option to enable armor output. */
147
CDK_CTL_COMPRESS = 13, /* Option to enable compression. */
148
CDK_CTL_COMPAT = 14, /* Option to switch in compat mode. */
149
CDK_CTL_OVERWRITE = 15, /* Option to enable file overwritting. */
150
CDK_CTL_S2K = 16, /* Option to set S2K values. */
151
CDK_CTL_FORCE_DIGEST = 19, /* Force the use of a digest algorithm. */
152
CDK_CTL_BLOCKMODE_ON = 20 /* Enable partial body lengths */
113
CDK_General_Error = 1,
118
CDK_Not_Implemented = 6,
120
CDK_Armor_CRC_Error = 9,
123
CDK_Error_No_Key = 12,
124
CDK_Chksum_Error = 13,
125
CDK_Time_Conflict = 14,
128
CDK_Out_Of_Core = 17,
129
CDK_Wrong_Seckey = 18,
132
CDK_Error_No_Keyring = 21,
133
CDK_Wrong_Format = 22,
134
CDK_Inv_Packet_Ver = 23,
136
CDK_Unusable_Key = 25,
138
CDK_No_Passphrase = 27,
139
CDK_Network_Error = 28
143
enum cdk_control_flags
145
CDK_CTLF_SET = 0, /* Value to set an option */
146
CDK_CTLF_GET = 1, /* Value to get an option */
147
CDK_CTL_DIGEST = 10, /* Option to set the digest algorithm. */
148
CDK_CTL_ARMOR = 12, /* Option to enable armor output. */
149
CDK_CTL_COMPRESS = 13, /* Option to enable compression. */
150
CDK_CTL_COMPAT = 14, /* Option to switch in compat mode. */
151
CDK_CTL_OVERWRITE = 15, /* Option to enable file overwritting. */
152
CDK_CTL_S2K = 16, /* Option to set S2K values. */
153
CDK_CTL_FORCE_DIGEST = 19, /* Force the use of a digest algorithm. */
154
CDK_CTL_BLOCKMODE_ON = 20 /* Enable partial body lengths */
156
158
/* Specifies all valid log levels. */
159
CDK_LOG_NONE = 0, /* No log message will be shown. */
162
CDK_LOG_DEBUG_PKT = 3
161
CDK_LOG_NONE = 0, /* No log message will be shown. */
164
CDK_LOG_DEBUG_PKT = 3
166
168
/* All valid compression algorithms in OpenPGP */
167
enum cdk_compress_algo_t
169
CDK_COMPRESS_NONE = 0,
170
CDK_COMPRESS_ZIP = 1,
171
CDK_COMPRESS_ZLIB = 2,
172
CDK_COMPRESS_BZIP2 = 3 /* Not supported in this version */
169
enum cdk_compress_algo_t
171
CDK_COMPRESS_NONE = 0,
172
CDK_COMPRESS_ZIP = 1,
173
CDK_COMPRESS_ZLIB = 2,
174
CDK_COMPRESS_BZIP2 = 3 /* Not supported in this version */
175
177
/* All valid public key algorithms valid in OpenPGP */
176
enum cdk_pubkey_algo_t
180
CDK_PK_RSA_E = 2, /* RSA-E and RSA-S are deprecated use RSA instead */
181
CDK_PK_RSA_S = 3, /* and use the key flags in the self signatures. */
178
enum cdk_pubkey_algo_t
182
CDK_PK_RSA_E = 2, /* RSA-E and RSA-S are deprecated use RSA instead */
183
CDK_PK_RSA_S = 3, /* and use the key flags in the self signatures. */
186
188
/* The valid 'String-To-Key' modes */
191
CDK_S2K_ITERSALTED = 3,
192
CDK_S2K_GNU_EXT = 101
193
/* GNU extensions: refer to DETAILS from GnuPG:
194
http://cvs.gnupg.org/cgi-bin/viewcvs.cgi/trunk/doc/DETAILS?root=GnuPG
193
CDK_S2K_ITERSALTED = 3,
194
CDK_S2K_GNU_EXT = 101
195
/* GNU extensions: refer to DETAILS from GnuPG:
196
http://cvs.gnupg.org/cgi-bin/viewcvs.cgi/trunk/doc/DETAILS?root=GnuPG
198
200
/* The different kind of user ID preferences. */
201
CDK_PREFTYPE_NONE = 0,
202
CDK_PREFTYPE_SYM = 1, /* Symmetric ciphers */
203
CDK_PREFTYPE_HASH = 2, /* Message digests */
204
CDK_PREFTYPE_ZIP = 3 /* Compression algorithms */
203
CDK_PREFTYPE_NONE = 0,
204
CDK_PREFTYPE_SYM = 1, /* Symmetric ciphers */
205
CDK_PREFTYPE_HASH = 2, /* Message digests */
206
CDK_PREFTYPE_ZIP = 3 /* Compression algorithms */
208
210
/* All valid sub packet types. */
209
enum cdk_sig_subpacket_t
211
CDK_SIGSUBPKT_NONE = 0,
212
CDK_SIGSUBPKT_SIG_CREATED = 2,
213
CDK_SIGSUBPKT_SIG_EXPIRE = 3,
214
CDK_SIGSUBPKT_EXPORTABLE = 4,
215
CDK_SIGSUBPKT_TRUST = 5,
216
CDK_SIGSUBPKT_REGEXP = 6,
217
CDK_SIGSUBPKT_REVOCABLE = 7,
218
CDK_SIGSUBPKT_KEY_EXPIRE = 9,
219
CDK_SIGSUBPKT_PREFS_SYM = 11,
220
CDK_SIGSUBPKT_REV_KEY = 12,
221
CDK_SIGSUBPKT_ISSUER = 16,
222
CDK_SIGSUBPKT_NOTATION = 20,
223
CDK_SIGSUBPKT_PREFS_HASH = 21,
224
CDK_SIGSUBPKT_PREFS_ZIP = 22,
225
CDK_SIGSUBPKT_KS_FLAGS = 23,
226
CDK_SIGSUBPKT_PREF_KS = 24,
227
CDK_SIGSUBPKT_PRIMARY_UID = 25,
228
CDK_SIGSUBPKT_POLICY = 26,
229
CDK_SIGSUBPKT_KEY_FLAGS = 27,
230
CDK_SIGSUBPKT_SIGNERS_UID = 28,
231
CDK_SIGSUBPKT_REVOC_REASON = 29,
232
CDK_SIGSUBPKT_FEATURES = 30
211
enum cdk_sig_subpacket_t
213
CDK_SIGSUBPKT_NONE = 0,
214
CDK_SIGSUBPKT_SIG_CREATED = 2,
215
CDK_SIGSUBPKT_SIG_EXPIRE = 3,
216
CDK_SIGSUBPKT_EXPORTABLE = 4,
217
CDK_SIGSUBPKT_TRUST = 5,
218
CDK_SIGSUBPKT_REGEXP = 6,
219
CDK_SIGSUBPKT_REVOCABLE = 7,
220
CDK_SIGSUBPKT_KEY_EXPIRE = 9,
221
CDK_SIGSUBPKT_PREFS_SYM = 11,
222
CDK_SIGSUBPKT_REV_KEY = 12,
223
CDK_SIGSUBPKT_ISSUER = 16,
224
CDK_SIGSUBPKT_NOTATION = 20,
225
CDK_SIGSUBPKT_PREFS_HASH = 21,
226
CDK_SIGSUBPKT_PREFS_ZIP = 22,
227
CDK_SIGSUBPKT_KS_FLAGS = 23,
228
CDK_SIGSUBPKT_PREF_KS = 24,
229
CDK_SIGSUBPKT_PRIMARY_UID = 25,
230
CDK_SIGSUBPKT_POLICY = 26,
231
CDK_SIGSUBPKT_KEY_FLAGS = 27,
232
CDK_SIGSUBPKT_SIGNERS_UID = 28,
233
CDK_SIGSUBPKT_REVOC_REASON = 29,
234
CDK_SIGSUBPKT_FEATURES = 30
236
238
/* All valid armor types. */
237
enum cdk_armor_type_t
239
CDK_ARMOR_MESSAGE = 0,
240
CDK_ARMOR_PUBKEY = 1,
241
CDK_ARMOR_SECKEY = 2,
242
CDK_ARMOR_SIGNATURE = 3,
243
CDK_ARMOR_CLEARSIG = 4
239
enum cdk_armor_type_t
241
CDK_ARMOR_MESSAGE = 0,
242
CDK_ARMOR_PUBKEY = 1,
243
CDK_ARMOR_SECKEY = 2,
244
CDK_ARMOR_SIGNATURE = 3,
245
CDK_ARMOR_CLEARSIG = 4
246
enum cdk_keydb_flag_t
248
/* Valid database search modes */
249
CDK_DBSEARCH_EXACT = 1, /* Exact string search */
250
CDK_DBSEARCH_SUBSTR = 2, /* Sub string search */
251
CDK_DBSEARCH_SHORT_KEYID = 3, /* 32-bit keyid search */
252
CDK_DBSEARCH_KEYID = 4, /* 64-bit keyid search */
253
CDK_DBSEARCH_FPR = 5, /* 160-bit fingerprint search */
254
CDK_DBSEARCH_NEXT = 6, /* Enumerate all keys */
255
CDK_DBSEARCH_AUTO = 7, /* Try to classify the string */
256
/* Valid database types */
257
CDK_DBTYPE_PK_KEYRING = 100, /* A file with one or more public keys */
258
CDK_DBTYPE_SK_KEYRING = 101, /* A file with one or more secret keys */
259
CDK_DBTYPE_DATA = 102, /* A buffer with at least one public key */
260
CDK_DBTYPE_STREAM = 103 /* A stream is used to read keys from */
248
enum cdk_keydb_flag_t
250
/* Valid database search modes */
251
CDK_DBSEARCH_EXACT = 1, /* Exact string search */
252
CDK_DBSEARCH_SUBSTR = 2, /* Sub string search */
253
CDK_DBSEARCH_SHORT_KEYID = 3, /* 32-bit keyid search */
254
CDK_DBSEARCH_KEYID = 4, /* 64-bit keyid search */
255
CDK_DBSEARCH_FPR = 5, /* 160-bit fingerprint search */
256
CDK_DBSEARCH_NEXT = 6, /* Enumerate all keys */
257
CDK_DBSEARCH_AUTO = 7, /* Try to classify the string */
258
/* Valid database types */
259
CDK_DBTYPE_PK_KEYRING = 100, /* A file with one or more public keys */
260
CDK_DBTYPE_SK_KEYRING = 101, /* A file with one or more secret keys */
261
CDK_DBTYPE_DATA = 102, /* A buffer with at least one public key */
262
CDK_DBTYPE_STREAM = 103 /* A stream is used to read keys from */
264
266
/* All valid modes for cdk_data_transform() */
265
enum cdk_crypto_mode_t
267
CDK_CRYPTYPE_NONE = 0,
268
CDK_CRYPTYPE_ENCRYPT = 1,
269
CDK_CRYPTYPE_DECRYPT = 2,
270
CDK_CRYPTYPE_SIGN = 3,
271
CDK_CRYPTYPE_VERIFY = 4,
272
CDK_CRYPTYPE_EXPORT = 5,
273
CDK_CRYPTYPE_IMPORT = 6
267
enum cdk_crypto_mode_t
269
CDK_CRYPTYPE_NONE = 0,
270
CDK_CRYPTYPE_ENCRYPT = 1,
271
CDK_CRYPTYPE_DECRYPT = 2,
272
CDK_CRYPTYPE_SIGN = 3,
273
CDK_CRYPTYPE_VERIFY = 4,
274
CDK_CRYPTYPE_EXPORT = 5,
275
CDK_CRYPTYPE_IMPORT = 6
276
278
#define CDK_KEY_USG_ENCR (CDK_KEY_USG_COMM_ENCR | CDK_KEY_USG_STORAGE_ENCR)
277
279
#define CDK_KEY_USG_SIGN (CDK_KEY_USG_DATA_SIGN | CDK_KEY_USG_CERT_SIGN)
278
280
/* A list of valid public key usages. */
281
CDK_KEY_USG_CERT_SIGN = 1,
282
CDK_KEY_USG_DATA_SIGN = 2,
283
CDK_KEY_USG_COMM_ENCR = 4,
284
CDK_KEY_USG_STORAGE_ENCR = 8,
285
CDK_KEY_USG_SPLIT_KEY = 16,
286
CDK_KEY_USG_AUTH = 32,
287
CDK_KEY_USG_SHARED_KEY = 128
283
CDK_KEY_USG_CERT_SIGN = 1,
284
CDK_KEY_USG_DATA_SIGN = 2,
285
CDK_KEY_USG_COMM_ENCR = 4,
286
CDK_KEY_USG_STORAGE_ENCR = 8,
287
CDK_KEY_USG_SPLIT_KEY = 16,
288
CDK_KEY_USG_AUTH = 32,
289
CDK_KEY_USG_SHARED_KEY = 128
291
293
/* Valid flags for keys. */
295
CDK_KEY_INVALID = 1, /* Missing or wrong self signature */
296
CDK_KEY_EXPIRED = 2, /* Key is expired. */
297
CDK_KEY_REVOKED = 4, /* Key has been revoked. */
297
CDK_KEY_INVALID = 1, /* Missing or wrong self signature */
298
CDK_KEY_EXPIRED = 2, /* Key is expired. */
299
CDK_KEY_REVOKED = 4, /* Key has been revoked. */
302
304
/* Trust values and flags for keys and user IDs */
303
enum cdk_trust_flag_t
305
CDK_TRUST_UNKNOWN = 0,
306
CDK_TRUST_EXPIRED = 1,
307
CDK_TRUST_UNDEFINED = 2,
309
CDK_TRUST_MARGINAL = 4,
311
CDK_TRUST_ULTIMATE = 6,
313
CDK_TFLAG_REVOKED = 32,
314
CDK_TFLAG_SUB_REVOKED = 64,
315
CDK_TFLAG_DISABLED = 128
305
enum cdk_trust_flag_t
307
CDK_TRUST_UNKNOWN = 0,
308
CDK_TRUST_EXPIRED = 1,
309
CDK_TRUST_UNDEFINED = 2,
311
CDK_TRUST_MARGINAL = 4,
313
CDK_TRUST_ULTIMATE = 6,
315
CDK_TFLAG_REVOKED = 32,
316
CDK_TFLAG_SUB_REVOKED = 64,
317
CDK_TFLAG_DISABLED = 128
319
321
/* Signature states and the signature modes. */
320
enum cdk_signature_stat_t
322
/* Signature status */
323
CDK_SIGSTAT_NONE = 0,
324
CDK_SIGSTAT_GOOD = 1,
326
CDK_SIGSTAT_NOKEY = 3,
327
CDK_SIGSTAT_VALID = 4, /* True if made with a valid key. */
328
/* FIXME: We need indicators for revoked/expires signatures. */
322
enum cdk_signature_stat_t
324
/* Signature status */
325
CDK_SIGSTAT_NONE = 0,
326
CDK_SIGSTAT_GOOD = 1,
328
CDK_SIGSTAT_NOKEY = 3,
329
CDK_SIGSTAT_VALID = 4, /* True if made with a valid key. */
330
/* FIXME: We need indicators for revoked/expires signatures. */
330
/* Signature modes */
331
CDK_SIGMODE_NORMAL = 100,
332
CDK_SIGMODE_DETACHED = 101,
333
CDK_SIGMODE_CLEAR = 102
332
/* Signature modes */
333
CDK_SIGMODE_NORMAL = 100,
334
CDK_SIGMODE_DETACHED = 101,
335
CDK_SIGMODE_CLEAR = 102
340
CDK_FLAG_KEY_REVOKED = 256,
341
CDK_FLAG_KEY_EXPIRED = 512,
342
CDK_FLAG_SIG_EXPIRED = 1024
342
CDK_FLAG_KEY_REVOKED = 256,
343
CDK_FLAG_KEY_EXPIRED = 512,
344
CDK_FLAG_SIG_EXPIRED = 1024
346
348
/* Possible format for the literal data. */
349
CDK_LITFMT_BINARY = 0,
351
CDK_LITFMT_UNICODE = 2
351
CDK_LITFMT_BINARY = 0,
353
CDK_LITFMT_UNICODE = 2
354
356
/* Valid OpenPGP packet types and their IDs */
357
CDK_PKT_RESERVED = 0,
358
CDK_PKT_PUBKEY_ENC = 1,
359
CDK_PKT_SIGNATURE = 2,
360
CDK_PKT_ONEPASS_SIG = 4,
361
CDK_PKT_SECRET_KEY = 5,
362
CDK_PKT_PUBLIC_KEY = 6,
363
CDK_PKT_SECRET_SUBKEY = 7,
364
CDK_PKT_COMPRESSED = 8,
366
CDK_PKT_LITERAL = 11,
367
CDK_PKT_RING_TRUST = 12,
368
CDK_PKT_USER_ID = 13,
369
CDK_PKT_PUBLIC_SUBKEY = 14,
370
CDK_PKT_OLD_COMMENT = 16,
371
CDK_PKT_ATTRIBUTE = 17,
359
CDK_PKT_RESERVED = 0,
360
CDK_PKT_PUBKEY_ENC = 1,
361
CDK_PKT_SIGNATURE = 2,
362
CDK_PKT_ONEPASS_SIG = 4,
363
CDK_PKT_SECRET_KEY = 5,
364
CDK_PKT_PUBLIC_KEY = 6,
365
CDK_PKT_SECRET_SUBKEY = 7,
366
CDK_PKT_COMPRESSED = 8,
368
CDK_PKT_LITERAL = 11,
369
CDK_PKT_RING_TRUST = 12,
370
CDK_PKT_USER_ID = 13,
371
CDK_PKT_PUBLIC_SUBKEY = 14,
372
CDK_PKT_OLD_COMMENT = 16,
373
CDK_PKT_ATTRIBUTE = 17,
375
377
/* Define the maximal number of multiprecion integers for
387
389
|| ((pkttype)==CDK_PKT_ENCRYPTED))
390
struct cdk_pkt_signature_s
392
unsigned char version;
393
unsigned char sig_class;
394
unsigned int timestamp;
395
unsigned int expiredate;
396
unsigned int keyid[2];
397
unsigned char pubkey_algo;
398
unsigned char digest_algo;
399
unsigned char digest_start[2];
400
unsigned short hashed_size;
402
unsigned short unhashed_size;
403
cdk_subpkt_t unhashed;
404
bigint_t mpi[MAX_CDK_DATA_PARTS];
405
cdk_desig_revoker_t revkeys;
408
unsigned exportable:1;
409
unsigned revocable:1;
410
unsigned policy_url:1;
415
unsigned missing_key:1;
417
unsigned int key[2]; /* only valid for key signatures */
419
typedef struct cdk_pkt_signature_s *cdk_pkt_signature_t;
422
struct cdk_pkt_userid_s
425
unsigned is_primary:1;
426
unsigned is_revoked:1;
427
unsigned mdc_feature:1;
428
cdk_prefitem_t prefs;
430
unsigned char *attrib_img; /* Tag 17 if not null */
432
cdk_pkt_signature_t selfsig;
435
typedef struct cdk_pkt_userid_s *cdk_pkt_userid_t;
438
struct cdk_pkt_pubkey_s
440
unsigned char version;
441
unsigned char pubkey_algo;
442
unsigned char fpr[20];
443
unsigned int keyid[2];
444
unsigned int main_keyid[2];
445
unsigned int timestamp;
446
unsigned int expiredate;
447
bigint_t mpi[MAX_CDK_PK_PARTS];
448
unsigned is_revoked:1;
449
unsigned is_invalid:1;
450
unsigned has_expired:1;
452
cdk_pkt_userid_t uid;
453
cdk_prefitem_t prefs;
455
cdk_desig_revoker_t revkeys;
457
typedef struct cdk_pkt_pubkey_s *cdk_pkt_pubkey_t;
392
struct cdk_pkt_signature_s
394
unsigned char version;
395
unsigned char sig_class;
396
unsigned int timestamp;
397
unsigned int expiredate;
398
unsigned int keyid[2];
399
unsigned char pubkey_algo;
400
unsigned char digest_algo;
401
unsigned char digest_start[2];
402
unsigned short hashed_size;
404
unsigned short unhashed_size;
405
cdk_subpkt_t unhashed;
406
bigint_t mpi[MAX_CDK_DATA_PARTS];
407
cdk_desig_revoker_t revkeys;
410
unsigned exportable:1;
411
unsigned revocable:1;
412
unsigned policy_url:1;
417
unsigned missing_key:1;
419
unsigned int key[2]; /* only valid for key signatures */
421
typedef struct cdk_pkt_signature_s *cdk_pkt_signature_t;
424
struct cdk_pkt_userid_s
427
unsigned is_primary:1;
428
unsigned is_revoked:1;
429
unsigned mdc_feature:1;
430
cdk_prefitem_t prefs;
432
unsigned char *attrib_img; /* Tag 17 if not null */
434
cdk_pkt_signature_t selfsig;
437
typedef struct cdk_pkt_userid_s *cdk_pkt_userid_t;
440
struct cdk_pkt_pubkey_s
442
unsigned char version;
443
unsigned char pubkey_algo;
444
unsigned char fpr[20];
445
unsigned int keyid[2];
446
unsigned int main_keyid[2];
447
unsigned int timestamp;
448
unsigned int expiredate;
449
bigint_t mpi[MAX_CDK_PK_PARTS];
450
unsigned is_revoked:1;
451
unsigned is_invalid:1;
452
unsigned has_expired:1;
454
cdk_pkt_userid_t uid;
455
cdk_prefitem_t prefs;
457
cdk_desig_revoker_t revkeys;
459
typedef struct cdk_pkt_pubkey_s *cdk_pkt_pubkey_t;
459
461
/* Alias to define a generic public key context. */
460
typedef cdk_pkt_pubkey_t cdk_pubkey_t;
463
struct cdk_pkt_seckey_s
466
unsigned int expiredate;
469
unsigned int keyid[2];
470
unsigned int main_keyid[2];
471
unsigned char s2k_usage;
462
typedef cdk_pkt_pubkey_t cdk_pubkey_t;
465
struct cdk_pkt_seckey_s
475
unsigned char sha1chk; /* SHA1 is used instead of a 16 bit checksum */
477
unsigned char iv[16];
481
bigint_t mpi[MAX_CDK_PK_PARTS];
482
unsigned char *encdata;
484
unsigned char is_protected;
485
unsigned is_primary:1;
486
unsigned has_expired:1;
487
unsigned is_revoked:1;
489
typedef struct cdk_pkt_seckey_s *cdk_pkt_seckey_t;
468
unsigned int expiredate;
471
unsigned int keyid[2];
472
unsigned int main_keyid[2];
473
unsigned char s2k_usage;
477
unsigned char sha1chk; /* SHA1 is used instead of a 16 bit checksum */
479
unsigned char iv[16];
483
bigint_t mpi[MAX_CDK_PK_PARTS];
484
unsigned char *encdata;
486
unsigned char is_protected;
487
unsigned is_primary:1;
488
unsigned has_expired:1;
489
unsigned is_revoked:1;
491
typedef struct cdk_pkt_seckey_s *cdk_pkt_seckey_t;
491
493
/* Alias to define a generic secret key context. */
492
typedef cdk_pkt_seckey_t cdk_seckey_t;
495
struct cdk_pkt_onepass_sig_s
497
unsigned char version;
498
unsigned int keyid[2];
499
unsigned char sig_class;
500
unsigned char digest_algo;
501
unsigned char pubkey_algo;
504
typedef struct cdk_pkt_onepass_sig_s *cdk_pkt_onepass_sig_t;
507
struct cdk_pkt_pubkey_enc_s
509
unsigned char version;
510
unsigned int keyid[2];
512
unsigned char pubkey_algo;
513
bigint_t mpi[MAX_CDK_DATA_PARTS];
515
typedef struct cdk_pkt_pubkey_enc_s *cdk_pkt_pubkey_enc_t;
517
struct cdk_pkt_encrypted_s
521
unsigned char mdc_method;
524
typedef struct cdk_pkt_encrypted_s *cdk_pkt_encrypted_t;
529
unsigned char hash[20];
531
typedef struct cdk_pkt_mdc_s *cdk_pkt_mdc_t;
534
struct cdk_pkt_literal_s
539
unsigned int timestamp;
543
typedef struct cdk_pkt_literal_s *cdk_pkt_literal_t;
546
struct cdk_pkt_compressed_s
552
typedef struct cdk_pkt_compressed_s *cdk_pkt_compressed_t;
494
typedef cdk_pkt_seckey_t cdk_seckey_t;
497
struct cdk_pkt_onepass_sig_s
499
unsigned char version;
500
unsigned int keyid[2];
501
unsigned char sig_class;
502
unsigned char digest_algo;
503
unsigned char pubkey_algo;
506
typedef struct cdk_pkt_onepass_sig_s *cdk_pkt_onepass_sig_t;
509
struct cdk_pkt_pubkey_enc_s
511
unsigned char version;
512
unsigned int keyid[2];
514
unsigned char pubkey_algo;
515
bigint_t mpi[MAX_CDK_DATA_PARTS];
517
typedef struct cdk_pkt_pubkey_enc_s *cdk_pkt_pubkey_enc_t;
519
struct cdk_pkt_encrypted_s
523
unsigned char mdc_method;
526
typedef struct cdk_pkt_encrypted_s *cdk_pkt_encrypted_t;
531
unsigned char hash[20];
533
typedef struct cdk_pkt_mdc_s *cdk_pkt_mdc_t;
536
struct cdk_pkt_literal_s
541
unsigned int timestamp;
545
typedef struct cdk_pkt_literal_s *cdk_pkt_literal_t;
548
struct cdk_pkt_compressed_s
554
typedef struct cdk_pkt_compressed_s *cdk_pkt_compressed_t;
555
557
/* Structure which represents a single OpenPGP packet. */
558
size_t pktlen; /* real packet length */
559
size_t pktsize; /* length with all headers */
560
int old_ctb; /* 1 if RFC1991 mode is used */
561
cdk_packet_type_t pkttype;
565
cdk_pkt_userid_t user_id;
566
cdk_pkt_pubkey_t public_key;
567
cdk_pkt_seckey_t secret_key;
568
cdk_pkt_signature_t signature;
569
cdk_pkt_pubkey_enc_t pubkey_enc;
570
cdk_pkt_compressed_t compressed;
571
cdk_pkt_encrypted_t encrypted;
572
cdk_pkt_literal_t literal;
573
cdk_pkt_onepass_sig_t onepass_sig;
576
typedef struct cdk_packet_s *cdk_packet_t;
560
size_t pktlen; /* real packet length */
561
size_t pktsize; /* length with all headers */
562
int old_ctb; /* 1 if RFC1991 mode is used */
563
cdk_packet_type_t pkttype;
567
cdk_pkt_userid_t user_id;
568
cdk_pkt_pubkey_t public_key;
569
cdk_pkt_seckey_t secret_key;
570
cdk_pkt_signature_t signature;
571
cdk_pkt_pubkey_enc_t pubkey_enc;
572
cdk_pkt_compressed_t compressed;
573
cdk_pkt_encrypted_t encrypted;
574
cdk_pkt_literal_t literal;
575
cdk_pkt_onepass_sig_t onepass_sig;
578
typedef struct cdk_packet_s *cdk_packet_t;
578
580
/* Session handle routines */
579
cdk_error_t cdk_handle_new (cdk_ctx_t * r_ctx);
580
void cdk_handle_free (cdk_ctx_t c);
581
cdk_error_t cdk_handle_new (cdk_ctx_t * r_ctx);
582
void cdk_handle_free (cdk_ctx_t c);
582
584
/* Set the key database handle for the given session handle.
583
585
The type of the key db handle (public or secret) decides
584
586
which session key db handle to use. */
585
void cdk_handle_set_keydb (cdk_ctx_t hd, cdk_keydb_hd_t db);
587
void cdk_handle_set_keydb (cdk_ctx_t hd, cdk_keydb_hd_t db);
587
589
/* Convenient function to avoid to open a key db first.
588
590
The user can directly use the file name, the rest is
589
591
done internally. */
590
cdk_error_t cdk_handle_set_keyring (cdk_ctx_t hd, int type,
591
const char *kringname);
592
cdk_error_t cdk_handle_set_keyring (cdk_ctx_t hd, int type,
593
const char *kringname);
593
595
/* Return keydb handle stored in the session handle. */
594
cdk_keydb_hd_t cdk_handle_get_keydb (cdk_ctx_t hd, int type);
595
int cdk_handle_control (cdk_ctx_t hd, int action, int cmd, ...);
596
cdk_keydb_hd_t cdk_handle_get_keydb (cdk_ctx_t hd, int type);
597
int cdk_handle_control (cdk_ctx_t hd, int action, int cmd, ...);
597
599
/* Set a passphrase callback for the given session handle. */
598
void cdk_handle_set_passphrase_cb (cdk_ctx_t hd,
599
char *(*cb) (void *opa,
600
void cdk_handle_set_passphrase_cb (cdk_ctx_t hd,
601
char *(*cb) (void *opa,
603
605
/* shortcuts for some controls */
713
717
/* Return a multi precision integer of the public key with the index @IDX
714
718
in the buffer @BUF. @R_NWRITTEN will contain the length in octets.
715
719
Optional @R_NBITS may contain the size in bits. */
716
cdk_error_t cdk_pk_get_mpi (cdk_pubkey_t pk, size_t idx,
717
unsigned char *buf, size_t buflen,
718
size_t * r_nwritten, size_t * r_nbits);
720
cdk_error_t cdk_pk_get_mpi (cdk_pubkey_t pk, size_t idx,
721
unsigned char *buf, size_t buflen,
722
size_t * r_nwritten, size_t * r_nbits);
720
724
/* Same as the function above but of the secret key. */
721
cdk_error_t cdk_sk_get_mpi (cdk_seckey_t sk, size_t idx,
722
unsigned char *buf, size_t buflen,
723
size_t * r_nwritten, size_t * r_nbits);
725
cdk_error_t cdk_sk_get_mpi (cdk_seckey_t sk, size_t idx,
726
unsigned char *buf, size_t buflen,
727
size_t * r_nwritten, size_t * r_nbits);
725
729
/* Helper to get the exact number of multi precision integers
726
730
for the given object. */
727
int cdk_pk_get_nbits (cdk_pubkey_t pk);
728
int cdk_pk_get_npkey (int algo);
729
int cdk_pk_get_nskey (int algo);
730
int cdk_pk_get_nsig (int algo);
731
int cdk_pk_get_nenc (int algo);
731
int cdk_pk_get_nbits (cdk_pubkey_t pk);
732
int cdk_pk_get_npkey (int algo);
733
int cdk_pk_get_nskey (int algo);
734
int cdk_pk_get_nsig (int algo);
735
int cdk_pk_get_nenc (int algo);
733
737
/* Fingerprint and key ID routines. */
735
739
/* Calculate the fingerprint of the given public key.
736
740
the FPR parameter must be at least 20 octets to hold the SHA1 hash. */
737
cdk_error_t cdk_pk_get_fingerprint (cdk_pubkey_t pk, unsigned char *fpr);
741
cdk_error_t cdk_pk_get_fingerprint (cdk_pubkey_t pk, unsigned char *fpr);
739
743
/* Same as above, but with additional sanity checks of the buffer size. */
740
cdk_error_t cdk_pk_to_fingerprint (cdk_pubkey_t pk,
741
unsigned char *fpr, size_t fprlen,
744
cdk_error_t cdk_pk_to_fingerprint (cdk_pubkey_t pk,
745
unsigned char *fpr, size_t fprlen,
744
748
/* Derive the keyid from the fingerprint. This is only possible for
745
749
modern, version 4 keys. */
746
unsigned int cdk_pk_fingerprint_get_keyid (const unsigned char *fpr,
748
unsigned int *keyid);
750
unsigned int cdk_pk_fingerprint_get_keyid (const unsigned char *fpr,
752
unsigned int *keyid);
750
754
/* Various functions to get the keyid from the specific packet type. */
751
unsigned int cdk_pk_get_keyid (cdk_pubkey_t pk, unsigned int *keyid);
752
unsigned int cdk_sk_get_keyid (cdk_seckey_t sk, unsigned int *keyid);
753
unsigned int cdk_sig_get_keyid (cdk_pkt_signature_t sig, unsigned int *keyid);
755
unsigned int cdk_pk_get_keyid (cdk_pubkey_t pk, unsigned int *keyid);
756
unsigned int cdk_sk_get_keyid (cdk_seckey_t sk, unsigned int *keyid);
757
unsigned int cdk_sig_get_keyid (cdk_pkt_signature_t sig,
758
unsigned int *keyid);
755
760
/* Key release functions. */
756
void cdk_pk_release (cdk_pubkey_t pk);
757
void cdk_sk_release (cdk_seckey_t sk);
761
void cdk_pk_release (cdk_pubkey_t pk);
762
void cdk_sk_release (cdk_seckey_t sk);
759
764
/* Create a public key with the data from the secret key @SK. */
760
cdk_error_t cdk_pk_from_secret_key (cdk_seckey_t sk, cdk_pubkey_t * ret_pk);
765
cdk_error_t cdk_pk_from_secret_key (cdk_seckey_t sk, cdk_pubkey_t * ret_pk);
762
767
/* Sexp conversion of keys. */
763
cdk_error_t cdk_pubkey_to_sexp (cdk_pubkey_t pk, char **sexp, size_t * len);
764
cdk_error_t cdk_seckey_to_sexp (cdk_seckey_t sk, char **sexp, size_t * len);
768
cdk_error_t cdk_pubkey_to_sexp (cdk_pubkey_t pk, char **sexp, size_t * len);
769
cdk_error_t cdk_seckey_to_sexp (cdk_seckey_t sk, char **sexp, size_t * len);
767
772
/* String to Key routines. */
768
cdk_error_t cdk_s2k_new (cdk_s2k_t * ret_s2k, int mode, int digest_algo,
769
const unsigned char *salt);
770
void cdk_s2k_free (cdk_s2k_t s2k);
773
cdk_error_t cdk_s2k_new (cdk_s2k_t * ret_s2k, int mode, int digest_algo,
774
const unsigned char *salt);
775
void cdk_s2k_free (cdk_s2k_t s2k);
772
cdk_error_t cdk_file_armor (cdk_ctx_t hd, const char *file,
774
cdk_error_t cdk_file_dearmor (const char *file, const char *output);
775
int cdk_armor_filter_use (cdk_stream_t inp);
777
cdk_error_t cdk_file_armor (cdk_ctx_t hd, const char *file,
779
cdk_error_t cdk_file_dearmor (const char *file, const char *output);
780
int cdk_armor_filter_use (cdk_stream_t inp);
777
782
/* Protect the inbuf with ASCII armor of the specified type.
778
783
If @outbuf and @outlen are NULL, the function returns the calculated
779
784
size of the base64 encoded data in @nwritten. */
780
cdk_error_t cdk_armor_encode_buffer (const unsigned char *inbuf, size_t inlen,
781
char *outbuf, size_t outlen,
782
size_t * nwritten, int type);
785
cdk_error_t cdk_armor_encode_buffer (const unsigned char *inbuf,
786
size_t inlen, char *outbuf,
787
size_t outlen, size_t * nwritten,
785
791
/* This context contain user callbacks for different stream operations.
786
792
Some of these callbacks might be NULL to indicate that the callback
788
struct cdk_stream_cbs_s
790
cdk_error_t (*open) (void *);
791
cdk_error_t (*release) (void *);
792
int (*read) (void *, void *buf, size_t);
793
int (*write) (void *, const void *buf, size_t);
794
int (*seek) (void *, off_t);
796
typedef struct cdk_stream_cbs_s *cdk_stream_cbs_t;
794
struct cdk_stream_cbs_s
796
cdk_error_t (*open) (void *);
797
cdk_error_t (*release) (void *);
798
int (*read) (void *, void *buf, size_t);
799
int (*write) (void *, const void *buf, size_t);
800
int (*seek) (void *, off_t);
802
typedef struct cdk_stream_cbs_s *cdk_stream_cbs_t;
798
int cdk_stream_is_compressed (cdk_stream_t s);
804
int cdk_stream_is_compressed (cdk_stream_t s);
800
806
/* Return a stream object which is associated to a socket. */
801
cdk_error_t cdk_stream_sockopen (const char *host, unsigned short port,
802
cdk_stream_t * ret_out);
807
cdk_error_t cdk_stream_sockopen (const char *host, unsigned short port,
808
cdk_stream_t * ret_out);
804
810
/* Return a stream object which is associated to an existing file. */
805
cdk_error_t cdk_stream_open (const char *file, cdk_stream_t * ret_s);
811
cdk_error_t cdk_stream_open (const char *file, cdk_stream_t * ret_s);
807
813
/* Return a stream object which is associated to a file which will
808
814
be created when the stream is closed. */
809
cdk_error_t cdk_stream_new (const char *file, cdk_stream_t * ret_s);
815
cdk_error_t cdk_stream_new (const char *file, cdk_stream_t * ret_s);
811
817
/* Return a stream object with custom callback functions for the
812
818
various core operations. */
813
cdk_error_t cdk_stream_new_from_cbs (cdk_stream_cbs_t cbs, void *opa,
814
cdk_stream_t * ret_s);
815
cdk_error_t cdk_stream_create (const char *file, cdk_stream_t * ret_s);
816
cdk_error_t cdk_stream_tmp_new (cdk_stream_t * r_out);
817
cdk_error_t cdk_stream_tmp_from_mem (const void *buf, size_t buflen,
818
cdk_stream_t * r_out);
819
void cdk_stream_tmp_set_mode (cdk_stream_t s, int val);
820
cdk_error_t cdk_stream_flush (cdk_stream_t s);
821
cdk_error_t cdk_stream_enable_cache (cdk_stream_t s, int val);
822
cdk_error_t cdk_stream_filter_disable (cdk_stream_t s, int type);
823
cdk_error_t cdk_stream_close (cdk_stream_t s);
824
off_t cdk_stream_get_length (cdk_stream_t s);
825
int cdk_stream_read (cdk_stream_t s, void *buf, size_t count);
826
int cdk_stream_write (cdk_stream_t s, const void *buf, size_t count);
827
int cdk_stream_putc (cdk_stream_t s, int c);
828
int cdk_stream_getc (cdk_stream_t s);
829
int cdk_stream_eof (cdk_stream_t s);
830
off_t cdk_stream_tell (cdk_stream_t s);
831
cdk_error_t cdk_stream_seek (cdk_stream_t s, off_t offset);
832
cdk_error_t cdk_stream_set_armor_flag (cdk_stream_t s, int type);
819
cdk_error_t cdk_stream_new_from_cbs (cdk_stream_cbs_t cbs, void *opa,
820
cdk_stream_t * ret_s);
821
cdk_error_t cdk_stream_create (const char *file, cdk_stream_t * ret_s);
822
cdk_error_t cdk_stream_tmp_new (cdk_stream_t * r_out);
823
cdk_error_t cdk_stream_tmp_from_mem (const void *buf, size_t buflen,
824
cdk_stream_t * r_out);
825
void cdk_stream_tmp_set_mode (cdk_stream_t s, int val);
826
cdk_error_t cdk_stream_flush (cdk_stream_t s);
827
cdk_error_t cdk_stream_enable_cache (cdk_stream_t s, int val);
828
cdk_error_t cdk_stream_filter_disable (cdk_stream_t s, int type);
829
cdk_error_t cdk_stream_close (cdk_stream_t s);
830
off_t cdk_stream_get_length (cdk_stream_t s);
831
int cdk_stream_read (cdk_stream_t s, void *buf, size_t count);
832
int cdk_stream_write (cdk_stream_t s, const void *buf, size_t count);
833
int cdk_stream_putc (cdk_stream_t s, int c);
834
int cdk_stream_getc (cdk_stream_t s);
835
int cdk_stream_eof (cdk_stream_t s);
836
off_t cdk_stream_tell (cdk_stream_t s);
837
cdk_error_t cdk_stream_seek (cdk_stream_t s, off_t offset);
838
cdk_error_t cdk_stream_set_armor_flag (cdk_stream_t s, int type);
834
840
/* Push the literal filter for the given stream. */
835
cdk_error_t cdk_stream_set_literal_flag (cdk_stream_t s,
836
cdk_lit_format_t mode,
841
cdk_error_t cdk_stream_set_literal_flag (cdk_stream_t s,
842
cdk_lit_format_t mode,
839
cdk_error_t cdk_stream_set_compress_flag (cdk_stream_t s, int algo,
841
cdk_error_t cdk_stream_set_hash_flag (cdk_stream_t s, int algo);
842
cdk_error_t cdk_stream_set_text_flag (cdk_stream_t s, const char *lf);
843
cdk_error_t cdk_stream_kick_off (cdk_stream_t inp, cdk_stream_t out);
844
cdk_error_t cdk_stream_mmap (cdk_stream_t s, unsigned char **ret_buf,
845
size_t * ret_buflen);
846
cdk_error_t cdk_stream_mmap_part (cdk_stream_t s, off_t off, size_t len,
847
unsigned char **ret_buf,
848
size_t * ret_buflen);
845
cdk_error_t cdk_stream_set_compress_flag (cdk_stream_t s, int algo,
847
cdk_error_t cdk_stream_set_hash_flag (cdk_stream_t s, int algo);
848
cdk_error_t cdk_stream_set_text_flag (cdk_stream_t s, const char *lf);
849
cdk_error_t cdk_stream_kick_off (cdk_stream_t inp, cdk_stream_t out);
850
cdk_error_t cdk_stream_mmap (cdk_stream_t s, unsigned char **ret_buf,
851
size_t * ret_buflen);
852
cdk_error_t cdk_stream_mmap_part (cdk_stream_t s, off_t off, size_t len,
853
unsigned char **ret_buf,
854
size_t * ret_buflen);
850
856
/* Read from the stream but restore the file pointer after reading
851
857
the requested amount of bytes. */
852
int cdk_stream_peek (cdk_stream_t inp, unsigned char *buf, size_t buflen);
858
int cdk_stream_peek (cdk_stream_t inp, unsigned char *buf, size_t buflen);
854
860
/* A wrapper around the various new_from_XXX functions. Because
855
861
the function does not support all combinations, the dedicated
856
862
functions should be preferred. */
857
cdk_error_t cdk_keydb_new (cdk_keydb_hd_t * r_hd, int type, void *data,
863
cdk_error_t cdk_keydb_new (cdk_keydb_hd_t * r_hd, int type, void *data,
860
866
/* Create a new key db handle from a memory buffer. */
861
cdk_error_t cdk_keydb_new_from_mem (cdk_keydb_hd_t * r_hd, int secret,
862
const void *data, size_t datlen);
867
cdk_error_t cdk_keydb_new_from_mem (cdk_keydb_hd_t * r_hd, int secret,
868
const void *data, size_t datlen);
864
870
/* Create a new key db which uses an existing file. */
865
cdk_error_t cdk_keydb_new_from_file (cdk_keydb_hd_t * r_hd, int secret,
871
cdk_error_t cdk_keydb_new_from_file (cdk_keydb_hd_t * r_hd, int secret,
868
874
/* Uses a stream as the key db input. For searching it is important
869
875
that the seek function is supported on the stream. Furthermore,
870
876
the stream is not closed in cdk_keydb_free(). The caller must do it. */
871
cdk_error_t cdk_keydb_new_from_stream (cdk_keydb_hd_t * r_hd, int secret,
877
cdk_error_t cdk_keydb_new_from_stream (cdk_keydb_hd_t * r_hd, int secret,
874
880
/* Check that a secret key with the given key ID is available. */
875
cdk_error_t cdk_keydb_check_sk (cdk_keydb_hd_t hd, unsigned int *keyid);
881
cdk_error_t cdk_keydb_check_sk (cdk_keydb_hd_t hd, unsigned int *keyid);
877
883
/* Prepare the key db search. */
878
cdk_error_t cdk_keydb_search_start (cdk_keydb_search_t * st,
879
cdk_keydb_hd_t db, int type, void *desc);
884
cdk_error_t cdk_keydb_search_start (cdk_keydb_search_t * st,
885
cdk_keydb_hd_t db, int type,
881
void cdk_keydb_search_release (cdk_keydb_search_t st);
888
void cdk_keydb_search_release (cdk_keydb_search_t st);
883
890
/* Return a key which matches a valid description given in
884
891
cdk_keydb_search_start(). */
885
cdk_error_t cdk_keydb_search (cdk_keydb_search_t st, cdk_keydb_hd_t hd,
886
cdk_kbnode_t * ret_key);
892
cdk_error_t cdk_keydb_search (cdk_keydb_search_t st, cdk_keydb_hd_t hd,
893
cdk_kbnode_t * ret_key);
888
895
/* Release the key db handle and all its resources. */
889
void cdk_keydb_free (cdk_keydb_hd_t hd);
896
void cdk_keydb_free (cdk_keydb_hd_t hd);
891
898
/* The following functions will try to find a key in the given key
892
899
db handle either by keyid, by fingerprint or by some pattern. */
893
cdk_error_t cdk_keydb_get_bykeyid (cdk_keydb_hd_t hd, unsigned int *keyid,
900
cdk_error_t cdk_keydb_get_bykeyid (cdk_keydb_hd_t hd, unsigned int *keyid,
901
cdk_kbnode_t * ret_pk);
902
cdk_error_t cdk_keydb_get_byfpr (cdk_keydb_hd_t hd,
903
const unsigned char *fpr,
894
904
cdk_kbnode_t * ret_pk);
895
cdk_error_t cdk_keydb_get_byfpr (cdk_keydb_hd_t hd, const unsigned char *fpr,
896
cdk_kbnode_t * ret_pk);
897
cdk_error_t cdk_keydb_get_bypattern (cdk_keydb_hd_t hd, const char *patt,
898
cdk_kbnode_t * ret_pk);
905
cdk_error_t cdk_keydb_get_bypattern (cdk_keydb_hd_t hd, const char *patt,
906
cdk_kbnode_t * ret_pk);
900
908
/* These function, in contrast to most other key db functions, only
901
909
return the public or secret key packet without the additional
902
910
signatures and user IDs. */
903
cdk_error_t cdk_keydb_get_pk (cdk_keydb_hd_t khd, unsigned int *keyid,
904
cdk_pubkey_t * ret_pk);
905
cdk_error_t cdk_keydb_get_sk (cdk_keydb_hd_t khd, unsigned int *keyid,
906
cdk_seckey_t * ret_sk);
911
cdk_error_t cdk_keydb_get_pk (cdk_keydb_hd_t khd, unsigned int *keyid,
912
cdk_pubkey_t * ret_pk);
913
cdk_error_t cdk_keydb_get_sk (cdk_keydb_hd_t khd, unsigned int *keyid,
914
cdk_seckey_t * ret_sk);
908
916
/* Try to read the next key block from the given input stream.
909
917
The key will be returned in @RET_KEY on success. */
910
cdk_error_t cdk_keydb_get_keyblock (cdk_stream_t inp, cdk_kbnode_t * ret_key);
918
cdk_error_t cdk_keydb_get_keyblock (cdk_stream_t inp,
919
cdk_kbnode_t * ret_key);
912
921
/* Rebuild the key db index if possible. */
913
cdk_error_t cdk_keydb_idx_rebuild (cdk_keydb_hd_t db, cdk_keydb_search_t dbs);
922
cdk_error_t cdk_keydb_idx_rebuild (cdk_keydb_hd_t db,
923
cdk_keydb_search_t dbs);
915
925
/* Export one or more keys from the given key db handle into
916
926
the stream @OUT. The export is done by substring search and
917
927
uses the string list @REMUSR for the pattern. */
918
cdk_error_t cdk_keydb_export (cdk_keydb_hd_t hd, cdk_stream_t out,
919
cdk_strlist_t remusr);
928
cdk_error_t cdk_keydb_export (cdk_keydb_hd_t hd, cdk_stream_t out,
929
cdk_strlist_t remusr);
921
931
/* Import the given key node @knode into the key db. */
922
cdk_error_t cdk_keydb_import (cdk_keydb_hd_t hd, cdk_kbnode_t knode);
932
cdk_error_t cdk_keydb_import (cdk_keydb_hd_t hd, cdk_kbnode_t knode);
925
935
/* List or enumerate keys from a given key db handle. */
927
937
/* Start the key list process. Either use @PATT for a pattern search
928
938
or @FPATT for a list of pattern. */
929
cdk_error_t cdk_listkey_start (cdk_listkey_t * r_ctx, cdk_keydb_hd_t db,
930
const char *patt, cdk_strlist_t fpatt);
931
void cdk_listkey_close (cdk_listkey_t ctx);
939
cdk_error_t cdk_listkey_start (cdk_listkey_t * r_ctx, cdk_keydb_hd_t db,
940
const char *patt, cdk_strlist_t fpatt);
941
void cdk_listkey_close (cdk_listkey_t ctx);
933
943
/* Return the next key which matches the pattern. */
934
cdk_error_t cdk_listkey_next (cdk_listkey_t ctx, cdk_kbnode_t * ret_key);
936
cdk_kbnode_t cdk_kbnode_new (cdk_packet_t pkt);
937
cdk_error_t cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node,
938
const unsigned char *buf,
940
cdk_error_t cdk_kbnode_write_to_mem (cdk_kbnode_t node,
941
unsigned char *buf, size_t * r_nbytes);
942
cdk_error_t cdk_kbnode_write_to_mem_alloc (cdk_kbnode_t node,
943
unsigned char **r_buf,
946
void cdk_kbnode_release (cdk_kbnode_t node);
947
void cdk_kbnode_delete (cdk_kbnode_t node);
948
void cdk_kbnode_insert (cdk_kbnode_t root, cdk_kbnode_t node,
949
cdk_packet_type_t pkttype);
950
int cdk_kbnode_commit (cdk_kbnode_t * root);
951
void cdk_kbnode_remove (cdk_kbnode_t * root, cdk_kbnode_t node);
952
void cdk_kbnode_move (cdk_kbnode_t * root, cdk_kbnode_t node,
954
cdk_kbnode_t cdk_kbnode_walk (cdk_kbnode_t root, cdk_kbnode_t * ctx, int all);
955
cdk_packet_t cdk_kbnode_find_packet (cdk_kbnode_t node,
956
cdk_packet_type_t pkttype);
957
cdk_packet_t cdk_kbnode_get_packet (cdk_kbnode_t node);
958
cdk_kbnode_t cdk_kbnode_find (cdk_kbnode_t node, cdk_packet_type_t pkttype);
959
cdk_kbnode_t cdk_kbnode_find_prev (cdk_kbnode_t root, cdk_kbnode_t node,
960
cdk_packet_type_t pkttype);
961
cdk_kbnode_t cdk_kbnode_find_next (cdk_kbnode_t node,
962
cdk_packet_type_t pkttype);
963
cdk_error_t cdk_kbnode_hash (cdk_kbnode_t node, digest_hd_st * md, int is_v4,
964
cdk_packet_type_t pkttype, int flags);
944
cdk_error_t cdk_listkey_next (cdk_listkey_t ctx, cdk_kbnode_t * ret_key);
946
cdk_kbnode_t cdk_kbnode_new (cdk_packet_t pkt);
947
cdk_error_t cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node,
948
const unsigned char *buf,
950
cdk_error_t cdk_kbnode_write_to_mem (cdk_kbnode_t node,
951
unsigned char *buf, size_t * r_nbytes);
952
cdk_error_t cdk_kbnode_write_to_mem_alloc (cdk_kbnode_t node,
953
unsigned char **r_buf,
956
void cdk_kbnode_release (cdk_kbnode_t node);
957
void cdk_kbnode_delete (cdk_kbnode_t node);
958
void cdk_kbnode_insert (cdk_kbnode_t root, cdk_kbnode_t node,
959
cdk_packet_type_t pkttype);
960
int cdk_kbnode_commit (cdk_kbnode_t * root);
961
void cdk_kbnode_remove (cdk_kbnode_t * root, cdk_kbnode_t node);
962
void cdk_kbnode_move (cdk_kbnode_t * root, cdk_kbnode_t node,
964
cdk_kbnode_t cdk_kbnode_walk (cdk_kbnode_t root, cdk_kbnode_t * ctx,
966
cdk_packet_t cdk_kbnode_find_packet (cdk_kbnode_t node,
967
cdk_packet_type_t pkttype);
968
cdk_packet_t cdk_kbnode_get_packet (cdk_kbnode_t node);
969
cdk_kbnode_t cdk_kbnode_find (cdk_kbnode_t node, cdk_packet_type_t pkttype);
970
cdk_kbnode_t cdk_kbnode_find_prev (cdk_kbnode_t root, cdk_kbnode_t node,
971
cdk_packet_type_t pkttype);
972
cdk_kbnode_t cdk_kbnode_find_next (cdk_kbnode_t node,
973
cdk_packet_type_t pkttype);
974
cdk_error_t cdk_kbnode_hash (cdk_kbnode_t node, digest_hd_st * md,
975
int is_v4, cdk_packet_type_t pkttype,
966
978
/* Check each signature in the key node and return a summary of the
967
979
key status in @r_status. Values of cdk_key_flag_t are used. */
968
cdk_error_t cdk_pk_check_sigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd,
980
cdk_error_t cdk_pk_check_sigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd,
971
983
/* Check the self signature of the key to make sure it is valid. */
972
cdk_error_t cdk_pk_check_self_sig (cdk_kbnode_t knode, int *r_status);
984
cdk_error_t cdk_pk_check_self_sig (cdk_kbnode_t knode, int *r_status);
974
986
/* Return a matching algorithm from the given public key list.
975
987
@PREFTYPE can be either sym-cipher/compress/digest. */
976
int cdk_pklist_select_algo (cdk_keylist_t pkl, int preftype);
988
int cdk_pklist_select_algo (cdk_keylist_t pkl, int preftype);
978
990
/* Return 0 or 1 if the given key list is able to understand the
980
int cdk_pklist_use_mdc (cdk_keylist_t pkl);
981
cdk_error_t cdk_pklist_build (cdk_keylist_t * ret_pkl, cdk_keydb_hd_t hd,
982
cdk_strlist_t remusr, int use);
983
void cdk_pklist_release (cdk_keylist_t pkl);
992
int cdk_pklist_use_mdc (cdk_keylist_t pkl);
993
cdk_error_t cdk_pklist_build (cdk_keylist_t * ret_pkl, cdk_keydb_hd_t hd,
994
cdk_strlist_t remusr, int use);
995
void cdk_pklist_release (cdk_keylist_t pkl);
985
997
/* Secret key lists */
986
cdk_error_t cdk_sklist_build (cdk_keylist_t * ret_skl,
987
cdk_keydb_hd_t db, cdk_ctx_t hd,
988
cdk_strlist_t locusr,
989
int unlock, unsigned int use);
990
void cdk_sklist_release (cdk_keylist_t skl);
991
cdk_error_t cdk_sklist_write (cdk_keylist_t skl, cdk_stream_t outp,
992
digest_hd_st * mdctx, int sigclass, int sigver);
993
cdk_error_t cdk_sklist_write_onepass (cdk_keylist_t skl, cdk_stream_t outp,
994
int sigclass, int mdalgo);
998
cdk_error_t cdk_sklist_build (cdk_keylist_t * ret_skl,
999
cdk_keydb_hd_t db, cdk_ctx_t hd,
1000
cdk_strlist_t locusr,
1001
int unlock, unsigned int use);
1002
void cdk_sklist_release (cdk_keylist_t skl);
1003
cdk_error_t cdk_sklist_write (cdk_keylist_t skl, cdk_stream_t outp,
1004
digest_hd_st * mdctx, int sigclass,
1006
cdk_error_t cdk_sklist_write_onepass (cdk_keylist_t skl, cdk_stream_t outp,
1007
int sigclass, int mdalgo);
996
1009
/* Encrypt the given stream @INP with the recipients given in @REMUSR.
997
1010
If @REMUSR is NULL, symmetric encryption will be used. The output
998
1011
will be written to @OUT. */
999
cdk_error_t cdk_stream_encrypt (cdk_ctx_t hd, cdk_strlist_t remusr,
1000
cdk_stream_t inp, cdk_stream_t out);
1012
cdk_error_t cdk_stream_encrypt (cdk_ctx_t hd, cdk_strlist_t remusr,
1013
cdk_stream_t inp, cdk_stream_t out);
1002
1015
/* Decrypt the @INP stream into @OUT. */
1003
cdk_error_t cdk_stream_decrypt (cdk_ctx_t hd, cdk_stream_t inp,
1016
cdk_error_t cdk_stream_decrypt (cdk_ctx_t hd, cdk_stream_t inp,
1006
1019
/* Same as the function above but it works on files. */
1007
cdk_error_t cdk_file_encrypt (cdk_ctx_t hd, cdk_strlist_t remusr,
1008
const char *file, const char *output);
1009
cdk_error_t cdk_file_decrypt (cdk_ctx_t hd, const char *file,
1010
const char *output);
1020
cdk_error_t cdk_file_encrypt (cdk_ctx_t hd, cdk_strlist_t remusr,
1021
const char *file, const char *output);
1022
cdk_error_t cdk_file_decrypt (cdk_ctx_t hd, const char *file,
1023
const char *output);
1012
1025
/* Generic function to transform data. The mode can be either sign,
1013
1026
verify, encrypt, decrypt, import or export. The meanings of the
1014
1027
parameters are similar to the functions above.
1015
1028
@OUTBUF will contain the output and @OUTSIZE the length of it. */
1016
cdk_error_t cdk_data_transform (cdk_ctx_t hd, enum cdk_crypto_mode_t mode,
1017
cdk_strlist_t locusr, cdk_strlist_t remusr,
1018
const void *inbuf, size_t insize,
1019
unsigned char **outbuf, size_t * outsize,
1029
cdk_error_t cdk_data_transform (cdk_ctx_t hd, enum cdk_crypto_mode_t mode,
1030
cdk_strlist_t locusr, cdk_strlist_t remusr,
1031
const void *inbuf, size_t insize,
1032
unsigned char **outbuf, size_t * outsize,
1022
1035
/* Sign the stream @INP. Optionally, the output will be encrypted
1023
1036
if @REMUSR is not NULL and the @ENCRYPTFLAG is set.
1024
1037
The output will be written to @OUT.
1025
1038
@LOCUSR contains one ore more pattern for the secret key(s) to use. */
1026
cdk_error_t cdk_stream_sign (cdk_ctx_t hd, cdk_stream_t inp, cdk_stream_t out,
1027
cdk_strlist_t locusr, cdk_strlist_t remusr,
1028
int encryptflag, int sigmode);
1039
cdk_error_t cdk_stream_sign (cdk_ctx_t hd, cdk_stream_t inp,
1040
cdk_stream_t out, cdk_strlist_t locusr,
1041
cdk_strlist_t remusr, int encryptflag,
1030
1044
/* Same as the function above but it works on files. */
1031
cdk_error_t cdk_file_sign (cdk_ctx_t hd, cdk_strlist_t locusr,
1032
cdk_strlist_t remusr,
1033
const char *file, const char *output,
1034
int sigmode, int encryptflag);
1045
cdk_error_t cdk_file_sign (cdk_ctx_t hd, cdk_strlist_t locusr,
1046
cdk_strlist_t remusr,
1047
const char *file, const char *output,
1048
int sigmode, int encryptflag);
1036
cdk_error_t cdk_stream_verify (cdk_ctx_t hd, cdk_stream_t inp,
1037
cdk_stream_t data, cdk_stream_t out);
1050
cdk_error_t cdk_stream_verify (cdk_ctx_t hd, cdk_stream_t inp,
1051
cdk_stream_t data, cdk_stream_t out);
1039
1053
/* Verify the given file @FILE. For a detached signature, @DATA_FILE
1040
1054
contains the actual file data and @FILE is only the signature.
1041
1055
If the @OUTPUT is not NULL, the plaintext will be written to this file. */
1042
cdk_error_t cdk_file_verify (cdk_ctx_t hd, const char *file,
1043
const char *data_file, const char *output);
1045
int cdk_trustdb_get_validity (cdk_stream_t inp, cdk_pkt_userid_t id,
1047
int cdk_trustdb_get_ownertrust (cdk_stream_t inp, cdk_pubkey_t pk,
1048
int *r_val, int *r_flags);
1050
void cdk_strlist_free (cdk_strlist_t sl);
1051
cdk_strlist_t cdk_strlist_add (cdk_strlist_t * list, const char *string);
1052
cdk_strlist_t cdk_strlist_next (cdk_strlist_t root, const char **r_str);
1053
const char *cdk_check_version (const char *req_version);
1056
cdk_error_t cdk_file_verify (cdk_ctx_t hd, const char *file,
1057
const char *data_file, const char *output);
1059
int cdk_trustdb_get_validity (cdk_stream_t inp, cdk_pkt_userid_t id,
1061
int cdk_trustdb_get_ownertrust (cdk_stream_t inp, cdk_pubkey_t pk,
1062
int *r_val, int *r_flags);
1064
void cdk_strlist_free (cdk_strlist_t sl);
1065
cdk_strlist_t cdk_strlist_add (cdk_strlist_t * list, const char *string);
1066
cdk_strlist_t cdk_strlist_next (cdk_strlist_t root, const char **r_str);
1067
const char *cdk_check_version (const char *req_version);
1055
char *cdk_utf8_encode (const char *string);
1056
char *cdk_utf8_decode (const char *string, size_t length, int delim);
1069
char *cdk_utf8_encode (const char *string);
1070
char *cdk_utf8_decode (const char *string, size_t length, int delim);
1058
1072
#ifdef __cplusplus
1062
#endif /* OPENCDK_H */
1076
#endif /* OPENCDK_H */