mgmt.h
1 /*
2  This file is part of Pretty Curved Privacy (pcp1).
3 
4  Copyright (C) 2014 T.v.Dein.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19  You can contact me by mail: <tom AT vondein DOT org>.
20 */
21 
22 /*
23  key management, namely import and export routines.
24  we're working with buffers only, no direct file i/o */
25 
26 #ifndef _HAVE_PCP_MGMT_H
27 #define _HAVE_PCP_MGMT_H
28 
29 #if defined __linux__ || defined __GNU__ || defined __GLIBC__
30 # ifndef _DEFAULT_SOURCE
31 # define _DEFAULT_SOURCE 1
32 # endif
33 #
34 # ifndef _XOPEN_SOURCE
35 # define _XOPEN_SOURCE 1
36 # endif
37 #
38 # ifndef _GNU_SOURCE
39 # define _GNU_SOURCE 1
40 # endif
41 #else
42 # define _BSD_SOURCE 1
43 #endif
44 
45 #include <sodium.h>
46 #include <string.h>
47 #include <stdio.h>
48 #include <time.h>
49 
50 #include "defines.h"
51 #include "platform.h"
52 #include "structs.h"
53 #include "mem.h"
54 #include "ed.h"
55 #include "key.h"
56 #include "keysig.h"
57 #include "buffer.h"
58 #include "scrypt.h"
59 #include "context.h"
60 
61 /* key management api, export, import, yaml and stuff */
62 
63 
167 
168 
180 
191 
202 
213 
256 Buffer *pcp_export_secret(PCPCTX *ptx, pcp_key_t *sk, char *passphrase);
257 
258 pcp_ks_bundle_t *pcp_import_binpub(PCPCTX *ptx, byte *raw, size_t rawsize);
259 pcp_ks_bundle_t *pcp_import_pub(PCPCTX *ptx, byte *raw, size_t rawsize); /* FIXME: deprecate */
260 pcp_ks_bundle_t *pcp_import_pub_rfc(PCPCTX *ptx, Buffer *blob);
261 pcp_ks_bundle_t *pcp_import_pub_pbp(PCPCTX *ptx, Buffer *blob);
262 
263 /* import secret key */
264 pcp_key_t *pcp_import_binsecret(PCPCTX *ptx, byte *raw, size_t rawsize, char *passphrase);
265 pcp_key_t *pcp_import_secret(PCPCTX *ptx, byte *raw, size_t rawsize, char *passphrase);
266 pcp_key_t *pcp_import_secret_native(PCPCTX *ptx, Buffer *cipher, char *passphrase);
267 
268 /* helpers */
269 int _check_keysig_h(PCPCTX *ptx, Buffer *blob, rfc_pub_sig_h *h);
270 int _check_hash_keysig(PCPCTX *ptx, Buffer *blob, pcp_pubkey_t *p, pcp_keysig_t *sk);
271 int _check_sigsubs(PCPCTX *ptx, Buffer *blob, pcp_pubkey_t *p, rfc_pub_sig_s *subheader);
272 
273 #endif // _HAVE_PCP_MGMT_H
274