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 "crypto.h"
35 #include "randomart.h"
36 #include "version.h"
37 #include "uthash.h"
38 #include "jenhash.h"
39 #include "structs.h"
40 #include "buffer.h"
41 #include "keysig.h"
42 #include "scrypt.h"
43 
57 #define PCP_RAW_KEYSIZE sizeof(pcp_key_t) - sizeof(UT_hash_handle)
58 #define PCP_RAW_PUBKEYSIZE sizeof(pcp_pubkey_t) - sizeof(UT_hash_handle)
59 
60 
70 
71 void pcp_keypairs(byte *msk, byte *mpk, byte *csk, byte *cpk, byte *esk, byte *epk);
72 
109 
119 char *pcpkey_get_art(pcp_key_t *k);
120 
145 pcp_key_t *pcpkey_encrypt(PCPCTX *ptx, pcp_key_t *key, char *passphrase);
146 
172 pcp_key_t *pcpkey_decrypt(PCPCTX *ptx, pcp_key_t *key, char *passphrase);
173 
186 
187 
204 char *pcp_getkeyid(pcp_key_t *k);
205 
206 
217 char *pcp_getpubkeyid(pcp_pubkey_t *k);
218 
233 
242 byte *pcpkey_getchecksum(pcp_key_t *k);
243 
244 
245 pcp_key_t * key2be(pcp_key_t *k);
246 pcp_key_t *key2native(pcp_key_t *k);
247 pcp_pubkey_t * pubkey2be(pcp_pubkey_t *k);
248 pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k);
249 
258 byte * pcp_gennonce();
259 
260 /* use scrypt() to create a key from a passphrase and a nonce
261  this is a wrapper around pcp_scrypt()
262 */
263 byte *pcp_derivekey(PCPCTX *ptx, char *passphrase, byte *nonce);
264 
265 /* convert the key struct into a binary blob */
266 void pcp_seckeyblob(Buffer *b, pcp_key_t *k);
267 void pcp_pubkeyblob(Buffer *b, pcp_pubkey_t *k);
268 Buffer *pcp_keyblob(void *k, int type); /* allocates blob */
269 
279 int pcp_sanitycheck_pub(PCPCTX *ptx, pcp_pubkey_t *key);
280 
290 int pcp_sanitycheck_key(PCPCTX *ptx, pcp_key_t *key);
291 
296 void pcp_dumpkey(pcp_key_t *k);
297 
303 
310 void pcpkey_setowner(pcp_key_t *key, char *owner, char *mail);
311 
312 #endif /* _HAVE_PCP_KEYPAIR_H */
313