Update NEWS.
[pwmd.git] / src / crypto.h
blob4694e8f69127b22b9a9570c27395719fffbbbe0b
1 /*
2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
3 2016
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 CRYPTO_FLAG_NEWFILE 0x0001
40 #define CRYPTO_FLAG_KEYFILE 0x0002 // --passphrase-file with --import
41 #define CRYPTO_FLAG_SYMMETRIC 0x0004
42 #define CRYPTO_FLAG_PASSWD 0x0008
43 #define CRYPTO_FLAG_PASSWD_NEW 0x0010
44 #define CRYPTO_FLAG_PASSWD_SIGN 0x0020
46 struct save_s
48 char **pubkey; /* SAVE --keyid */
49 char *sigkey; /* SAVE --sign-keyid */
50 char *userid; /* SAVE genkey parameters */
51 gpgme_key_t *mainkey; /* GENKEY --subkey-of */
52 char *algo;
53 unsigned long expire;
54 unsigned flags;
57 struct crypto_s
59 assuan_context_t client_ctx;
60 gpgme_ctx_t ctx;
61 unsigned char *plaintext;
62 size_t plaintext_size;
63 gpgme_data_t cipher;
64 char **pubkey;
65 char *sigkey;
66 char *filename; /* the currently opened data file */
67 struct save_s save;
68 gpg_error_t progress_rc;
69 time_t status_timeout;
70 unsigned flags;
71 char *keyfile;
74 gpgme_error_t crypto_init (struct crypto_s **, void *, const char *, int,
75 char *passphrase_file);
76 gpgme_error_t crypto_init_ctx (struct crypto_s *, int, char *passphrase_file);
77 gpgme_error_t crypto_genkey (struct client_s *, struct crypto_s *);
78 gpgme_error_t crypto_encrypt (struct client_s *, struct crypto_s *);
79 gpgme_error_t crypto_decrypt (struct client_s *, struct crypto_s *);
80 gpgme_error_t crypto_passwd (struct client_s *, struct crypto_s *);
81 void crypto_free (struct crypto_s *);
82 void crypto_free_save (struct save_s *);
83 void crypto_free_non_keys (struct crypto_s *);
84 gpgme_error_t crypto_data_to_buf (const gpgme_data_t, unsigned char **,
85 size_t *);
86 gpg_error_t crypto_write_file (struct crypto_s *, unsigned char **crc,
87 size_t *len);
88 gpgme_error_t crypto_list_keys (struct crypto_s *, char **, int secret,
89 gpgme_key_t **);
90 char *crypto_key_info (const gpgme_key_t);
91 void crypto_free_key_list (gpgme_key_t *);
92 gpg_error_t crypto_try_decrypt (struct client_s *, int);
93 void crypto_set_keepalive ();
94 gpg_error_t crypto_is_symmetric (const char *filename);
95 gpg_error_t crypto_keyid_to_16b (char **keys);
96 gpg_error_t crypto_keyid_to_16b_once (char *key);
97 gpg_error_t crypto_delete_key (struct client_s *client, struct crypto_s *,
98 const gpgme_key_t, int secret);
100 #endif