diff --git a/include/pcp/base85.h b/include/pcp/base85.h index 6a604b3..a6d18b8 100644 --- a/include/pcp/base85.h +++ b/include/pcp/base85.h @@ -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 error(...) (fatal(__VA_ARGS__), -1) -#endif // HAVE_BASE85_H +#endif /* HAVE_BASE85_H */ diff --git a/include/pcp/crypto.h b/include/pcp/crypto.h index 035910d..178dec4 100644 --- a/include/pcp/crypto.h +++ b/include/pcp/crypto.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); void pcp_rec_free(pcp_rec_t *r); -#endif // _HAVE_PCP_CRYPTO_H +#endif /* _HAVE_PCP_CRYPTO_H */ diff --git a/include/pcp/defines.h b/include/pcp/defines.h index 08b4530..651e412 100644 --- a/include/pcp/defines.h +++ b/include/pcp/defines.h @@ -25,11 +25,11 @@ #include "config.h" -typedef unsigned char byte; // Single unsigned byte = 8 bits -typedef unsigned short dbyte; // Double byte = 16 bits -typedef unsigned int qbyte; // Quad byte = 32 bits +typedef unsigned char byte; /* Single unsigned byte = 8 bits */ +typedef unsigned short dbyte; /* Double byte = 16 bits */ +typedef unsigned int qbyte; /* Quad byte = 32 bits */ -// key stuff +/* key stuff */ #define PCP_KEY_HEADER "----- BEGIN 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_PUBLIC 3 -// save typing, dammit +/* save typing, dammit */ #define PCP_ENCRYPT_PAD crypto_secretbox_ZEROBYTES + crypto_secretbox_NONCEBYTES -// vault id +/* vault id */ #define PCP_VAULT_ID 14 #define PCP_VAULT_VERSION 2 -// sigs +/* sigs */ #define PCP_SIG_VERSION 2 -// crypto file format stuff -// enabled via config.h (configure --enable-cbc) +/* crypto file format stuff */ +/* enabled via config.h (configure --enable-cbc) */ #ifndef PCP_CBC #define PCP_ASYM_CIPHER 5 #define PCP_SYM_CIPHER 23 #define PCP_BLOCK_SIZE 32 * 1024 #else -// CBC mode, use smaller blocks +/* CBC mode, use smaller blocks */ #define PCP_ASYM_CIPHER 7 #define PCP_SYM_CIPHER 25 #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_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_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,rSYI2GRDd:Bcm" -// error handling +/* error handling */ extern char *PCP_ERR; extern byte PCP_ERRSET; extern int PCP_EXIT; -//set error +/* set error */ void fatal(const char * fmt, ...); -// fetch error +/* fetch error */ void fatals_ifany(); -// reset +/* reset */ void fatals_reset(); -#endif // _DEFINES_H +#endif /* _DEFINES_H */ diff --git a/include/pcp/ed.h b/include/pcp/ed.h index 4ed7975..41d2a40 100644 --- a/include/pcp/ed.h +++ b/include/pcp/ed.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); 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 */ diff --git a/include/pcp/getpass.h b/include/pcp/getpass.h index 1f95ea4..c4eda0a 100644 --- a/include/pcp/getpass.h +++ b/include/pcp/getpass.h @@ -19,4 +19,4 @@ void pcp_echo_on(); char *pcp_get_stdin(); char *pcp_get_passphrase(char *prompt); -#endif // _HAVE_PCP_GETPASS +#endif /* _HAVE_PCP_GETPASS */ diff --git a/include/pcp/jenhash.h b/include/pcp/jenhash.h index ebf6a60..c73a203 100644 --- a/include/pcp/jenhash.h +++ b/include/pcp/jenhash.h @@ -1,8 +1,8 @@ #ifndef _HAVE_JENHASH_H #define _HAVE_JENHASH_H -// Bob Jenkins 32bit hash function -// via: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx +/* Bob Jenkins 32bit hash function */ +/* via: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */ #define jen_mix(a,b,c) \ { \ @@ -22,4 +22,4 @@ unsigned jen_hash ( unsigned char *k, unsigned length, unsigned initval ); -#endif // _HAVE_JENHASH_H +#endif /* _HAVE_JENHASH_H */ diff --git a/include/pcp/key.h b/include/pcp/key.h index a1b7444..ffafe6b 100644 --- a/include/pcp/key.h +++ b/include/pcp/key.h @@ -80,14 +80,14 @@ struct _pcp_key_t { byte edpub[32]; byte edsecret[64]; byte nonce[24]; - byte encrypted[112]; // both ed+curve encrypted + byte encrypted[112]; /* both ed+curve encrypted */ char owner[255]; char mail[255]; char id[17]; uint8_t type; - uint64_t ctime; // 8 - uint32_t version; // 4 - uint32_t serial; // 4 + uint64_t ctime; /* 8 */ + uint32_t version; /* 4 */ + uint32_t serial; /* 4 */ UT_hash_handle hh; }; @@ -104,8 +104,8 @@ struct _pcp_pubkey_t { UT_hash_handle hh; }; -// the PBP public key format -// keys.mp+keys.cp+keys.sp+keys.name +/* the PBP public key format */ +/* keys.mp+keys.cp+keys.sp+keys.name */ struct _pbp_pubkey_t { byte sigpub[crypto_sign_PUBLICKEYBYTES]; byte pub[crypto_box_PUBLICKEYBYTES]; @@ -165,17 +165,17 @@ unsigned char * pcp_gennonce(); 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); pcp_key_t *pcp_derive_pcpkey (pcp_key_t *ours, char *theirs); void pcp_seckeyblob(void *blob, pcp_key_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_key(pcp_key_t *key); -#endif // _HAVE_PCP_KEYPAIR_H +#endif /* _HAVE_PCP_KEYPAIR_H */ diff --git a/include/pcp/keyhash.h b/include/pcp/keyhash.h index 9ff24cf..db320e8 100644 --- a/include/pcp/keyhash.h +++ b/include/pcp/keyhash.h @@ -30,7 +30,7 @@ extern pcp_pubkey_t *pcppubkey_hash; extern pcp_key_t *__k; extern pcp_pubkey_t *__p; -// wrapper for HASH_ITER +/* wrapper for HASH_ITER */ #define pcphash_iterate(key) \ __k = NULL; \ HASH_ITER(hh, pcpkey_hash, key, __k) @@ -52,4 +52,4 @@ void pcphash_add(void *key, int type); int pcphash_count(); int pcphash_countpub(); -#endif // _HAVE_KEYHASH_H +#endif /* _HAVE_KEYHASH_H */ diff --git a/include/pcp/mac.h b/include/pcp/mac.h index ae142e4..429ef0c 100644 --- a/include/pcp/mac.h +++ b/include/pcp/mac.h @@ -31,38 +31,38 @@ #include "mem.h" -// how many times do we hash the passphrase +/* how many times do we hash the passphrase */ #define HCYCLES 128000 -// encrypt some arbitrary cleartext using -// a curve25519 secret key and a given nonce. -// -// expects a pointer to the target binary -// stream containing the encrypted data, -// the cleartext string, its size, the nonce -// (24 bytes) and the secret key (32 bytes). -// -// allocates memory for the returned cipher -// and it is up to the user to free it after use. -// -// returns the size of the returned cipherstream. -// in case of an error, the cipher will be set -// to NULL. +/* encrypt some arbitrary cleartext using */ +/* a curve25519 secret key and a given nonce. */ +/* */ +/* expects a pointer to the target binary */ +/* stream containing the encrypted data, */ +/* the cleartext string, its size, the nonce */ +/* (24 bytes) and the secret key (32 bytes). */ +/* */ +/* allocates memory for the returned cipher */ +/* and it is up to the user to free it after use. */ +/* */ +/* returns the size of the returned cipherstream. */ +/* in case of an error, the cipher will be set */ +/* to NULL. */ size_t pcp_sodium_mac(unsigned char **cipher, unsigned char *cleartext, size_t clearsize, unsigned char *nonce, unsigned char *key); -// does the opposite of pcp_sodium_mac and decrypts -// a given encrypted binary stream using a nonce and -// a secret key (sizes: see above). -// -// allocates memory for the returned cleartext and -// it is up to the user to free it after use. -// -// returns 0 if decryption and verification were -// successful, otherwise -1. +/* does the opposite of pcp_sodium_mac and decrypts */ +/* a given encrypted binary stream using a nonce and */ +/* a secret key (sizes: see above). */ +/* */ +/* allocates memory for the returned cleartext and */ +/* it is up to the user to free it after use. */ +/* */ +/* returns 0 if decryption and verification were */ +/* successful, otherwise -1. */ int pcp_sodium_verify_mac(unsigned char **cleartext, unsigned char* message, size_t messagesize, @@ -72,4 +72,4 @@ int pcp_sodium_verify_mac(unsigned char **cleartext, -#endif // _HAVE_PCP_MAC +#endif /* _HAVE_PCP_MAC */ diff --git a/include/pcp/mem.h b/include/pcp/mem.h index faa42fa..6bf2909 100644 --- a/include/pcp/mem.h +++ b/include/pcp/mem.h @@ -27,19 +27,16 @@ #include #include "platform.h" -// simple malloc() wrapper -// behaves like calloc(), which -// I don't have here. -// -// exits if there's no more memory -// available. +/* simple malloc() wrapper */ +/* behaves like calloc(), which */ +/* I don't have here. */ +/* */ +/* exits if there's no more memory */ +/* available. */ 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); -// dito. -void *ucfree(void *ptr); - -#endif // _HAVE_PCP_MEM +#endif /* _HAVE_PCP_MEM */ diff --git a/include/pcp/pad.h b/include/pcp/pad.h index 7ab9cd6..d9c7cf6 100644 --- a/include/pcp/pad.h +++ b/include/pcp/pad.h @@ -37,62 +37,62 @@ #define ZPADCHAR 0 #endif -// prepends a binary stream with a number of -// \0's as required by the secret_box and -// secret_box_open functions of libsodium. -// -// parameters: -// -// padded: destination array (ref) -// unpadded: source array without padding -// padlen: length of padding -// unpadlen: length of source array -// -// turns "efa5" into "00000000efa5" with padlen 8 -// -// if DEBUG is set, destination will be padded with -// the character '0', NOT the integer 0. -// -// allocates memory for padded and it is up to the -// user to free it after use. -// -// sample call: -// -// char unpadded[] = {0xef, 0xa5}; -// unsigned char *padded; -// pcp_pad_prepend(&padded, unpadded, 8, 2); -// -// the result, padded, would be 10 bytes long, 8 -// bytes for the leading zeros and 2 for the content -// of the original unpadded. +/* prepends a binary stream with a number of */ +/* \0's as required by the secret_box and */ +/* secret_box_open functions of libsodium. */ +/* */ +/* parameters: */ +/* */ +/* padded: destination array (ref) */ +/* unpadded: source array without padding */ +/* padlen: length of padding */ +/* unpadlen: length of source array */ +/* */ +/* turns "efa5" into "00000000efa5" with padlen 8 */ +/* */ +/* if DEBUG is set, destination will be padded with */ +/* the character '0', NOT the integer 0. */ +/* */ +/* allocates memory for padded and it is up to the */ +/* user to free it after use. */ +/* */ +/* sample call: */ +/* */ +/* char unpadded[] = {0xef, 0xa5}; */ +/* unsigned char *padded; */ +/* pcp_pad_prepend(&padded, unpadded, 8, 2); */ +/* */ +/* the result, padded, would be 10 bytes long, 8 */ +/* bytes for the leading zeros and 2 for the content */ +/* of the original unpadded. */ void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded, size_t padlen, size_t unpadlen); -// removes zero's of a binary stream, which is -// the reverse of pcp_pad_prepend(). -// -// parameters: -// -// unpadded: destination array (ref), with padding removed -// padded: source array with padding -// padlen: length of padding -// unpadlen: length of source array -// -// turns "00000000efa5" into "efa5" with padlen 8 -// -// allocates memory for unpadded and it is up to the -// user to free it after use. -// -// sample call: -// -// char padded[] = {0x0, 0x0, 0x0, 0x0, 0xef, 0xa5}; -// unsigned char *unpadded; -// pcp_pad_remove(unpadded, padded, 4, 2); -// -// the result, unpadded would be 2 bytes long containing -// only the 2 bytes we want to have with zeros removed. +/* removes zero's of a binary stream, which is */ +/* the reverse of pcp_pad_prepend(). */ +/* */ +/* parameters: */ +/* */ +/* unpadded: destination array (ref), with padding removed */ +/* padded: source array with padding */ +/* padlen: length of padding */ +/* unpadlen: length of source array */ +/* */ +/* turns "00000000efa5" into "efa5" with padlen 8 */ +/* */ +/* allocates memory for unpadded and it is up to the */ +/* user to free it after use. */ +/* */ +/* sample call: */ +/* */ +/* char padded[] = {0x0, 0x0, 0x0, 0x0, 0xef, 0xa5}; */ +/* unsigned char *unpadded; */ +/* pcp_pad_remove(unpadded, padded, 4, 2); */ +/* */ +/* the result, unpadded would be 2 bytes long containing */ +/* only the 2 bytes we want to have with zeros removed. */ void pcp_pad_remove(unsigned char **unpadded, unsigned char *padded, size_t padlen, size_t unpadlen); -#endif // _HAVE_PCP_ZPADDING +#endif /* _HAVE_PCP_ZPADDING */ diff --git a/include/pcp/platform.h b/include/pcp/platform.h index 913c531..3bae160 100644 --- a/include/pcp/platform.h +++ b/include/pcp/platform.h @@ -27,16 +27,16 @@ #ifdef HAVE_ENDIAN_H # include -#else // no endian.h +#else /* no endian.h */ # ifdef HAVE_SYS_ENDIAN_H # include # include # ifndef HAVE_BE32TOH -# // openbsd, use aliases +# /* openbsd, use aliases */ # define be32toh betoh32 # define be64toh betoh64 # endif -# else // no sys/endian.h +# else /* no sys/endian.h */ # ifdef __CPU_IS_BIG_ENDIAN # define be32toh(x) (x) # define htobe32(x) (x) @@ -57,12 +57,12 @@ # define be64toh(x) ((u_int64_t)ntohl((u_int64_t)(x))) # define htobe64(x) ((u_int64_t)htonl((u_int64_t)(x))) # endif -# endif // HAVE_SYS_ENDIAN_H -#endif // HAVE_ENDIAN_H +# endif /* HAVE_SYS_ENDIAN_H */ +#endif /* HAVE_ENDIAN_H */ #ifndef HAVE_ARC4RANDOM_BUF -// shitty OS. we're using libsodium's implementation +/* shitty OS. we're using libsodium's implementation */ #include @@ -127,7 +127,7 @@ int vasprintf(char **ret, const char *format, va_list args) { *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; } diff --git a/include/pcp/plist.h b/include/pcp/plist.h index 92aebee..9e1b1a3 100644 --- a/include/pcp/plist.h +++ b/include/pcp/plist.h @@ -73,4 +73,4 @@ static inline void p_clean(plist_t *lst) { } -#endif // _HAVE_PCP_PLIST_H +#endif /* _HAVE_PCP_PLIST_H */ diff --git a/include/pcp/randomart.h b/include/pcp/randomart.h index 09dc4de..df0a314 100644 --- a/include/pcp/randomart.h +++ b/include/pcp/randomart.h @@ -33,7 +33,7 @@ * 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 #define _HAVE_PCP_RANDOMART_H @@ -41,7 +41,7 @@ #include "mem.h" #include -// from openssh key.c +/* from openssh key.c */ #ifndef MAX # 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); -#endif // _HAVE_PCP_RANDOMART_H +#endif /* _HAVE_PCP_RANDOMART_H */ diff --git a/include/pcp/scrypt.h b/include/pcp/scrypt.h index bfd85f3..b0d44d0 100644 --- a/include/pcp/scrypt.h +++ b/include/pcp/scrypt.h @@ -38,5 +38,5 @@ 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 */ diff --git a/include/pcp/util.h b/include/pcp/util.h index 42c7cc0..db580f9 100644 --- a/include/pcp/util.h +++ b/include/pcp/util.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 #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 _dump(char *n, unsigned char *d, size_t s); -#endif // _HAVE_PCP_UTIL_H +#endif /* _HAVE_PCP_UTIL_H */ diff --git a/include/pcp/vault.h b/include/pcp/vault.h index d7dcf9c..5eb2463 100644 --- a/include/pcp/vault.h +++ b/include/pcp/vault.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 * ih2native(vault_item_header_t *h); -#endif // _HAVE_PCP_VAULT +#endif /* _HAVE_PCP_VAULT */ diff --git a/include/pcp/version.h b/include/pcp/version.h index 2cf175e..ae152e9 100644 --- a/include/pcp/version.h +++ b/include/pcp/version.h @@ -34,4 +34,4 @@ int pcp_version(); -#endif // _HAVE_PCP_VERSION +#endif /* _HAVE_PCP_VERSION */ diff --git a/include/pcp/z85.h b/include/pcp/z85.h index 7b13f9c..274b803 100644 --- a/include/pcp/z85.h +++ b/include/pcp/z85.h @@ -20,27 +20,27 @@ */ -// from https://github.com/tlinden/curve-keygen/ +/* from https://github.com/tlinden/curve-keygen/ */ #ifndef _HAVE_PCP_Z85_H #include "defines.h" #include "zmq_z85.h" #include "mem.h" -// 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 +/* 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 */ 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); -// wrapper around zmq Z85 encoding function +/* wrapper around zmq Z85 encoding function */ 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_readz85file(FILE *infile); char *pcp_readz85string(unsigned char *input, size_t bufsize); -#endif // _HAVE_PCP_Z85_H +#endif /* _HAVE_PCP_Z85_H */ diff --git a/libpcp/base85.c b/libpcp/base85.c index c8cbf49..6f74f98 100644 --- a/libpcp/base85.c +++ b/libpcp/base85.c @@ -61,7 +61,7 @@ int decode_85(char *dst, const char *buffer, int len) 0xffffffff - de < (acc *= 85)) return error("invalid base85 sequence %.5s => %08x\n", buffer-5, acc); acc += de; - // say1(" %08x\n", acc); + /* say1(" %08x\n", acc); */ say1("%.5s", buffer-5); say2("=> %08x (len: %d)\n", acc, len); diff --git a/libpcp/crypto.c b/libpcp/crypto.c index 49d4a14..8f1194e 100644 --- a/libpcp/crypto.c +++ b/libpcp/crypto.c @@ -37,7 +37,7 @@ size_t pcp_sodium_box(unsigned char **cipher, pad_cipher = ucmalloc(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, 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, size_t messagesize, unsigned char *nonce, unsigned char *secret, unsigned char *pub) { - // verify/decrypt the box + /* verify/decrypt the box */ unsigned char *pad_cipher; unsigned char *pad_clear; 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); 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, messagesize + crypto_box_BOXZEROBYTES, nonce, pub, secret) == 0) { @@ -97,13 +97,13 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, goto errbec; } - // scip - //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, "cipher: "); pcpprint_bin(stderr, cipher, es); fprintf(stderr, "\n"); - //fprintf(stderr, " nonce: "); pcpprint_bin(stderr, nonce, crypto_secretbox_NONCEBYTES); fprintf(stderr, "\n"); + /* scip */ + /* 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, "cipher: "); pcpprint_bin(stderr, cipher, es); 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); memcpy(combined, nonce, crypto_secretbox_NONCEBYTES); 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(cipheronly); - // resulting size: - // ciphersize - crypto_secretbox_ZEROBYTES + /* resulting size: */ + /* ciphersize - crypto_secretbox_ZEROBYTES */ *dsize = ciphersize - crypto_secretbox_NONCEBYTES - PCP_CRYPTO_ADD; 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; if(ftell(in) == 1) { - // header has already been determined outside the lib + /* header has already been determined outside the lib */ if(symkey != NULL) self = 1; } else { - // step 1, check header + /* step 1, check header */ cur_bufsize = fread(head, 1, 1, in); if(cur_bufsize != 1 && !feof(in) && !ferror(in)) { 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) { - // just decrypt symetrically and go outa here + /* just decrypt symetrically and go outa here */ return pcp_decrypt_file_sym(in, out, symkey, NULL); } #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); if(cur_bufsize != crypto_box_PUBLICKEYBYTES && !feof(in) && !ferror(in)) { 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 - // step 3, check len recipients + /* step 3, check len recipients */ cur_bufsize = fread(&lenrec, 1, 4, in); if(cur_bufsize != 4 && !feof(in) && !ferror(in)) { 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); } - // 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; nrecpub, 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) goto errec1; #endif - // step 3, len recipients, big endian + /* step 3, len recipients, big endian */ lenrec = recipient_count; lenrec = htobe32(lenrec); 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) goto errec1; - // step 4, recipient list + /* step 4, recipient list */ 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) goto errec1; 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; if(sign) { 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 - // write the IV, pad it with rubbish, since pcp_decrypt_file_sym - // reads in with PCP_BLOCK_SIZE_IN buffersize and uses the last - // PCP_BLOCK_SIZE as IV. + /* write the IV, pad it with rubbish, since pcp_decrypt_file_sym */ + /* reads in with PCP_BLOCK_SIZE_IN buffersize and uses the last */ + /* PCP_BLOCK_SIZE as IV. */ unsigned char *iv = urmalloc(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(iv, PCP_BLOCK_SIZE, 1, out); #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)) { cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE, in); 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(); #ifdef PCP_CBC - // apply IV to current clear + /* apply IV to current clear */ _xorbuf(iv, in_buf, cur_bufsize); #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); #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); #endif } @@ -514,17 +514,17 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_ } #ifdef PCP_CBC - unsigned char *iv = NULL; // will be filled during 1st loop + unsigned char *iv = NULL; /* will be filled during 1st loop */ #endif while(!feof(in)) { cur_bufsize = fread(&in_buf, 1, PCP_BLOCK_SIZE_IN, in); if(cur_bufsize <= PCP_CRYPTO_ADD) - break; // no valid cipher block + break; /* no valid cipher block */ if(recverify != NULL) { 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); 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 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); memcpy(iv, &in_buf[PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES], PCP_BLOCK_SIZE); 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); #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)); #endif @@ -573,7 +573,7 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_ break; } #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); #endif } @@ -597,7 +597,7 @@ size_t pcp_decrypt_file_sym(FILE *in, FILE* out, unsigned char *symkey, pcp_rec_ out_size = 0; else { 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"); out_size = 0; } diff --git a/libpcp/digital_crc32.c b/libpcp/digital_crc32.c index 15c87cf..94d8ddd 100644 --- a/libpcp/digital_crc32.c +++ b/libpcp/digital_crc32.c @@ -30,8 +30,8 @@ #include -// Automatically generated CRC function -// polynomial: 0x104C11DB7 +/* Automatically generated CRC function */ +/* polynomial: 0x104C11DB7 */ unsigned int digital_update_crc32(unsigned int crc, const unsigned char *data, size_t len) { diff --git a/libpcp/ed.c b/libpcp/ed.c index 22f881a..2e4ba21 100644 --- a/libpcp/ed.c +++ b/libpcp/ed.c @@ -23,7 +23,7 @@ unsigned char * pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey_t *p) { 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) { 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) { - size_t mlen = messagesize + crypto_sign_BYTES; + unsigned long long mlen = messagesize + crypto_sign_BYTES; unsigned char *signature = ucmalloc(mlen); 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]; char zhead[] = 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 zlen = 262; // FIXME: calculate + size_t zlen = 262; /* FIXME: calculate */ unsigned char z85encoded[zlen]; unsigned char sighash[mlen]; 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 */ 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) { - // it is armored - next_bufsize = cur_bufsize - (hlen+hlen2); // size - the header - memcpy(in_next, &in_buf[hlen+hlen2], next_bufsize); // tmp save - memcpy(in_buf, in_next, next_bufsize); // put into inbuf without header + /* it is armored */ + next_bufsize = cur_bufsize - (hlen+hlen2); /* size - the header */ + memcpy(in_next, &in_buf[hlen+hlen2], next_bufsize); /* tmp save */ + memcpy(in_buf, in_next, next_bufsize); /* put into inbuf without header */ 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 += next_bufsize; next_bufsize = 0; - // now we've got the 1st half block in in_buf - // unless the file was smaller than blocksize/2, - // in which case it contains all the rest til eof + /* now we've got the 1st half block in in_buf */ + /* unless the file was smaller than blocksize/2, */ + /* in which case it contains all the rest til eof */ } z85 = 1; } @@ -163,13 +163,13 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) { while (cur_bufsize > 0) { if(cur_bufsize == PCP_BLOCK_SIZE/2) { - // probably not eof + /* probably not eof */ next_bufsize = fread(&in_next, 1, PCP_BLOCK_SIZE/2, in); } 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) memcpy(in_full, in_buf, cur_bufsize); else { @@ -178,14 +178,14 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) { } full_bufsize = cur_bufsize+next_bufsize; - // find signature offset + /* find signature offset */ 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) { - // sig begins within the first half, adjust in_buf size - //printf("1st half\n"); + /* sig begins within the first half, adjust in_buf size */ + /* printf("1st half\n"); */ next_bufsize = 0; cur_bufsize = offset; 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); } else if(full_bufsize - offset == siglen) { - // sig fits within the 2nd half - // offset: 28279, full: 28413, cur: 16384 - //printf("2nd half\n"); + /* sig fits within the 2nd half */ + /* offset: 28279, full: 28413, cur: 16384 */ + /* printf("2nd half\n"); */ next_bufsize -= siglen; gotsig = 1; if(z85) { @@ -212,17 +212,17 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) { else offset = 0; - // add previous half block to hash + /* add previous half block to hash */ crypto_generichash_update(st, in_buf, cur_bufsize); - // next => in + /* next => in */ if(next_bufsize > 0) { memcpy(in_buf, in_next, next_bufsize); cur_bufsize = next_bufsize; } else break; - } // while + } /* while */ if(gotsig == 0) { 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); } - // 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; if(p == NULL) { pcphash_iteratepub(p) { @@ -263,7 +263,7 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) { goto errvb1; 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"); free(verifiedhash); 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); - // read the sig + /* read the sig */ unsigned char *sig = NULL; size_t inputBufSize = 0; unsigned char byte[1]; @@ -386,7 +386,7 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(FILE *in, FILE *sigfd, pcp_pubkey_t * goto errdea4; 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"); goto errdea5; } diff --git a/libpcp/getpass.c b/libpcp/getpass.c index 74affd4..b0a51e0 100644 --- a/libpcp/getpass.c +++ b/libpcp/getpass.c @@ -37,7 +37,7 @@ char *pcp_get_stdin() { return NULL; } else { - line[linelen - 1] = '\0'; // remove newline at end + line[linelen - 1] = '\0'; /* remove newline at end */ return line; } } diff --git a/libpcp/key.c b/libpcp/key.c index d40fae2..6783a84 100644 --- a/libpcp/key.c +++ b/libpcp/key.c @@ -32,13 +32,13 @@ unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) { unsigned char *key = ucmalloc(crypto_secretbox_KEYBYTES); 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); - // make a hash from the scrypt() result + /* make a hash from the scrypt() result */ 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[31] &= 127; key[31] |= 64; @@ -48,41 +48,6 @@ unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) { 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; ipub, 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) { - // generate ed25519 + curve25519 keypair from random seed + /* generate ed25519 + curve25519 keypair from random seed */ byte *seed = urmalloc(32); byte *tmp = urmalloc(32); - // ed25519 signing key + /* ed25519 signing key */ crypto_sign_seed_keypair(epk, esk, seed); - // curve25519 secret key + /* curve25519 secret key */ tmp[0] &= 248; tmp[31] &= 63; tmp[31] |= 64; memcpy(csk, tmp, 32); - // curve25519 public key + /* curve25519 public key */ crypto_scalarmult_curve25519_base(cpk, csk); memset(tmp, 0, 32); } @@ -130,7 +95,7 @@ pcp_key_t * pcpkey_new () { pcp_keypairs(secret, pub, edsec, edpub); - // fill in our struct + /* fill in our struct */ pcp_key_t *key = urmalloc(sizeof(pcp_key_t)); memcpy (key->pub, pub, 32); memcpy (key->secret, secret, 32); @@ -175,7 +140,7 @@ pcp_key_t *pcpkey_encrypt(pcp_key_t *key, char *passphrase) { free(both); if(es == 112) { - // success + /* success */ memcpy(key->encrypted, encrypted, 112); arc4random_buf(key->secret, 32); arc4random_buf(key->edsecret, 64); @@ -203,7 +168,7 @@ pcp_key_t *pcpkey_decrypt(pcp_key_t *key, char *passphrase) { free(encryptkey); if(es == 0) { - // success + /* success */ memcpy(key->edsecret, decrypted, 64); 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_dumpkey(key); + /* pcp_dumpkey(key); */ pcp_pubkey_t *pub = urmalloc(sizeof (pcp_pubkey_t)); memcpy(pub->pub, key->pub, 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; c = localtime(&t); 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); return 1; } @@ -416,7 +381,7 @@ int pcp_sanitycheck_key(pcp_key_t *key) { time_t t = (time_t)key->ctime; c = localtime(&t); 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); return 1; } diff --git a/libpcp/keyhash.c b/libpcp/keyhash.c index 7ed70e8..fbbbf08 100644 --- a/libpcp/keyhash.c +++ b/libpcp/keyhash.c @@ -65,13 +65,13 @@ void pcphash_clean() { pcp_key_t *pcphash_keyexists(char *id) { pcp_key_t *key = NULL; 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 *key = NULL; HASH_FIND_STR(pcppubkey_hash, id, key); - return key; // maybe NULL! + return key; /* maybe NULL! */ } void pcphash_add(void *key, int type) { diff --git a/libpcp/mac.c b/libpcp/mac.c index 8ef10f4..d059458 100644 --- a/libpcp/mac.c +++ b/libpcp/mac.c @@ -51,7 +51,7 @@ size_t pcp_sodium_mac(unsigned char **cipher, int pcp_sodium_verify_mac(unsigned char **cleartext, unsigned char* message, size_t messagesize, unsigned char *nonce, unsigned char *key) { - // verify the mac + /* verify the mac */ unsigned char *pad_cipher; unsigned char *pad_clear; int success = -1; diff --git a/libpcp/mem.c b/libpcp/mem.c index b67838d..945d258 100644 --- a/libpcp/mem.c +++ b/libpcp/mem.c @@ -38,7 +38,7 @@ void *ucmalloc(size_t s) { 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; } @@ -52,7 +52,3 @@ void *urmalloc(size_t s) { } -void *ucfree(void *ptr) { - free(ptr); - ptr = NULL; -} diff --git a/libpcp/pad.c b/libpcp/pad.c index 94ef386..3575013 100644 --- a/libpcp/pad.c +++ b/libpcp/pad.c @@ -27,7 +27,7 @@ void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded, *padded = ucmalloc(unpadlen + padlen); unsigned char *tmp = ucmalloc(unpadlen + padlen); - // pcp_append orig + /* pcp_append orig */ int i; for(i=0; i \n"); + /* fprintf(stderr, "Usage: pad \n"); */ return -1; } #endif diff --git a/libpcp/scrypt.c b/libpcp/scrypt.c index 2be0e43..046023d 100644 --- a/libpcp/scrypt.c +++ b/libpcp/scrypt.c @@ -22,9 +22,9 @@ #include "scrypt.h" 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; uint32_t r = 8; uint32_t p = 1; diff --git a/libpcp/vault.c b/libpcp/vault.c index a786b3c..3af86b1 100644 --- a/libpcp/vault.c +++ b/libpcp/vault.c @@ -34,7 +34,7 @@ vault_t *pcpvault_init(char *filename) { } else { 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); return NULL; } @@ -161,7 +161,7 @@ int pcpvault_addkey(vault_t *vault, void *item, uint8_t type) { saveitem = ucmalloc(sizeof(pcp_pubkey_t)); memcpy(saveitem, item, sizeof(pcp_pubkey_t)); pubkey2be((pcp_pubkey_t *)item); - //pcp_dumppubkey((pcp_pubkey_t *)saveitem); + /* pcp_dumppubkey((pcp_pubkey_t *)saveitem); */ } else { 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); - // scip - //printf("BLOB (%d):\n", (int)itemsize); - //pcpprint_bin(stdout, saveitem, itemsize); printf("\n"); + /* scip */ + /* printf("BLOB (%d):\n", (int)itemsize); */ + /* pcpprint_bin(stdout, saveitem, itemsize); printf("\n"); */ if(tmp != NULL) { if(pcpvault_copy(vault, tmp) != 0) @@ -253,7 +253,7 @@ void pcpvault_update_checksum(vault_t *vault) { memcpy(header->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); @@ -282,16 +282,16 @@ unsigned char *pcpvault_create_checksum(vault_t *vault) { pcp_pubkey_t *p = NULL; pcphash_iteratepub(p) { - //pcp_dumppubkey(p); + /* pcp_dumppubkey(p); */ pubkey2be(p); memcpy(&data[datapos], p, PCP_RAW_PUBKEYSIZE); pubkey2native(p); datapos += PCP_RAW_PUBKEYSIZE; } - // scip - //printf("DATA (%d) (s: %d, p: %d):\n", (int)datasize, numskeys, numpkeys); - //pcpprint_bin(stdout, data, datasize); printf("\n"); + /* scip */ + /* printf("DATA (%d) (s: %d, p: %d):\n", (int)datasize, numskeys, numpkeys); */ + /* pcpprint_bin(stdout, data, datasize); printf("\n"); */ 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) { - // fetch tmp content + /* fetch tmp content */ fseek(tmp->fd, 0, SEEK_END); int tmpsize = ftell(tmp->fd); fseek(tmp->fd, 0, SEEK_SET); unsigned char *in = ucmalloc(tmpsize); 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); if(fwrite(in, tmpsize, 1, vault->fd) != 1) { fatal("Failed to copy %s to %s (write) [keeping %s]\n", @@ -405,12 +405,12 @@ int pcpvault_fetchall(vault_t *vault) { vh2native(header); 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; pcp_key_t *key; pcp_pubkey_t *pubkey; int bytesleft = 0; - int ksize = PCP_RAW_PUBKEYSIZE; // smallest possbile item + int ksize = PCP_RAW_PUBKEYSIZE; /* smallest possbile item */ pcphash_init(); @@ -420,28 +420,28 @@ int pcpvault_fetchall(vault_t *vault) { for(;;) { readpos = ftell(vault->fd); 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); ih2native(item); if(item->size > 0) { - // item is valid + /* item is valid */ readpos = ftell(vault->fd); bytesleft = vault->size - readpos; if(bytesleft >= ksize) { - // a key follows + /* a key follows */ if(item->type == PCP_KEY_TYPE_MAINSECRET || item->type == PCP_KEY_TYPE_SECRET) { - // read a secret key + /* read a secret key */ key = ucmalloc(sizeof(pcp_key_t)); fread(key, PCP_RAW_KEYSIZE, 1, vault->fd); key2native(key); - //pcp_dumpkey(key); - //pcpprint_bin(stdout, key, sizeof(pcp_key_t));printf("\n"); + /* pcp_dumpkey(key); */ + /* pcpprint_bin(stdout, key, sizeof(pcp_key_t));printf("\n"); */ pcphash_add((void *)key, item->type); } else if(item->type == PCP_KEY_TYPE_PUBLIC) { - // read a public key + /* read a public key */ pubkey = ucmalloc(sizeof(pcp_pubkey_t)); fread(pubkey, PCP_RAW_PUBKEYSIZE, 1, vault->fd); pubkey2native(pubkey); @@ -464,7 +464,7 @@ int pcpvault_fetchall(vault_t *vault) { } } else { - // no more items + /* no more items */ break; } } @@ -476,9 +476,9 @@ int pcpvault_fetchall(vault_t *vault) { unsigned char *checksum = NULL; 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) { - // only validate the checksum if there are keys + /* only validate the checksum if there are keys */ if(memcmp(checksum, vault->checksum, 32) != 0) { fatal("Error: the checksum of the key vault doesn't match its contents!\n"); goto err; @@ -493,7 +493,7 @@ int pcpvault_fetchall(vault_t *vault) { err: free(item); free(header); - //pcphash_clean(); + /* pcphash_clean(); */ return -1; } diff --git a/libpcp/z85.c b/libpcp/z85.c index 66aa711..70e001c 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -26,14 +26,14 @@ unsigned char *pcp_padfour(unsigned char *src, size_t srclen, size_t *dstlen) { size_t outlen, zerolen; unsigned char *dst; - outlen = srclen + 1; // 1 for the pad flag + outlen = srclen + 1; /* 1 for the pad flag */ while (outlen % 4 != 0) outlen++; zerolen = outlen - (srclen + 1); dst = (unsigned char*)ucmalloc(outlen); - dst[0] = zerolen; // add the number of zeros we add - memcpy(&dst[1], src, srclen); // add the original - memset(&dst[srclen+1], 0, zerolen); // pad with zeroes + dst[0] = zerolen; /* add the number of zeros we add */ + memcpy(&dst[1], src, srclen); /* add the original */ + memset(&dst[srclen+1], 0, zerolen); /* pad with zeroes */ *dstlen = outlen; @@ -45,7 +45,7 @@ unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen) size_t numzeroes; 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; dst = malloc(outlen); @@ -65,7 +65,7 @@ unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) { zlen = strlen(z85block); char *z85 = ucmalloc(zlen+1); - // remove newlines + /* remove newlines */ pos = 0; for(i=0; i\n", z85block); + /* fprintf(stderr, "z85block len: %d\n", blocklen, strlen(z85block)); */ + /* fprintf(stderr, "z85block: <%s>\n", z85block); */ *dstlen = blocklen; free(z85); @@ -189,7 +189,7 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) { for(i=0; i MAXLINE) { - // huh, now that's suspicious + /* huh, now that's suspicious */ fatal("Invalid input, line is too long (%d bytes so far)!\n", lpos); goto rferr; } diff --git a/libpcp/zmq_z85.c b/libpcp/zmq_z85.c index 5e214ec..efc8ad7 100644 --- a/libpcp/zmq_z85.c +++ b/libpcp/zmq_z85.c @@ -19,17 +19,17 @@ #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] = { "0123456789" "abcdefghij" "klmnopqrst" "uvwxyzABCD" "EFGHIJKLMN" "OPQRSTUVWX" "YZ.-:+=^!/" "*?&<>()[]{" "}@%$#" }; -// Maps base 85 to base 256 -// We chop off lower 32 and higher 128 ranges +/* Maps base 85 to base 256 */ +/* We chop off lower 32 and higher 128 ranges */ static uint8_t decoder [96] = { 0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00, 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 }; -// -------------------------------------------------------------------------- -// 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 -// dest. Size must be a multiple of 4. +/* -------------------------------------------------------------------------- */ +/* 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 */ +/* dest. Size must be a multiple of 4. */ char *zmq_z85_encode (char *dest, uint8_t *data, size_t size) { if (size % 4 != 0) - return NULL; // !assert + return NULL; /* !assert */ unsigned int char_nbr = 0; unsigned int byte_nbr = 0; uint32_t value = 0; while (byte_nbr < size) { - // Accumulate value in base 256 (binary) + /* Accumulate value in base 256 (binary) */ value = value * 256 + data [byte_nbr++]; if (byte_nbr % 4 == 0) { - // Output value in base 85 + /* Output value in base 85 */ unsigned int divisor = 85 * 85 * 85 * 85; while (divisor) { 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) - return NULL; // !assert + return NULL; /* !assert */ dest [char_nbr] = 0; return dest; } -// -------------------------------------------------------------------------- -// Decode an encoded string into a binary frame; dest must be at least -// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string) -// must be a multiple of 5. +/* -------------------------------------------------------------------------- */ +/* Decode an encoded string into a binary frame; dest must be at least */ +/* strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string) */ +/* must be a multiple of 5. */ uint8_t *zmq_z85_decode (uint8_t *dest, char *string) { if (strlen (string) % 5 != 0) - return NULL; // !assert + return NULL; /* !assert */ unsigned int byte_nbr = 0; unsigned int char_nbr = 0; uint32_t value = 0; size_t string_len = strlen (string); 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]; if (char_nbr % 5 == 0) { - // Output value in base 256 + /* Output value in base 256 */ unsigned int divisor = 256 * 256 * 256; while (divisor) { 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) - return NULL; //!assert + return NULL; /* !assert */ return dest; } diff --git a/src/encryption.c b/src/encryption.c index f825fe5..a576dc0 100644 --- a/src/encryption.c +++ b/src/encryption.c @@ -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); if(!feof(in) && !ferror(in)) { if(head == PCP_SYM_CIPHER) { - // symetric mode + /* symetric mode */ unsigned char *salt = ucmalloc(90); char stsalt[] = PBP_COMPAT_SALT; memcpy(salt, stsalt, 90); @@ -73,7 +73,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i free(salt); } else { - // asymetric mode + /* asymetric mode */ if(useid) { HASH_FIND_STR(pcpkey_hash, id, secret); 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) { - // encrypted, decrypt it + /* encrypted, decrypt it */ char *passphrase; if(passwd == NULL) { 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) { FILE *in = 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 *pub = 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; if(id == NULL && recipient == NULL) { - // self mode + /* self mode */ self = 1; char *passphrase; 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); 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; memcpy(salt, stsalt, 90); symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt, 90); free(salt); } else if(id != NULL && recipient == NULL) { - // lookup by id + /* lookup by id */ HASH_FIND_STR(pcppubkey_hash, id, tmp); if(tmp == NULL) { - // self-encryption: look if its a secret one + /* self-encryption: look if its a secret one */ pcp_key_t *s = NULL; HASH_FIND_STR(pcpkey_hash, id, s); if(s != NULL) { @@ -179,16 +179,16 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec } } else { - // found one by id, copy into local hash + /* found one by id, copy into local hash */ pub = ucmalloc(sizeof(pcp_pubkey_t)); memcpy(pub, tmp, sizeof(pcp_pubkey_t)); HASH_ADD_STR( pubhash, id, tmp); } } else if(recipient != NULL) { - // lookup by recipient list - // iterate through global hashlist - // copy matches into temporary pubhash + /* lookup by recipient list */ + /* iterate through global hashlist */ + /* copy matches into temporary pubhash */ plist_t *rec; pcphash_iteratepub(tmp) { 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)); memcpy(pub, tmp, sizeof(pcp_pubkey_t)); 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; } @@ -211,7 +211,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec 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 secret = pcpkey_new(); #else @@ -222,7 +222,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec } if(secret->secret[0] == 0) { - // encrypted, decrypt it + /* encrypted, decrypt it */ char *passphrase; if(passwd == NULL) { pcp_readpass(&passphrase, @@ -284,7 +284,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec } 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(pub); diff --git a/src/encryption.h b/src/encryption.h index b1cb54f..d830e23 100644 --- a/src/encryption.h +++ b/src/encryption.h @@ -39,4 +39,4 @@ 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); -#endif // _HAVE_ENCRYPTION_H +#endif /* _HAVE_ENCRYPTION_H */ diff --git a/src/keymgmt.c b/src/keymgmt.c index aa5b27f..91f8dcc 100644 --- a/src/keymgmt.c +++ b/src/keymgmt.c @@ -192,7 +192,7 @@ pcp_key_t *pcp_find_primary_secret() { } } - // no primary? whoops + /* no primary? whoops */ int nkeys = HASH_COUNT(pcpkey_hash); if(nkeys == 1) { pcphash_iterate(k) { @@ -209,7 +209,7 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile) { pcp_key_t *key = NULL; if(useid == 1) { - // look if we've got that one + /* look if we've got that one */ HASH_FIND_STR(pcpkey_hash, keyid, key); if(key == NULL) { 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 { - // look for our primary key + /* look for our primary key */ key = pcp_find_primary_secret(); if(key == NULL) { 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); else pcpkey_print(key, out); - // scip - //printf("EXPORT:\n"); - // pcpprint_bin(stdout, key, PCP_RAW_KEYSIZE); printf("\n"); + /* scip */ + /* printf("EXPORT:\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; if(keyid != NULL) { - // look if we've got that one + /* look if we've got that one */ HASH_FIND_STR(pcppubkey_hash, keyid, key); if(key == NULL) { - // maybe it's a secret key? + /* maybe it's a secret key? */ pcp_key_t *s = NULL; HASH_FIND_STR(pcpkey_hash, keyid, s); if(s == NULL) { @@ -279,7 +279,7 @@ void pcp_exportpublic(char *keyid, char *recipient, char *passwd, char *outfile, } } else { - // look for the primary secret + /* look for the primary secret */ pcp_key_t *s = NULL; s = pcp_find_primary_secret(); if(s == NULL) { @@ -304,9 +304,9 @@ void pcp_exportpublic(char *keyid, char *recipient, char *passwd, char *outfile, } if(out != NULL) { - // scip - //printf("EXPORT:\n"); - //pcpprint_bin(stdout, key, PCP_RAW_PUBKEYSIZE); printf("\n"); + /* scip */ + /* printf("EXPORT:\n"); */ + /* pcpprint_bin(stdout, key, PCP_RAW_PUBKEYSIZE); printf("\n"); */ pcppubkey_print(key, out, pbpcompat); if(pbpcompat) fprintf(stderr, "public key exported in PBP format.\n"); @@ -341,7 +341,7 @@ int pcp_importsecret (vault_t *vault, FILE *in) { return 1; } - // all good now, import the blob + /* all good now, import the blob */ pcp_key_t *key = ucmalloc(sizeof(pcp_key_t)); memcpy(key, z85decoded, PCP_RAW_KEYSIZE); key2native(key); @@ -351,7 +351,7 @@ int pcp_importsecret (vault_t *vault, FILE *in) { if(pcp_sanitycheck_key(key) == 0) { if(key->secret[0] != 0) { - // unencrypted, encrypt it + /* unencrypted, encrypt it */ fprintf(stderr, "Key to be imported is unencrypted.\n"); char *passphrase; 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 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; nlen = buflen; for(i=buflen; i>0; --i) { @@ -407,7 +407,7 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) { goto errimp1; } - // unpad result, if any + /* unpad result, if any */ for(i=klen; i>0; --i) { if(bin[i] != '\0' && i < klen) { 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); - // parse the name + /* parse the name */ parts = strtok (b->name, "<>"); pnum = 0; while (parts != NULL) { @@ -437,8 +437,8 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) { free(owner); } - // fill in the fields - pub->ctime = (long)time(0); // pbp exports no ctime + /* fill in the fields */ + pub->ctime = (long)time(0); /* pbp exports no ctime */ pub->type = PCP_KEY_TYPE_PUBLIC; pub->version = PCP_KEY_VERSION; pub->serial = arc4random(); @@ -487,7 +487,7 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) { return 1; } - // all good now + /* all good now */ pub = ucmalloc(sizeof(pcp_pubkey_t)); memcpy(pub, z85decoded, PCP_RAW_PUBKEYSIZE); pubkey2native(pub); @@ -513,7 +513,7 @@ void pcpdelete_key(char *keyid) { pcp_pubkey_t *p = pcphash_pubkeyexists(keyid); if(p != NULL) { - // delete public + /* delete public */ HASH_DEL(pcppubkey_hash, p); free(p); vault->unsafed = 1; @@ -522,7 +522,7 @@ void pcpdelete_key(char *keyid) { else { pcp_key_t *s = pcphash_keyexists(keyid); if(s != NULL) { - // delete secret + /* delete secret */ HASH_DEL(pcpkey_hash, s); free(s); vault->unsafed = 1; @@ -559,7 +559,7 @@ void pcpedit_key(char *keyid) { if(debug) pcp_dumpkey(key); - vault->unsafed = 1; // will be safed automatically + vault->unsafed = 1; /* will be safed automatically */ fprintf(stderr, "Key key changed.\n"); } } diff --git a/src/keymgmt.h b/src/keymgmt.h index 1dcc98f..49af972 100644 --- a/src/keymgmt.h +++ b/src/keymgmt.h @@ -58,4 +58,4 @@ int pcp_importsecret (vault_t *vault, FILE *in); void pcpdelete_key(char *keyid); char *pcp_find_id_byrec(char *recipient); -#endif // _HAVE_KEYMGMT_H +#endif /* _HAVE_KEYMGMT_H */ diff --git a/src/keyprint.c b/src/keyprint.c index 97bfae4..c6d316e 100644 --- a/src/keyprint.c +++ b/src/keyprint.c @@ -41,7 +41,7 @@ int pcptext_infile(char *infile) { goto tdone; } - // maybe a vault? + /* maybe a vault? */ vault_t *v = pcpvault_init(infile); if(v != NULL) { fprintf(stdout, "%s is a vault file\n", infile); @@ -49,7 +49,7 @@ int pcptext_infile(char *infile) { goto tdone; } - // try z85ing it + /* try z85ing it */ char *z85 = pcp_readz85file(in); if(z85 == NULL) { fprintf(stdout, "Can't handle %s - unknown file type.\n", infile); @@ -65,11 +65,11 @@ int pcptext_infile(char *infile) { goto errtinf1; } - //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)); + /* 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)); */ if(clen == PCP_RAW_KEYSIZE) { - // secret key? + /* secret key? */ pcp_key_t *key = (pcp_key_t *)bin; key2native(key); if(pcp_sanitycheck_key(key) == 0) { @@ -86,7 +86,7 @@ int pcptext_infile(char *infile) { } if(clen == PCP_RAW_PUBKEYSIZE) { - // public key? + /* public key? */ pcp_pubkey_t *key = (pcp_pubkey_t *)bin; pubkey2native(key); 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); tdone: @@ -199,7 +199,7 @@ void pcpkey_print(pcp_key_t *key, FILE* out) { 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", c->tm_year+1900, c->tm_mon+1, c->tm_mday, 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); 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) { size_t siglen = pbplen + crypto_sign_BYTES; size_t blen = ((siglen / 4) * 5) + siglen; @@ -266,7 +266,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) { else { size_t zlen; - //printf("version: %08x\n", key->version); + /* printf("version: %08x\n", key->version); */ 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, " 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", c->tm_year+1900, c->tm_mon+1, c->tm_mday, c->tm_hour, c->tm_min, c->tm_sec); diff --git a/src/keyprint.h b/src/keyprint.h index 22f1de2..2a9775f 100644 --- a/src/keyprint.h +++ b/src/keyprint.h @@ -50,4 +50,4 @@ int pcptext_infile(char *infile); void pcpexport_yaml(char *outfile); void pcpprint_bin(FILE *out, unsigned char *data, size_t len); -#endif // _HAVE_PCP_KEYPRINT_H +#endif /* _HAVE_PCP_KEYPRINT_H */ diff --git a/src/pcp.c b/src/pcp.c index e39643c..7008408 100644 --- a/src/pcp.c +++ b/src/pcp.c @@ -71,7 +71,7 @@ int main (int argc, char **argv) { pbpcompat = 0; static struct option longopts[] = { - // generics + /* generics */ { "vault", required_argument, NULL, 'V' }, { "outfile", required_argument, NULL, 'O' }, { "infile", required_argument, NULL, 'I' }, @@ -80,7 +80,7 @@ int main (int argc, char **argv) { { "xpass", required_argument, NULL, 'x' }, { "recipient", required_argument, NULL, 'r' }, - // key management + /* key management */ { "keygen", no_argument, NULL, 'k' }, { "listkeys", no_argument, NULL, 'l' }, { "export-secret", no_argument, NULL, 's' }, @@ -92,21 +92,21 @@ int main (int argc, char **argv) { { "export-yaml", no_argument, NULL, 'y' }, { "pbpcompat", no_argument, NULL, 'b' }, - // crypto + /* crypto */ { "encrypt", no_argument, NULL, 'e' }, { "encrypt-me", no_argument, NULL, 'm' }, { "decrypt", no_argument, NULL, 'd' }, - // encoding + /* encoding */ { "z85-encode", no_argument, NULL, 'z' }, { "z85-decode", no_argument, NULL, 'Z' }, - // globals + /* globals */ { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { "debug", no_argument, NULL, 'D' }, - // signing + /* signing */ { "sign", no_argument, NULL, 'g' }, { "check-signature", no_argument, NULL, 'c' }, { "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) { usevault = 0; @@ -361,16 +361,16 @@ int main (int argc, char **argv) { case PCP_MODE_ENCRYPT: 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); pcpencrypt(id, infile, outfile, xpass, NULL, signcrypt); } else if(useid == 0 && userec == 1) { - // multiple dst + /* multiple dst */ pcpencrypt(NULL, infile, outfile, xpass, recipient, signcrypt); } else { - // -i and -r specified + /* -i and -r specified */ fatal("You can't specify both -i and -r, use either -i or -r!\n"); } if(id != NULL) @@ -426,14 +426,14 @@ int main (int argc, char **argv) { break; default: - // + /* */ goto ELSEMODE; break; } } pcpvault_close(vault); pcphash_clean(); - ucfree(vaultfile); + free(vaultfile); } else { ELSEMODE: @@ -469,12 +469,12 @@ int main (int argc, char **argv) { } pcpvault_close(vault); pcphash_clean(); - ucfree(vaultfile); + free(vaultfile); } break; default: - // mode params mixed + /* mode params mixed */ fatal("Sorry, invalid combination of commandline parameters (0x%04X)!\n", mode); break; } diff --git a/src/pcp.h b/src/pcp.h index 00e98e9..4c503aa 100644 --- a/src/pcp.h +++ b/src/pcp.h @@ -32,7 +32,7 @@ #include #include -// lib +/* lib */ #include "mem.h" #include "z85.h" #include "zmq_z85.h" @@ -40,7 +40,7 @@ #include "version.h" #include "vault.h" -// subs +/* subs */ #include "keymgmt.h" #include "usage.h" #include "encryption.h" @@ -48,8 +48,8 @@ #include "keyhash.h" #include "plist.h" -// operation modi -// perl -e '$x=0; while ($x<100000) { $x++; $x *= 1.7; printf "0x%08X: %d\n", $x, $x }' +/* operation modi */ +/* 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_LISTKEYS 0x00000004 #define PCP_MODE_EXPORT_SECRET 0x00000009 @@ -88,4 +88,4 @@ void version(); void usage(); char *default_vault(); -#endif // _HAVE_PCP_H +#endif /* _HAVE_PCP_H */ diff --git a/src/signature.c b/src/signature.c index ec47d66..713f4dd 100644 --- a/src/signature.c +++ b/src/signature.c @@ -55,7 +55,7 @@ int pcpsign(char *infile, char *outfile, char *passwd, int z85, int detach) { } if(secret->secret[0] == 0) { - // encrypted, decrypt it + /* encrypted, decrypt it */ char *passphrase; if(passwd == NULL) { 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); - errv4: - errv1: return 1; } diff --git a/src/signature.h b/src/signature.h index d8b9919..9dda88e 100644 --- a/src/signature.h +++ b/src/signature.h @@ -37,4 +37,4 @@ int pcpverify(char *infile, char *sigfile, char *id, int detach); -#endif // _HAVE_SIGNATURE_H +#endif /* _HAVE_SIGNATURE_H */