libpcp  0.2.4
key.h
1 /*
2  This file is part of Pretty Curved Privacy (pcp1).
3 
4  Copyright (C) 2013-2015 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 #ifndef _HAVE_PCP_KEYPAIR_H
24 #define _HAVE_PCP_KEYPAIR_H
25 
26 #include <sodium.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <time.h>
30 
31 #include "defines.h"
32 #include "platform.h"
33 #include "mem.h"
34 #include "mac.h"
35 #include "randomart.h"
36 #include "version.h"
37 //#include "z85.h"
38 #include "uthash.h"
39 #include "jenhash.h"
40 #include "structs.h"
41 #include "buffer.h"
42 #include "keysig.h"
43 #include "scrypt.h"
44 
58 #define PCP_RAW_KEYSIZE sizeof(pcp_key_t) - sizeof(UT_hash_handle)
59 #define PCP_RAW_PUBKEYSIZE sizeof(pcp_pubkey_t) - sizeof(UT_hash_handle)
60 
61 
71 
72 void pcp_keypairs(byte *msk, byte *mpk, byte *csk, byte *cpk, byte *esk, byte *epk);
73 
110 
120 char *pcpkey_get_art(pcp_key_t *k);
121 
146 pcp_key_t *pcpkey_encrypt(PCPCTX *ptx, pcp_key_t *key, char *passphrase);
147 
173 pcp_key_t *pcpkey_decrypt(PCPCTX *ptx, pcp_key_t *key, char *passphrase);
174 
187 
188 
205 char *pcp_getkeyid(pcp_key_t *k);
206 
207 
218 char *pcp_getpubkeyid(pcp_pubkey_t *k);
219 
234 
243 byte *pcpkey_getchecksum(pcp_key_t *k);
244 
245 
246 pcp_key_t * key2be(pcp_key_t *k);
247 pcp_key_t *key2native(pcp_key_t *k);
248 pcp_pubkey_t * pubkey2be(pcp_pubkey_t *k);
249 pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k);
250 
259 byte * pcp_gennonce();
260 
261 /* use scrypt() to create a key from a passphrase and a nonce
262  this is a wrapper around pcp_scrypt()
263 */
264 byte *pcp_derivekey(PCPCTX *ptx, char *passphrase, byte *nonce);
265 
266 /* convert the key struct into a binary blob */
267 void pcp_seckeyblob(Buffer *b, pcp_key_t *k);
268 void pcp_pubkeyblob(Buffer *b, pcp_pubkey_t *k);
269 Buffer *pcp_keyblob(void *k, int type); /* allocates blob */
270 
280 int pcp_sanitycheck_pub(PCPCTX *ptx, pcp_pubkey_t *key);
281 
291 int pcp_sanitycheck_key(PCPCTX *ptx, pcp_key_t *key);
292 
297 void pcp_dumpkey(pcp_key_t *k);
298 
304 
311 void pcpkey_setowner(pcp_key_t *key, char *owner, char *mail);
312 
313 #endif /* _HAVE_PCP_KEYPAIR_H */
314