libpcp  0.2.1
key.h
1 /*
2  This file is part of Pretty Curved Privacy (pcp1).
3 
4  Copyright (C) 2013-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 #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 "scrypt.h"
41 #include "keysig.h"
42 
43 
93 struct _pcp_key_t {
94  byte masterpub[32];
95  byte mastersecret[64];
96  byte pub[32];
97  byte secret[32];
98  byte edpub[32];
99  byte edsecret[64];
100  byte nonce[24];
101  byte encrypted[176];
102  char owner[255];
103  char mail[255];
104  char id[17];
105  uint8_t type;
106  uint64_t ctime;
107  uint32_t version;
108  uint32_t serial;
109  UT_hash_handle hh;
110 };
111 
113 typedef struct _pcp_key_t pcp_key_t;
114 
123  byte masterpub[32];
124  byte sigpub[32];
125  byte pub[32];
126  byte edpub[32];
127  char owner[255];
128  char mail[255];
129  char id[17];
130  uint8_t type;
131  uint64_t ctime;
132  uint32_t version;
133  uint32_t serial;
134  uint8_t valid;
135  byte signature[crypto_generichash_BYTES_MAX + crypto_sign_BYTES];
136  UT_hash_handle hh;
137 };
138 
141 
142 
143 /* the PBP public key format */
144 /* keys.mp+keys.cp+keys.sp+keys.name */
145 struct _pbp_pubkey_t {
146  byte sigpub[crypto_sign_PUBLICKEYBYTES];
147  byte edpub[crypto_sign_PUBLICKEYBYTES];
148  byte pub[crypto_box_PUBLICKEYBYTES];
149  char iso_ctime[32];
150  char iso_expire[32];
151  char name[1024];
152 };
153 
154 typedef struct _pbp_pubkey_t pbp_pubkey_t;
155 
166 struct _pcp_rec_t {
167  size_t ciphersize;
168  byte *cipher;
171 };
172 
174 typedef struct _pcp_rec_t pcp_rec_t;
175 
176 #define PCP_RAW_KEYSIZE sizeof(pcp_key_t) - sizeof(UT_hash_handle)
177 #define PCP_RAW_PUBKEYSIZE sizeof(pcp_pubkey_t) - sizeof(UT_hash_handle)
178 
179 
189 
190 void pcp_keypairs(byte *msk, byte *mpk, byte *csk, byte *cpk, byte *esk, byte *epk);
191 
228 
238 char *pcpkey_get_art(pcp_key_t *k);
239 
262 pcp_key_t *pcpkey_encrypt(pcp_key_t *key, char *passphrase);
263 
287 pcp_key_t *pcpkey_decrypt(pcp_key_t *key, char *passphrase);
288 
301 
302 
319 char *pcp_getkeyid(pcp_key_t *k);
320 
321 
332 char *pcp_getpubkeyid(pcp_pubkey_t *k);
333 
347 unsigned char *pcppubkey_getchecksum(pcp_pubkey_t *k);
348 
357 unsigned char *pcpkey_getchecksum(pcp_key_t *k);
358 
359 
372 pcp_key_t *pcpkey_exists(char *id);
373 
386 pcp_pubkey_t *pcppubkey_exists(char *id);
387 
388 pcp_key_t * key2be(pcp_key_t *k);
389 pcp_key_t *key2native(pcp_key_t *k);
390 pcp_pubkey_t * pubkey2be(pcp_pubkey_t *k);
391 pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k);
392 
401 unsigned char * pcp_gennonce();
402 
403 /* use scrypt() to create a key from a passphrase and a nonce
404  FIXME: use pure scrypt() instead.
405 */
406 unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce);
407 
408 /* FIXME: abandon and use Buffer instead */
409 void pcp_seckeyblob(void *blob, pcp_key_t *k);
410 void pcp_pubkeyblob(void *blob, pcp_pubkey_t *k);
411 void *pcp_keyblob(void *k, int type); /* allocates blob */
412 
421 
430 
435 void pcp_dumpkey(pcp_key_t *k);
436 
442 
443 
444 #endif /* _HAVE_PCP_KEYPAIR_H */
445