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