structs.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 #ifndef _HAVE_PCP_STRUCTS_H
23 #define _HAVE_PCP_STRUCTS_H
24 
25 #include "defines.h"
26 #include "uthash.h"
27 #include <sodium.h>
28 
72 struct _pcp_key_t {
73  byte masterpub[32];
74  byte mastersecret[64];
75  byte pub[32];
76  byte secret[32];
77  byte edpub[32];
78  byte edsecret[64];
79  byte nonce[24];
80  byte encrypted[176];
81  char owner[255];
82  char mail[255];
83  char id[17];
84  uint8_t type;
85  uint64_t ctime;
86  uint32_t version;
87  uint32_t serial;
88  UT_hash_handle hh;
89 };
90 
92 typedef struct _pcp_key_t pcp_key_t;
93 
102  byte masterpub[32];
103  byte sigpub[32];
104  byte pub[32];
105  byte edpub[32];
106  char owner[255];
107  char mail[255];
108  char id[17];
109  uint8_t type;
110  uint64_t ctime;
111  uint32_t version;
112  uint32_t serial;
113  uint8_t valid;
114  byte signature[crypto_generichash_BYTES_MAX + crypto_sign_BYTES];
115  UT_hash_handle hh;
116 };
117 
120 
121 
122 /* the PBP public key format */
123 /* keys.mp+keys.cp+keys.sp+keys.name */
124 struct _pbp_pubkey_t {
125  byte sigpub[crypto_sign_PUBLICKEYBYTES];
126  byte edpub[crypto_sign_PUBLICKEYBYTES];
127  byte pub[crypto_box_PUBLICKEYBYTES];
128  char iso_ctime[32];
129  char iso_expire[32];
130  char name[1024];
131 };
132 
133 typedef struct _pbp_pubkey_t pbp_pubkey_t;
134 
145 struct _pcp_rec_t {
146  size_t ciphersize;
147  byte *cipher;
150 };
151 
153 typedef struct _pcp_rec_t pcp_rec_t;
154 
155 
156 /* holds a public key signature */
157 struct _pcp_keysig_t {
158  uint8_t type;
159  uint32_t size;
160  char id[17];
161  byte checksum[32];
162  byte *blob;
163  UT_hash_handle hh;
164 };
165 
166 typedef struct _pcp_keysig_t pcp_keysig_t;
167 
193 struct _pcp_ctx_t {
194  char *pcp_err;
195  byte pcp_errset;
196  int pcp_exit;
197  int verbose;
201  pcp_keysig_t *pcpkeysig_hash;
202 };
203 
204 typedef struct _pcp_ctx_t PCPCTX;
205 
223 struct _vault_t {
224  char *filename;
225  FILE *fd;
226  uint8_t unsafed;
227  uint8_t isnew;
228  uint32_t size;
229  time_t modified;
230  mode_t mode;
231  uint32_t version;
232  byte checksum[32];
233 };
236 typedef struct _vault_t vault_t;
237 
241  uint8_t fileid;
242  uint32_t version;
243  byte checksum[32];
244 };
247 typedef struct _vault_header_t vault_header_t;
248 
252  uint8_t type;
253  uint32_t size;
254  uint32_t version;
255  byte checksum[32];
256 };
260 
275 struct _pcp_buffer {
276  char *name;
277  uint8_t allocated;
278  size_t blocksize;
279  size_t size;
280  size_t offset;
281  size_t end;
282  uint8_t isstring;
283  void *buf;
284 };
285 
287 typedef struct _pcp_buffer Buffer;
288 
289 
310  FILE *fd;
315  uint8_t is_buffer;
316  uint8_t eof;
317  uint8_t err;
318  uint8_t armor;
319  uint8_t determine;
320  uint8_t firstread;
321  size_t linewr;
322  size_t blocksize;
323  uint8_t is_output;
324  uint8_t have_begin;
325  size_t pos;
326 };
327 
328 typedef enum _PSVARS {
329  PSMAXLINE = 20000
330 } PSVARS;
331 
332 
334 typedef struct _pcp_stream_t Pcpstream;
343 /* various helper structs for mgmt.c, used internally only */
344 struct _pcp_rfc_pubkey_header_t {
345  uint8_t version;
346  uint64_t ctime;
347  uint8_t cipher;
348 };
349 
350 struct _pcp_rfc_pubkey_0x21_t {
351  byte sig_ed25519_pub[crypto_sign_PUBLICKEYBYTES];
352  byte ed25519_pub[crypto_sign_PUBLICKEYBYTES];
353  byte curve25519_pub[crypto_box_PUBLICKEYBYTES];
354 };
355 
356 struct _pcp_rfc_pubkey_sigheader_0x21_t {
357  uint8_t version;
358  uint8_t type;
359  uint8_t pkcipher;
360  uint8_t hashcipher;
361  uint16_t numsubs;
362 };
363 
364 struct _pcp_rfc_pubkey_sigsub_0x21_t {
365  uint32_t size;
366  uint8_t type;
367 };
368 
369 typedef struct _pcp_rfc_pubkey_header_t rfc_pub_h;
370 typedef struct _pcp_rfc_pubkey_0x21_t rfc_pub_k;
371 typedef struct _pcp_rfc_pubkey_sigheader_0x21_t rfc_pub_sig_h;
372 typedef struct _pcp_rfc_pubkey_sigsub_0x21_t rfc_pub_sig_s;
373 
374 struct _pcp_ks_bundle_t {
375  pcp_pubkey_t *p;
376  pcp_keysig_t *s;
377 };
378 typedef struct _pcp_ks_bundle_t pcp_ks_bundle_t;
379 
380 
381 
382 
383 
384 #endif //_HAVE_PCP_STRUCTS_H