Fix potential memory leak.
[pwmd.git] / src / crypto.h
blob1de13edb845789097d31230132a52572d9cae782
1 /*
2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
3 2016, 2017
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of pwmd.
8 Pwmd is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 Pwmd is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef CRYPTO_H
22 #define CRYPTO_H
24 #include <assuan.h>
25 #include <gpg-error.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <gpgme.h>
29 #include <time.h>
31 #ifdef HAVE_STDINT_H
32 #include <stdint.h>
33 #elif defined (HAVE_INTTYPES_H)
34 #include <inttypes.h>
35 #endif
37 #include "common.h"
39 #define DEFAULT_EXPIRE (unsigned long)(60*60*24*365*3) // 3 years
41 #define CRYPTO_FLAG_NEWFILE 0x0001
42 #define CRYPTO_FLAG_KEYFILE 0x0002 // --passphrase-file with --import
43 #define CRYPTO_FLAG_SYMMETRIC 0x0004
44 #define CRYPTO_FLAG_PASSWD 0x0008
45 #define CRYPTO_FLAG_PASSWD_NEW 0x0010
46 #define CRYPTO_FLAG_PASSWD_SIGN 0x0020
48 struct save_s
50 char **pubkey; /* SAVE --keyid */
51 char *sigkey; /* SAVE --sign-keyid */
52 char *userid; /* SAVE genkey parameters */
53 gpgme_key_t *mainkey; /* GENKEY --subkey-of */
54 char *algo;
55 unsigned long expire;
56 unsigned flags;
59 struct crypto_s
61 assuan_context_t client_ctx;
62 gpgme_ctx_t ctx;
63 unsigned char *plaintext;
64 size_t plaintext_size;
65 gpgme_data_t cipher;
66 char **pubkey;
67 char *sigkey;
68 char *filename; /* the currently opened data file */
69 struct save_s save;
70 gpg_error_t progress_rc;
71 time_t status_timeout;
72 unsigned flags;
73 char *keyfile;
76 gpgme_error_t crypto_init (struct crypto_s **, void *, const char *, int,
77 char *passphrase_file);
78 gpgme_error_t crypto_init_ctx (struct crypto_s *, int, char *passphrase_file);
79 gpgme_error_t crypto_genkey (struct client_s *, struct crypto_s *);
80 gpgme_error_t crypto_encrypt (struct client_s *, struct crypto_s *);
81 gpgme_error_t crypto_decrypt (struct client_s *, struct crypto_s *);
82 gpgme_error_t crypto_passwd (struct client_s *, struct crypto_s *);
83 void crypto_free (struct crypto_s *);
84 void crypto_free_save (struct save_s *);
85 void crypto_free_non_keys (struct crypto_s *);
86 gpgme_error_t crypto_data_to_buf (const gpgme_data_t, unsigned char **,
87 size_t *);
88 gpg_error_t crypto_write_file (struct crypto_s *, unsigned char **crc,
89 size_t *len);
90 gpgme_error_t crypto_list_keys (struct crypto_s *, char **, int secret,
91 gpgme_key_t **);
92 char *crypto_key_info (const gpgme_key_t);
93 void crypto_free_key_list (gpgme_key_t *);
94 gpg_error_t crypto_try_decrypt (struct client_s *, int);
95 void crypto_set_keepalive ();
96 gpg_error_t crypto_is_symmetric (const char *filename);
97 gpg_error_t crypto_keyid_to_16b (char **keys);
98 gpg_error_t crypto_keyid_to_16b_once (char *key);
99 gpg_error_t crypto_delete_key (struct client_s *client, struct crypto_s *,
100 const gpgme_key_t, int secret);
102 #endif