Fix for bug 797.
[gnupg.git] / g10 / main.h
blob1860853da514599e0ed0d2daca7fa6908ce1a9ac
1 /* main.h
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 * 2006 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 2 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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
22 #ifndef G10_MAIN_H
23 #define G10_MAIN_H
25 #include "types.h"
26 #include "../common/iobuf.h"
27 #include "cipher.h"
28 #include "keydb.h"
30 /* It could be argued that the default cipher should be 3DES rather
31 than CAST5, and the default compression should be 0
32 (i.e. uncompressed) rather than 1 (zip). However, the real world
33 issues of speed and size come into play here. */
35 #define DEFAULT_CIPHER_ALGO CIPHER_ALGO_CAST5
36 #define DEFAULT_DIGEST_ALGO DIGEST_ALGO_SHA1
37 #define DEFAULT_COMPRESS_ALGO COMPRESS_ALGO_ZIP
38 #define DEFAULT_S2K_DIGEST_ALGO DIGEST_ALGO_SHA1
40 #define S2K_DIGEST_ALGO (opt.s2k_digest_algo?opt.s2k_digest_algo:DEFAULT_S2K_DIGEST_ALGO)
42 typedef struct
44 int header_okay;
45 PK_LIST pk_list;
46 DEK *symkey_dek;
47 STRING2KEY *symkey_s2k;
48 cipher_filter_context_t cfx;
49 } encrypt_filter_context_t;
51 struct groupitem
53 char *name;
54 strlist_t values;
55 struct groupitem *next;
58 /*-- gpg.c --*/
59 extern int g10_errors_seen;
61 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
62 void g10_exit(int rc) __attribute__ ((noreturn));
63 #else
64 void g10_exit(int rc);
65 #endif
66 void print_pubkey_algo_note( int algo );
67 void print_cipher_algo_note( int algo );
68 void print_digest_algo_note( int algo );
70 /*-- armor.c --*/
71 char *make_radix64_string( const byte *data, size_t len );
73 /*-- misc.c --*/
74 void trap_unaligned(void);
75 int disable_core_dumps(void);
76 void register_secured_file (const char *fname);
77 void unregister_secured_file (const char *fname);
78 int is_secured_file (int fd);
79 int is_secured_filename (const char *fname);
80 u16 checksum_u16( unsigned n );
81 u16 checksum( byte *p, unsigned n );
82 u16 checksum_mpi( gcry_mpi_t a );
83 u32 buffer_to_u32( const byte *buffer );
84 const byte *get_session_marker( size_t *rlen );
85 int openpgp_cipher_test_algo( int algo );
86 int openpgp_pk_test_algo( int algo );
87 int openpgp_pk_test_algo2 ( int algo, unsigned int use );
88 int openpgp_pk_algo_usage ( int algo );
89 int openpgp_md_test_algo( int algo );
91 #ifdef USE_IDEA
92 void idea_cipher_warn( int show );
93 #else
94 #define idea_cipher_warn(a)
95 #endif
97 struct expando_args
99 PKT_public_key *pk;
100 PKT_secret_key *sk;
101 byte imagetype;
104 char *pct_expando(const char *string,struct expando_args *args);
105 void deprecated_warning(const char *configname,unsigned int configlineno,
106 const char *option,const char *repl1,const char *repl2);
107 void deprecated_command (const char *name);
108 void obsolete_option (const char *configname, unsigned int configlineno,
109 const char *name);
111 int string_to_cipher_algo (const char *string);
112 int string_to_digest_algo (const char *string);
114 const char *compress_algo_to_string(int algo);
115 int string_to_compress_algo(const char *string);
116 int check_compress_algo(int algo);
117 int default_cipher_algo(void);
118 int default_compress_algo(void);
119 const char *compliance_option_string(void);
120 void compliance_failure(void);
122 struct parse_options
124 char *name;
125 unsigned int bit;
126 char **value;
127 char *help;
130 char *optsep(char **stringp);
131 char *argsplit(char *string);
132 int parse_options(char *str,unsigned int *options,
133 struct parse_options *opts,int noisy);
134 char *unescape_percent_string (const unsigned char *s);
135 int has_invalid_email_chars (const char *s);
136 int is_valid_mailbox (const char *name);
137 const char *get_libexecdir (void);
138 int path_access(const char *file,int mode);
140 /* Temporary helpers. */
141 int pubkey_get_npkey( int algo );
142 int pubkey_get_nskey( int algo );
143 int pubkey_get_nsig( int algo );
144 int pubkey_get_nenc( int algo );
145 unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
146 int mpi_print( FILE *fp, gcry_mpi_t a, int mode );
149 /*-- helptext.c --*/
150 void display_online_help( const char *keyword );
152 /*-- encode.c --*/
153 int setup_symkey(STRING2KEY **symkey_s2k,DEK **symkey_dek);
154 int encode_symmetric( const char *filename );
155 int encode_store( const char *filename );
156 int encode_crypt( const char *filename, strlist_t remusr, int use_symkey );
157 void encode_crypt_files(int nfiles, char **files, strlist_t remusr);
158 int encrypt_filter( void *opaque, int control,
159 iobuf_t a, byte *buf, size_t *ret_len);
162 /*-- sign.c --*/
163 int complete_sig( PKT_signature *sig, PKT_secret_key *sk, gcry_md_hd_t md );
164 int sign_file( strlist_t filenames, int detached, strlist_t locusr,
165 int do_encrypt, strlist_t remusr, const char *outfile );
166 int clearsign_file( const char *fname, strlist_t locusr, const char *outfile );
167 int sign_symencrypt_file (const char *fname, strlist_t locusr);
169 /*-- sig-check.c --*/
170 int check_revocation_keys (PKT_public_key *pk, PKT_signature *sig);
171 int check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk,
172 PKT_signature *backsig);
173 int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig );
174 int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
175 PKT_public_key *ret_pk, int *is_selfsig,
176 u32 *r_expiredate, int *r_expired );
178 /*-- delkey.c --*/
179 int delete_keys( strlist_t names, int secret, int allow_both );
181 /*-- keyedit.c --*/
182 void keyedit_menu( const char *username, strlist_t locusr,
183 strlist_t commands, int quiet, int seckey_check );
184 void show_basic_key_info (KBNODE keyblock);
186 /*-- keygen.c --*/
187 u32 parse_expire_string(const char *string);
188 u32 ask_expire_interval(int object,const char *def_expire);
189 u32 ask_expiredate(void);
190 void generate_keypair( const char *fname, const char *card_serialno,
191 const char *backup_encryption_dir );
192 int keygen_set_std_prefs (const char *string,int personal);
193 PKT_user_id *keygen_get_std_prefs (void);
194 int keygen_add_key_expire( PKT_signature *sig, void *opaque );
195 int keygen_add_std_prefs( PKT_signature *sig, void *opaque );
196 int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );
197 int keygen_add_keyserver_url(PKT_signature *sig, void *opaque);
198 int keygen_add_notations(PKT_signature *sig,void *opaque);
199 int keygen_add_revkey(PKT_signature *sig, void *opaque);
200 int make_backsig(PKT_signature *sig,PKT_public_key *pk,
201 PKT_public_key *sub_pk,PKT_secret_key *sub_sk);
202 int generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock );
203 #ifdef ENABLE_CARD_SUPPORT
204 int generate_card_subkeypair (KBNODE pub_keyblock, KBNODE sec_keyblock,
205 int keyno, const char *serialno);
206 int save_unprotected_key_to_card (PKT_secret_key *sk, int keyno);
207 #endif
209 /*-- openfile.c --*/
210 int overwrite_filep( const char *fname );
211 char *make_outfile_name( const char *iname );
212 char *ask_outfile_name( const char *name, size_t namelen );
213 int open_outfile( const char *iname, int mode, iobuf_t *a );
214 iobuf_t open_sigfile( const char *iname, progress_filter_context_t *pfx );
215 void try_make_homedir( const char *fname );
217 /*-- seskey.c --*/
218 void make_session_key( DEK *dek );
219 gcry_mpi_t encode_session_key( DEK *dek, unsigned nbits );
220 gcry_mpi_t encode_md_value( PKT_public_key *pk, PKT_secret_key *sk,
221 gcry_md_hd_t md, int hash_algo );
223 /*-- import.c --*/
224 int parse_import_options(char *str,unsigned int *options,int noisy);
225 void import_keys( char **fnames, int nnames,
226 void *stats_hd, unsigned int options );
227 int import_keys_stream( iobuf_t inp,void *stats_hd,unsigned char **fpr,
228 size_t *fpr_len,unsigned int options );
229 void *import_new_stats_handle (void);
230 void import_release_stats_handle (void *p);
231 void import_print_stats (void *hd);
233 int collapse_uids( KBNODE *keyblock );
235 int auto_create_card_key_stub ( const char *serialnostr,
236 const unsigned char *fpr1,
237 const unsigned char *fpr2,
238 const unsigned char *fpr3);
240 /*-- export.c --*/
241 int parse_export_options(char *str,unsigned int *options,int noisy);
242 int export_pubkeys( strlist_t users, unsigned int options );
243 int export_pubkeys_stream( iobuf_t out, strlist_t users,
244 KBNODE *keyblock_out, unsigned int options );
245 int export_seckeys( strlist_t users );
246 int export_secsubkeys( strlist_t users );
248 /* dearmor.c --*/
249 int dearmor_file( const char *fname );
250 int enarmor_file( const char *fname );
252 /*-- revoke.c --*/
253 struct revocation_reason_info;
254 int gen_revoke( const char *uname );
255 int gen_desig_revoke( const char *uname, strlist_t locusr);
256 int revocation_reason_build_cb( PKT_signature *sig, void *opaque );
257 struct revocation_reason_info *
258 ask_revocation_reason( int key_rev, int cert_rev, int hint );
259 void release_revocation_reason_info( struct revocation_reason_info *reason );
261 /*-- keylist.c --*/
262 void public_key_list( strlist_t list );
263 void secret_key_list( strlist_t list );
264 void print_subpackets_colon(PKT_signature *sig);
265 void reorder_keyblock (KBNODE keyblock);
266 void list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque );
267 void print_fingerprint (PKT_public_key *pk, PKT_secret_key *sk, int mode);
268 void print_revokers(PKT_public_key *pk);
269 void show_policy_url(PKT_signature *sig,int indent,int mode);
270 void show_keyserver_url(PKT_signature *sig,int indent,int mode);
271 void show_notation(PKT_signature *sig,int indent,int mode,int which);
272 void dump_attribs(const PKT_user_id *uid,
273 PKT_public_key *pk,PKT_secret_key *sk);
274 void set_attrib_fd(int fd);
275 void print_seckey_info (PKT_secret_key *sk);
276 void print_pubkey_info (FILE *fp, PKT_public_key *pk);
277 void print_card_key_info (FILE *fp, KBNODE keyblock);
279 /*-- verify.c --*/
280 void print_file_status( int status, const char *name, int what );
281 int verify_signatures( int nfiles, char **files );
282 int verify_files( int nfiles, char **files );
283 int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, FILE *out_fp);
285 /*-- decrypt.c --*/
286 int decrypt_message( const char *filename );
287 void decrypt_messages(int nfiles, char *files[]);
289 /*-- plaintext.c --*/
290 int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2,
291 strlist_t files, const char *sigfilename, int textmode );
292 int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd,
293 int textmode );
294 PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
296 /*-- signal.c --*/
297 void init_signals(void);
298 void pause_on_sigusr( int which );
299 void block_all_signals(void);
300 void unblock_all_signals(void);
303 #ifdef ENABLE_CARD_SUPPORT
304 /*-- card-util.c --*/
305 void change_pin (int no, int allow_admin);
306 void card_status (FILE *fp, char *serialno, size_t serialnobuflen);
307 void card_edit (strlist_t commands);
308 int card_generate_subkey (KBNODE pub_keyblock, KBNODE sec_keyblock);
309 int card_store_subkey (KBNODE node, int use);
310 #endif
312 #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6))
314 #endif /*G10_MAIN_H*/