~ubuntu-branches/ubuntu/quantal/gnutls26/quantal-security

« back to all changes in this revision

Viewing changes to lib/opencdk/opencdk.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* opencdk.h - Open Crypto Development Kit (OpenCDK)
2
 
 * Copyright (C) 2001, 2002, 2003, 2006, 2007, 2008 Free Software Foundation, Inc.
 
2
 * Copyright (C) 2001, 2002, 2003, 2006, 2007, 2008, 2010 Free Software
 
3
 * Foundation, Inc.
3
4
 *
4
5
 * Author: Timo Schulz
5
6
 *
42
43
#define OPENCDK_VERSION_PATCH 6
43
44
 
44
45
#ifdef __cplusplus
45
 
extern "C" {
 
46
extern "C"
 
47
{
46
48
#endif
47
49
 
48
50
/* General contexts */
49
51
 
50
52
/* 'Session' handle to support the various options and run-time
51
53
   information. */
52
 
struct cdk_ctx_s;
53
 
typedef struct cdk_ctx_s *cdk_ctx_t;
 
54
  struct cdk_ctx_s;
 
55
  typedef struct cdk_ctx_s *cdk_ctx_t;
54
56
 
55
57
/* A generic context to store list of strings. */
56
 
struct cdk_strlist_s;
57
 
typedef struct cdk_strlist_s *cdk_strlist_t;
 
58
  struct cdk_strlist_s;
 
59
  typedef struct cdk_strlist_s *cdk_strlist_t;
58
60
 
59
61
/* Context used to list keys of a keyring. */
60
 
struct cdk_listkey_s;
61
 
typedef struct cdk_listkey_s *cdk_listkey_t;
 
62
  struct cdk_listkey_s;
 
63
  typedef struct cdk_listkey_s *cdk_listkey_t;
62
64
 
63
65
/* Opaque String to Key (S2K) handle. */
64
 
struct cdk_s2k_s;
65
 
typedef struct cdk_s2k_s *cdk_s2k_t;
 
66
  struct cdk_s2k_s;
 
67
  typedef struct cdk_s2k_s *cdk_s2k_t;
66
68
 
67
69
/* Abstract I/O object, a stream, which is used for most operations. */
68
 
struct cdk_stream_s;
69
 
typedef struct cdk_stream_s *cdk_stream_t;
 
70
  struct cdk_stream_s;
 
71
  typedef struct cdk_stream_s *cdk_stream_t;
70
72
 
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;
74
76
 
75
77
/* Node to store a single key node packet. */
76
 
struct cdk_kbnode_s;
77
 
typedef struct cdk_kbnode_s *cdk_kbnode_t;
 
78
  struct cdk_kbnode_s;
 
79
  typedef struct cdk_kbnode_s *cdk_kbnode_t;
78
80
 
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;
82
84
 
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;
85
87
 
86
88
/* Context to store a list of recipient keys. */
87
 
struct cdk_keylist_s;
88
 
typedef struct cdk_keylist_s *cdk_keylist_t;
 
89
  struct cdk_keylist_s;
 
90
  typedef struct cdk_keylist_s *cdk_keylist_t;
89
91
 
90
92
/* Context to encapsulate a single sub packet of a signature. */
91
 
struct cdk_subpkt_s;
92
 
typedef struct cdk_subpkt_s *cdk_subpkt_t;
 
93
  struct cdk_subpkt_s;
 
94
  typedef struct cdk_subpkt_s *cdk_subpkt_t;
93
95
 
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;
97
99
 
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;
101
103
 
102
104
/* Alias for backward compatibility. */
103
 
typedef bigint_t cdk_mpi_t;
 
105
  typedef bigint_t cdk_mpi_t;
104
106
 
105
107
 
106
108
/* All valid error constants. */
107
 
typedef enum
108
 
{
109
 
  CDK_EOF = -1,
110
 
  CDK_Success = 0,
111
 
  CDK_General_Error = 1,
112
 
  CDK_File_Error = 2,
113
 
  CDK_Bad_Sig = 3,
114
 
  CDK_Inv_Packet = 4,
115
 
  CDK_Inv_Algo = 5,
116
 
  CDK_Not_Implemented = 6,
117
 
  CDK_Armor_Error = 8,
118
 
  CDK_Armor_CRC_Error = 9,
119
 
  CDK_MPI_Error = 10,
120
 
  CDK_Inv_Value = 11,
121
 
  CDK_Error_No_Key = 12,
122
 
  CDK_Chksum_Error = 13,
123
 
  CDK_Time_Conflict = 14,
124
 
  CDK_Zlib_Error = 15,
125
 
  CDK_Weak_Key = 16,
126
 
  CDK_Out_Of_Core = 17,
127
 
  CDK_Wrong_Seckey = 18,
128
 
  CDK_Bad_MDC = 19,
129
 
  CDK_Inv_Mode = 20,
130
 
  CDK_Error_No_Keyring = 21,
131
 
  CDK_Wrong_Format = 22,
132
 
  CDK_Inv_Packet_Ver = 23,
133
 
  CDK_Too_Short = 24,
134
 
  CDK_Unusable_Key = 25,
135
 
  CDK_No_Data = 26,
136
 
  CDK_No_Passphrase = 27,
137
 
  CDK_Network_Error = 28
138
 
} cdk_error_t;
139
 
 
140
 
 
141
 
enum cdk_control_flags
142
 
{
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 */
153
 
};
 
109
  typedef enum
 
110
  {
 
111
    CDK_EOF = -1,
 
112
    CDK_Success = 0,
 
113
    CDK_General_Error = 1,
 
114
    CDK_File_Error = 2,
 
115
    CDK_Bad_Sig = 3,
 
116
    CDK_Inv_Packet = 4,
 
117
    CDK_Inv_Algo = 5,
 
118
    CDK_Not_Implemented = 6,
 
119
    CDK_Armor_Error = 8,
 
120
    CDK_Armor_CRC_Error = 9,
 
121
    CDK_MPI_Error = 10,
 
122
    CDK_Inv_Value = 11,
 
123
    CDK_Error_No_Key = 12,
 
124
    CDK_Chksum_Error = 13,
 
125
    CDK_Time_Conflict = 14,
 
126
    CDK_Zlib_Error = 15,
 
127
    CDK_Weak_Key = 16,
 
128
    CDK_Out_Of_Core = 17,
 
129
    CDK_Wrong_Seckey = 18,
 
130
    CDK_Bad_MDC = 19,
 
131
    CDK_Inv_Mode = 20,
 
132
    CDK_Error_No_Keyring = 21,
 
133
    CDK_Wrong_Format = 22,
 
134
    CDK_Inv_Packet_Ver = 23,
 
135
    CDK_Too_Short = 24,
 
136
    CDK_Unusable_Key = 25,
 
137
    CDK_No_Data = 26,
 
138
    CDK_No_Passphrase = 27,
 
139
    CDK_Network_Error = 28
 
140
  } cdk_error_t;
 
141
 
 
142
 
 
143
  enum cdk_control_flags
 
144
  {
 
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 */
 
155
  };
154
156
 
155
157
 
156
158
/* Specifies all valid log levels. */
157
 
enum cdk_log_level_t
158
 
{
159
 
  CDK_LOG_NONE = 0,             /* No log message will be shown. */
160
 
  CDK_LOG_INFO = 1,
161
 
  CDK_LOG_DEBUG = 2,
162
 
  CDK_LOG_DEBUG_PKT = 3
163
 
};
 
159
  enum cdk_log_level_t
 
160
  {
 
161
    CDK_LOG_NONE = 0,           /* No log message will be shown. */
 
162
    CDK_LOG_INFO = 1,
 
163
    CDK_LOG_DEBUG = 2,
 
164
    CDK_LOG_DEBUG_PKT = 3
 
165
  };
164
166
 
165
167
 
166
168
/* All valid compression algorithms in OpenPGP */
167
 
enum cdk_compress_algo_t
168
 
{
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 */
173
 
};
 
169
  enum cdk_compress_algo_t
 
170
  {
 
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
  };
174
176
 
175
177
/* All valid public key algorithms valid in OpenPGP */
176
 
enum cdk_pubkey_algo_t
177
 
{
178
 
  CDK_PK_UNKNOWN = 0,
179
 
  CDK_PK_RSA = 1,
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. */
182
 
  CDK_PK_ELG_E = 16,
183
 
  CDK_PK_DSA = 17
184
 
};
 
178
  enum cdk_pubkey_algo_t
 
179
  {
 
180
    CDK_PK_UNKNOWN = 0,
 
181
    CDK_PK_RSA = 1,
 
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. */
 
184
    CDK_PK_ELG_E = 16,
 
185
    CDK_PK_DSA = 17
 
186
  };
185
187
 
186
188
/* The valid 'String-To-Key' modes */
187
 
enum cdk_s2k_type_t
188
 
{
189
 
  CDK_S2K_SIMPLE = 0,
190
 
  CDK_S2K_SALTED = 1,
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
195
 
     */
196
 
};
 
189
  enum cdk_s2k_type_t
 
190
  {
 
191
    CDK_S2K_SIMPLE = 0,
 
192
    CDK_S2K_SALTED = 1,
 
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
 
197
       */
 
198
  };
197
199
 
198
200
/* The different kind of user ID preferences. */
199
 
enum cdk_pref_type_t
200
 
{
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 */
205
 
};
 
201
  enum cdk_pref_type_t
 
202
  {
 
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 */
 
207
  };
206
208
 
207
209
 
208
210
/* All valid sub packet types. */
209
 
enum cdk_sig_subpacket_t
210
 
{
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
233
 
};
 
211
  enum cdk_sig_subpacket_t
 
212
  {
 
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
 
235
  };
234
236
 
235
237
 
236
238
/* All valid armor types. */
237
 
enum cdk_armor_type_t
238
 
{
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
244
 
};
 
239
  enum cdk_armor_type_t
 
240
  {
 
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
  };
245
247
 
246
 
enum cdk_keydb_flag_t
247
 
{
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 */
261
 
};
 
248
  enum cdk_keydb_flag_t
 
249
  {
 
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 */
 
263
  };
262
264
 
263
265
 
264
266
/* All valid modes for cdk_data_transform() */
265
 
enum cdk_crypto_mode_t
266
 
{
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
274
 
};
 
267
  enum cdk_crypto_mode_t
 
268
  {
 
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
  };
275
277
 
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. */
279
 
enum cdk_key_usage_t
280
 
{
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
288
 
};
 
281
  enum cdk_key_usage_t
 
282
  {
 
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
 
290
  };
289
291
 
290
292
 
291
293
/* Valid flags for keys. */
292
 
enum cdk_key_flag_t
293
 
{
294
 
  CDK_KEY_VALID = 0,
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. */
298
 
  CDK_KEY_NOSIGNER = 8
299
 
};
 
294
  enum cdk_key_flag_t
 
295
  {
 
296
    CDK_KEY_VALID = 0,
 
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. */
 
300
    CDK_KEY_NOSIGNER = 8
 
301
  };
300
302
 
301
303
 
302
304
/* Trust values and flags for keys and user IDs */
303
 
enum cdk_trust_flag_t
304
 
{
305
 
  CDK_TRUST_UNKNOWN = 0,
306
 
  CDK_TRUST_EXPIRED = 1,
307
 
  CDK_TRUST_UNDEFINED = 2,
308
 
  CDK_TRUST_NEVER = 3,
309
 
  CDK_TRUST_MARGINAL = 4,
310
 
  CDK_TRUST_FULLY = 5,
311
 
  CDK_TRUST_ULTIMATE = 6,
312
 
  /* trust flags */
313
 
  CDK_TFLAG_REVOKED = 32,
314
 
  CDK_TFLAG_SUB_REVOKED = 64,
315
 
  CDK_TFLAG_DISABLED = 128
316
 
};
 
305
  enum cdk_trust_flag_t
 
306
  {
 
307
    CDK_TRUST_UNKNOWN = 0,
 
308
    CDK_TRUST_EXPIRED = 1,
 
309
    CDK_TRUST_UNDEFINED = 2,
 
310
    CDK_TRUST_NEVER = 3,
 
311
    CDK_TRUST_MARGINAL = 4,
 
312
    CDK_TRUST_FULLY = 5,
 
313
    CDK_TRUST_ULTIMATE = 6,
 
314
    /* trust flags */
 
315
    CDK_TFLAG_REVOKED = 32,
 
316
    CDK_TFLAG_SUB_REVOKED = 64,
 
317
    CDK_TFLAG_DISABLED = 128
 
318
  };
317
319
 
318
320
 
319
321
/* Signature states and the signature modes. */
320
 
enum cdk_signature_stat_t
321
 
{
322
 
  /* Signature status */
323
 
  CDK_SIGSTAT_NONE = 0,
324
 
  CDK_SIGSTAT_GOOD = 1,
325
 
  CDK_SIGSTAT_BAD = 2,
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
 
323
  {
 
324
    /* Signature status */
 
325
    CDK_SIGSTAT_NONE = 0,
 
326
    CDK_SIGSTAT_GOOD = 1,
 
327
    CDK_SIGSTAT_BAD = 2,
 
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. */
329
331
 
330
 
  /* Signature modes */
331
 
  CDK_SIGMODE_NORMAL = 100,
332
 
  CDK_SIGMODE_DETACHED = 101,
333
 
  CDK_SIGMODE_CLEAR = 102
334
 
};
 
332
    /* Signature modes */
 
333
    CDK_SIGMODE_NORMAL = 100,
 
334
    CDK_SIGMODE_DETACHED = 101,
 
335
    CDK_SIGMODE_CLEAR = 102
 
336
  };
335
337
 
336
338
 
337
339
/* Key flags. */
338
 
typedef enum
339
 
{
340
 
  CDK_FLAG_KEY_REVOKED = 256,
341
 
  CDK_FLAG_KEY_EXPIRED = 512,
342
 
  CDK_FLAG_SIG_EXPIRED = 1024
343
 
} cdk_key_flags_t;
 
340
  typedef enum
 
341
  {
 
342
    CDK_FLAG_KEY_REVOKED = 256,
 
343
    CDK_FLAG_KEY_EXPIRED = 512,
 
344
    CDK_FLAG_SIG_EXPIRED = 1024
 
345
  } cdk_key_flags_t;
344
346
 
345
347
 
346
348
/* Possible format for the literal data. */
347
 
typedef enum
348
 
{
349
 
  CDK_LITFMT_BINARY = 0,
350
 
  CDK_LITFMT_TEXT = 1,
351
 
  CDK_LITFMT_UNICODE = 2
352
 
} cdk_lit_format_t;
 
349
  typedef enum
 
350
  {
 
351
    CDK_LITFMT_BINARY = 0,
 
352
    CDK_LITFMT_TEXT = 1,
 
353
    CDK_LITFMT_UNICODE = 2
 
354
  } cdk_lit_format_t;
353
355
 
354
356
/* Valid OpenPGP packet types and their IDs */
355
 
typedef enum
356
 
{
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,
365
 
  CDK_PKT_MARKER = 10,
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,
372
 
  CDK_PKT_MDC = 19
373
 
} cdk_packet_type_t;
 
357
  typedef enum
 
358
  {
 
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,
 
367
    CDK_PKT_MARKER = 10,
 
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,
 
374
    CDK_PKT_MDC = 19
 
375
  } cdk_packet_type_t;
374
376
 
375
377
/* Define the maximal number of multiprecion integers for
376
378
   a public key. */
387
389
  || ((pkttype)==CDK_PKT_ENCRYPTED))
388
390
 
389
391
 
390
 
struct cdk_pkt_signature_s
391
 
{
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;
401
 
  cdk_subpkt_t hashed;
402
 
  unsigned short unhashed_size;
403
 
  cdk_subpkt_t unhashed;
404
 
  bigint_t mpi[MAX_CDK_DATA_PARTS];
405
 
  cdk_desig_revoker_t revkeys;
406
 
  struct
407
 
  {
408
 
    unsigned exportable:1;
409
 
    unsigned revocable:1;
410
 
    unsigned policy_url:1;
411
 
    unsigned notation:1;
412
 
    unsigned expired:1;
413
 
    unsigned checked:1;
414
 
    unsigned valid:1;
415
 
    unsigned missing_key:1;
416
 
  } flags;
417
 
  unsigned int key[2];          /* only valid for key signatures */
418
 
};
419
 
typedef struct cdk_pkt_signature_s *cdk_pkt_signature_t;
420
 
 
421
 
 
422
 
struct cdk_pkt_userid_s
423
 
{
424
 
  unsigned int len;
425
 
  unsigned is_primary:1;
426
 
  unsigned is_revoked:1;
427
 
  unsigned mdc_feature:1;
428
 
  cdk_prefitem_t prefs;
429
 
  size_t prefs_size;
430
 
  unsigned char *attrib_img;    /* Tag 17 if not null */
431
 
  size_t attrib_len;
432
 
  cdk_pkt_signature_t selfsig;
433
 
  char *name;
434
 
};
435
 
typedef struct cdk_pkt_userid_s *cdk_pkt_userid_t;
436
 
 
437
 
 
438
 
struct cdk_pkt_pubkey_s
439
 
{
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;
451
 
  int pubkey_usage;
452
 
  cdk_pkt_userid_t uid;
453
 
  cdk_prefitem_t prefs;
454
 
  size_t prefs_size;
455
 
  cdk_desig_revoker_t revkeys;
456
 
};
457
 
typedef struct cdk_pkt_pubkey_s *cdk_pkt_pubkey_t;
 
392
  struct cdk_pkt_signature_s
 
393
  {
 
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;
 
403
    cdk_subpkt_t hashed;
 
404
    unsigned short unhashed_size;
 
405
    cdk_subpkt_t unhashed;
 
406
    bigint_t mpi[MAX_CDK_DATA_PARTS];
 
407
    cdk_desig_revoker_t revkeys;
 
408
    struct
 
409
    {
 
410
      unsigned exportable:1;
 
411
      unsigned revocable:1;
 
412
      unsigned policy_url:1;
 
413
      unsigned notation:1;
 
414
      unsigned expired:1;
 
415
      unsigned checked:1;
 
416
      unsigned valid:1;
 
417
      unsigned missing_key:1;
 
418
    } flags;
 
419
    unsigned int key[2];        /* only valid for key signatures */
 
420
  };
 
421
  typedef struct cdk_pkt_signature_s *cdk_pkt_signature_t;
 
422
 
 
423
 
 
424
  struct cdk_pkt_userid_s
 
425
  {
 
426
    unsigned int len;
 
427
    unsigned is_primary:1;
 
428
    unsigned is_revoked:1;
 
429
    unsigned mdc_feature:1;
 
430
    cdk_prefitem_t prefs;
 
431
    size_t prefs_size;
 
432
    unsigned char *attrib_img;  /* Tag 17 if not null */
 
433
    size_t attrib_len;
 
434
    cdk_pkt_signature_t selfsig;
 
435
    char *name;
 
436
  };
 
437
  typedef struct cdk_pkt_userid_s *cdk_pkt_userid_t;
 
438
 
 
439
 
 
440
  struct cdk_pkt_pubkey_s
 
441
  {
 
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;
 
453
    int pubkey_usage;
 
454
    cdk_pkt_userid_t uid;
 
455
    cdk_prefitem_t prefs;
 
456
    size_t prefs_size;
 
457
    cdk_desig_revoker_t revkeys;
 
458
  };
 
459
  typedef struct cdk_pkt_pubkey_s *cdk_pkt_pubkey_t;
458
460
 
459
461
/* Alias to define a generic public key context. */
460
 
typedef cdk_pkt_pubkey_t cdk_pubkey_t;
461
 
 
462
 
 
463
 
struct cdk_pkt_seckey_s
464
 
{
465
 
  cdk_pkt_pubkey_t pk;
466
 
  unsigned int expiredate;
467
 
  int version;
468
 
  int pubkey_algo;
469
 
  unsigned int keyid[2];
470
 
  unsigned int main_keyid[2];
471
 
  unsigned char s2k_usage;
472
 
  struct
 
462
  typedef cdk_pkt_pubkey_t cdk_pubkey_t;
 
463
 
 
464
 
 
465
  struct cdk_pkt_seckey_s
473
466
  {
474
 
    unsigned char algo;
475
 
    unsigned char sha1chk;      /* SHA1 is used instead of a 16 bit checksum */
476
 
    cdk_s2k_t s2k;
477
 
    unsigned char iv[16];
478
 
    unsigned char ivlen;
479
 
  } protect;
480
 
  unsigned short csum;
481
 
  bigint_t mpi[MAX_CDK_PK_PARTS];
482
 
  unsigned char *encdata;
483
 
  size_t enclen;
484
 
  unsigned char is_protected;
485
 
  unsigned is_primary:1;
486
 
  unsigned has_expired:1;
487
 
  unsigned is_revoked:1;
488
 
};
489
 
typedef struct cdk_pkt_seckey_s *cdk_pkt_seckey_t;
 
467
    cdk_pkt_pubkey_t pk;
 
468
    unsigned int expiredate;
 
469
    int version;
 
470
    int pubkey_algo;
 
471
    unsigned int keyid[2];
 
472
    unsigned int main_keyid[2];
 
473
    unsigned char s2k_usage;
 
474
    struct
 
475
    {
 
476
      unsigned char algo;
 
477
      unsigned char sha1chk;    /* SHA1 is used instead of a 16 bit checksum */
 
478
      cdk_s2k_t s2k;
 
479
      unsigned char iv[16];
 
480
      unsigned char ivlen;
 
481
    } protect;
 
482
    unsigned short csum;
 
483
    bigint_t mpi[MAX_CDK_PK_PARTS];
 
484
    unsigned char *encdata;
 
485
    size_t enclen;
 
486
    unsigned char is_protected;
 
487
    unsigned is_primary:1;
 
488
    unsigned has_expired:1;
 
489
    unsigned is_revoked:1;
 
490
  };
 
491
  typedef struct cdk_pkt_seckey_s *cdk_pkt_seckey_t;
490
492
 
491
493
/* Alias to define a generic secret key context. */
492
 
typedef cdk_pkt_seckey_t cdk_seckey_t;
493
 
 
494
 
 
495
 
struct cdk_pkt_onepass_sig_s
496
 
{
497
 
  unsigned char version;
498
 
  unsigned int keyid[2];
499
 
  unsigned char sig_class;
500
 
  unsigned char digest_algo;
501
 
  unsigned char pubkey_algo;
502
 
  unsigned char last;
503
 
};
504
 
typedef struct cdk_pkt_onepass_sig_s *cdk_pkt_onepass_sig_t;
505
 
 
506
 
 
507
 
struct cdk_pkt_pubkey_enc_s
508
 
{
509
 
  unsigned char version;
510
 
  unsigned int keyid[2];
511
 
  int throw_keyid;
512
 
  unsigned char pubkey_algo;
513
 
  bigint_t mpi[MAX_CDK_DATA_PARTS];
514
 
};
515
 
typedef struct cdk_pkt_pubkey_enc_s *cdk_pkt_pubkey_enc_t;
516
 
 
517
 
struct cdk_pkt_encrypted_s
518
 
{
519
 
  unsigned int len;
520
 
  int extralen;
521
 
  unsigned char mdc_method;
522
 
  cdk_stream_t buf;
523
 
};
524
 
typedef struct cdk_pkt_encrypted_s *cdk_pkt_encrypted_t;
525
 
 
526
 
 
527
 
struct cdk_pkt_mdc_s
528
 
{
529
 
  unsigned char hash[20];
530
 
};
531
 
typedef struct cdk_pkt_mdc_s *cdk_pkt_mdc_t;
532
 
 
533
 
 
534
 
struct cdk_pkt_literal_s
535
 
{
536
 
  unsigned int len;
537
 
  cdk_stream_t buf;
538
 
  int mode;
539
 
  unsigned int timestamp;
540
 
  int namelen;
541
 
  char *name;
542
 
};
543
 
typedef struct cdk_pkt_literal_s *cdk_pkt_literal_t;
544
 
 
545
 
 
546
 
struct cdk_pkt_compressed_s
547
 
{
548
 
  unsigned int len;
549
 
  int algorithm;
550
 
  cdk_stream_t buf;
551
 
};
552
 
typedef struct cdk_pkt_compressed_s *cdk_pkt_compressed_t;
 
494
  typedef cdk_pkt_seckey_t cdk_seckey_t;
 
495
 
 
496
 
 
497
  struct cdk_pkt_onepass_sig_s
 
498
  {
 
499
    unsigned char version;
 
500
    unsigned int keyid[2];
 
501
    unsigned char sig_class;
 
502
    unsigned char digest_algo;
 
503
    unsigned char pubkey_algo;
 
504
    unsigned char last;
 
505
  };
 
506
  typedef struct cdk_pkt_onepass_sig_s *cdk_pkt_onepass_sig_t;
 
507
 
 
508
 
 
509
  struct cdk_pkt_pubkey_enc_s
 
510
  {
 
511
    unsigned char version;
 
512
    unsigned int keyid[2];
 
513
    int throw_keyid;
 
514
    unsigned char pubkey_algo;
 
515
    bigint_t mpi[MAX_CDK_DATA_PARTS];
 
516
  };
 
517
  typedef struct cdk_pkt_pubkey_enc_s *cdk_pkt_pubkey_enc_t;
 
518
 
 
519
  struct cdk_pkt_encrypted_s
 
520
  {
 
521
    unsigned int len;
 
522
    int extralen;
 
523
    unsigned char mdc_method;
 
524
    cdk_stream_t buf;
 
525
  };
 
526
  typedef struct cdk_pkt_encrypted_s *cdk_pkt_encrypted_t;
 
527
 
 
528
 
 
529
  struct cdk_pkt_mdc_s
 
530
  {
 
531
    unsigned char hash[20];
 
532
  };
 
533
  typedef struct cdk_pkt_mdc_s *cdk_pkt_mdc_t;
 
534
 
 
535
 
 
536
  struct cdk_pkt_literal_s
 
537
  {
 
538
    unsigned int len;
 
539
    cdk_stream_t buf;
 
540
    int mode;
 
541
    unsigned int timestamp;
 
542
    int namelen;
 
543
    char *name;
 
544
  };
 
545
  typedef struct cdk_pkt_literal_s *cdk_pkt_literal_t;
 
546
 
 
547
 
 
548
  struct cdk_pkt_compressed_s
 
549
  {
 
550
    unsigned int len;
 
551
    int algorithm;
 
552
    cdk_stream_t buf;
 
553
  };
 
554
  typedef struct cdk_pkt_compressed_s *cdk_pkt_compressed_t;
553
555
 
554
556
 
555
557
/* Structure which represents a single OpenPGP packet. */
556
 
struct cdk_packet_s
557
 
{
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;
562
 
  union
 
558
  struct cdk_packet_s
563
559
  {
564
 
    cdk_pkt_mdc_t mdc;
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;
574
 
  } pkt;
575
 
};
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;
 
564
    union
 
565
    {
 
566
      cdk_pkt_mdc_t mdc;
 
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;
 
576
    } pkt;
 
577
  };
 
578
  typedef struct cdk_packet_s *cdk_packet_t;
577
579
 
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);
581
583
 
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);
586
588
 
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);
592
594
 
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, ...);
596
598
 
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
 
                                                const char *prompt),
601
 
                                   void *cb_value);
 
600
  void cdk_handle_set_passphrase_cb (cdk_ctx_t hd,
 
601
                                     char *(*cb) (void *opa,
 
602
                                                  const char *prompt),
 
603
                                     void *cb_value);
602
604
 
603
605
/* shortcuts for some controls */
604
606
 
626
628
 
627
629
 
628
630
/* This context holds all information of the verification process. */
629
 
struct cdk_verify_result_s
630
 
{
631
 
  int sig_ver;                  /* Version of the signature. */
632
 
  int sig_status;               /* The status (GOOD, BAD) of the signature */
633
 
  int sig_flags;                /* May contain expired or revoked flags */
634
 
  unsigned int keyid[2];        /* The issuer key ID */
635
 
  unsigned int created;         /* Timestamp when the sig was created. */
636
 
  unsigned int expires;
637
 
  int pubkey_algo;
638
 
  int digest_algo;
639
 
  char *user_id;                /* NULL or user ID which issued the signature. */
640
 
  char *policy_url;             /* If set, the policy the sig was created under. */
641
 
  size_t sig_len;               /* Size of the signature data inbits. */
642
 
  unsigned char *sig_data;      /* Raw signature data. */
643
 
};
644
 
typedef struct cdk_verify_result_s *cdk_verify_result_t;
 
631
  struct cdk_verify_result_s
 
632
  {
 
633
    int sig_ver;                /* Version of the signature. */
 
634
    int sig_status;             /* The status (GOOD, BAD) of the signature */
 
635
    int sig_flags;              /* May contain expired or revoked flags */
 
636
    unsigned int keyid[2];      /* The issuer key ID */
 
637
    unsigned int created;       /* Timestamp when the sig was created. */
 
638
    unsigned int expires;
 
639
    int pubkey_algo;
 
640
    int digest_algo;
 
641
    char *user_id;              /* NULL or user ID which issued the signature. */
 
642
    char *policy_url;           /* If set, the policy the sig was created under. */
 
643
    size_t sig_len;             /* Size of the signature data inbits. */
 
644
    unsigned char *sig_data;    /* Raw signature data. */
 
645
  };
 
646
  typedef struct cdk_verify_result_s *cdk_verify_result_t;
645
647
 
646
648
/* Return the verify result. Do not free the data. */
647
 
cdk_verify_result_t cdk_handle_verify_get_result (cdk_ctx_t hd);
 
649
  cdk_verify_result_t cdk_handle_verify_get_result (cdk_ctx_t hd);
648
650
 
649
651
/* Raw packet routines. */
650
652
 
651
653
/* Allocate a new packet or a new packet with the given packet type. */
652
 
cdk_error_t cdk_pkt_new (cdk_packet_t * r_pkt);
653
 
cdk_error_t cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype);
 
654
  cdk_error_t cdk_pkt_new (cdk_packet_t * r_pkt);
 
655
  cdk_error_t cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype);
654
656
 
655
657
/* Only release the contents of the packet but not @PKT itself. */
656
 
void cdk_pkt_free (cdk_packet_t pkt);
 
658
  void cdk_pkt_free (cdk_packet_t pkt);
657
659
 
658
660
/* Release the packet contents and the packet structure @PKT itself. */
659
 
void cdk_pkt_release (cdk_packet_t pkt);
 
661
  void cdk_pkt_release (cdk_packet_t pkt);
660
662
 
661
663
/* Read or write the given output from or to the stream. */
662
 
cdk_error_t cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt);
663
 
cdk_error_t cdk_pkt_write (cdk_stream_t out, cdk_packet_t pkt);
 
664
  cdk_error_t cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt);
 
665
  cdk_error_t cdk_pkt_write (cdk_stream_t out, cdk_packet_t pkt);
664
666
 
665
667
/* Sub packet routines */
666
 
cdk_subpkt_t cdk_subpkt_new (size_t size);
667
 
void cdk_subpkt_free (cdk_subpkt_t ctx);
668
 
cdk_subpkt_t cdk_subpkt_find (cdk_subpkt_t ctx, size_t type);
669
 
cdk_subpkt_t cdk_subpkt_find_next (cdk_subpkt_t root, size_t type);
670
 
size_t cdk_subpkt_type_count (cdk_subpkt_t ctx, size_t type);
671
 
cdk_subpkt_t cdk_subpkt_find_nth (cdk_subpkt_t ctx, size_t type,
672
 
                                  size_t index);
673
 
cdk_error_t cdk_subpkt_add (cdk_subpkt_t root, cdk_subpkt_t node);
674
 
const unsigned char *cdk_subpkt_get_data (cdk_subpkt_t ctx,
675
 
                                          size_t * r_type, size_t * r_nbytes);
676
 
void cdk_subpkt_init (cdk_subpkt_t node, size_t type,
677
 
                      const void *buf, size_t buflen);
 
668
  cdk_subpkt_t cdk_subpkt_new (size_t size);
 
669
  void cdk_subpkt_free (cdk_subpkt_t ctx);
 
670
  cdk_subpkt_t cdk_subpkt_find (cdk_subpkt_t ctx, size_t type);
 
671
  cdk_subpkt_t cdk_subpkt_find_next (cdk_subpkt_t root, size_t type);
 
672
  size_t cdk_subpkt_type_count (cdk_subpkt_t ctx, size_t type);
 
673
  cdk_subpkt_t cdk_subpkt_find_nth (cdk_subpkt_t ctx, size_t type,
 
674
                                    size_t index);
 
675
  cdk_error_t cdk_subpkt_add (cdk_subpkt_t root, cdk_subpkt_t node);
 
676
  const unsigned char *cdk_subpkt_get_data (cdk_subpkt_t ctx,
 
677
                                            size_t * r_type,
 
678
                                            size_t * r_nbytes);
 
679
  void cdk_subpkt_init (cdk_subpkt_t node, size_t type, const void *buf,
 
680
                        size_t buflen);
678
681
 
679
682
/* Designated Revoker routines */
680
 
const unsigned char *cdk_key_desig_revoker_walk (cdk_desig_revoker_t root,
681
 
                                                 cdk_desig_revoker_t * ctx,
682
 
                                                 int *r_class, int *r_algid);
 
683
  const unsigned char *cdk_key_desig_revoker_walk (cdk_desig_revoker_t root,
 
684
                                                   cdk_desig_revoker_t * ctx,
 
685
                                                   int *r_class,
 
686
                                                   int *r_algid);
683
687
 
684
688
#define is_RSA(a) ((a) == CDK_PK_RSA            \
685
689
                   || (a) == CDK_PK_RSA_E       \
689
693
 
690
694
/* Encrypt the given session key @SK with the public key @PK
691
695
   and write the contents into the packet @PKE. */
692
 
cdk_error_t cdk_pk_encrypt (cdk_pubkey_t pk, cdk_pkt_pubkey_enc_t pke,
693
 
                            bigint_t sk);
 
696
  cdk_error_t cdk_pk_encrypt (cdk_pubkey_t pk, cdk_pkt_pubkey_enc_t pke,
 
697
                              bigint_t sk);
694
698
 
695
699
/* Decrypt the given encrypted session key in @PKE with the secret key
696
700
   @SK and store it in @R_SK. */
697
 
cdk_error_t cdk_pk_decrypt (cdk_seckey_t sk, cdk_pkt_pubkey_enc_t pke,
698
 
                            bigint_t * r_sk);
 
701
  cdk_error_t cdk_pk_decrypt (cdk_seckey_t sk, cdk_pkt_pubkey_enc_t pke,
 
702
                              bigint_t * r_sk);
699
703
 
700
704
/* Sign the given message digest @MD with the secret key @SK and
701
705
   store the signature in the packet @SIG. */
702
 
cdk_error_t cdk_pk_sign (cdk_seckey_t sk, cdk_pkt_signature_t sig,
703
 
                         const unsigned char *md);
 
706
  cdk_error_t cdk_pk_sign (cdk_seckey_t sk, cdk_pkt_signature_t sig,
 
707
                           const unsigned char *md);
704
708
 
705
709
/* Verify the given signature in @SIG with the public key @PK
706
710
   and compare it against the message digest @MD. */
707
 
cdk_error_t cdk_pk_verify (cdk_pubkey_t pk, cdk_pkt_signature_t sig,
708
 
                           const unsigned char *md);
 
711
  cdk_error_t cdk_pk_verify (cdk_pubkey_t pk, cdk_pkt_signature_t sig,
 
712
                             const unsigned char *md);
709
713
 
710
714
/* Use cdk_pk_get_npkey() and cdk_pk_get_nskey to find out how much
711
715
   multiprecision integers a key consists of. */
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);
719
723
 
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);
724
728
 
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);
732
736
 
733
737
/* Fingerprint and key ID routines. */
734
738
 
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);
738
742
 
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,
742
 
                                   size_t * r_nout);
 
744
  cdk_error_t cdk_pk_to_fingerprint (cdk_pubkey_t pk,
 
745
                                     unsigned char *fpr, size_t fprlen,
 
746
                                     size_t * r_nout);
743
747
 
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,
747
 
                                           size_t fprlen,
748
 
                                           unsigned int *keyid);
 
750
  unsigned int cdk_pk_fingerprint_get_keyid (const unsigned char *fpr,
 
751
                                             size_t fprlen,
 
752
                                             unsigned int *keyid);
749
753
 
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);
754
759
 
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);
758
763
 
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);
761
766
 
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);
765
770
 
766
771
 
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);
771
776
 
772
 
cdk_error_t cdk_file_armor (cdk_ctx_t hd, const char *file,
773
 
                            const char *output);
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,
 
778
                              const char *output);
 
779
  cdk_error_t cdk_file_dearmor (const char *file, const char *output);
 
780
  int cdk_armor_filter_use (cdk_stream_t inp);
776
781
 
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,
 
788
                                       int type);
783
789
 
784
790
 
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
787
793
   is not used. */
788
 
struct cdk_stream_cbs_s
789
 
{
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);
795
 
};
796
 
typedef struct cdk_stream_cbs_s *cdk_stream_cbs_t;
 
794
  struct cdk_stream_cbs_s
 
795
  {
 
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);
 
801
  };
 
802
  typedef struct cdk_stream_cbs_s *cdk_stream_cbs_t;
797
803
 
798
 
int cdk_stream_is_compressed (cdk_stream_t s);
 
804
  int cdk_stream_is_compressed (cdk_stream_t s);
799
805
 
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);
803
809
 
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);
806
812
 
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);
810
816
 
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);
833
839
 
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,
837
 
                                         const char *fname);
 
841
  cdk_error_t cdk_stream_set_literal_flag (cdk_stream_t s,
 
842
                                           cdk_lit_format_t mode,
 
843
                                           const char *fname);
838
844
 
839
 
cdk_error_t cdk_stream_set_compress_flag (cdk_stream_t s, int algo,
840
 
                                          int level);
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,
 
846
                                            int level);
 
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);
849
855
 
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);
853
859
 
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,
858
 
                           size_t count);
 
863
  cdk_error_t cdk_keydb_new (cdk_keydb_hd_t * r_hd, int type, void *data,
 
864
                             size_t count);
859
865
 
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);
863
869
 
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,
866
 
                                     const char *fname);
 
871
  cdk_error_t cdk_keydb_new_from_file (cdk_keydb_hd_t * r_hd, int secret,
 
872
                                       const char *fname);
867
873
 
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,
872
 
                                       cdk_stream_t in);
 
877
  cdk_error_t cdk_keydb_new_from_stream (cdk_keydb_hd_t * r_hd, int secret,
 
878
                                         cdk_stream_t in);
873
879
 
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);
876
882
 
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,
 
886
                                      void *desc);
880
887
 
881
 
void cdk_keydb_search_release (cdk_keydb_search_t st);
 
888
  void cdk_keydb_search_release (cdk_keydb_search_t st);
882
889
 
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);
887
894
 
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);
890
897
 
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);
899
907
 
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);
907
915
 
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);
911
920
 
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);
914
924
 
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);
920
930
 
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);
923
933
 
924
934
 
925
935
/* List or enumerate keys from a given key db handle. */
926
936
 
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);
932
942
 
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);
935
 
 
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,
939
 
                                      size_t buflen);
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,
944
 
                                           size_t * r_buflen);
945
 
 
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,
953
 
                      cdk_kbnode_t where);
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);
 
945
 
 
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,
 
949
                                        size_t buflen);
 
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,
 
954
                                             size_t * r_buflen);
 
955
 
 
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,
 
963
                        cdk_kbnode_t where);
 
964
  cdk_kbnode_t cdk_kbnode_walk (cdk_kbnode_t root, cdk_kbnode_t * ctx,
 
965
                                int all);
 
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,
 
976
                               int flags);
965
977
 
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,
969
 
                               int *r_status);
 
980
  cdk_error_t cdk_pk_check_sigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd,
 
981
                                 int *r_status);
970
982
 
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);
973
985
 
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);
977
989
 
978
990
/* Return 0 or 1 if the given key list is able to understand the
979
991
   MDC feature. */
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);
984
996
 
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,
 
1005
                                int sigver);
 
1006
  cdk_error_t cdk_sklist_write_onepass (cdk_keylist_t skl, cdk_stream_t outp,
 
1007
                                        int sigclass, int mdalgo);
995
1008
 
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);
1001
1014
 
1002
1015
/* Decrypt the @INP stream into @OUT. */
1003
 
cdk_error_t cdk_stream_decrypt (cdk_ctx_t hd, cdk_stream_t inp,
1004
 
                                cdk_stream_t out);
 
1016
  cdk_error_t cdk_stream_decrypt (cdk_ctx_t hd, cdk_stream_t inp,
 
1017
                                  cdk_stream_t out);
1005
1018
 
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);
1011
1024
 
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,
1020
 
                                int modval);
 
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,
 
1033
                                  int modval);
1021
1034
 
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,
 
1042
                               int sigmode);
1029
1043
 
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);
1035
1049
 
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);
1038
1052
 
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);
1044
 
 
1045
 
int cdk_trustdb_get_validity (cdk_stream_t inp, cdk_pkt_userid_t id,
1046
 
                              int *r_val);
1047
 
int cdk_trustdb_get_ownertrust (cdk_stream_t inp, cdk_pubkey_t pk,
1048
 
                                int *r_val, int *r_flags);
1049
 
 
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);
 
1058
 
 
1059
  int cdk_trustdb_get_validity (cdk_stream_t inp, cdk_pkt_userid_t id,
 
1060
                                int *r_val);
 
1061
  int cdk_trustdb_get_ownertrust (cdk_stream_t inp, cdk_pubkey_t pk,
 
1062
                                  int *r_val, int *r_flags);
 
1063
 
 
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);
1054
1068
/* UTF8 */
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);
1057
1071
 
1058
1072
#ifdef __cplusplus
1059
1073
}
1060
1074
#endif
1061
1075
 
1062
 
#endif /* OPENCDK_H */
 
1076
#endif                          /* OPENCDK_H */