libpcp  0.2.1
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 #include <sodium.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <time.h>
33 
34 #include "defines.h"
35 #include "platform.h"
36 #include "mem.h"
37 #include "ed.h"
38 #include "key.h"
39 #include "keysig.h"
40 #include "buffer.h"
41 #include "scrypt.h"
42 
43 /* key management api, export, import, yaml and stuff */
44 
45 
55 /* various helper structs, used internally only */
56 struct _pcp_rfc_pubkey_header_t {
57  uint8_t version;
58  uint32_t ctime;
59  uint8_t cipher;
60 };
61 
62 struct _pcp_rfc_pubkey_0x21_t {
63  byte sig_ed25519_pub[crypto_sign_PUBLICKEYBYTES];
64  byte ed25519_pub[crypto_sign_PUBLICKEYBYTES];
65  byte curve25519_pub[crypto_box_PUBLICKEYBYTES];
66 };
67 
68 struct _pcp_rfc_pubkey_sigheader_0x21_t {
69  uint8_t version;
70  uint8_t type;
71  uint8_t pkcipher;
72  uint8_t hashcipher;
73  uint16_t numsubs;
74 };
75 
76 struct _pcp_rfc_pubkey_sigsub_0x21_t {
77  uint32_t size;
78  uint8_t type;
79 };
80 
81 typedef struct _pcp_rfc_pubkey_header_t rfc_pub_h;
82 typedef struct _pcp_rfc_pubkey_0x21_t rfc_pub_k;
83 typedef struct _pcp_rfc_pubkey_sigheader_0x21_t rfc_pub_sig_h;
84 typedef struct _pcp_rfc_pubkey_sigsub_0x21_t rfc_pub_sig_s;
85 
86 struct _pcp_ks_bundle_t {
87  pcp_pubkey_t *p;
88  pcp_keysig_t *s;
89 };
90 typedef struct _pcp_ks_bundle_t pcp_ks_bundle_t;
91 
92 #define EXP_PK_CIPHER 0x21
93 #define EXP_PK_CIPHER_NAME "CURVE25519-ED25519-POLY1305-SALSA20"
94 
95 #define EXP_HASH_CIPHER 0x22
96 #define EXP_HASH_NAME "BLAKE2"
97 
98 #define EXP_SIG_CIPHER 0x23
99 #define EXP_SIG_CIPHER_NAME "ED25519"
100 
101 #define EXP_SIG_VERSION 0x01
102 #define EXP_SIG_TYPE 0x1F /* self signed */
103 
104 /* sig sub notiation we support */
105 #define EXP_SIG_SUB_CTIME 2
106 #define EXP_SIG_SUB_SIGEXPIRE 3
107 #define EXP_SIG_SUB_KEYEXPIRE 9
108 #define EXP_SIG_SUB_NOTATION 20
109 #define EXP_SIG_SUB_KEYFLAGS 27
110 
111 /* in armored mode, we're using the usual head+foot */
112 #define EXP_PK_HEADER "-----BEGIN ED25519-CURVE29915 PUBLIC KEY-----"
113 #define EXP_PK_FOOTER "------END ED25519-CURVE29915 PUBLIC KEY------"
114 #define EXP_SK_HEADER "-----BEGIN ED25519-CURVE29915 PRIVATE KEY-----"
115 #define EXP_SK_FOOTER "------END ED25519-CURVE29915 PRIVATE KEY------"
116 
117 
118 /* pubkey export formats */
119 #define EXP_FORMAT_NATIVE 1
120 #define EXP_FORMAT_PBP 2
121 #define EXP_FORMAT_YAML 3
122 #define EXP_FORMAT_C 4
123 #define EXP_FORMAT_PY 5
124 #define EXP_FORMAT_PERL 6
125 
212 
213 
225 
236 
247 
258 
299 Buffer *pcp_export_secret(pcp_key_t *sk, char *passphrase);
300 
301 pcp_ks_bundle_t *pcp_import_pub(unsigned char *raw, size_t rawsize);
302 pcp_ks_bundle_t *pcp_import_pub_rfc(Buffer *blob);
303 pcp_ks_bundle_t *pcp_import_pub_pbp(Buffer *blob);
304 
305 /* import secret key */
306 pcp_key_t *pcp_import_secret(unsigned char *raw, size_t rawsize, char *passphrase);
307 pcp_key_t *pcp_import_secret_native(Buffer *cipher, char *passphrase);
308 
309 #endif // _HAVE_PCP_MGMT_H
310