mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-16 19:40:57 +01:00
changed invalid // c++ comments to valid /* .. */ C comments
This commit is contained in:
@@ -32,4 +32,4 @@ void encode_85(char *buf, const unsigned char *data, int bytes);
|
|||||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||||
#define error(...) (fatal(__VA_ARGS__), -1)
|
#define error(...) (fatal(__VA_ARGS__), -1)
|
||||||
|
|
||||||
#endif // HAVE_BASE85_H
|
#endif /* HAVE_BASE85_H */
|
||||||
|
|||||||
@@ -65,4 +65,4 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_
|
|||||||
pcp_rec_t *pcp_rec_new(unsigned char *cipher, size_t clen, pcp_key_t *secret, pcp_pubkey_t *pub);
|
pcp_rec_t *pcp_rec_new(unsigned char *cipher, size_t clen, pcp_key_t *secret, pcp_pubkey_t *pub);
|
||||||
void pcp_rec_free(pcp_rec_t *r);
|
void pcp_rec_free(pcp_rec_t *r);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_CRYPTO_H
|
#endif /* _HAVE_PCP_CRYPTO_H */
|
||||||
|
|||||||
@@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef unsigned char byte; // Single unsigned byte = 8 bits
|
typedef unsigned char byte; /* Single unsigned byte = 8 bits */
|
||||||
typedef unsigned short dbyte; // Double byte = 16 bits
|
typedef unsigned short dbyte; /* Double byte = 16 bits */
|
||||||
typedef unsigned int qbyte; // Quad byte = 32 bits
|
typedef unsigned int qbyte; /* Quad byte = 32 bits */
|
||||||
|
|
||||||
// key stuff
|
/* key stuff */
|
||||||
#define PCP_KEY_HEADER "----- BEGIN PCP SECRET KEY -----"
|
#define PCP_KEY_HEADER "----- BEGIN PCP SECRET KEY -----"
|
||||||
#define PCP_KEY_FOOTER "------ END PCP SECRET KEY ------"
|
#define PCP_KEY_FOOTER "------ END PCP SECRET KEY ------"
|
||||||
|
|
||||||
@@ -56,24 +56,24 @@ typedef unsigned int qbyte; // Quad byte = 32 bits
|
|||||||
#define PCP_KEY_TYPE_SECRET 2
|
#define PCP_KEY_TYPE_SECRET 2
|
||||||
#define PCP_KEY_TYPE_PUBLIC 3
|
#define PCP_KEY_TYPE_PUBLIC 3
|
||||||
|
|
||||||
// save typing, dammit
|
/* save typing, dammit */
|
||||||
#define PCP_ENCRYPT_PAD crypto_secretbox_ZEROBYTES + crypto_secretbox_NONCEBYTES
|
#define PCP_ENCRYPT_PAD crypto_secretbox_ZEROBYTES + crypto_secretbox_NONCEBYTES
|
||||||
|
|
||||||
// vault id
|
/* vault id */
|
||||||
#define PCP_VAULT_ID 14
|
#define PCP_VAULT_ID 14
|
||||||
#define PCP_VAULT_VERSION 2
|
#define PCP_VAULT_VERSION 2
|
||||||
|
|
||||||
// sigs
|
/* sigs */
|
||||||
#define PCP_SIG_VERSION 2
|
#define PCP_SIG_VERSION 2
|
||||||
|
|
||||||
// crypto file format stuff
|
/* crypto file format stuff */
|
||||||
// enabled via config.h (configure --enable-cbc)
|
/* enabled via config.h (configure --enable-cbc) */
|
||||||
#ifndef PCP_CBC
|
#ifndef PCP_CBC
|
||||||
#define PCP_ASYM_CIPHER 5
|
#define PCP_ASYM_CIPHER 5
|
||||||
#define PCP_SYM_CIPHER 23
|
#define PCP_SYM_CIPHER 23
|
||||||
#define PCP_BLOCK_SIZE 32 * 1024
|
#define PCP_BLOCK_SIZE 32 * 1024
|
||||||
#else
|
#else
|
||||||
// CBC mode, use smaller blocks
|
/* CBC mode, use smaller blocks */
|
||||||
#define PCP_ASYM_CIPHER 7
|
#define PCP_ASYM_CIPHER 7
|
||||||
#define PCP_SYM_CIPHER 25
|
#define PCP_SYM_CIPHER 25
|
||||||
#define PCP_BLOCK_SIZE 1 * 1024
|
#define PCP_BLOCK_SIZE 1 * 1024
|
||||||
@@ -82,23 +82,23 @@ typedef unsigned int qbyte; // Quad byte = 32 bits
|
|||||||
#define PCP_CRYPTO_ADD (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
|
#define PCP_CRYPTO_ADD (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
|
||||||
#define PCP_BLOCK_SIZE_IN (PCP_BLOCK_SIZE) + PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES
|
#define PCP_BLOCK_SIZE_IN (PCP_BLOCK_SIZE) + PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES
|
||||||
#define PCP_ASYM_RECIPIENT_SIZE crypto_secretbox_KEYBYTES + PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES
|
#define PCP_ASYM_RECIPIENT_SIZE crypto_secretbox_KEYBYTES + PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES
|
||||||
//#define PCP_ASYM_ADD_SENDER_PUB
|
/* #define PCP_ASYM_ADD_SENDER_PUB */
|
||||||
|
|
||||||
// used for self encryption only
|
/* used for self encryption only */
|
||||||
#define PBP_COMPAT_SALT "qa~t](84z<1t<1oz:ik.@IRNyhG=8q(on9}4#!/_h#a7wqK{Nt$T?W>,mt8NqYq&6U<GB1$,<$j>,rSYI2GRDd:Bcm"
|
#define PBP_COMPAT_SALT "qa~t](84z<1t<1oz:ik.@IRNyhG=8q(on9}4#!/_h#a7wqK{Nt$T?W>,mt8NqYq&6U<GB1$,<$j>,rSYI2GRDd:Bcm"
|
||||||
|
|
||||||
// error handling
|
/* error handling */
|
||||||
extern char *PCP_ERR;
|
extern char *PCP_ERR;
|
||||||
extern byte PCP_ERRSET;
|
extern byte PCP_ERRSET;
|
||||||
extern int PCP_EXIT;
|
extern int PCP_EXIT;
|
||||||
|
|
||||||
//set error
|
/* set error */
|
||||||
void fatal(const char * fmt, ...);
|
void fatal(const char * fmt, ...);
|
||||||
|
|
||||||
// fetch error
|
/* fetch error */
|
||||||
void fatals_ifany();
|
void fatals_ifany();
|
||||||
|
|
||||||
// reset
|
/* reset */
|
||||||
void fatals_reset();
|
void fatals_reset();
|
||||||
|
|
||||||
#endif // _DEFINES_H
|
#endif /* _DEFINES_H */
|
||||||
|
|||||||
@@ -58,4 +58,4 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p);
|
|||||||
size_t pcp_ed_detachsign_buffered(FILE *in, FILE *out, pcp_key_t *s);
|
size_t pcp_ed_detachsign_buffered(FILE *in, FILE *out, pcp_key_t *s);
|
||||||
pcp_pubkey_t *pcp_ed_detachverify_buffered(FILE *in, FILE *sigfd, pcp_pubkey_t *p);
|
pcp_pubkey_t *pcp_ed_detachverify_buffered(FILE *in, FILE *sigfd, pcp_pubkey_t *p);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_ED_H
|
#endif /* _HAVE_PCP_ED_H */
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ void pcp_echo_on();
|
|||||||
char *pcp_get_stdin();
|
char *pcp_get_stdin();
|
||||||
char *pcp_get_passphrase(char *prompt);
|
char *pcp_get_passphrase(char *prompt);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_GETPASS
|
#endif /* _HAVE_PCP_GETPASS */
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef _HAVE_JENHASH_H
|
#ifndef _HAVE_JENHASH_H
|
||||||
#define _HAVE_JENHASH_H
|
#define _HAVE_JENHASH_H
|
||||||
|
|
||||||
// Bob Jenkins 32bit hash function
|
/* Bob Jenkins 32bit hash function */
|
||||||
// via: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
|
/* via: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */
|
||||||
|
|
||||||
#define jen_mix(a,b,c) \
|
#define jen_mix(a,b,c) \
|
||||||
{ \
|
{ \
|
||||||
@@ -22,4 +22,4 @@
|
|||||||
|
|
||||||
unsigned jen_hash ( unsigned char *k, unsigned length, unsigned initval );
|
unsigned jen_hash ( unsigned char *k, unsigned length, unsigned initval );
|
||||||
|
|
||||||
#endif // _HAVE_JENHASH_H
|
#endif /* _HAVE_JENHASH_H */
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ struct _pcp_key_t {
|
|||||||
byte edpub[32];
|
byte edpub[32];
|
||||||
byte edsecret[64];
|
byte edsecret[64];
|
||||||
byte nonce[24];
|
byte nonce[24];
|
||||||
byte encrypted[112]; // both ed+curve encrypted
|
byte encrypted[112]; /* both ed+curve encrypted */
|
||||||
char owner[255];
|
char owner[255];
|
||||||
char mail[255];
|
char mail[255];
|
||||||
char id[17];
|
char id[17];
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint64_t ctime; // 8
|
uint64_t ctime; /* 8 */
|
||||||
uint32_t version; // 4
|
uint32_t version; /* 4 */
|
||||||
uint32_t serial; // 4
|
uint32_t serial; /* 4 */
|
||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,8 +104,8 @@ struct _pcp_pubkey_t {
|
|||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
};
|
};
|
||||||
|
|
||||||
// the PBP public key format
|
/* the PBP public key format */
|
||||||
// keys.mp+keys.cp+keys.sp+keys.name
|
/* keys.mp+keys.cp+keys.sp+keys.name */
|
||||||
struct _pbp_pubkey_t {
|
struct _pbp_pubkey_t {
|
||||||
byte sigpub[crypto_sign_PUBLICKEYBYTES];
|
byte sigpub[crypto_sign_PUBLICKEYBYTES];
|
||||||
byte pub[crypto_box_PUBLICKEYBYTES];
|
byte pub[crypto_box_PUBLICKEYBYTES];
|
||||||
@@ -165,17 +165,17 @@ unsigned char * pcp_gennonce();
|
|||||||
|
|
||||||
void pcpedit_key(char *keyid);
|
void pcpedit_key(char *keyid);
|
||||||
|
|
||||||
// use scrypt() to create a key from a passphrase and a nonce
|
/* use scrypt() to create a key from a passphrase and a nonce */
|
||||||
unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce);
|
unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce);
|
||||||
|
|
||||||
pcp_key_t *pcp_derive_pcpkey (pcp_key_t *ours, char *theirs);
|
pcp_key_t *pcp_derive_pcpkey (pcp_key_t *ours, char *theirs);
|
||||||
|
|
||||||
void pcp_seckeyblob(void *blob, pcp_key_t *k);
|
void pcp_seckeyblob(void *blob, pcp_key_t *k);
|
||||||
void pcp_pubkeyblob(void *blob, pcp_pubkey_t *k);
|
void pcp_pubkeyblob(void *blob, pcp_pubkey_t *k);
|
||||||
void *pcp_keyblob(void *k, int type); // allocates blob
|
void *pcp_keyblob(void *k, int type); /* allocates blob */
|
||||||
|
|
||||||
int pcp_sanitycheck_pub(pcp_pubkey_t *key);
|
int pcp_sanitycheck_pub(pcp_pubkey_t *key);
|
||||||
int pcp_sanitycheck_key(pcp_key_t *key);
|
int pcp_sanitycheck_key(pcp_key_t *key);
|
||||||
|
|
||||||
|
|
||||||
#endif // _HAVE_PCP_KEYPAIR_H
|
#endif /* _HAVE_PCP_KEYPAIR_H */
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ extern pcp_pubkey_t *pcppubkey_hash;
|
|||||||
extern pcp_key_t *__k;
|
extern pcp_key_t *__k;
|
||||||
extern pcp_pubkey_t *__p;
|
extern pcp_pubkey_t *__p;
|
||||||
|
|
||||||
// wrapper for HASH_ITER
|
/* wrapper for HASH_ITER */
|
||||||
#define pcphash_iterate(key) \
|
#define pcphash_iterate(key) \
|
||||||
__k = NULL; \
|
__k = NULL; \
|
||||||
HASH_ITER(hh, pcpkey_hash, key, __k)
|
HASH_ITER(hh, pcpkey_hash, key, __k)
|
||||||
@@ -52,4 +52,4 @@ void pcphash_add(void *key, int type);
|
|||||||
int pcphash_count();
|
int pcphash_count();
|
||||||
int pcphash_countpub();
|
int pcphash_countpub();
|
||||||
|
|
||||||
#endif // _HAVE_KEYHASH_H
|
#endif /* _HAVE_KEYHASH_H */
|
||||||
|
|||||||
@@ -31,38 +31,38 @@
|
|||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
|
|
||||||
// how many times do we hash the passphrase
|
/* how many times do we hash the passphrase */
|
||||||
#define HCYCLES 128000
|
#define HCYCLES 128000
|
||||||
|
|
||||||
// encrypt some arbitrary cleartext using
|
/* encrypt some arbitrary cleartext using */
|
||||||
// a curve25519 secret key and a given nonce.
|
/* a curve25519 secret key and a given nonce. */
|
||||||
//
|
/* */
|
||||||
// expects a pointer to the target binary
|
/* expects a pointer to the target binary */
|
||||||
// stream containing the encrypted data,
|
/* stream containing the encrypted data, */
|
||||||
// the cleartext string, its size, the nonce
|
/* the cleartext string, its size, the nonce */
|
||||||
// (24 bytes) and the secret key (32 bytes).
|
/* (24 bytes) and the secret key (32 bytes). */
|
||||||
//
|
/* */
|
||||||
// allocates memory for the returned cipher
|
/* allocates memory for the returned cipher */
|
||||||
// and it is up to the user to free it after use.
|
/* and it is up to the user to free it after use. */
|
||||||
//
|
/* */
|
||||||
// returns the size of the returned cipherstream.
|
/* returns the size of the returned cipherstream. */
|
||||||
// in case of an error, the cipher will be set
|
/* in case of an error, the cipher will be set */
|
||||||
// to NULL.
|
/* to NULL. */
|
||||||
size_t pcp_sodium_mac(unsigned char **cipher,
|
size_t pcp_sodium_mac(unsigned char **cipher,
|
||||||
unsigned char *cleartext,
|
unsigned char *cleartext,
|
||||||
size_t clearsize,
|
size_t clearsize,
|
||||||
unsigned char *nonce,
|
unsigned char *nonce,
|
||||||
unsigned char *key);
|
unsigned char *key);
|
||||||
|
|
||||||
// does the opposite of pcp_sodium_mac and decrypts
|
/* does the opposite of pcp_sodium_mac and decrypts */
|
||||||
// a given encrypted binary stream using a nonce and
|
/* a given encrypted binary stream using a nonce and */
|
||||||
// a secret key (sizes: see above).
|
/* a secret key (sizes: see above). */
|
||||||
//
|
/* */
|
||||||
// allocates memory for the returned cleartext and
|
/* allocates memory for the returned cleartext and */
|
||||||
// it is up to the user to free it after use.
|
/* it is up to the user to free it after use. */
|
||||||
//
|
/* */
|
||||||
// returns 0 if decryption and verification were
|
/* returns 0 if decryption and verification were */
|
||||||
// successful, otherwise -1.
|
/* successful, otherwise -1. */
|
||||||
int pcp_sodium_verify_mac(unsigned char **cleartext,
|
int pcp_sodium_verify_mac(unsigned char **cleartext,
|
||||||
unsigned char* message,
|
unsigned char* message,
|
||||||
size_t messagesize,
|
size_t messagesize,
|
||||||
@@ -72,4 +72,4 @@ int pcp_sodium_verify_mac(unsigned char **cleartext,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _HAVE_PCP_MAC
|
#endif /* _HAVE_PCP_MAC */
|
||||||
|
|||||||
@@ -27,19 +27,16 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
// simple malloc() wrapper
|
/* simple malloc() wrapper */
|
||||||
// behaves like calloc(), which
|
/* behaves like calloc(), which */
|
||||||
// I don't have here.
|
/* I don't have here. */
|
||||||
//
|
/* */
|
||||||
// exits if there's no more memory
|
/* exits if there's no more memory */
|
||||||
// available.
|
/* available. */
|
||||||
void *ucmalloc(size_t s);
|
void *ucmalloc(size_t s);
|
||||||
|
|
||||||
// the same but it fills the pointer with random values
|
/* the same but it fills the pointer with random values */
|
||||||
void *urmalloc(size_t s);
|
void *urmalloc(size_t s);
|
||||||
|
|
||||||
// dito.
|
|
||||||
void *ucfree(void *ptr);
|
|
||||||
|
|
||||||
|
#endif /* _HAVE_PCP_MEM */
|
||||||
#endif // _HAVE_PCP_MEM
|
|
||||||
|
|||||||
@@ -37,62 +37,62 @@
|
|||||||
#define ZPADCHAR 0
|
#define ZPADCHAR 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// prepends a binary stream with a number of
|
/* prepends a binary stream with a number of */
|
||||||
// \0's as required by the secret_box and
|
/* \0's as required by the secret_box and */
|
||||||
// secret_box_open functions of libsodium.
|
/* secret_box_open functions of libsodium. */
|
||||||
//
|
/* */
|
||||||
// parameters:
|
/* parameters: */
|
||||||
//
|
/* */
|
||||||
// padded: destination array (ref)
|
/* padded: destination array (ref) */
|
||||||
// unpadded: source array without padding
|
/* unpadded: source array without padding */
|
||||||
// padlen: length of padding
|
/* padlen: length of padding */
|
||||||
// unpadlen: length of source array
|
/* unpadlen: length of source array */
|
||||||
//
|
/* */
|
||||||
// turns "efa5" into "00000000efa5" with padlen 8
|
/* turns "efa5" into "00000000efa5" with padlen 8 */
|
||||||
//
|
/* */
|
||||||
// if DEBUG is set, destination will be padded with
|
/* if DEBUG is set, destination will be padded with */
|
||||||
// the character '0', NOT the integer 0.
|
/* the character '0', NOT the integer 0. */
|
||||||
//
|
/* */
|
||||||
// allocates memory for padded and it is up to the
|
/* allocates memory for padded and it is up to the */
|
||||||
// user to free it after use.
|
/* user to free it after use. */
|
||||||
//
|
/* */
|
||||||
// sample call:
|
/* sample call: */
|
||||||
//
|
/* */
|
||||||
// char unpadded[] = {0xef, 0xa5};
|
/* char unpadded[] = {0xef, 0xa5}; */
|
||||||
// unsigned char *padded;
|
/* unsigned char *padded; */
|
||||||
// pcp_pad_prepend(&padded, unpadded, 8, 2);
|
/* pcp_pad_prepend(&padded, unpadded, 8, 2); */
|
||||||
//
|
/* */
|
||||||
// the result, padded, would be 10 bytes long, 8
|
/* the result, padded, would be 10 bytes long, 8 */
|
||||||
// bytes for the leading zeros and 2 for the content
|
/* bytes for the leading zeros and 2 for the content */
|
||||||
// of the original unpadded.
|
/* of the original unpadded. */
|
||||||
void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded,
|
void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded,
|
||||||
size_t padlen, size_t unpadlen);
|
size_t padlen, size_t unpadlen);
|
||||||
|
|
||||||
// removes zero's of a binary stream, which is
|
/* removes zero's of a binary stream, which is */
|
||||||
// the reverse of pcp_pad_prepend().
|
/* the reverse of pcp_pad_prepend(). */
|
||||||
//
|
/* */
|
||||||
// parameters:
|
/* parameters: */
|
||||||
//
|
/* */
|
||||||
// unpadded: destination array (ref), with padding removed
|
/* unpadded: destination array (ref), with padding removed */
|
||||||
// padded: source array with padding
|
/* padded: source array with padding */
|
||||||
// padlen: length of padding
|
/* padlen: length of padding */
|
||||||
// unpadlen: length of source array
|
/* unpadlen: length of source array */
|
||||||
//
|
/* */
|
||||||
// turns "00000000efa5" into "efa5" with padlen 8
|
/* turns "00000000efa5" into "efa5" with padlen 8 */
|
||||||
//
|
/* */
|
||||||
// allocates memory for unpadded and it is up to the
|
/* allocates memory for unpadded and it is up to the */
|
||||||
// user to free it after use.
|
/* user to free it after use. */
|
||||||
//
|
/* */
|
||||||
// sample call:
|
/* sample call: */
|
||||||
//
|
/* */
|
||||||
// char padded[] = {0x0, 0x0, 0x0, 0x0, 0xef, 0xa5};
|
/* char padded[] = {0x0, 0x0, 0x0, 0x0, 0xef, 0xa5}; */
|
||||||
// unsigned char *unpadded;
|
/* unsigned char *unpadded; */
|
||||||
// pcp_pad_remove(unpadded, padded, 4, 2);
|
/* pcp_pad_remove(unpadded, padded, 4, 2); */
|
||||||
//
|
/* */
|
||||||
// the result, unpadded would be 2 bytes long containing
|
/* the result, unpadded would be 2 bytes long containing */
|
||||||
// only the 2 bytes we want to have with zeros removed.
|
/* only the 2 bytes we want to have with zeros removed. */
|
||||||
void pcp_pad_remove(unsigned char **unpadded, unsigned char *padded,
|
void pcp_pad_remove(unsigned char **unpadded, unsigned char *padded,
|
||||||
size_t padlen, size_t unpadlen);
|
size_t padlen, size_t unpadlen);
|
||||||
|
|
||||||
|
|
||||||
#endif // _HAVE_PCP_ZPADDING
|
#endif /* _HAVE_PCP_ZPADDING */
|
||||||
|
|||||||
@@ -27,16 +27,16 @@
|
|||||||
|
|
||||||
#ifdef HAVE_ENDIAN_H
|
#ifdef HAVE_ENDIAN_H
|
||||||
# include <endian.h>
|
# include <endian.h>
|
||||||
#else // no endian.h
|
#else /* no endian.h */
|
||||||
# ifdef HAVE_SYS_ENDIAN_H
|
# ifdef HAVE_SYS_ENDIAN_H
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/endian.h>
|
# include <sys/endian.h>
|
||||||
# ifndef HAVE_BE32TOH
|
# ifndef HAVE_BE32TOH
|
||||||
# // openbsd, use aliases
|
# /* openbsd, use aliases */
|
||||||
# define be32toh betoh32
|
# define be32toh betoh32
|
||||||
# define be64toh betoh64
|
# define be64toh betoh64
|
||||||
# endif
|
# endif
|
||||||
# else // no sys/endian.h
|
# else /* no sys/endian.h */
|
||||||
# ifdef __CPU_IS_BIG_ENDIAN
|
# ifdef __CPU_IS_BIG_ENDIAN
|
||||||
# define be32toh(x) (x)
|
# define be32toh(x) (x)
|
||||||
# define htobe32(x) (x)
|
# define htobe32(x) (x)
|
||||||
@@ -57,12 +57,12 @@
|
|||||||
# define be64toh(x) ((u_int64_t)ntohl((u_int64_t)(x)))
|
# define be64toh(x) ((u_int64_t)ntohl((u_int64_t)(x)))
|
||||||
# define htobe64(x) ((u_int64_t)htonl((u_int64_t)(x)))
|
# define htobe64(x) ((u_int64_t)htonl((u_int64_t)(x)))
|
||||||
# endif
|
# endif
|
||||||
# endif // HAVE_SYS_ENDIAN_H
|
# endif /* HAVE_SYS_ENDIAN_H */
|
||||||
#endif // HAVE_ENDIAN_H
|
#endif /* HAVE_ENDIAN_H */
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_ARC4RANDOM_BUF
|
#ifndef HAVE_ARC4RANDOM_BUF
|
||||||
// shitty OS. we're using libsodium's implementation
|
/* shitty OS. we're using libsodium's implementation */
|
||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ int vasprintf(char **ret, const char *format, va_list args) {
|
|||||||
*ret = buffer;
|
*ret = buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
va_end(copy); // Each va_start() or va_copy() needs a va_end()
|
va_end(copy); /* Each va_start() or va_copy() needs a va_end() */
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,4 +73,4 @@ static inline void p_clean(plist_t *lst) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _HAVE_PCP_PLIST_H
|
#endif /* _HAVE_PCP_PLIST_H */
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// key_fingerprint_randomart comitted by Alexander von Gernler in rev 1.70
|
/* key_fingerprint_randomart comitted by Alexander von Gernler in rev 1.70 */
|
||||||
|
|
||||||
#ifndef _HAVE_PCP_RANDOMART_H
|
#ifndef _HAVE_PCP_RANDOMART_H
|
||||||
#define _HAVE_PCP_RANDOMART_H
|
#define _HAVE_PCP_RANDOMART_H
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// from openssh key.c
|
/* from openssh key.c */
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
# define MAX(a,b) (((a)>(b))?(a):(b))
|
# define MAX(a,b) (((a)>(b))?(a):(b))
|
||||||
@@ -51,4 +51,4 @@
|
|||||||
|
|
||||||
char *key_fingerprint_randomart(unsigned char *dgst_raw, unsigned int dgst_raw_len);
|
char *key_fingerprint_randomart(unsigned char *dgst_raw, unsigned int dgst_raw_len);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_RANDOMART_H
|
#endif /* _HAVE_PCP_RANDOMART_H */
|
||||||
|
|||||||
@@ -38,5 +38,5 @@
|
|||||||
|
|
||||||
unsigned char * pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen);
|
unsigned char * pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_SCRYPT_H
|
#endif /* _HAVE_PCP_SCRYPT_H */
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// various helpers, too small to put into own c
|
/* various helpers, too small to put into own c */
|
||||||
|
|
||||||
#ifndef _HAVE_PCP_UTIL_H
|
#ifndef _HAVE_PCP_UTIL_H
|
||||||
#define _HAVE_PCP_UTIL_H
|
#define _HAVE_PCP_UTIL_H
|
||||||
@@ -36,4 +36,4 @@ size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hle
|
|||||||
void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen);
|
void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen);
|
||||||
void _dump(char *n, unsigned char *d, size_t s);
|
void _dump(char *n, unsigned char *d, size_t s);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_UTIL_H
|
#endif /* _HAVE_PCP_UTIL_H */
|
||||||
|
|||||||
@@ -83,4 +83,4 @@ vault_header_t * vh2native(vault_header_t *h);
|
|||||||
vault_item_header_t * ih2be(vault_item_header_t *h);
|
vault_item_header_t * ih2be(vault_item_header_t *h);
|
||||||
vault_item_header_t * ih2native(vault_item_header_t *h);
|
vault_item_header_t * ih2native(vault_item_header_t *h);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_VAULT
|
#endif /* _HAVE_PCP_VAULT */
|
||||||
|
|||||||
@@ -34,4 +34,4 @@
|
|||||||
|
|
||||||
int pcp_version();
|
int pcp_version();
|
||||||
|
|
||||||
#endif // _HAVE_PCP_VERSION
|
#endif /* _HAVE_PCP_VERSION */
|
||||||
|
|||||||
@@ -20,27 +20,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// from https://github.com/tlinden/curve-keygen/
|
/* from https://github.com/tlinden/curve-keygen/ */
|
||||||
#ifndef _HAVE_PCP_Z85_H
|
#ifndef _HAVE_PCP_Z85_H
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "zmq_z85.h"
|
#include "zmq_z85.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
// convert a binary stream to one which gets accepted by zmq_z85_encode
|
/* convert a binary stream to one which gets accepted by zmq_z85_encode */
|
||||||
// we pad it with zeroes and put the number of zerores in front of it
|
/* we pad it with zeroes and put the number of zerores in front of it */
|
||||||
unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen);
|
unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen);
|
||||||
|
|
||||||
// the reverse of the above
|
/* the reverse of the above */
|
||||||
unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen);
|
unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen);
|
||||||
|
|
||||||
// wrapper around zmq Z85 encoding function
|
/* wrapper around zmq Z85 encoding function */
|
||||||
unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen);
|
unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen);
|
||||||
|
|
||||||
// the reverse of the above
|
/* the reverse of the above */
|
||||||
char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen);
|
char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen);
|
||||||
|
|
||||||
char *pcp_readz85file(FILE *infile);
|
char *pcp_readz85file(FILE *infile);
|
||||||
char *pcp_readz85string(unsigned char *input, size_t bufsize);
|
char *pcp_readz85string(unsigned char *input, size_t bufsize);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_Z85_H
|
#endif /* _HAVE_PCP_Z85_H */
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ int decode_85(char *dst, const char *buffer, int len)
|
|||||||
0xffffffff - de < (acc *= 85))
|
0xffffffff - de < (acc *= 85))
|
||||||
return error("invalid base85 sequence %.5s => %08x\n", buffer-5, acc);
|
return error("invalid base85 sequence %.5s => %08x\n", buffer-5, acc);
|
||||||
acc += de;
|
acc += de;
|
||||||
// say1(" %08x\n", acc);
|
/* say1(" %08x\n", acc); */
|
||||||
say1("%.5s", buffer-5);
|
say1("%.5s", buffer-5);
|
||||||
say2("=> %08x (len: %d)\n", acc, len);
|
say2("=> %08x (len: %d)\n", acc, len);
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ size_t pcp_sodium_box(unsigned char **cipher,
|
|||||||
pad_cipher = ucmalloc(crypto_box_ZEROBYTES + clearsize);
|
pad_cipher = ucmalloc(crypto_box_ZEROBYTES + clearsize);
|
||||||
pcp_pad_prepend(&pad_clear, cleartext, crypto_box_ZEROBYTES, clearsize);
|
pcp_pad_prepend(&pad_clear, cleartext, crypto_box_ZEROBYTES, clearsize);
|
||||||
|
|
||||||
// crypto_box(c,m,mlen,n,pk,sk);
|
/* crypto_box(c,m,mlen,n,pk,sk); */
|
||||||
crypto_box(pad_cipher, pad_clear,
|
crypto_box(pad_cipher, pad_clear,
|
||||||
clearsize + crypto_box_ZEROBYTES, nonce, pub, secret);
|
clearsize + crypto_box_ZEROBYTES, nonce, pub, secret);
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ size_t pcp_sodium_box(unsigned char **cipher,
|
|||||||
int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
|
int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
|
||||||
size_t messagesize, unsigned char *nonce,
|
size_t messagesize, unsigned char *nonce,
|
||||||
unsigned char *secret, unsigned char *pub) {
|
unsigned char *secret, unsigned char *pub) {
|
||||||
// verify/decrypt the box
|
/* verify/decrypt the box */
|
||||||
unsigned char *pad_cipher;
|
unsigned char *pad_cipher;
|
||||||
unsigned char *pad_clear;
|
unsigned char *pad_clear;
|
||||||
int success = -1;
|
int success = -1;
|
||||||
@@ -63,7 +63,7 @@ int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
|
|||||||
pcp_pad_prepend(&pad_cipher, message, crypto_box_BOXZEROBYTES, messagesize);
|
pcp_pad_prepend(&pad_cipher, message, crypto_box_BOXZEROBYTES, messagesize);
|
||||||
pad_clear = (unsigned char *)ucmalloc((crypto_box_ZEROBYTES+ messagesize));
|
pad_clear = (unsigned char *)ucmalloc((crypto_box_ZEROBYTES+ messagesize));
|
||||||
|
|
||||||
// crypto_box_open(m,c,clen,n,pk,sk);
|
/* crypto_box_open(m,c,clen,n,pk,sk); */
|
||||||
if (crypto_box_open(pad_clear, pad_cipher,
|
if (crypto_box_open(pad_clear, pad_cipher,
|
||||||
messagesize + crypto_box_BOXZEROBYTES,
|
messagesize + crypto_box_BOXZEROBYTES,
|
||||||
nonce, pub, secret) == 0) {
|
nonce, pub, secret) == 0) {
|
||||||
@@ -97,13 +97,13 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
|
|||||||
goto errbec;
|
goto errbec;
|
||||||
}
|
}
|
||||||
|
|
||||||
// scip
|
/* scip */
|
||||||
//fprintf(stderr, "public: "); pcpprint_bin(stderr, pub->pub, 32); fprintf(stderr, "\n");
|
/* fprintf(stderr, "public: "); pcpprint_bin(stderr, pub->pub, 32); fprintf(stderr, "\n"); */
|
||||||
//fprintf(stderr, "secret: "); pcpprint_bin(stderr, secret->secret, 32); fprintf(stderr, "\n");
|
/* fprintf(stderr, "secret: "); pcpprint_bin(stderr, secret->secret, 32); fprintf(stderr, "\n"); */
|
||||||
//fprintf(stderr, "cipher: "); pcpprint_bin(stderr, cipher, es); fprintf(stderr, "\n");
|
/* fprintf(stderr, "cipher: "); pcpprint_bin(stderr, cipher, es); fprintf(stderr, "\n"); */
|
||||||
//fprintf(stderr, " nonce: "); pcpprint_bin(stderr, nonce, crypto_secretbox_NONCEBYTES); fprintf(stderr, "\n");
|
/* fprintf(stderr, " nonce: "); pcpprint_bin(stderr, nonce, crypto_secretbox_NONCEBYTES); fprintf(stderr, "\n"); */
|
||||||
|
|
||||||
// put nonce and cipher together
|
/* put nonce and cipher together */
|
||||||
unsigned char *combined = ucmalloc(es + crypto_secretbox_NONCEBYTES);
|
unsigned char *combined = ucmalloc(es + crypto_secretbox_NONCEBYTES);
|
||||||
memcpy(combined, nonce, crypto_secretbox_NONCEBYTES);
|
memcpy(combined, nonce, crypto_secretbox_NONCEBYTES);
|
||||||
memcpy(&combined[crypto_secretbox_NONCEBYTES], cipher, es);
|
memcpy(&combined[crypto_secretbox_NONCEBYTES], cipher, es);
|
||||||
@@ -147,8 +147,8 @@ unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
|
|||||||
free(nonce);
|
free(nonce);
|
||||||
free(cipheronly);
|
free(cipheronly);
|
||||||
|
|
||||||
// resulting size:
|
/* resulting size: */
|
||||||
// ciphersize - crypto_secretbox_ZEROBYTES
|
/* ciphersize - crypto_secretbox_ZEROBYTES */
|
||||||
*dsize = ciphersize - crypto_secretbox_NONCEBYTES - PCP_CRYPTO_ADD;
|
*dsize = ciphersize - crypto_secretbox_NONCEBYTES - PCP_CRYPTO_ADD;
|
||||||
return message;
|
return message;
|
||||||
|
|
||||||
@@ -179,12 +179,12 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey
|
|||||||
int self = 0;
|
int self = 0;
|
||||||
|
|
||||||
if(ftell(in) == 1) {
|
if(ftell(in) == 1) {
|
||||||
// header has already been determined outside the lib
|
/* header has already been determined outside the lib */
|
||||||
if(symkey != NULL)
|
if(symkey != NULL)
|
||||||
self = 1;
|
self = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// step 1, check header
|
/* step 1, check header */
|
||||||
cur_bufsize = fread(head, 1, 1, in);
|
cur_bufsize = fread(head, 1, 1, in);
|
||||||
if(cur_bufsize != 1 && !feof(in) && !ferror(in)) {
|
if(cur_bufsize != 1 && !feof(in) && !ferror(in)) {
|
||||||
if(head[0] == PCP_SYM_CIPHER) {
|
if(head[0] == PCP_SYM_CIPHER) {
|
||||||
@@ -202,12 +202,12 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(self) {
|
if(self) {
|
||||||
// just decrypt symetrically and go outa here
|
/* just decrypt symetrically and go outa here */
|
||||||
return pcp_decrypt_file_sym(in, out, symkey, NULL);
|
return pcp_decrypt_file_sym(in, out, symkey, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PCP_ASYM_ADD_SENDER_PUB
|
#ifdef PCP_ASYM_ADD_SENDER_PUB
|
||||||
// step 2, sender's pubkey
|
/* step 2, sender's pubkey */
|
||||||
cur_bufsize = fread(&in_buf, 1, crypto_box_PUBLICKEYBYTES, in);
|
cur_bufsize = fread(&in_buf, 1, crypto_box_PUBLICKEYBYTES, in);
|
||||||
if(cur_bufsize != crypto_box_PUBLICKEYBYTES && !feof(in) && !ferror(in)) {
|
if(cur_bufsize != crypto_box_PUBLICKEYBYTES && !feof(in) && !ferror(in)) {
|
||||||
fatal("Error: input file doesn't contain senders public key\n");
|
fatal("Error: input file doesn't contain senders public key\n");
|
||||||
@@ -215,7 +215,7 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// step 3, check len recipients
|
/* step 3, check len recipients */
|
||||||
cur_bufsize = fread(&lenrec, 1, 4, in);
|
cur_bufsize = fread(&lenrec, 1, 4, in);
|
||||||
if(cur_bufsize != 4 && !feof(in) && !ferror(in)) {
|
if(cur_bufsize != 4 && !feof(in) && !ferror(in)) {
|
||||||
fatal("Error: input file doesn't contain recipient count\n");
|
fatal("Error: input file doesn't contain recipient count\n");
|
||||||
@@ -227,7 +227,7 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey
|
|||||||
reccipher = ucmalloc(lenrec * PCP_ASYM_RECIPIENT_SIZE);
|
reccipher = ucmalloc(lenrec * PCP_ASYM_RECIPIENT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 4, fetch recipient list and try to decrypt it for us
|
/* step 4, fetch recipient list and try to decrypt it for us */
|
||||||
for(nrec=0; nrec<lenrec; nrec++) {
|
for(nrec=0; nrec<lenrec; nrec++) {
|
||||||
cur_bufsize = fread(&rec_buf, 1, PCP_ASYM_RECIPIENT_SIZE, in);
|
cur_bufsize = fread(&rec_buf, 1, PCP_ASYM_RECIPIENT_SIZE, in);
|
||||||
if(cur_bufsize != PCP_ASYM_RECIPIENT_SIZE && !feof(in) && !ferror(in)) {
|
if(cur_bufsize != PCP_ASYM_RECIPIENT_SIZE && !feof(in) && !ferror(in)) {
|
||||||
@@ -239,7 +239,7 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey
|
|||||||
unsigned char *recipient;
|
unsigned char *recipient;
|
||||||
recipient = pcp_box_decrypt(s, cur, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size);
|
recipient = pcp_box_decrypt(s, cur, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size);
|
||||||
if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) {
|
if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) {
|
||||||
// found a match
|
/* found a match */
|
||||||
recmatch = 1;
|
recmatch = 1;
|
||||||
sender = cur;
|
sender = cur;
|
||||||
symkey = ucmalloc(crypto_secretbox_KEYBYTES);
|
symkey = ucmalloc(crypto_secretbox_KEYBYTES);
|
||||||
@@ -259,7 +259,7 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// step 5, actually decrypt the file, finally
|
/* step 5, actually decrypt the file, finally */
|
||||||
if(verify) {
|
if(verify) {
|
||||||
pcp_rec_t *rec = pcp_rec_new(reccipher, nrec * PCP_ASYM_RECIPIENT_SIZE, NULL, cur);
|
pcp_rec_t *rec = pcp_rec_new(reccipher, nrec * PCP_ASYM_RECIPIENT_SIZE, NULL, cur);
|
||||||
return pcp_decrypt_file_sym(in, out, symkey, rec);
|
return pcp_decrypt_file_sym(in, out, symkey, rec);
|
||||||
@@ -290,11 +290,11 @@ size_t pcp_encrypt_file(FILE *in, FILE* out, pcp_key_t *s, pcp_pubkey_t *p, int
|
|||||||
random_nonce|box(temp_keypair.privkey, recipient crypto pk, random_nonce, packet key)
|
random_nonce|box(temp_keypair.privkey, recipient crypto pk, random_nonce, packet key)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// preparation
|
/* preparation */
|
||||||
// A, generate sym key
|
/* A, generate sym key */
|
||||||
symkey = urmalloc(crypto_secretbox_KEYBYTES);
|
symkey = urmalloc(crypto_secretbox_KEYBYTES);
|
||||||
|
|
||||||
// B, encrypt it asymetrically for each recipient
|
/* B, encrypt it asymetrically for each recipient */
|
||||||
recipient_count = HASH_COUNT(p);
|
recipient_count = HASH_COUNT(p);
|
||||||
rec_size = PCP_ASYM_RECIPIENT_SIZE;
|
rec_size = PCP_ASYM_RECIPIENT_SIZE;
|
||||||
recipients_cipher = ucmalloc(rec_size * recipient_count);
|
recipients_cipher = ucmalloc(rec_size * recipient_count);
|
||||||
@@ -308,45 +308,45 @@ size_t pcp_encrypt_file(FILE *in, FILE* out, pcp_key_t *s, pcp_pubkey_t *p, int
|
|||||||
free(rec_cipher);
|
free(rec_cipher);
|
||||||
goto errec1;
|
goto errec1;
|
||||||
}
|
}
|
||||||
memcpy(&recipients_cipher[nrec * rec_size], rec_cipher, rec_size); // already includes the nonce
|
memcpy(&recipients_cipher[nrec * rec_size], rec_cipher, rec_size); /* already includes the nonce */
|
||||||
nrec++;
|
nrec++;
|
||||||
free(rec_cipher);
|
free(rec_cipher);
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 1, file header
|
/* step 1, file header */
|
||||||
head[0] = PCP_ASYM_CIPHER;
|
head[0] = PCP_ASYM_CIPHER;
|
||||||
fwrite(head, 1, 1, out);
|
fwrite(head, 1, 1, out);
|
||||||
//fprintf(stderr, "D: header - 1\n");
|
/* fprintf(stderr, "D: header - 1\n"); */
|
||||||
if(ferror(out) != 0) {
|
if(ferror(out) != 0) {
|
||||||
fatal("Failed to write encrypted output!\n");
|
fatal("Failed to write encrypted output!\n");
|
||||||
goto errec1;
|
goto errec1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PCP_ASYM_ADD_SENDER_PUB
|
#ifdef PCP_ASYM_ADD_SENDER_PUB
|
||||||
// step 2, sender's pubkey
|
/* step 2, sender's pubkey */
|
||||||
fwrite(s->pub, crypto_box_PUBLICKEYBYTES, 1, out);
|
fwrite(s->pub, crypto_box_PUBLICKEYBYTES, 1, out);
|
||||||
//fprintf(stderr, "D: sender pub - %d\n", crypto_box_PUBLICKEYBYTES);
|
/* fprintf(stderr, "D: sender pub - %d\n", crypto_box_PUBLICKEYBYTES); */
|
||||||
if(ferror(out) != 0)
|
if(ferror(out) != 0)
|
||||||
goto errec1;
|
goto errec1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// step 3, len recipients, big endian
|
/* step 3, len recipients, big endian */
|
||||||
lenrec = recipient_count;
|
lenrec = recipient_count;
|
||||||
lenrec = htobe32(lenrec);
|
lenrec = htobe32(lenrec);
|
||||||
fwrite(&lenrec, 4, 1, out);
|
fwrite(&lenrec, 4, 1, out);
|
||||||
//fprintf(stderr, "D: %d recipients - 4\n", recipient_count);
|
/* fprintf(stderr, "D: %d recipients - 4\n", recipient_count); */
|
||||||
if(ferror(out) != 0)
|
if(ferror(out) != 0)
|
||||||
goto errec1;
|
goto errec1;
|
||||||
|
|
||||||
// step 4, recipient list
|
/* step 4, recipient list */
|
||||||
fwrite(recipients_cipher, rec_size * recipient_count, 1, out);
|
fwrite(recipients_cipher, rec_size * recipient_count, 1, out);
|
||||||
//fprintf(stderr, "D: recipients - %ld * %d\n", rec_size, recipient_count);
|
/* fprintf(stderr, "D: recipients - %ld * %d\n", rec_size, recipient_count); */
|
||||||
if(ferror(out) != 0)
|
if(ferror(out) != 0)
|
||||||
goto errec1;
|
goto errec1;
|
||||||
|
|
||||||
out_size = 5 + (rec_size * recipient_count) + crypto_box_PUBLICKEYBYTES;
|
out_size = 5 + (rec_size * recipient_count) + crypto_box_PUBLICKEYBYTES;
|
||||||
|
|
||||||
// step 5, actual encrypted data
|
/* step 5, actual encrypted data */
|
||||||
size_t sym_size = 0;
|
size_t sym_size = 0;
|
||||||
if(sign) {
|
if(sign) {
|
||||||
pcp_rec_t *rec = pcp_rec_new(recipients_cipher, rec_size * recipient_count, s, NULL);
|
pcp_rec_t *rec = pcp_rec_new(recipients_cipher, rec_size * recipient_count, s, NULL);
|
||||||
@@ -409,16 +409,16 @@ size_t pcp_encrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, int have
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PCP_CBC
|
#ifdef PCP_CBC
|
||||||
// write the IV, pad it with rubbish, since pcp_decrypt_file_sym
|
/* write the IV, pad it with rubbish, since pcp_decrypt_file_sym */
|
||||||
// reads in with PCP_BLOCK_SIZE_IN buffersize and uses the last
|
/* reads in with PCP_BLOCK_SIZE_IN buffersize and uses the last */
|
||||||
// PCP_BLOCK_SIZE as IV.
|
/* PCP_BLOCK_SIZE as IV. */
|
||||||
unsigned char *iv = urmalloc(PCP_BLOCK_SIZE);
|
unsigned char *iv = urmalloc(PCP_BLOCK_SIZE);
|
||||||
unsigned char *ivpad = urmalloc(PCP_BLOCK_SIZE_IN - PCP_BLOCK_SIZE);
|
unsigned char *ivpad = urmalloc(PCP_BLOCK_SIZE_IN - PCP_BLOCK_SIZE);
|
||||||
fwrite(ivpad, PCP_BLOCK_SIZE_IN - PCP_BLOCK_SIZE, 1, out);
|
fwrite(ivpad, PCP_BLOCK_SIZE_IN - PCP_BLOCK_SIZE, 1, out);
|
||||||
fwrite(iv, PCP_BLOCK_SIZE, 1, out);
|
fwrite(iv, PCP_BLOCK_SIZE, 1, out);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 32k-ECB-mode. FIXME: maybe support CBC as well or only use CBC?
|
/* 32k-ECB-mode. FIXME: maybe support CBC as well or only use CBC? */
|
||||||
while(!feof(in)) {
|
while(!feof(in)) {
|
||||||
cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE, in);
|
cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE, in);
|
||||||
if(cur_bufsize <= 0)
|
if(cur_bufsize <= 0)
|
||||||
@@ -426,7 +426,7 @@ size_t pcp_encrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, int have
|
|||||||
buf_nonce = pcp_gennonce();
|
buf_nonce = pcp_gennonce();
|
||||||
|
|
||||||
#ifdef PCP_CBC
|
#ifdef PCP_CBC
|
||||||
// apply IV to current clear
|
/* apply IV to current clear */
|
||||||
_xorbuf(iv, in_buf, cur_bufsize);
|
_xorbuf(iv, in_buf, cur_bufsize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -442,7 +442,7 @@ size_t pcp_encrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, int have
|
|||||||
crypto_generichash_update(st, in_buf, cur_bufsize);
|
crypto_generichash_update(st, in_buf, cur_bufsize);
|
||||||
|
|
||||||
#ifdef PCP_CBC
|
#ifdef PCP_CBC
|
||||||
// make current cipher to next IV, ignore nonce and pad
|
/* make current cipher to next IV, ignore nonce and pad */
|
||||||
memcpy(iv, &buf_cipher[PCP_CRYPTO_ADD], PCP_BLOCK_SIZE);
|
memcpy(iv, &buf_cipher[PCP_CRYPTO_ADD], PCP_BLOCK_SIZE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -514,17 +514,17 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PCP_CBC
|
#ifdef PCP_CBC
|
||||||
unsigned char *iv = NULL; // will be filled during 1st loop
|
unsigned char *iv = NULL; /* will be filled during 1st loop */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(!feof(in)) {
|
while(!feof(in)) {
|
||||||
cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE_IN, in);
|
cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE_IN, in);
|
||||||
if(cur_bufsize <= PCP_CRYPTO_ADD)
|
if(cur_bufsize <= PCP_CRYPTO_ADD)
|
||||||
break; // no valid cipher block
|
break; /* no valid cipher block */
|
||||||
|
|
||||||
if(recverify != NULL) {
|
if(recverify != NULL) {
|
||||||
if(cur_bufsize < PCP_BLOCK_SIZE_IN || feof(in)) {
|
if(cur_bufsize < PCP_BLOCK_SIZE_IN || feof(in)) {
|
||||||
// pull out signature
|
/* pull out signature */
|
||||||
memcpy(signature_cr, &in_buf[cur_bufsize - siglen_cr], siglen_cr);
|
memcpy(signature_cr, &in_buf[cur_bufsize - siglen_cr], siglen_cr);
|
||||||
cur_bufsize -= siglen_cr;
|
cur_bufsize -= siglen_cr;
|
||||||
}
|
}
|
||||||
@@ -532,7 +532,7 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_
|
|||||||
|
|
||||||
#ifdef PCP_CBC
|
#ifdef PCP_CBC
|
||||||
if(iv == NULL) {
|
if(iv == NULL) {
|
||||||
// first block is the IV, don't write it out and skip to the next block
|
/* first block is the IV, don't write it out and skip to the next block */
|
||||||
iv = ucmalloc(PCP_BLOCK_SIZE);
|
iv = ucmalloc(PCP_BLOCK_SIZE);
|
||||||
memcpy(iv, &in_buf[PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES], PCP_BLOCK_SIZE);
|
memcpy(iv, &in_buf[PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES], PCP_BLOCK_SIZE);
|
||||||
continue;
|
continue;
|
||||||
@@ -546,7 +546,7 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_
|
|||||||
es = pcp_sodium_verify_mac(&buf_clear, buf_cipher, ciphersize, buf_nonce, symkey);
|
es = pcp_sodium_verify_mac(&buf_clear, buf_cipher, ciphersize, buf_nonce, symkey);
|
||||||
|
|
||||||
#ifdef PCP_CBC
|
#ifdef PCP_CBC
|
||||||
// take last IV and apply it to current clear
|
/* take last IV and apply it to current clear */
|
||||||
_xorbuf(iv, buf_clear, cur_bufsize - (PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES));
|
_xorbuf(iv, buf_clear, cur_bufsize - (PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -573,7 +573,7 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef PCP_CBC
|
#ifdef PCP_CBC
|
||||||
// use last cipher as next IV
|
/* use last cipher as next IV */
|
||||||
memcpy(iv, &in_buf[PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES], PCP_BLOCK_SIZE);
|
memcpy(iv, &in_buf[PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES], PCP_BLOCK_SIZE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -597,7 +597,7 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_
|
|||||||
out_size = 0;
|
out_size = 0;
|
||||||
else {
|
else {
|
||||||
if(memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) {
|
if(memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) {
|
||||||
// sig verified, but the hash doesn't match
|
/* sig verified, but the hash doesn't match */
|
||||||
fatal("signed hash doesn't match actual hash of signed decrypted file content\n");
|
fatal("signed hash doesn't match actual hash of signed decrypted file content\n");
|
||||||
out_size = 0;
|
out_size = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
#include <digital_crc32.h>
|
#include <digital_crc32.h>
|
||||||
|
|
||||||
|
|
||||||
// Automatically generated CRC function
|
/* Automatically generated CRC function */
|
||||||
// polynomial: 0x104C11DB7
|
/* polynomial: 0x104C11DB7 */
|
||||||
unsigned int
|
unsigned int
|
||||||
digital_update_crc32(unsigned int crc, const unsigned char *data, size_t len)
|
digital_update_crc32(unsigned int crc, const unsigned char *data, size_t len)
|
||||||
{
|
{
|
||||||
|
|||||||
62
libpcp/ed.c
62
libpcp/ed.c
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
unsigned char * pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey_t *p) {
|
unsigned char * pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey_t *p) {
|
||||||
unsigned char *message = ucmalloc(siglen - crypto_sign_BYTES);
|
unsigned char *message = ucmalloc(siglen - crypto_sign_BYTES);
|
||||||
size_t mlen;
|
unsigned long long mlen;
|
||||||
|
|
||||||
if(crypto_sign_open(message, &mlen, signature, siglen, p->edpub) != 0) {
|
if(crypto_sign_open(message, &mlen, signature, siglen, p->edpub) != 0) {
|
||||||
fatal("Failed to open the signature using the public key 0x%s!\n", p->id);
|
fatal("Failed to open the signature using the public key 0x%s!\n", p->id);
|
||||||
@@ -38,7 +38,7 @@ unsigned char * pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubke
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t *s) {
|
unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t *s) {
|
||||||
size_t mlen = messagesize + crypto_sign_BYTES;
|
unsigned long long mlen = messagesize + crypto_sign_BYTES;
|
||||||
unsigned char *signature = ucmalloc(mlen);
|
unsigned char *signature = ucmalloc(mlen);
|
||||||
|
|
||||||
crypto_sign(signature, &mlen, message, messagesize, s->edsecret);
|
crypto_sign(signature, &mlen, message, messagesize, s->edsecret);
|
||||||
@@ -114,9 +114,9 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
unsigned char hash[crypto_generichash_BYTES_MAX];
|
unsigned char hash[crypto_generichash_BYTES_MAX];
|
||||||
char zhead[] = PCP_SIG_HEADER;
|
char zhead[] = PCP_SIG_HEADER;
|
||||||
size_t hlen = strlen(PCP_SIG_HEADER);
|
size_t hlen = strlen(PCP_SIG_HEADER);
|
||||||
size_t hlen2 = 15; // hash: blake2\n\n
|
size_t hlen2 = 15; /* hash: blake2\n\n */
|
||||||
size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX;
|
size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX;
|
||||||
size_t zlen = 262; // FIXME: calculate
|
size_t zlen = 262; /* FIXME: calculate */
|
||||||
unsigned char z85encoded[zlen];
|
unsigned char z85encoded[zlen];
|
||||||
unsigned char sighash[mlen];
|
unsigned char sighash[mlen];
|
||||||
char z85sigstart[] = PCP_SIG_START;
|
char z85sigstart[] = PCP_SIG_START;
|
||||||
@@ -131,20 +131,20 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
/* use two half blocks, to overcome sigs spanning block boundaries */
|
/* use two half blocks, to overcome sigs spanning block boundaries */
|
||||||
cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE/2, in);
|
cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE/2, in);
|
||||||
|
|
||||||
// look for z85 header and cut it out
|
/* look for z85 header and cut it out */
|
||||||
if(_findoffset(in_buf, cur_bufsize, zhead, hlen) == 0) {
|
if(_findoffset(in_buf, cur_bufsize, zhead, hlen) == 0) {
|
||||||
// it is armored
|
/* it is armored */
|
||||||
next_bufsize = cur_bufsize - (hlen+hlen2); // size - the header
|
next_bufsize = cur_bufsize - (hlen+hlen2); /* size - the header */
|
||||||
memcpy(in_next, &in_buf[hlen+hlen2], next_bufsize); // tmp save
|
memcpy(in_next, &in_buf[hlen+hlen2], next_bufsize); /* tmp save */
|
||||||
memcpy(in_buf, in_next, next_bufsize); // put into inbuf without header
|
memcpy(in_buf, in_next, next_bufsize); /* put into inbuf without header */
|
||||||
if(cur_bufsize == PCP_BLOCK_SIZE/2) {
|
if(cur_bufsize == PCP_BLOCK_SIZE/2) {
|
||||||
// more to come
|
/* more to come */
|
||||||
cur_bufsize = fread(&in_buf[next_bufsize], 1, ((PCP_BLOCK_SIZE/2) - next_bufsize), in);
|
cur_bufsize = fread(&in_buf[next_bufsize], 1, ((PCP_BLOCK_SIZE/2) - next_bufsize), in);
|
||||||
cur_bufsize += next_bufsize;
|
cur_bufsize += next_bufsize;
|
||||||
next_bufsize = 0;
|
next_bufsize = 0;
|
||||||
// now we've got the 1st half block in in_buf
|
/* now we've got the 1st half block in in_buf */
|
||||||
// unless the file was smaller than blocksize/2,
|
/* unless the file was smaller than blocksize/2, */
|
||||||
// in which case it contains all the rest til eof
|
/* in which case it contains all the rest til eof */
|
||||||
}
|
}
|
||||||
z85 = 1;
|
z85 = 1;
|
||||||
}
|
}
|
||||||
@@ -163,13 +163,13 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
|
|
||||||
while (cur_bufsize > 0) {
|
while (cur_bufsize > 0) {
|
||||||
if(cur_bufsize == PCP_BLOCK_SIZE/2) {
|
if(cur_bufsize == PCP_BLOCK_SIZE/2) {
|
||||||
// probably not eof
|
/* probably not eof */
|
||||||
next_bufsize = fread(&in_next, 1, PCP_BLOCK_SIZE/2, in);
|
next_bufsize = fread(&in_next, 1, PCP_BLOCK_SIZE/2, in);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
next_bufsize = 0; // <= this is eof
|
next_bufsize = 0; /* <= this is eof */
|
||||||
|
|
||||||
// concatenate previous and current buffer
|
/* concatenate previous and current buffer */
|
||||||
if(next_bufsize == 0)
|
if(next_bufsize == 0)
|
||||||
memcpy(in_full, in_buf, cur_bufsize);
|
memcpy(in_full, in_buf, cur_bufsize);
|
||||||
else {
|
else {
|
||||||
@@ -178,14 +178,14 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
}
|
}
|
||||||
full_bufsize = cur_bufsize+next_bufsize;
|
full_bufsize = cur_bufsize+next_bufsize;
|
||||||
|
|
||||||
// find signature offset
|
/* find signature offset */
|
||||||
offset = _findoffset(in_full, full_bufsize, sigstart, startlen);
|
offset = _findoffset(in_full, full_bufsize, sigstart, startlen);
|
||||||
|
|
||||||
//printf("offset: %ld, full: %ld, cur: %ld\n", offset, full_bufsize, cur_bufsize);
|
/* printf("offset: %ld, full: %ld, cur: %ld\n", offset, full_bufsize, cur_bufsize); */
|
||||||
|
|
||||||
if(offset >= 0 && offset <= PCP_BLOCK_SIZE/2) {
|
if(offset >= 0 && offset <= PCP_BLOCK_SIZE/2) {
|
||||||
// sig begins within the first half, adjust in_buf size
|
/* sig begins within the first half, adjust in_buf size */
|
||||||
//printf("1st half\n");
|
/* printf("1st half\n"); */
|
||||||
next_bufsize = 0;
|
next_bufsize = 0;
|
||||||
cur_bufsize = offset;
|
cur_bufsize = offset;
|
||||||
gotsig = 1;
|
gotsig = 1;
|
||||||
@@ -197,9 +197,9 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
memcpy(sighash, &in_full[offset + strlen(binsigstart)], mlen);
|
memcpy(sighash, &in_full[offset + strlen(binsigstart)], mlen);
|
||||||
}
|
}
|
||||||
else if(full_bufsize - offset == siglen) {
|
else if(full_bufsize - offset == siglen) {
|
||||||
// sig fits within the 2nd half
|
/* sig fits within the 2nd half */
|
||||||
// offset: 28279, full: 28413, cur: 16384
|
/* offset: 28279, full: 28413, cur: 16384 */
|
||||||
//printf("2nd half\n");
|
/* printf("2nd half\n"); */
|
||||||
next_bufsize -= siglen;
|
next_bufsize -= siglen;
|
||||||
gotsig = 1;
|
gotsig = 1;
|
||||||
if(z85) {
|
if(z85) {
|
||||||
@@ -212,17 +212,17 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
else
|
else
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
// add previous half block to hash
|
/* add previous half block to hash */
|
||||||
crypto_generichash_update(st, in_buf, cur_bufsize);
|
crypto_generichash_update(st, in_buf, cur_bufsize);
|
||||||
|
|
||||||
// next => in
|
/* next => in */
|
||||||
if(next_bufsize > 0) {
|
if(next_bufsize > 0) {
|
||||||
memcpy(in_buf, in_next, next_bufsize);
|
memcpy(in_buf, in_next, next_bufsize);
|
||||||
cur_bufsize = next_bufsize;
|
cur_bufsize = next_bufsize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} // while
|
} /* while */
|
||||||
|
|
||||||
if(gotsig == 0) {
|
if(gotsig == 0) {
|
||||||
fatal("Error, the signature doesn't contain the ed25519 signed hash\n");
|
fatal("Error, the signature doesn't contain the ed25519 signed hash\n");
|
||||||
@@ -244,9 +244,9 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
}
|
}
|
||||||
memcpy(sighash, z85decoded, mlen);
|
memcpy(sighash, z85decoded, mlen);
|
||||||
}
|
}
|
||||||
// else: if unarmored, sighash is already filled
|
/* else: if unarmored, sighash is already filled */
|
||||||
|
|
||||||
// huh, how did we made it til here?
|
/* huh, how did we made it til here? */
|
||||||
unsigned char *verifiedhash = NULL;
|
unsigned char *verifiedhash = NULL;
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
pcphash_iteratepub(p) {
|
pcphash_iteratepub(p) {
|
||||||
@@ -263,7 +263,7 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
|
|||||||
goto errvb1;
|
goto errvb1;
|
||||||
|
|
||||||
if(memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) {
|
if(memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) {
|
||||||
// sig verified, but the hash doesn't
|
/* sig verified, but the hash doesn't */
|
||||||
fatal("signed hash doesn't match actual hash of signed file content\n");
|
fatal("signed hash doesn't match actual hash of signed file content\n");
|
||||||
free(verifiedhash);
|
free(verifiedhash);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -335,7 +335,7 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(FILE *in, FILE *sigfd, pcp_pubkey_t *
|
|||||||
|
|
||||||
crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX);
|
crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX);
|
||||||
|
|
||||||
// read the sig
|
/* read the sig */
|
||||||
unsigned char *sig = NULL;
|
unsigned char *sig = NULL;
|
||||||
size_t inputBufSize = 0;
|
size_t inputBufSize = 0;
|
||||||
unsigned char byte[1];
|
unsigned char byte[1];
|
||||||
@@ -386,7 +386,7 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(FILE *in, FILE *sigfd, pcp_pubkey_t *
|
|||||||
goto errdea4;
|
goto errdea4;
|
||||||
|
|
||||||
if(memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) {
|
if(memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) {
|
||||||
// sig verified, but the hash doesn't
|
/* sig verified, but the hash doesn't */
|
||||||
fatal("signed hash doesn't match actual hash of signed file content\n");
|
fatal("signed hash doesn't match actual hash of signed file content\n");
|
||||||
goto errdea5;
|
goto errdea5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ char *pcp_get_stdin() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
line[linelen - 1] = '\0'; // remove newline at end
|
line[linelen - 1] = '\0'; /* remove newline at end */
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
63
libpcp/key.c
63
libpcp/key.c
@@ -32,13 +32,13 @@ unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) {
|
|||||||
unsigned char *key = ucmalloc(crypto_secretbox_KEYBYTES);
|
unsigned char *key = ucmalloc(crypto_secretbox_KEYBYTES);
|
||||||
size_t plen = strnlen(passphrase, 255);
|
size_t plen = strnlen(passphrase, 255);
|
||||||
|
|
||||||
// create the scrypt hash
|
/* create the scrypt hash */
|
||||||
unsigned char *scrypted = pcp_scrypt(passphrase, plen, nonce, crypto_secretbox_NONCEBYTES);
|
unsigned char *scrypted = pcp_scrypt(passphrase, plen, nonce, crypto_secretbox_NONCEBYTES);
|
||||||
|
|
||||||
// make a hash from the scrypt() result
|
/* make a hash from the scrypt() result */
|
||||||
crypto_hash_sha256(key, (unsigned char*)scrypted, 64);
|
crypto_hash_sha256(key, (unsigned char*)scrypted, 64);
|
||||||
|
|
||||||
// turn the 32byte hash into a secret key
|
/* turn the 32byte hash into a secret key */
|
||||||
key[0] &= 248;
|
key[0] &= 248;
|
||||||
key[31] &= 127;
|
key[31] &= 127;
|
||||||
key[31] |= 64;
|
key[31] |= 64;
|
||||||
@@ -48,41 +48,6 @@ unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* deprecated
|
|
||||||
unsigned char *pcp_derivekey(char *passphrase) {
|
|
||||||
unsigned char *hash32 = ucmalloc(crypto_hash_sha256_BYTES);
|
|
||||||
unsigned char *key = ucmalloc(crypto_secretbox_KEYBYTES);
|
|
||||||
|
|
||||||
size_t plen = strnlen(passphrase, 255);
|
|
||||||
unsigned char *temp = ucmalloc(crypto_hash_sha256_BYTES);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// make a hash from the passphrase and then HCYCLES times from the result
|
|
||||||
crypto_hash_sha256(temp, (unsigned char*)passphrase, plen);
|
|
||||||
|
|
||||||
for(i=0; i<HCYCLES; ++i) {
|
|
||||||
if(crypto_hash_sha256(hash32, temp, crypto_hash_sha256_BYTES) == 0) {
|
|
||||||
memcpy(temp, hash32, crypto_hash_sha256_BYTES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// turn the 32byte hash into a secret key
|
|
||||||
temp[0] &= 248;
|
|
||||||
temp[31] &= 127;
|
|
||||||
temp[31] |= 64;
|
|
||||||
|
|
||||||
memcpy(key, temp, crypto_secretbox_KEYBYTES);
|
|
||||||
|
|
||||||
memset(passphrase, 0, plen);
|
|
||||||
memset(temp, 0, crypto_hash_sha256_BYTES);
|
|
||||||
|
|
||||||
free(temp);
|
|
||||||
free(hash32);
|
|
||||||
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *pcp_getkeyid(pcp_key_t *k) {
|
char *pcp_getkeyid(pcp_key_t *k) {
|
||||||
uint32_t s, p;
|
uint32_t s, p;
|
||||||
@@ -93,7 +58,7 @@ char *pcp_getkeyid(pcp_key_t *k) {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// same as above but for imported pbp keys
|
/* same as above but for imported pbp keys */
|
||||||
char *pcp_getpubkeyid(pcp_pubkey_t *k) {
|
char *pcp_getpubkeyid(pcp_pubkey_t *k) {
|
||||||
uint32_t s, p;
|
uint32_t s, p;
|
||||||
p = jen_hash(k->pub, 32, JEN_PSALT);
|
p = jen_hash(k->pub, 32, JEN_PSALT);
|
||||||
@@ -104,20 +69,20 @@ char *pcp_getpubkeyid(pcp_pubkey_t *k) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pcp_keypairs(byte *csk, byte *cpk, byte *esk, byte *epk) {
|
void pcp_keypairs(byte *csk, byte *cpk, byte *esk, byte *epk) {
|
||||||
// generate ed25519 + curve25519 keypair from random seed
|
/* generate ed25519 + curve25519 keypair from random seed */
|
||||||
byte *seed = urmalloc(32);
|
byte *seed = urmalloc(32);
|
||||||
byte *tmp = urmalloc(32);
|
byte *tmp = urmalloc(32);
|
||||||
|
|
||||||
// ed25519 signing key
|
/* ed25519 signing key */
|
||||||
crypto_sign_seed_keypair(epk, esk, seed);
|
crypto_sign_seed_keypair(epk, esk, seed);
|
||||||
|
|
||||||
// curve25519 secret key
|
/* curve25519 secret key */
|
||||||
tmp[0] &= 248;
|
tmp[0] &= 248;
|
||||||
tmp[31] &= 63;
|
tmp[31] &= 63;
|
||||||
tmp[31] |= 64;
|
tmp[31] |= 64;
|
||||||
memcpy(csk, tmp, 32);
|
memcpy(csk, tmp, 32);
|
||||||
|
|
||||||
// curve25519 public key
|
/* curve25519 public key */
|
||||||
crypto_scalarmult_curve25519_base(cpk, csk);
|
crypto_scalarmult_curve25519_base(cpk, csk);
|
||||||
memset(tmp, 0, 32);
|
memset(tmp, 0, 32);
|
||||||
}
|
}
|
||||||
@@ -130,7 +95,7 @@ pcp_key_t * pcpkey_new () {
|
|||||||
|
|
||||||
pcp_keypairs(secret, pub, edsec, edpub);
|
pcp_keypairs(secret, pub, edsec, edpub);
|
||||||
|
|
||||||
// fill in our struct
|
/* fill in our struct */
|
||||||
pcp_key_t *key = urmalloc(sizeof(pcp_key_t));
|
pcp_key_t *key = urmalloc(sizeof(pcp_key_t));
|
||||||
memcpy (key->pub, pub, 32);
|
memcpy (key->pub, pub, 32);
|
||||||
memcpy (key->secret, secret, 32);
|
memcpy (key->secret, secret, 32);
|
||||||
@@ -175,7 +140,7 @@ pcp_key_t *pcpkey_encrypt(pcp_key_t *key, char *passphrase) {
|
|||||||
free(both);
|
free(both);
|
||||||
|
|
||||||
if(es == 112) {
|
if(es == 112) {
|
||||||
// success
|
/* success */
|
||||||
memcpy(key->encrypted, encrypted, 112);
|
memcpy(key->encrypted, encrypted, 112);
|
||||||
arc4random_buf(key->secret, 32);
|
arc4random_buf(key->secret, 32);
|
||||||
arc4random_buf(key->edsecret, 64);
|
arc4random_buf(key->edsecret, 64);
|
||||||
@@ -203,7 +168,7 @@ pcp_key_t *pcpkey_decrypt(pcp_key_t *key, char *passphrase) {
|
|||||||
free(encryptkey);
|
free(encryptkey);
|
||||||
|
|
||||||
if(es == 0) {
|
if(es == 0) {
|
||||||
// success
|
/* success */
|
||||||
memcpy(key->edsecret, decrypted, 64);
|
memcpy(key->edsecret, decrypted, 64);
|
||||||
memcpy(key->secret, &decrypted[64], 32);
|
memcpy(key->secret, &decrypted[64], 32);
|
||||||
}
|
}
|
||||||
@@ -217,7 +182,7 @@ pcp_key_t *pcpkey_decrypt(pcp_key_t *key, char *passphrase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pcp_pubkey_t *pcpkey_pub_from_secret(pcp_key_t *key) {
|
pcp_pubkey_t *pcpkey_pub_from_secret(pcp_key_t *key) {
|
||||||
//pcp_dumpkey(key);
|
/* pcp_dumpkey(key); */
|
||||||
pcp_pubkey_t *pub = urmalloc(sizeof (pcp_pubkey_t));
|
pcp_pubkey_t *pub = urmalloc(sizeof (pcp_pubkey_t));
|
||||||
memcpy(pub->pub, key->pub, 32);
|
memcpy(pub->pub, key->pub, 32);
|
||||||
memcpy(pub->edpub, key->edpub, 32);
|
memcpy(pub->edpub, key->edpub, 32);
|
||||||
@@ -365,7 +330,7 @@ int pcp_sanitycheck_pub(pcp_pubkey_t *key) {
|
|||||||
time_t t = (time_t)key->ctime;
|
time_t t = (time_t)key->ctime;
|
||||||
c = localtime(&t);
|
c = localtime(&t);
|
||||||
if(c->tm_year <= 0 || c->tm_year > 1100) {
|
if(c->tm_year <= 0 || c->tm_year > 1100) {
|
||||||
// well, I'm perhaps overacting here :)
|
/* well, I'm perhaps overacting here :) */
|
||||||
fatal("Pubkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
|
fatal("Pubkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -416,7 +381,7 @@ int pcp_sanitycheck_key(pcp_key_t *key) {
|
|||||||
time_t t = (time_t)key->ctime;
|
time_t t = (time_t)key->ctime;
|
||||||
c = localtime(&t);
|
c = localtime(&t);
|
||||||
if(c->tm_year <= 0 || c->tm_year > 1100) {
|
if(c->tm_year <= 0 || c->tm_year > 1100) {
|
||||||
// well, I'm perhaps overacting here :)
|
/* well, I'm perhaps overacting here :) */
|
||||||
fatal("Secretkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
|
fatal("Secretkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,13 +65,13 @@ void pcphash_clean() {
|
|||||||
pcp_key_t *pcphash_keyexists(char *id) {
|
pcp_key_t *pcphash_keyexists(char *id) {
|
||||||
pcp_key_t *key = NULL;
|
pcp_key_t *key = NULL;
|
||||||
HASH_FIND_STR(pcpkey_hash, id, key);
|
HASH_FIND_STR(pcpkey_hash, id, key);
|
||||||
return key; // maybe NULL!
|
return key; /* maybe NULL! */
|
||||||
}
|
}
|
||||||
|
|
||||||
pcp_pubkey_t *pcphash_pubkeyexists(char *id) {
|
pcp_pubkey_t *pcphash_pubkeyexists(char *id) {
|
||||||
pcp_pubkey_t *key = NULL;
|
pcp_pubkey_t *key = NULL;
|
||||||
HASH_FIND_STR(pcppubkey_hash, id, key);
|
HASH_FIND_STR(pcppubkey_hash, id, key);
|
||||||
return key; // maybe NULL!
|
return key; /* maybe NULL! */
|
||||||
}
|
}
|
||||||
|
|
||||||
void pcphash_add(void *key, int type) {
|
void pcphash_add(void *key, int type) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ size_t pcp_sodium_mac(unsigned char **cipher,
|
|||||||
int pcp_sodium_verify_mac(unsigned char **cleartext, unsigned char* message,
|
int pcp_sodium_verify_mac(unsigned char **cleartext, unsigned char* message,
|
||||||
size_t messagesize, unsigned char *nonce,
|
size_t messagesize, unsigned char *nonce,
|
||||||
unsigned char *key) {
|
unsigned char *key) {
|
||||||
// verify the mac
|
/* verify the mac */
|
||||||
unsigned char *pad_cipher;
|
unsigned char *pad_cipher;
|
||||||
unsigned char *pad_clear;
|
unsigned char *pad_clear;
|
||||||
int success = -1;
|
int success = -1;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ void *ucmalloc(size_t s) {
|
|||||||
|
|
||||||
memset (value, 0, size);
|
memset (value, 0, size);
|
||||||
|
|
||||||
//printf("allocated %d bytes at %p\n", (int)size, value);
|
/* printf("allocated %d bytes at %p\n", (int)size, value); */
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,3 @@ void *urmalloc(size_t s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *ucfree(void *ptr) {
|
|
||||||
free(ptr);
|
|
||||||
ptr = NULL;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded,
|
|||||||
*padded = ucmalloc(unpadlen + padlen);
|
*padded = ucmalloc(unpadlen + padlen);
|
||||||
unsigned char *tmp = ucmalloc(unpadlen + padlen);
|
unsigned char *tmp = ucmalloc(unpadlen + padlen);
|
||||||
|
|
||||||
// pcp_append orig
|
/* pcp_append orig */
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<unpadlen; ++i) {
|
for(i=0; i<unpadlen; ++i) {
|
||||||
tmp[i + padlen] = unpadded[i];
|
tmp[i + padlen] = unpadded[i];
|
||||||
@@ -60,15 +60,15 @@ int main(int argc, char **argv) {
|
|||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
|
|
||||||
pcp_pad_prepend(&dst, argv[1], padlen, unpadlen);
|
pcp_pad_prepend(&dst, argv[1], padlen, unpadlen);
|
||||||
//printf(" prev: %s\n after: %s\n", argv[1], dst);
|
/* printf(" prev: %s\n after: %s\n", argv[1], dst); */
|
||||||
|
|
||||||
unsigned char *reverse;
|
unsigned char *reverse;
|
||||||
pcp_pad_remove(&reverse, dst, padlen, unpadlen);
|
pcp_pad_remove(&reverse, dst, padlen, unpadlen);
|
||||||
//printf("reverse: %s\n", reverse);
|
/* printf("reverse: %s\n", reverse); */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//fprintf(stderr, "Usage: pad <string> <padlen>\n");
|
/* fprintf(stderr, "Usage: pad <string> <padlen>\n"); */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
#include "scrypt.h"
|
#include "scrypt.h"
|
||||||
|
|
||||||
unsigned char* pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen) {
|
unsigned char* pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen) {
|
||||||
uint8_t *dk = ucmalloc(64); // resulting hash
|
uint8_t *dk = ucmalloc(64); /* resulting hash */
|
||||||
|
|
||||||
// constants
|
/* constants */
|
||||||
uint64_t N = 1 << 14;
|
uint64_t N = 1 << 14;
|
||||||
uint32_t r = 8;
|
uint32_t r = 8;
|
||||||
uint32_t p = 1;
|
uint32_t p = 1;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ vault_t *pcpvault_init(char *filename) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(pcpvault_fetchall(vault) != 0) {
|
if(pcpvault_fetchall(vault) != 0) {
|
||||||
errno = 0; // weird, something sets it to ENOENT and it's not me
|
errno = 0; /* weird, something sets it to ENOENT and it's not me */
|
||||||
pcpvault_close(vault);
|
pcpvault_close(vault);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ int pcpvault_addkey(vault_t *vault, void *item, uint8_t type) {
|
|||||||
saveitem = ucmalloc(sizeof(pcp_pubkey_t));
|
saveitem = ucmalloc(sizeof(pcp_pubkey_t));
|
||||||
memcpy(saveitem, item, sizeof(pcp_pubkey_t));
|
memcpy(saveitem, item, sizeof(pcp_pubkey_t));
|
||||||
pubkey2be((pcp_pubkey_t *)item);
|
pubkey2be((pcp_pubkey_t *)item);
|
||||||
//pcp_dumppubkey((pcp_pubkey_t *)saveitem);
|
/* pcp_dumppubkey((pcp_pubkey_t *)saveitem); */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
itemsize = PCP_RAW_KEYSIZE;
|
itemsize = PCP_RAW_KEYSIZE;
|
||||||
@@ -172,9 +172,9 @@ int pcpvault_addkey(vault_t *vault, void *item, uint8_t type) {
|
|||||||
|
|
||||||
void *blob = pcp_keyblob(item, type);
|
void *blob = pcp_keyblob(item, type);
|
||||||
|
|
||||||
// scip
|
/* scip */
|
||||||
//printf("BLOB (%d):\n", (int)itemsize);
|
/* printf("BLOB (%d):\n", (int)itemsize); */
|
||||||
//pcpprint_bin(stdout, saveitem, itemsize); printf("\n");
|
/* pcpprint_bin(stdout, saveitem, itemsize); printf("\n"); */
|
||||||
|
|
||||||
if(tmp != NULL) {
|
if(tmp != NULL) {
|
||||||
if(pcpvault_copy(vault, tmp) != 0)
|
if(pcpvault_copy(vault, tmp) != 0)
|
||||||
@@ -253,7 +253,7 @@ void pcpvault_update_checksum(vault_t *vault) {
|
|||||||
memcpy(header->checksum, checksum, 32);
|
memcpy(header->checksum, checksum, 32);
|
||||||
memcpy(vault->checksum, checksum, 32);
|
memcpy(vault->checksum, checksum, 32);
|
||||||
|
|
||||||
//printf("write checksum: "); pcpprint_bin(stdout, checksum, 32); printf("\n");
|
/* printf("write checksum: "); pcpprint_bin(stdout, checksum, 32); printf("\n"); */
|
||||||
|
|
||||||
vh2be(header);
|
vh2be(header);
|
||||||
|
|
||||||
@@ -282,16 +282,16 @@ unsigned char *pcpvault_create_checksum(vault_t *vault) {
|
|||||||
|
|
||||||
pcp_pubkey_t *p = NULL;
|
pcp_pubkey_t *p = NULL;
|
||||||
pcphash_iteratepub(p) {
|
pcphash_iteratepub(p) {
|
||||||
//pcp_dumppubkey(p);
|
/* pcp_dumppubkey(p); */
|
||||||
pubkey2be(p);
|
pubkey2be(p);
|
||||||
memcpy(&data[datapos], p, PCP_RAW_PUBKEYSIZE);
|
memcpy(&data[datapos], p, PCP_RAW_PUBKEYSIZE);
|
||||||
pubkey2native(p);
|
pubkey2native(p);
|
||||||
datapos += PCP_RAW_PUBKEYSIZE;
|
datapos += PCP_RAW_PUBKEYSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// scip
|
/* scip */
|
||||||
//printf("DATA (%d) (s: %d, p: %d):\n", (int)datasize, numskeys, numpkeys);
|
/* printf("DATA (%d) (s: %d, p: %d):\n", (int)datasize, numskeys, numpkeys); */
|
||||||
//pcpprint_bin(stdout, data, datasize); printf("\n");
|
/* pcpprint_bin(stdout, data, datasize); printf("\n"); */
|
||||||
|
|
||||||
crypto_hash_sha256(checksum, data, datasize);
|
crypto_hash_sha256(checksum, data, datasize);
|
||||||
|
|
||||||
@@ -303,14 +303,14 @@ unsigned char *pcpvault_create_checksum(vault_t *vault) {
|
|||||||
|
|
||||||
|
|
||||||
int pcpvault_copy(vault_t *tmp, vault_t *vault) {
|
int pcpvault_copy(vault_t *tmp, vault_t *vault) {
|
||||||
// fetch tmp content
|
/* fetch tmp content */
|
||||||
fseek(tmp->fd, 0, SEEK_END);
|
fseek(tmp->fd, 0, SEEK_END);
|
||||||
int tmpsize = ftell(tmp->fd);
|
int tmpsize = ftell(tmp->fd);
|
||||||
fseek(tmp->fd, 0, SEEK_SET);
|
fseek(tmp->fd, 0, SEEK_SET);
|
||||||
unsigned char *in = ucmalloc(tmpsize);
|
unsigned char *in = ucmalloc(tmpsize);
|
||||||
fread(in, tmpsize, 1, tmp->fd);
|
fread(in, tmpsize, 1, tmp->fd);
|
||||||
|
|
||||||
// and put it into the new file
|
/* and put it into the new file */
|
||||||
vault->fd = freopen(vault->filename, "wb+", vault->fd);
|
vault->fd = freopen(vault->filename, "wb+", vault->fd);
|
||||||
if(fwrite(in, tmpsize, 1, vault->fd) != 1) {
|
if(fwrite(in, tmpsize, 1, vault->fd) != 1) {
|
||||||
fatal("Failed to copy %s to %s (write) [keeping %s]\n",
|
fatal("Failed to copy %s to %s (write) [keeping %s]\n",
|
||||||
@@ -405,12 +405,12 @@ int pcpvault_fetchall(vault_t *vault) {
|
|||||||
vh2native(header);
|
vh2native(header);
|
||||||
|
|
||||||
if(header->fileid == PCP_VAULT_ID && header->version == PCP_VAULT_VERSION) {
|
if(header->fileid == PCP_VAULT_ID && header->version == PCP_VAULT_VERSION) {
|
||||||
// loop over the file and slurp everything in
|
/* loop over the file and slurp everything in */
|
||||||
int readpos = 0;
|
int readpos = 0;
|
||||||
pcp_key_t *key;
|
pcp_key_t *key;
|
||||||
pcp_pubkey_t *pubkey;
|
pcp_pubkey_t *pubkey;
|
||||||
int bytesleft = 0;
|
int bytesleft = 0;
|
||||||
int ksize = PCP_RAW_PUBKEYSIZE; // smallest possbile item
|
int ksize = PCP_RAW_PUBKEYSIZE; /* smallest possbile item */
|
||||||
|
|
||||||
pcphash_init();
|
pcphash_init();
|
||||||
|
|
||||||
@@ -420,28 +420,28 @@ int pcpvault_fetchall(vault_t *vault) {
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
readpos = ftell(vault->fd);
|
readpos = ftell(vault->fd);
|
||||||
if(vault->size - readpos >= sizeof(vault_item_header_t)) {
|
if(vault->size - readpos >= sizeof(vault_item_header_t)) {
|
||||||
// an item header follows
|
/* an item header follows */
|
||||||
fread(item, sizeof(vault_item_header_t), 1, vault->fd);
|
fread(item, sizeof(vault_item_header_t), 1, vault->fd);
|
||||||
ih2native(item);
|
ih2native(item);
|
||||||
|
|
||||||
if(item->size > 0) {
|
if(item->size > 0) {
|
||||||
// item is valid
|
/* item is valid */
|
||||||
readpos = ftell(vault->fd);
|
readpos = ftell(vault->fd);
|
||||||
bytesleft = vault->size - readpos;
|
bytesleft = vault->size - readpos;
|
||||||
if(bytesleft >= ksize) {
|
if(bytesleft >= ksize) {
|
||||||
// a key follows
|
/* a key follows */
|
||||||
if(item->type == PCP_KEY_TYPE_MAINSECRET ||
|
if(item->type == PCP_KEY_TYPE_MAINSECRET ||
|
||||||
item->type == PCP_KEY_TYPE_SECRET) {
|
item->type == PCP_KEY_TYPE_SECRET) {
|
||||||
// read a secret key
|
/* read a secret key */
|
||||||
key = ucmalloc(sizeof(pcp_key_t));
|
key = ucmalloc(sizeof(pcp_key_t));
|
||||||
fread(key, PCP_RAW_KEYSIZE, 1, vault->fd);
|
fread(key, PCP_RAW_KEYSIZE, 1, vault->fd);
|
||||||
key2native(key);
|
key2native(key);
|
||||||
//pcp_dumpkey(key);
|
/* pcp_dumpkey(key); */
|
||||||
//pcpprint_bin(stdout, key, sizeof(pcp_key_t));printf("\n");
|
/* pcpprint_bin(stdout, key, sizeof(pcp_key_t));printf("\n"); */
|
||||||
pcphash_add((void *)key, item->type);
|
pcphash_add((void *)key, item->type);
|
||||||
}
|
}
|
||||||
else if(item->type == PCP_KEY_TYPE_PUBLIC) {
|
else if(item->type == PCP_KEY_TYPE_PUBLIC) {
|
||||||
// read a public key
|
/* read a public key */
|
||||||
pubkey = ucmalloc(sizeof(pcp_pubkey_t));
|
pubkey = ucmalloc(sizeof(pcp_pubkey_t));
|
||||||
fread(pubkey, PCP_RAW_PUBKEYSIZE, 1, vault->fd);
|
fread(pubkey, PCP_RAW_PUBKEYSIZE, 1, vault->fd);
|
||||||
pubkey2native(pubkey);
|
pubkey2native(pubkey);
|
||||||
@@ -464,7 +464,7 @@ int pcpvault_fetchall(vault_t *vault) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// no more items
|
/* no more items */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,9 +476,9 @@ int pcpvault_fetchall(vault_t *vault) {
|
|||||||
|
|
||||||
unsigned char *checksum = NULL;
|
unsigned char *checksum = NULL;
|
||||||
checksum = pcpvault_create_checksum(vault);
|
checksum = pcpvault_create_checksum(vault);
|
||||||
//printf(" calc checksum: "); pcpprint_bin(stdout, checksum, 32); printf("\n");
|
/* printf(" calc checksum: "); pcpprint_bin(stdout, checksum, 32); printf("\n"); */
|
||||||
if(pcphash_count() + pcphash_countpub() > 0) {
|
if(pcphash_count() + pcphash_countpub() > 0) {
|
||||||
// only validate the checksum if there are keys
|
/* only validate the checksum if there are keys */
|
||||||
if(memcmp(checksum, vault->checksum, 32) != 0) {
|
if(memcmp(checksum, vault->checksum, 32) != 0) {
|
||||||
fatal("Error: the checksum of the key vault doesn't match its contents!\n");
|
fatal("Error: the checksum of the key vault doesn't match its contents!\n");
|
||||||
goto err;
|
goto err;
|
||||||
@@ -493,7 +493,7 @@ int pcpvault_fetchall(vault_t *vault) {
|
|||||||
err:
|
err:
|
||||||
free(item);
|
free(item);
|
||||||
free(header);
|
free(header);
|
||||||
//pcphash_clean();
|
/* pcphash_clean(); */
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
28
libpcp/z85.c
28
libpcp/z85.c
@@ -26,14 +26,14 @@ unsigned char *pcp_padfour(unsigned char *src, size_t srclen, size_t *dstlen) {
|
|||||||
size_t outlen, zerolen;
|
size_t outlen, zerolen;
|
||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
|
|
||||||
outlen = srclen + 1; // 1 for the pad flag
|
outlen = srclen + 1; /* 1 for the pad flag */
|
||||||
while (outlen % 4 != 0) outlen++;
|
while (outlen % 4 != 0) outlen++;
|
||||||
zerolen = outlen - (srclen + 1);
|
zerolen = outlen - (srclen + 1);
|
||||||
|
|
||||||
dst = (unsigned char*)ucmalloc(outlen);
|
dst = (unsigned char*)ucmalloc(outlen);
|
||||||
dst[0] = zerolen; // add the number of zeros we add
|
dst[0] = zerolen; /* add the number of zeros we add */
|
||||||
memcpy(&dst[1], src, srclen); // add the original
|
memcpy(&dst[1], src, srclen); /* add the original */
|
||||||
memset(&dst[srclen+1], 0, zerolen); // pad with zeroes
|
memset(&dst[srclen+1], 0, zerolen); /* pad with zeroes */
|
||||||
|
|
||||||
*dstlen = outlen;
|
*dstlen = outlen;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen)
|
|||||||
size_t numzeroes;
|
size_t numzeroes;
|
||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
|
|
||||||
numzeroes = src[0]; // first byte tells us how many zeroes we've got
|
numzeroes = src[0]; /* first byte tells us how many zeroes we've got */
|
||||||
outlen = srclen - 1 - numzeroes;
|
outlen = srclen - 1 - numzeroes;
|
||||||
|
|
||||||
dst = malloc(outlen);
|
dst = malloc(outlen);
|
||||||
@@ -65,7 +65,7 @@ unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) {
|
|||||||
zlen = strlen(z85block);
|
zlen = strlen(z85block);
|
||||||
char *z85 = ucmalloc(zlen+1);
|
char *z85 = ucmalloc(zlen+1);
|
||||||
|
|
||||||
// remove newlines
|
/* remove newlines */
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for(i=0; i<zlen+1; ++i) {
|
for(i=0; i<zlen+1; ++i) {
|
||||||
if(z85block[i] != '\r' && z85block[i] != '\n') {
|
if(z85block[i] != '\r' && z85block[i] != '\n') {
|
||||||
@@ -94,21 +94,21 @@ char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen) {
|
|||||||
int pos, b;
|
int pos, b;
|
||||||
size_t outlen, blocklen, zlen;
|
size_t outlen, blocklen, zlen;
|
||||||
|
|
||||||
// make z85 happy (size % 4)
|
/* make z85 happy (size % 4) */
|
||||||
unsigned char *padded = pcp_padfour(raw, srclen, &outlen);
|
unsigned char *padded = pcp_padfour(raw, srclen, &outlen);
|
||||||
|
|
||||||
// encode to z85
|
/* encode to z85 */
|
||||||
zlen = (outlen * 5 / 4) + 1;
|
zlen = (outlen * 5 / 4) + 1;
|
||||||
char *z85 = ucmalloc(zlen);
|
char *z85 = ucmalloc(zlen);
|
||||||
z85 = zmq_z85_encode(z85, padded, outlen);
|
z85 = zmq_z85_encode(z85, padded, outlen);
|
||||||
|
|
||||||
|
|
||||||
// make it a 72 chars wide block
|
/* make it a 72 chars wide block */
|
||||||
blocklen = (zlen + ((zlen / 72) * 2)) + 1;
|
blocklen = (zlen + ((zlen / 72) * 2)) + 1;
|
||||||
char *z85block = ucmalloc(blocklen);
|
char *z85block = ucmalloc(blocklen);
|
||||||
|
|
||||||
//fprintf(stderr, "zlen: %d, outlen: %d, srclen: %d, blocklen: %d\n",
|
/* fprintf(stderr, "zlen: %d, outlen: %d, srclen: %d, blocklen: %d\n", */
|
||||||
// zlen, outlen, srclen, blocklen);
|
/* zlen, outlen, srclen, blocklen); */
|
||||||
|
|
||||||
pos = b = 0;
|
pos = b = 0;
|
||||||
/*
|
/*
|
||||||
@@ -141,8 +141,8 @@ char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen) {
|
|||||||
}
|
}
|
||||||
*B = '\0';
|
*B = '\0';
|
||||||
|
|
||||||
//fprintf(stderr, "z85block len: %d\n", blocklen, strlen(z85block));
|
/* fprintf(stderr, "z85block len: %d\n", blocklen, strlen(z85block)); */
|
||||||
//fprintf(stderr, "z85block: <%s>\n", z85block);
|
/* fprintf(stderr, "z85block: <%s>\n", z85block); */
|
||||||
|
|
||||||
*dstlen = blocklen;
|
*dstlen = blocklen;
|
||||||
free(z85);
|
free(z85);
|
||||||
@@ -189,7 +189,7 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) {
|
|||||||
|
|
||||||
for(i=0; i<bufsize; ++i) {
|
for(i=0; i<bufsize; ++i) {
|
||||||
if(lpos > MAXLINE) {
|
if(lpos > MAXLINE) {
|
||||||
// huh, now that's suspicious
|
/* huh, now that's suspicious */
|
||||||
fatal("Invalid input, line is too long (%d bytes so far)!\n", lpos);
|
fatal("Invalid input, line is too long (%d bytes so far)!\n", lpos);
|
||||||
goto rferr;
|
goto rferr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,17 +19,17 @@
|
|||||||
|
|
||||||
#include "zmq_z85.h"
|
#include "zmq_z85.h"
|
||||||
|
|
||||||
// Z85 codec, taken from 0MQ RFC project, implements RFC32 Z85 encoding
|
/* Z85 codec, taken from 0MQ RFC project, implements RFC32 Z85 encoding */
|
||||||
|
|
||||||
// Maps base 256 to base 85
|
/* Maps base 256 to base 85 */
|
||||||
static char encoder [85 + 1] = {
|
static char encoder [85 + 1] = {
|
||||||
"0123456789" "abcdefghij" "klmnopqrst" "uvwxyzABCD"
|
"0123456789" "abcdefghij" "klmnopqrst" "uvwxyzABCD"
|
||||||
"EFGHIJKLMN" "OPQRSTUVWX" "YZ.-:+=^!/" "*?&<>()[]{"
|
"EFGHIJKLMN" "OPQRSTUVWX" "YZ.-:+=^!/" "*?&<>()[]{"
|
||||||
"}@%$#"
|
"}@%$#"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Maps base 85 to base 256
|
/* Maps base 85 to base 256 */
|
||||||
// We chop off lower 32 and higher 128 ranges
|
/* We chop off lower 32 and higher 128 ranges */
|
||||||
static uint8_t decoder [96] = {
|
static uint8_t decoder [96] = {
|
||||||
0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00,
|
0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00,
|
||||||
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45,
|
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45,
|
||||||
@@ -45,24 +45,24 @@ static uint8_t decoder [96] = {
|
|||||||
0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00
|
0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------- */
|
||||||
// Encode a binary frame as a string; destination string MUST be at least
|
/* Encode a binary frame as a string; destination string MUST be at least */
|
||||||
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
|
/* size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns */
|
||||||
// dest. Size must be a multiple of 4.
|
/* dest. Size must be a multiple of 4. */
|
||||||
|
|
||||||
char *zmq_z85_encode (char *dest, uint8_t *data, size_t size)
|
char *zmq_z85_encode (char *dest, uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
if (size % 4 != 0)
|
if (size % 4 != 0)
|
||||||
return NULL; // !assert
|
return NULL; /* !assert */
|
||||||
|
|
||||||
unsigned int char_nbr = 0;
|
unsigned int char_nbr = 0;
|
||||||
unsigned int byte_nbr = 0;
|
unsigned int byte_nbr = 0;
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
while (byte_nbr < size) {
|
while (byte_nbr < size) {
|
||||||
// Accumulate value in base 256 (binary)
|
/* Accumulate value in base 256 (binary) */
|
||||||
value = value * 256 + data [byte_nbr++];
|
value = value * 256 + data [byte_nbr++];
|
||||||
if (byte_nbr % 4 == 0) {
|
if (byte_nbr % 4 == 0) {
|
||||||
// Output value in base 85
|
/* Output value in base 85 */
|
||||||
unsigned int divisor = 85 * 85 * 85 * 85;
|
unsigned int divisor = 85 * 85 * 85 * 85;
|
||||||
while (divisor) {
|
while (divisor) {
|
||||||
dest [char_nbr++] = encoder [value / divisor % 85];
|
dest [char_nbr++] = encoder [value / divisor % 85];
|
||||||
@@ -72,31 +72,31 @@ char *zmq_z85_encode (char *dest, uint8_t *data, size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (char_nbr != size * 5 / 4)
|
if (char_nbr != size * 5 / 4)
|
||||||
return NULL; // !assert
|
return NULL; /* !assert */
|
||||||
|
|
||||||
dest [char_nbr] = 0;
|
dest [char_nbr] = 0;
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------- */
|
||||||
// Decode an encoded string into a binary frame; dest must be at least
|
/* Decode an encoded string into a binary frame; dest must be at least */
|
||||||
// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string)
|
/* strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string) */
|
||||||
// must be a multiple of 5.
|
/* must be a multiple of 5. */
|
||||||
|
|
||||||
uint8_t *zmq_z85_decode (uint8_t *dest, char *string)
|
uint8_t *zmq_z85_decode (uint8_t *dest, char *string)
|
||||||
{
|
{
|
||||||
if (strlen (string) % 5 != 0)
|
if (strlen (string) % 5 != 0)
|
||||||
return NULL; // !assert
|
return NULL; /* !assert */
|
||||||
unsigned int byte_nbr = 0;
|
unsigned int byte_nbr = 0;
|
||||||
unsigned int char_nbr = 0;
|
unsigned int char_nbr = 0;
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
size_t string_len = strlen (string);
|
size_t string_len = strlen (string);
|
||||||
while (char_nbr < string_len) {
|
while (char_nbr < string_len) {
|
||||||
// Accumulate value in base 85
|
/* Accumulate value in base 85 */
|
||||||
value = value * 85 + decoder [(uint8_t) string [char_nbr++] - 32];
|
value = value * 85 + decoder [(uint8_t) string [char_nbr++] - 32];
|
||||||
if (char_nbr % 5 == 0) {
|
if (char_nbr % 5 == 0) {
|
||||||
// Output value in base 256
|
/* Output value in base 256 */
|
||||||
unsigned int divisor = 256 * 256 * 256;
|
unsigned int divisor = 256 * 256 * 256;
|
||||||
while (divisor) {
|
while (divisor) {
|
||||||
dest [byte_nbr++] = value / divisor % 256;
|
dest [byte_nbr++] = value / divisor % 256;
|
||||||
@@ -106,6 +106,6 @@ uint8_t *zmq_z85_decode (uint8_t *dest, char *string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (byte_nbr != strlen (string) * 4 / 5)
|
if (byte_nbr != strlen (string) * 4 / 5)
|
||||||
return NULL; //!assert
|
return NULL; /* !assert */
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine crypt mode
|
/* determine crypt mode */
|
||||||
fread(&head, 1, 1, in);
|
fread(&head, 1, 1, in);
|
||||||
if(!feof(in) && !ferror(in)) {
|
if(!feof(in) && !ferror(in)) {
|
||||||
if(head == PCP_SYM_CIPHER) {
|
if(head == PCP_SYM_CIPHER) {
|
||||||
// symetric mode
|
/* symetric mode */
|
||||||
unsigned char *salt = ucmalloc(90);
|
unsigned char *salt = ucmalloc(90);
|
||||||
char stsalt[] = PBP_COMPAT_SALT;
|
char stsalt[] = PBP_COMPAT_SALT;
|
||||||
memcpy(salt, stsalt, 90);
|
memcpy(salt, stsalt, 90);
|
||||||
@@ -73,7 +73,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
|||||||
free(salt);
|
free(salt);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// asymetric mode
|
/* asymetric mode */
|
||||||
if(useid) {
|
if(useid) {
|
||||||
HASH_FIND_STR(pcpkey_hash, id, secret);
|
HASH_FIND_STR(pcpkey_hash, id, secret);
|
||||||
if(secret == NULL) {
|
if(secret == NULL) {
|
||||||
@@ -90,7 +90,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(secret->secret[0] == 0) {
|
if(secret->secret[0] == 0) {
|
||||||
// encrypted, decrypt it
|
/* encrypted, decrypt it */
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
if(passwd == NULL) {
|
if(passwd == NULL) {
|
||||||
pcp_readpass(&passphrase,
|
pcp_readpass(&passphrase,
|
||||||
@@ -135,7 +135,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
|||||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt) {
|
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt) {
|
||||||
FILE *in = NULL;
|
FILE *in = NULL;
|
||||||
FILE *out = NULL;
|
FILE *out = NULL;
|
||||||
pcp_pubkey_t *pubhash = NULL; // FIXME: add free()
|
pcp_pubkey_t *pubhash = NULL; /* FIXME: add free() */
|
||||||
pcp_pubkey_t *tmp = NULL;
|
pcp_pubkey_t *tmp = NULL;
|
||||||
pcp_pubkey_t *pub = NULL;
|
pcp_pubkey_t *pub = NULL;
|
||||||
pcp_key_t *secret = NULL;
|
pcp_key_t *secret = NULL;
|
||||||
@@ -143,7 +143,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
int self = 0;
|
int self = 0;
|
||||||
|
|
||||||
if(id == NULL && recipient == NULL) {
|
if(id == NULL && recipient == NULL) {
|
||||||
// self mode
|
/* self mode */
|
||||||
self = 1;
|
self = 1;
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
if(passwd == NULL) {
|
if(passwd == NULL) {
|
||||||
@@ -154,17 +154,17 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
passphrase = ucmalloc(strlen(passwd)+1);
|
passphrase = ucmalloc(strlen(passwd)+1);
|
||||||
strncpy(passphrase, passwd, strlen(passwd)+1);
|
strncpy(passphrase, passwd, strlen(passwd)+1);
|
||||||
}
|
}
|
||||||
unsigned char *salt = ucmalloc(90); // FIXME: use random salt, concat it with result afterwards
|
unsigned char *salt = ucmalloc(90); /* FIXME: use random salt, concat it with result afterwards */
|
||||||
char stsalt[] = PBP_COMPAT_SALT;
|
char stsalt[] = PBP_COMPAT_SALT;
|
||||||
memcpy(salt, stsalt, 90);
|
memcpy(salt, stsalt, 90);
|
||||||
symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt, 90);
|
symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt, 90);
|
||||||
free(salt);
|
free(salt);
|
||||||
}
|
}
|
||||||
else if(id != NULL && recipient == NULL) {
|
else if(id != NULL && recipient == NULL) {
|
||||||
// lookup by id
|
/* lookup by id */
|
||||||
HASH_FIND_STR(pcppubkey_hash, id, tmp);
|
HASH_FIND_STR(pcppubkey_hash, id, tmp);
|
||||||
if(tmp == NULL) {
|
if(tmp == NULL) {
|
||||||
// self-encryption: look if its a secret one
|
/* self-encryption: look if its a secret one */
|
||||||
pcp_key_t *s = NULL;
|
pcp_key_t *s = NULL;
|
||||||
HASH_FIND_STR(pcpkey_hash, id, s);
|
HASH_FIND_STR(pcpkey_hash, id, s);
|
||||||
if(s != NULL) {
|
if(s != NULL) {
|
||||||
@@ -179,16 +179,16 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// found one by id, copy into local hash
|
/* found one by id, copy into local hash */
|
||||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||||
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
||||||
HASH_ADD_STR( pubhash, id, tmp);
|
HASH_ADD_STR( pubhash, id, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(recipient != NULL) {
|
else if(recipient != NULL) {
|
||||||
// lookup by recipient list
|
/* lookup by recipient list */
|
||||||
// iterate through global hashlist
|
/* iterate through global hashlist */
|
||||||
// copy matches into temporary pubhash
|
/* copy matches into temporary pubhash */
|
||||||
plist_t *rec;
|
plist_t *rec;
|
||||||
pcphash_iteratepub(tmp) {
|
pcphash_iteratepub(tmp) {
|
||||||
rec = recipient->first;
|
rec = recipient->first;
|
||||||
@@ -198,7 +198,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||||
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
||||||
HASH_ADD_STR( pubhash, id, tmp);
|
HASH_ADD_STR( pubhash, id, tmp);
|
||||||
//fprintf(stderr, " => found a matching key %s\n", tmp->id);
|
/* fprintf(stderr, " => found a matching key %s\n", tmp->id); */
|
||||||
}
|
}
|
||||||
rec = rec->next;
|
rec = rec->next;
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
|
|
||||||
|
|
||||||
if(self != 1) {
|
if(self != 1) {
|
||||||
// we're using a random secret keypair on our side
|
/* we're using a random secret keypair on our side */
|
||||||
#ifdef PCP_ASYM_ADD_SENDER_PUB
|
#ifdef PCP_ASYM_ADD_SENDER_PUB
|
||||||
secret = pcpkey_new();
|
secret = pcpkey_new();
|
||||||
#else
|
#else
|
||||||
@@ -222,7 +222,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(secret->secret[0] == 0) {
|
if(secret->secret[0] == 0) {
|
||||||
// encrypted, decrypt it
|
/* encrypted, decrypt it */
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
if(passwd == NULL) {
|
if(passwd == NULL) {
|
||||||
pcp_readpass(&passphrase,
|
pcp_readpass(&passphrase,
|
||||||
@@ -284,7 +284,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
}
|
}
|
||||||
|
|
||||||
erren2:
|
erren2:
|
||||||
free(pubhash); // FIXME: it's a uthash, dont use free() but func instead
|
free(pubhash); /* FIXME: it's a uthash, dont use free() but func instead */
|
||||||
free(tmp);
|
free(tmp);
|
||||||
free(pub);
|
free(pub);
|
||||||
|
|
||||||
|
|||||||
@@ -39,4 +39,4 @@
|
|||||||
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, int verify);
|
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, int verify);
|
||||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt);
|
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt);
|
||||||
|
|
||||||
#endif // _HAVE_ENCRYPTION_H
|
#endif /* _HAVE_ENCRYPTION_H */
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ pcp_key_t *pcp_find_primary_secret() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no primary? whoops
|
/* no primary? whoops */
|
||||||
int nkeys = HASH_COUNT(pcpkey_hash);
|
int nkeys = HASH_COUNT(pcpkey_hash);
|
||||||
if(nkeys == 1) {
|
if(nkeys == 1) {
|
||||||
pcphash_iterate(k) {
|
pcphash_iterate(k) {
|
||||||
@@ -209,7 +209,7 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile) {
|
|||||||
pcp_key_t *key = NULL;
|
pcp_key_t *key = NULL;
|
||||||
|
|
||||||
if(useid == 1) {
|
if(useid == 1) {
|
||||||
// look if we've got that one
|
/* look if we've got that one */
|
||||||
HASH_FIND_STR(pcpkey_hash, keyid, key);
|
HASH_FIND_STR(pcpkey_hash, keyid, key);
|
||||||
if(key == NULL) {
|
if(key == NULL) {
|
||||||
fatal("Could not find a secret key with id 0x%s in vault %s!\n", keyid, vault->filename);
|
fatal("Could not find a secret key with id 0x%s in vault %s!\n", keyid, vault->filename);
|
||||||
@@ -217,7 +217,7 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// look for our primary key
|
/* look for our primary key */
|
||||||
key = pcp_find_primary_secret();
|
key = pcp_find_primary_secret();
|
||||||
if(key == NULL) {
|
if(key == NULL) {
|
||||||
fatal("There's no primary secret key in the vault %s!\n", vault->filename);
|
fatal("There's no primary secret key in the vault %s!\n", vault->filename);
|
||||||
@@ -246,9 +246,9 @@ void pcp_exportsecretkey(pcp_key_t *key, char *outfile) {
|
|||||||
pcp_dumpkey(key);
|
pcp_dumpkey(key);
|
||||||
else
|
else
|
||||||
pcpkey_print(key, out);
|
pcpkey_print(key, out);
|
||||||
// scip
|
/* scip */
|
||||||
//printf("EXPORT:\n");
|
/* printf("EXPORT:\n"); */
|
||||||
// pcpprint_bin(stdout, key, PCP_RAW_KEYSIZE); printf("\n");
|
/* pcpprint_bin(stdout, key, PCP_RAW_KEYSIZE); printf("\n"); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,10 +263,10 @@ void pcp_exportpublic(char *keyid, char *recipient, char *passwd, char *outfile,
|
|||||||
pcp_pubkey_t *key = NULL;
|
pcp_pubkey_t *key = NULL;
|
||||||
|
|
||||||
if(keyid != NULL) {
|
if(keyid != NULL) {
|
||||||
// look if we've got that one
|
/* look if we've got that one */
|
||||||
HASH_FIND_STR(pcppubkey_hash, keyid, key);
|
HASH_FIND_STR(pcppubkey_hash, keyid, key);
|
||||||
if(key == NULL) {
|
if(key == NULL) {
|
||||||
// maybe it's a secret key?
|
/* maybe it's a secret key? */
|
||||||
pcp_key_t *s = NULL;
|
pcp_key_t *s = NULL;
|
||||||
HASH_FIND_STR(pcpkey_hash, keyid, s);
|
HASH_FIND_STR(pcpkey_hash, keyid, s);
|
||||||
if(s == NULL) {
|
if(s == NULL) {
|
||||||
@@ -279,7 +279,7 @@ void pcp_exportpublic(char *keyid, char *recipient, char *passwd, char *outfile,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// look for the primary secret
|
/* look for the primary secret */
|
||||||
pcp_key_t *s = NULL;
|
pcp_key_t *s = NULL;
|
||||||
s = pcp_find_primary_secret();
|
s = pcp_find_primary_secret();
|
||||||
if(s == NULL) {
|
if(s == NULL) {
|
||||||
@@ -304,9 +304,9 @@ void pcp_exportpublic(char *keyid, char *recipient, char *passwd, char *outfile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(out != NULL) {
|
if(out != NULL) {
|
||||||
// scip
|
/* scip */
|
||||||
//printf("EXPORT:\n");
|
/* printf("EXPORT:\n"); */
|
||||||
//pcpprint_bin(stdout, key, PCP_RAW_PUBKEYSIZE); printf("\n");
|
/* pcpprint_bin(stdout, key, PCP_RAW_PUBKEYSIZE); printf("\n"); */
|
||||||
pcppubkey_print(key, out, pbpcompat);
|
pcppubkey_print(key, out, pbpcompat);
|
||||||
if(pbpcompat)
|
if(pbpcompat)
|
||||||
fprintf(stderr, "public key exported in PBP format.\n");
|
fprintf(stderr, "public key exported in PBP format.\n");
|
||||||
@@ -341,7 +341,7 @@ int pcp_importsecret (vault_t *vault, FILE *in) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// all good now, import the blob
|
/* all good now, import the blob */
|
||||||
pcp_key_t *key = ucmalloc(sizeof(pcp_key_t));
|
pcp_key_t *key = ucmalloc(sizeof(pcp_key_t));
|
||||||
memcpy(key, z85decoded, PCP_RAW_KEYSIZE);
|
memcpy(key, z85decoded, PCP_RAW_KEYSIZE);
|
||||||
key2native(key);
|
key2native(key);
|
||||||
@@ -351,7 +351,7 @@ int pcp_importsecret (vault_t *vault, FILE *in) {
|
|||||||
|
|
||||||
if(pcp_sanitycheck_key(key) == 0) {
|
if(pcp_sanitycheck_key(key) == 0) {
|
||||||
if(key->secret[0] != 0) {
|
if(key->secret[0] != 0) {
|
||||||
// unencrypted, encrypt it
|
/* unencrypted, encrypt it */
|
||||||
fprintf(stderr, "Key to be imported is unencrypted.\n");
|
fprintf(stderr, "Key to be imported is unencrypted.\n");
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
pcp_readpass(&passphrase, "Enter passphrase for key encryption", NULL, 1);
|
pcp_readpass(&passphrase, "Enter passphrase for key encryption", NULL, 1);
|
||||||
@@ -385,9 +385,9 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
|||||||
size_t buflen;
|
size_t buflen;
|
||||||
size_t klen;
|
size_t klen;
|
||||||
|
|
||||||
buflen = fread(buf, 1, 2048, in); // base85 encoded
|
buflen = fread(buf, 1, 2048, in); /* base85 encoded */
|
||||||
|
|
||||||
// remove trailing newline, if any
|
/* remove trailing newline, if any */
|
||||||
size_t i, nlen;
|
size_t i, nlen;
|
||||||
nlen = buflen;
|
nlen = buflen;
|
||||||
for(i=buflen; i>0; --i) {
|
for(i=buflen; i>0; --i) {
|
||||||
@@ -407,7 +407,7 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
|||||||
goto errimp1;
|
goto errimp1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unpad result, if any
|
/* unpad result, if any */
|
||||||
for(i=klen; i>0; --i) {
|
for(i=klen; i>0; --i) {
|
||||||
if(bin[i] != '\0' && i < klen) {
|
if(bin[i] != '\0' && i < klen) {
|
||||||
klen = i + 1;
|
klen = i + 1;
|
||||||
@@ -415,10 +415,10 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use first part as sig and verify
|
/* use first part as sig and verify */
|
||||||
memcpy(b, &bin[crypto_sign_BYTES], klen - crypto_sign_BYTES);
|
memcpy(b, &bin[crypto_sign_BYTES], klen - crypto_sign_BYTES);
|
||||||
|
|
||||||
// parse the name
|
/* parse the name */
|
||||||
parts = strtok (b->name, "<>");
|
parts = strtok (b->name, "<>");
|
||||||
pnum = 0;
|
pnum = 0;
|
||||||
while (parts != NULL) {
|
while (parts != NULL) {
|
||||||
@@ -437,8 +437,8 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
|||||||
free(owner);
|
free(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill in the fields
|
/* fill in the fields */
|
||||||
pub->ctime = (long)time(0); // pbp exports no ctime
|
pub->ctime = (long)time(0); /* pbp exports no ctime */
|
||||||
pub->type = PCP_KEY_TYPE_PUBLIC;
|
pub->type = PCP_KEY_TYPE_PUBLIC;
|
||||||
pub->version = PCP_KEY_VERSION;
|
pub->version = PCP_KEY_VERSION;
|
||||||
pub->serial = arc4random();
|
pub->serial = arc4random();
|
||||||
@@ -487,7 +487,7 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// all good now
|
/* all good now */
|
||||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||||
memcpy(pub, z85decoded, PCP_RAW_PUBKEYSIZE);
|
memcpy(pub, z85decoded, PCP_RAW_PUBKEYSIZE);
|
||||||
pubkey2native(pub);
|
pubkey2native(pub);
|
||||||
@@ -513,7 +513,7 @@ void pcpdelete_key(char *keyid) {
|
|||||||
pcp_pubkey_t *p = pcphash_pubkeyexists(keyid);
|
pcp_pubkey_t *p = pcphash_pubkeyexists(keyid);
|
||||||
|
|
||||||
if(p != NULL) {
|
if(p != NULL) {
|
||||||
// delete public
|
/* delete public */
|
||||||
HASH_DEL(pcppubkey_hash, p);
|
HASH_DEL(pcppubkey_hash, p);
|
||||||
free(p);
|
free(p);
|
||||||
vault->unsafed = 1;
|
vault->unsafed = 1;
|
||||||
@@ -522,7 +522,7 @@ void pcpdelete_key(char *keyid) {
|
|||||||
else {
|
else {
|
||||||
pcp_key_t *s = pcphash_keyexists(keyid);
|
pcp_key_t *s = pcphash_keyexists(keyid);
|
||||||
if(s != NULL) {
|
if(s != NULL) {
|
||||||
// delete secret
|
/* delete secret */
|
||||||
HASH_DEL(pcpkey_hash, s);
|
HASH_DEL(pcpkey_hash, s);
|
||||||
free(s);
|
free(s);
|
||||||
vault->unsafed = 1;
|
vault->unsafed = 1;
|
||||||
@@ -559,7 +559,7 @@ void pcpedit_key(char *keyid) {
|
|||||||
if(debug)
|
if(debug)
|
||||||
pcp_dumpkey(key);
|
pcp_dumpkey(key);
|
||||||
|
|
||||||
vault->unsafed = 1; // will be safed automatically
|
vault->unsafed = 1; /* will be safed automatically */
|
||||||
fprintf(stderr, "Key key changed.\n");
|
fprintf(stderr, "Key key changed.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,4 +58,4 @@ int pcp_importsecret (vault_t *vault, FILE *in);
|
|||||||
void pcpdelete_key(char *keyid);
|
void pcpdelete_key(char *keyid);
|
||||||
char *pcp_find_id_byrec(char *recipient);
|
char *pcp_find_id_byrec(char *recipient);
|
||||||
|
|
||||||
#endif // _HAVE_KEYMGMT_H
|
#endif /* _HAVE_KEYMGMT_H */
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ int pcptext_infile(char *infile) {
|
|||||||
goto tdone;
|
goto tdone;
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe a vault?
|
/* maybe a vault? */
|
||||||
vault_t *v = pcpvault_init(infile);
|
vault_t *v = pcpvault_init(infile);
|
||||||
if(v != NULL) {
|
if(v != NULL) {
|
||||||
fprintf(stdout, "%s is a vault file\n", infile);
|
fprintf(stdout, "%s is a vault file\n", infile);
|
||||||
@@ -49,7 +49,7 @@ int pcptext_infile(char *infile) {
|
|||||||
goto tdone;
|
goto tdone;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try z85ing it
|
/* try z85ing it */
|
||||||
char *z85 = pcp_readz85file(in);
|
char *z85 = pcp_readz85file(in);
|
||||||
if(z85 == NULL) {
|
if(z85 == NULL) {
|
||||||
fprintf(stdout, "Can't handle %s - unknown file type.\n", infile);
|
fprintf(stdout, "Can't handle %s - unknown file type.\n", infile);
|
||||||
@@ -65,11 +65,11 @@ int pcptext_infile(char *infile) {
|
|||||||
goto errtinf1;
|
goto errtinf1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//fprintf(stdout, "have: %d, secret: %d, public: %d, sig: %d, hh: %d\n", (int)clen,
|
/* fprintf(stdout, "have: %d, secret: %d, public: %d, sig: %d, hh: %d\n", (int)clen, */
|
||||||
// (int)sizeof(pcp_key_t), (int)sizeof(pcp_pubkey_t), (int)sizeof(pcp_sig_t), (int)sizeof(UT_hash_handle));
|
/* (int)sizeof(pcp_key_t), (int)sizeof(pcp_pubkey_t), (int)sizeof(pcp_sig_t), (int)sizeof(UT_hash_handle)); */
|
||||||
|
|
||||||
if(clen == PCP_RAW_KEYSIZE) {
|
if(clen == PCP_RAW_KEYSIZE) {
|
||||||
// secret key?
|
/* secret key? */
|
||||||
pcp_key_t *key = (pcp_key_t *)bin;
|
pcp_key_t *key = (pcp_key_t *)bin;
|
||||||
key2native(key);
|
key2native(key);
|
||||||
if(pcp_sanitycheck_key(key) == 0) {
|
if(pcp_sanitycheck_key(key) == 0) {
|
||||||
@@ -86,7 +86,7 @@ int pcptext_infile(char *infile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(clen == PCP_RAW_PUBKEYSIZE) {
|
if(clen == PCP_RAW_PUBKEYSIZE) {
|
||||||
// public key?
|
/* public key? */
|
||||||
pcp_pubkey_t *key = (pcp_pubkey_t *)bin;
|
pcp_pubkey_t *key = (pcp_pubkey_t *)bin;
|
||||||
pubkey2native(key);
|
pubkey2native(key);
|
||||||
if(pcp_sanitycheck_pub(key) == 0) {
|
if(pcp_sanitycheck_pub(key) == 0) {
|
||||||
@@ -102,7 +102,7 @@ int pcptext_infile(char *infile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// still there?
|
/* still there? */
|
||||||
fprintf(stdout, "%s looks Z85 encoded but otherwise unknown and is possibly encrypted.\n", infile);
|
fprintf(stdout, "%s looks Z85 encoded but otherwise unknown and is possibly encrypted.\n", infile);
|
||||||
|
|
||||||
tdone:
|
tdone:
|
||||||
@@ -199,7 +199,7 @@ void pcpkey_print(pcp_key_t *key, FILE* out) {
|
|||||||
|
|
||||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||||
|
|
||||||
//2004-06-14T23:34:30.
|
/* 2004-06-14T23:34:30. */
|
||||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||||
c->tm_hour, c->tm_min, c->tm_sec);
|
c->tm_hour, c->tm_min, c->tm_sec);
|
||||||
@@ -249,7 +249,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
|
|||||||
|
|
||||||
unsigned char *sig = pcp_ed_sign(blob, pbplen, secret);
|
unsigned char *sig = pcp_ed_sign(blob, pbplen, secret);
|
||||||
fprintf(stderr, " sig: "); pcpprint_bin(stderr, sig, pbplen+crypto_sign_BYTES); fprintf(stderr, "\n");
|
fprintf(stderr, " sig: "); pcpprint_bin(stderr, sig, pbplen+crypto_sign_BYTES); fprintf(stderr, "\n");
|
||||||
fprintf(stderr, "siglen: %ld, inlen: %ld\n", crypto_sign_BYTES, pbplen);
|
fprintf(stderr, "siglen: %d, inlen: %ld\n", crypto_sign_BYTES, pbplen);
|
||||||
if(sig != NULL) {
|
if(sig != NULL) {
|
||||||
size_t siglen = pbplen + crypto_sign_BYTES;
|
size_t siglen = pbplen + crypto_sign_BYTES;
|
||||||
size_t blen = ((siglen / 4) * 5) + siglen;
|
size_t blen = ((siglen / 4) * 5) + siglen;
|
||||||
@@ -266,7 +266,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
|
|||||||
else {
|
else {
|
||||||
size_t zlen;
|
size_t zlen;
|
||||||
|
|
||||||
//printf("version: %08x\n", key->version);
|
/* printf("version: %08x\n", key->version); */
|
||||||
|
|
||||||
pubkey2be(key);
|
pubkey2be(key);
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
|
|||||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||||
fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->pub, 32, &zlen));
|
fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->pub, 32, &zlen));
|
||||||
|
|
||||||
//2004-06-14T23:34:30.
|
/* 2004-06-14T23:34:30. */
|
||||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||||
c->tm_hour, c->tm_min, c->tm_sec);
|
c->tm_hour, c->tm_min, c->tm_sec);
|
||||||
|
|||||||
@@ -50,4 +50,4 @@ int pcptext_infile(char *infile);
|
|||||||
void pcpexport_yaml(char *outfile);
|
void pcpexport_yaml(char *outfile);
|
||||||
void pcpprint_bin(FILE *out, unsigned char *data, size_t len);
|
void pcpprint_bin(FILE *out, unsigned char *data, size_t len);
|
||||||
|
|
||||||
#endif // _HAVE_PCP_KEYPRINT_H
|
#endif /* _HAVE_PCP_KEYPRINT_H */
|
||||||
|
|||||||
28
src/pcp.c
28
src/pcp.c
@@ -71,7 +71,7 @@ int main (int argc, char **argv) {
|
|||||||
pbpcompat = 0;
|
pbpcompat = 0;
|
||||||
|
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
// generics
|
/* generics */
|
||||||
{ "vault", required_argument, NULL, 'V' },
|
{ "vault", required_argument, NULL, 'V' },
|
||||||
{ "outfile", required_argument, NULL, 'O' },
|
{ "outfile", required_argument, NULL, 'O' },
|
||||||
{ "infile", required_argument, NULL, 'I' },
|
{ "infile", required_argument, NULL, 'I' },
|
||||||
@@ -80,7 +80,7 @@ int main (int argc, char **argv) {
|
|||||||
{ "xpass", required_argument, NULL, 'x' },
|
{ "xpass", required_argument, NULL, 'x' },
|
||||||
{ "recipient", required_argument, NULL, 'r' },
|
{ "recipient", required_argument, NULL, 'r' },
|
||||||
|
|
||||||
// key management
|
/* key management */
|
||||||
{ "keygen", no_argument, NULL, 'k' },
|
{ "keygen", no_argument, NULL, 'k' },
|
||||||
{ "listkeys", no_argument, NULL, 'l' },
|
{ "listkeys", no_argument, NULL, 'l' },
|
||||||
{ "export-secret", no_argument, NULL, 's' },
|
{ "export-secret", no_argument, NULL, 's' },
|
||||||
@@ -92,21 +92,21 @@ int main (int argc, char **argv) {
|
|||||||
{ "export-yaml", no_argument, NULL, 'y' },
|
{ "export-yaml", no_argument, NULL, 'y' },
|
||||||
{ "pbpcompat", no_argument, NULL, 'b' },
|
{ "pbpcompat", no_argument, NULL, 'b' },
|
||||||
|
|
||||||
// crypto
|
/* crypto */
|
||||||
{ "encrypt", no_argument, NULL, 'e' },
|
{ "encrypt", no_argument, NULL, 'e' },
|
||||||
{ "encrypt-me", no_argument, NULL, 'm' },
|
{ "encrypt-me", no_argument, NULL, 'm' },
|
||||||
{ "decrypt", no_argument, NULL, 'd' },
|
{ "decrypt", no_argument, NULL, 'd' },
|
||||||
|
|
||||||
// encoding
|
/* encoding */
|
||||||
{ "z85-encode", no_argument, NULL, 'z' },
|
{ "z85-encode", no_argument, NULL, 'z' },
|
||||||
{ "z85-decode", no_argument, NULL, 'Z' },
|
{ "z85-decode", no_argument, NULL, 'Z' },
|
||||||
|
|
||||||
// globals
|
/* globals */
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "version", no_argument, NULL, 'v' },
|
{ "version", no_argument, NULL, 'v' },
|
||||||
{ "debug", no_argument, NULL, 'D' },
|
{ "debug", no_argument, NULL, 'D' },
|
||||||
|
|
||||||
// signing
|
/* signing */
|
||||||
{ "sign", no_argument, NULL, 'g' },
|
{ "sign", no_argument, NULL, 'g' },
|
||||||
{ "check-signature", no_argument, NULL, 'c' },
|
{ "check-signature", no_argument, NULL, 'c' },
|
||||||
{ "sigfile", required_argument, NULL, 'f' },
|
{ "sigfile", required_argument, NULL, 'f' },
|
||||||
@@ -256,7 +256,7 @@ int main (int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sodium_init(); // FIXME: better called from the lib?
|
sodium_init(); /* FIXME: better called from the lib? */
|
||||||
|
|
||||||
if(mode == PCP_MODE_ENCRYPT && useid == 0 && userec == 0) {
|
if(mode == PCP_MODE_ENCRYPT && useid == 0 && userec == 0) {
|
||||||
usevault = 0;
|
usevault = 0;
|
||||||
@@ -361,16 +361,16 @@ int main (int argc, char **argv) {
|
|||||||
|
|
||||||
case PCP_MODE_ENCRYPT:
|
case PCP_MODE_ENCRYPT:
|
||||||
if(useid == 1 && userec == 0) {
|
if(useid == 1 && userec == 0) {
|
||||||
// one dst, FIXME: make id a list as well
|
/* one dst, FIXME: make id a list as well */
|
||||||
id = pcp_normalize_id(keyid);
|
id = pcp_normalize_id(keyid);
|
||||||
pcpencrypt(id, infile, outfile, xpass, NULL, signcrypt);
|
pcpencrypt(id, infile, outfile, xpass, NULL, signcrypt);
|
||||||
}
|
}
|
||||||
else if(useid == 0 && userec == 1) {
|
else if(useid == 0 && userec == 1) {
|
||||||
// multiple dst
|
/* multiple dst */
|
||||||
pcpencrypt(NULL, infile, outfile, xpass, recipient, signcrypt);
|
pcpencrypt(NULL, infile, outfile, xpass, recipient, signcrypt);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// -i and -r specified
|
/* -i and -r specified */
|
||||||
fatal("You can't specify both -i and -r, use either -i or -r!\n");
|
fatal("You can't specify both -i and -r, use either -i or -r!\n");
|
||||||
}
|
}
|
||||||
if(id != NULL)
|
if(id != NULL)
|
||||||
@@ -426,14 +426,14 @@ int main (int argc, char **argv) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
//
|
/* */
|
||||||
goto ELSEMODE;
|
goto ELSEMODE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pcpvault_close(vault);
|
pcpvault_close(vault);
|
||||||
pcphash_clean();
|
pcphash_clean();
|
||||||
ucfree(vaultfile);
|
free(vaultfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ELSEMODE:
|
ELSEMODE:
|
||||||
@@ -469,12 +469,12 @@ int main (int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
pcpvault_close(vault);
|
pcpvault_close(vault);
|
||||||
pcphash_clean();
|
pcphash_clean();
|
||||||
ucfree(vaultfile);
|
free(vaultfile);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// mode params mixed
|
/* mode params mixed */
|
||||||
fatal("Sorry, invalid combination of commandline parameters (0x%04X)!\n", mode);
|
fatal("Sorry, invalid combination of commandline parameters (0x%04X)!\n", mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/pcp.h
10
src/pcp.h
@@ -32,7 +32,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <compat_getopt.h>
|
#include <compat_getopt.h>
|
||||||
|
|
||||||
// lib
|
/* lib */
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "z85.h"
|
#include "z85.h"
|
||||||
#include "zmq_z85.h"
|
#include "zmq_z85.h"
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "vault.h"
|
#include "vault.h"
|
||||||
|
|
||||||
// subs
|
/* subs */
|
||||||
#include "keymgmt.h"
|
#include "keymgmt.h"
|
||||||
#include "usage.h"
|
#include "usage.h"
|
||||||
#include "encryption.h"
|
#include "encryption.h"
|
||||||
@@ -48,8 +48,8 @@
|
|||||||
#include "keyhash.h"
|
#include "keyhash.h"
|
||||||
#include "plist.h"
|
#include "plist.h"
|
||||||
|
|
||||||
// operation modi
|
/* operation modi */
|
||||||
// perl -e '$x=0; while ($x<100000) { $x++; $x *= 1.7; printf "0x%08X: %d\n", $x, $x }'
|
/* perl -e '$x=0; while ($x<100000) { $x++; $x *= 1.7; printf "0x%08X: %d\n", $x, $x }' */
|
||||||
#define PCP_MODE_KEYGEN 0x00000001
|
#define PCP_MODE_KEYGEN 0x00000001
|
||||||
#define PCP_MODE_LISTKEYS 0x00000004
|
#define PCP_MODE_LISTKEYS 0x00000004
|
||||||
#define PCP_MODE_EXPORT_SECRET 0x00000009
|
#define PCP_MODE_EXPORT_SECRET 0x00000009
|
||||||
@@ -88,4 +88,4 @@ void version();
|
|||||||
void usage();
|
void usage();
|
||||||
char *default_vault();
|
char *default_vault();
|
||||||
|
|
||||||
#endif // _HAVE_PCP_H
|
#endif /* _HAVE_PCP_H */
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ int pcpsign(char *infile, char *outfile, char *passwd, int z85, int detach) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(secret->secret[0] == 0) {
|
if(secret->secret[0] == 0) {
|
||||||
// encrypted, decrypt it
|
/* encrypted, decrypt it */
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
if(passwd == NULL) {
|
if(passwd == NULL) {
|
||||||
pcp_readpass(&passphrase,
|
pcp_readpass(&passphrase,
|
||||||
@@ -121,8 +121,6 @@ int pcpverify(char *infile, char *sigfile, char *id, int detach) {
|
|||||||
fprintf(stderr, "Signature verified (signed by %s <%s>).\n", pub->owner, pub->mail);
|
fprintf(stderr, "Signature verified (signed by %s <%s>).\n", pub->owner, pub->mail);
|
||||||
|
|
||||||
|
|
||||||
errv4:
|
|
||||||
|
|
||||||
errv1:
|
errv1:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,4 @@ int pcpverify(char *infile, char *sigfile, char *id, int detach);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _HAVE_SIGNATURE_H
|
#endif /* _HAVE_SIGNATURE_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user