2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 * 2008, 2009, 2010 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 /* It could be argued that the default cipher should be 3DES rather
29 than AES128, and the default compression should be 0
30 (i.e. uncompressed) rather than 1 (zip). However, the real world
31 issues of speed and size come into play here. */
34 # define DEFAULT_CIPHER_ALGO CIPHER_ALGO_AES
36 # define DEFAULT_CIPHER_ALGO CIPHER_ALGO_CAST5
38 # define DEFAULT_CIPHER_ALGO CIPHER_ALGO_3DES
41 #define DEFAULT_DIGEST_ALGO ((GNUPG)? DIGEST_ALGO_SHA256:DIGEST_ALGO_SHA1)
42 #define DEFAULT_S2K_DIGEST_ALGO DIGEST_ALGO_SHA1
44 # define DEFAULT_COMPRESS_ALGO COMPRESS_ALGO_ZIP
46 # define DEFAULT_COMPRESS_ALGO COMPRESS_ALGO_NONE
50 #define S2K_DIGEST_ALGO (opt.s2k_digest_algo?opt.s2k_digest_algo:DEFAULT_S2K_DIGEST_ALGO)
53 /* Various data objects. */
60 STRING2KEY *symkey_s2k;
61 cipher_filter_context_t cfx;
62 } encrypt_filter_context_t;
69 struct groupitem *next;
74 extern int g10_errors_seen;
76 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
77 void g10_exit(int rc) __attribute__ ((noreturn));
79 void g10_exit(int rc);
81 void print_pubkey_algo_note (pubkey_algo_t algo);
82 void print_cipher_algo_note (cipher_algo_t algo);
83 void print_digest_algo_note (digest_algo_t algo);
84 void print_md5_rejected_note (void);
87 char *make_radix64_string( const byte *data, size_t len );
90 void trap_unaligned(void);
91 int disable_core_dumps(void);
92 void register_secured_file (const char *fname);
93 void unregister_secured_file (const char *fname);
94 int is_secured_file (int fd);
95 int is_secured_filename (const char *fname);
96 u16 checksum_u16( unsigned n );
97 u16 checksum( byte *p, unsigned n );
98 u16 checksum_mpi( gcry_mpi_t a );
99 u32 buffer_to_u32( const byte *buffer );
100 const byte *get_session_marker( size_t *rlen );
102 enum gcry_cipher_algos map_cipher_openpgp_to_gcry (cipher_algo_t algo);
103 #define openpgp_cipher_open(_a,_b,_c,_d) \
104 gcry_cipher_open((_a),map_cipher_openpgp_to_gcry((_b)),(_c),(_d))
105 #define openpgp_cipher_get_algo_keylen(_a) \
106 gcry_cipher_get_algo_keylen(map_cipher_openpgp_to_gcry((_a)))
107 #define openpgp_cipher_get_algo_blklen(_a) \
108 gcry_cipher_get_algo_blklen(map_cipher_openpgp_to_gcry((_a)))
109 int openpgp_cipher_blocklen (cipher_algo_t algo);
110 int openpgp_cipher_test_algo(cipher_algo_t algo);
111 const char *openpgp_cipher_algo_name (cipher_algo_t algo);
113 pubkey_algo_t map_pk_gcry_to_openpgp (enum gcry_pk_algos algo);
114 int openpgp_pk_test_algo (pubkey_algo_t algo);
115 int openpgp_pk_test_algo2 (pubkey_algo_t algo, unsigned int use);
116 int openpgp_pk_algo_usage ( int algo );
117 const char *openpgp_pk_algo_name (pubkey_algo_t algo);
119 enum gcry_md_algos map_md_openpgp_to_gcry (digest_algo_t algo);
120 int openpgp_md_test_algo (digest_algo_t algo);
121 const char *openpgp_md_algo_name (int algo);
126 PKT_public_key *pksk;
129 const char *validity_string;
130 const byte *namehash;
133 char *pct_expando(const char *string,struct expando_args *args);
134 void deprecated_warning(const char *configname,unsigned int configlineno,
135 const char *option,const char *repl1,const char *repl2);
136 void deprecated_command (const char *name);
137 void obsolete_option (const char *configname, unsigned int configlineno,
139 void obsolete_scdaemon_option (const char *configname,
140 unsigned int configlineno, const char *name);
142 int string_to_cipher_algo (const char *string);
143 int string_to_digest_algo (const char *string);
145 const char *compress_algo_to_string(int algo);
146 int string_to_compress_algo(const char *string);
147 int check_compress_algo(int algo);
148 int default_cipher_algo(void);
149 int default_compress_algo(void);
150 const char *compliance_option_string(void);
151 void compliance_failure(void);
161 char *optsep(char **stringp);
162 char *argsplit(char *string);
163 int parse_options(char *str,unsigned int *options,
164 struct parse_options *opts,int noisy);
165 const char *get_libexecdir (void);
166 int path_access(const char *file,int mode);
168 int pubkey_get_npkey (pubkey_algo_t algo);
169 int pubkey_get_nskey (pubkey_algo_t algo);
170 int pubkey_get_nsig (pubkey_algo_t algo);
171 int pubkey_get_nenc (pubkey_algo_t algo);
173 /* Temporary helpers. */
174 unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
175 int mpi_print (estream_t stream, gcry_mpi_t a, int mode);
176 unsigned int ecdsa_qbits_from_Q (unsigned int qbits);
180 void set_status_fd ( int fd );
181 int is_status_enabled ( void );
182 void write_status ( int no );
183 void write_status_error (const char *where, gpg_error_t err);
184 void write_status_errcode (const char *where, int errcode);
185 void write_status_text ( int no, const char *text );
186 void write_status_strings (int no, const char *text,
187 ...) GNUPG_GCC_A_SENTINEL(0);
188 void write_status_buffer ( int no,
189 const char *buffer, size_t len, int wrap );
190 void write_status_text_and_buffer ( int no, const char *text,
191 const char *buffer, size_t len, int wrap );
193 void write_status_begin_signing (gcry_md_hd_t md);
196 int cpr_enabled(void);
197 char *cpr_get( const char *keyword, const char *prompt );
198 char *cpr_get_no_help( const char *keyword, const char *prompt );
199 char *cpr_get_utf8( const char *keyword, const char *prompt );
200 char *cpr_get_hidden( const char *keyword, const char *prompt );
201 void cpr_kill_prompt(void);
202 int cpr_get_answer_is_yes_def (const char *keyword, const char *prompt,
204 int cpr_get_answer_is_yes( const char *keyword, const char *prompt );
205 int cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt );
206 int cpr_get_answer_okay_cancel (const char *keyword,
211 void display_online_help( const char *keyword );
214 int setup_symkey (STRING2KEY **symkey_s2k,DEK **symkey_dek);
215 int encrypt_symmetric (const char *filename );
216 int encrypt_store (const char *filename );
217 int encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
218 strlist_t remusr, int use_symkey, pk_list_t provided_keys,
220 void encrypt_crypt_files (ctrl_t ctrl,
221 int nfiles, char **files, strlist_t remusr);
222 int encrypt_filter (void *opaque, int control,
223 iobuf_t a, byte *buf, size_t *ret_len);
227 int complete_sig (PKT_signature *sig, PKT_public_key *pksk, gcry_md_hd_t md,
228 const char *cache_nonce);
229 int sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
230 int do_encrypt, strlist_t remusr, const char *outfile );
231 int clearsign_file( const char *fname, strlist_t locusr, const char *outfile );
232 int sign_symencrypt_file (const char *fname, strlist_t locusr);
234 /*-- sig-check.c --*/
235 int check_revocation_keys (PKT_public_key *pk, PKT_signature *sig);
236 int check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk,
237 PKT_signature *backsig);
238 int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig );
239 int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
240 PKT_public_key *ret_pk, int *is_selfsig,
241 u32 *r_expiredate, int *r_expired );
244 gpg_error_t delete_keys (strlist_t names, int secret, int allow_both);
247 void keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
248 strlist_t commands, int quiet, int seckey_check );
249 void keyedit_passwd (ctrl_t ctrl, const char *username);
250 void keyedit_quick_adduid (ctrl_t ctrl, const char *username,
252 void keyedit_quick_sign (ctrl_t ctrl, const char *fpr,
253 strlist_t uids, strlist_t locusr, int local);
254 void show_basic_key_info (KBNODE keyblock);
257 u32 parse_expire_string(const char *string);
258 u32 ask_expire_interval(int object,const char *def_expire);
259 u32 ask_expiredate(void);
260 void quick_generate_keypair (const char *uid);
261 void generate_keypair (ctrl_t ctrl, int full, const char *fname,
262 const char *card_serialno, int card_backup_key);
263 int keygen_set_std_prefs (const char *string,int personal);
264 PKT_user_id *keygen_get_std_prefs (void);
265 int keygen_add_key_expire( PKT_signature *sig, void *opaque );
266 int keygen_add_std_prefs( PKT_signature *sig, void *opaque );
267 int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );
268 int keygen_add_keyserver_url(PKT_signature *sig, void *opaque);
269 int keygen_add_notations(PKT_signature *sig,void *opaque);
270 int keygen_add_revkey(PKT_signature *sig, void *opaque);
271 gpg_error_t make_backsig (PKT_signature *sig, PKT_public_key *pk,
272 PKT_public_key *sub_pk, PKT_public_key *sub_psk,
273 u32 timestamp, const char *cache_nonce);
274 gpg_error_t generate_subkeypair (ctrl_t ctrl, kbnode_t pub_keyblock);
275 #ifdef ENABLE_CARD_SUPPORT
276 gpg_error_t generate_card_subkeypair (kbnode_t pub_keyblock,
277 int keyno, const char *serialno);
278 int save_unprotected_key_to_card (PKT_public_key *sk, int keyno);
283 int overwrite_filep( const char *fname );
284 char *make_outfile_name( const char *iname );
285 char *ask_outfile_name( const char *name, size_t namelen );
286 int open_outfile (int inp_fd, const char *iname, int mode,
287 int restrictedperm, iobuf_t *a);
288 char *get_matching_datafile (const char *sigfilename);
289 iobuf_t open_sigfile (const char *sigfilename, progress_filter_context_t *pfx);
290 void try_make_homedir( const char *fname );
291 char *get_openpgp_revocdir (const char *home);
294 void make_session_key( DEK *dek );
295 gcry_mpi_t encode_session_key( int openpgp_pk_algo, DEK *dek, unsigned nbits );
296 gcry_mpi_t encode_md_value (PKT_public_key *pk,
297 gcry_md_hd_t md, int hash_algo );
300 typedef gpg_error_t (*import_screener_t)(kbnode_t keyblock, void *arg);
302 int parse_import_options(char *str,unsigned int *options,int noisy);
303 void import_keys (ctrl_t ctrl, char **fnames, int nnames,
304 void *stats_hd, unsigned int options);
305 int import_keys_stream (ctrl_t ctrl, iobuf_t inp, void *stats_hd,
307 size_t *fpr_len, unsigned int options);
308 int import_keys_es_stream (ctrl_t ctrl, estream_t fp, void *stats_handle,
309 unsigned char **fpr, size_t *fpr_len,
310 unsigned int options,
311 import_screener_t screener, void *screener_arg);
312 gpg_error_t import_old_secring (ctrl_t ctrl, const char *fname);
313 void *import_new_stats_handle (void);
314 void import_release_stats_handle (void *p);
315 void import_print_stats (void *hd);
317 int collapse_uids( KBNODE *keyblock );
321 int parse_export_options(char *str,unsigned int *options,int noisy);
322 int export_pubkeys (ctrl_t ctrl, strlist_t users, unsigned int options );
323 int export_pubkeys_stream (ctrl_t ctrl, iobuf_t out, strlist_t users,
324 kbnode_t *keyblock_out, unsigned int options );
325 gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec,
326 unsigned int options,
327 kbnode_t *r_keyblock,
328 void **r_data, size_t *r_datalen);
329 int export_seckeys (ctrl_t ctrl, strlist_t users);
330 int export_secsubkeys (ctrl_t ctrl, strlist_t users);
333 int dearmor_file( const char *fname );
334 int enarmor_file( const char *fname );
337 struct revocation_reason_info;
338 int gen_standard_revoke (PKT_public_key *psk, const char *cache_nonce);
339 int gen_revoke( const char *uname );
340 int gen_desig_revoke( const char *uname, strlist_t locusr);
341 int revocation_reason_build_cb( PKT_signature *sig, void *opaque );
342 struct revocation_reason_info *
343 ask_revocation_reason( int key_rev, int cert_rev, int hint );
344 void release_revocation_reason_info( struct revocation_reason_info *reason );
347 void public_key_list (ctrl_t ctrl, strlist_t list, int locate_mode );
348 void secret_key_list (ctrl_t ctrl, strlist_t list );
349 void print_subpackets_colon(PKT_signature *sig);
350 void reorder_keyblock (KBNODE keyblock);
351 void list_keyblock_direct (kbnode_t keyblock, int secret, int has_secret,
353 void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode);
354 void print_revokers (estream_t fp, PKT_public_key *pk);
355 void show_policy_url(PKT_signature *sig,int indent,int mode);
356 void show_keyserver_url(PKT_signature *sig,int indent,int mode);
357 void show_notation(PKT_signature *sig,int indent,int mode,int which);
358 void dump_attribs (const PKT_user_id *uid, PKT_public_key *pk);
359 void set_attrib_fd(int fd);
360 void print_seckey_info (PKT_public_key *pk);
361 void print_pubkey_info (estream_t fp, PKT_public_key *pk);
362 void print_card_key_info (estream_t fp, KBNODE keyblock);
365 void print_file_status( int status, const char *name, int what );
366 int verify_signatures (ctrl_t ctrl, int nfiles, char **files );
367 int verify_files (ctrl_t ctrl, int nfiles, char **files );
368 int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp);
371 int decrypt_message (ctrl_t ctrl, const char *filename );
372 gpg_error_t decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd);
373 void decrypt_messages (ctrl_t ctrl, int nfiles, char *files[]);
375 /*-- plaintext.c --*/
376 int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2,
377 strlist_t files, const char *sigfilename, int textmode);
378 int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd,
380 PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
383 int gpg_server (ctrl_t);
384 gpg_error_t gpg_proxy_pinentry_notify (ctrl_t ctrl,
385 const unsigned char *line);
387 #ifdef ENABLE_CARD_SUPPORT
388 /*-- card-util.c --*/
389 void change_pin (int no, int allow_admin);
390 void card_status (estream_t fp, char *serialno, size_t serialnobuflen);
391 void card_edit (ctrl_t ctrl, strlist_t commands);
392 gpg_error_t card_generate_subkey (KBNODE pub_keyblock);
393 int card_store_subkey (KBNODE node, int use);
396 #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6))
399 void migrate_secring (ctrl_t ctrl);
402 #endif /*G10_MAIN_H*/