diff --git a/include/pcp/buffer.h b/include/pcp/buffer.h index ef184b5..c3dbbf8 100644 --- a/include/pcp/buffer.h +++ b/include/pcp/buffer.h @@ -283,7 +283,7 @@ int buffer_done(Buffer *b); Then the following code would: @code - unsigned char g[4]; + byte g[4]; buffer_get_chunk(b, g, 4); // => g now contains 'AAAA' buffer_get_chunk(b, g, 4); // => g now contains 'BBBB' buffer_get_chunk(b, g, 4); // => g now contains 'CCCC' @@ -316,7 +316,7 @@ size_t buffer_get_chunk(Buffer *b, void *buf, size_t len); \return Pointer to the buffer data storage. */ -unsigned char *buffer_get(Buffer *b); +byte *buffer_get(Buffer *b); /** Read the whole Buffer content as string. @@ -365,8 +365,8 @@ char *buffer_get_str(Buffer *b); @code [..] - unsigned char g[4]; - unsigned char *r = NULL; + byte g[4]; + byte *r = NULL; buffer_get_chunk(b, g, 4); // => g now contains 'AAAA' size_t rs = buffer_left(b); // => rs = 8 r = buffer_get_remainder(b); // => r now contains 'BBBBCCCC' and has a size of 8 @@ -378,7 +378,7 @@ char *buffer_get_str(Buffer *b); \return Pointer to the remaining chunk of data (copy). */ -unsigned char *buffer_get_remainder(Buffer *b); +byte *buffer_get_remainder(Buffer *b); /** Read some data inside the Buffer. @@ -399,7 +399,7 @@ unsigned char *buffer_get_remainder(Buffer *b); Then: @code [..] - unsigned char g[4]; + byte g[4]; buffer_extract(b, g, 4, 4); // => g now contains 'BBBB' @endcode @@ -455,8 +455,8 @@ size_t buffer_size(const Buffer *b); Then: @code [..] - unsigned char g[4]; - unsigned char x[16]; + byte g[4]; + byte x[16]; buffer_get_chunk(b, g, 4); // => g now contains 'BBBB' if(buffer_left(b) >= 16) // => will return 8 and therefore fail buffer_get_chunk(b, x, 16); diff --git a/include/pcp/crypto.h b/include/pcp/crypto.h index 50aa8b8..5b85535 100644 --- a/include/pcp/crypto.h +++ b/include/pcp/crypto.h @@ -115,16 +115,16 @@ of 32k, N is a nonce (new per block) and S the symmetric key. */ -size_t pcp_sodium_box(unsigned char **cipher, - unsigned char *cleartext, +size_t pcp_sodium_box(byte **cipher, + byte *cleartext, size_t clearsize, - unsigned char *nonce, - unsigned char *secret, - unsigned char *pub); + byte *nonce, + byte *secret, + byte *pub); -int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message, - size_t messagesize, unsigned char *nonce, - unsigned char *secret, unsigned char *pub); +int pcp_sodium_verify_box(byte **cleartext, byte* message, + size_t messagesize, byte *nonce, + byte *secret, byte *pub); /** Asymmetrically encrypt a message. @@ -143,11 +143,11 @@ int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message, \param[out] csize A pointer which will be set to the size of the encrypted result if successful. - \return Returns an allocated unsigned char array of the size csize which contains the encrypted result. + \return Returns an allocated byte array of the size csize which contains the encrypted result. In case of an error, it returns NULL sets csize to 0. Use fatals_ifany() to check for errors. */ -unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, - unsigned char *message, size_t messagesize, +byte *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, + byte *message, size_t messagesize, size_t *csize); /** Asymmetrically decrypt a message. @@ -167,11 +167,11 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, \param[out] dsize A pointer which will be set to the size of the decrypted result if successful. - \return Returns an allocated unsigned char array of the size csize which contains the encrypted result. + \return Returns an allocated byte array of the size csize which contains the encrypted result. In case of an error, it returns NULL sets csize to 0. Use fatals_ifany() to check for errors. */ -unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub, - unsigned char *cipher, size_t ciphersize, +byte *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub, + byte *cipher, size_t ciphersize, size_t *dsize); @@ -217,7 +217,7 @@ size_t pcp_encrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, pcp_pubke \return Returns the size of the output written to the output stream or 0 in case of errors. */ -size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symkey, int havehead, pcp_rec_t *recsign); +size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream* out, byte *symkey, int havehead, pcp_rec_t *recsign); /** Asymmetrically decrypt a file or a buffer stream. @@ -241,7 +241,7 @@ size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symk \return Returns the size of the output written to the output stream or 0 in case of errors. */ -size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, unsigned char *symkey, int verify); +size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, byte *symkey, int verify); /** Symmetrically decrypt a file or a buffer stream. @@ -263,9 +263,9 @@ size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, unsigned \return Returns the size of the output written to the output stream or 0 in case of errors. */ -size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symkey, pcp_rec_t *recverify); +size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, byte *symkey, pcp_rec_t *recverify); -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(byte *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 */ diff --git a/include/pcp/ed.h b/include/pcp/ed.h index 8c9371c..9864780 100644 --- a/include/pcp/ed.h +++ b/include/pcp/ed.h @@ -56,7 +56,7 @@ \return Returns message+signature with size of messagesize + crypto_sign_BYTES, or NULL in case of an error. */ -unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t *s); +byte *pcp_ed_sign(byte *message, size_t messagesize, pcp_key_t *s); /** Sign a raw message using s->mastersecret. @@ -72,7 +72,7 @@ unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t \return Returns message+signature with size of messagesize + crypto_sign_BYTES, or NULL in case of an error. -*/unsigned char *pcp_ed_sign_key(unsigned char *message, size_t messagesize, pcp_key_t *s); +*/byte *pcp_ed_sign_key(byte *message, size_t messagesize, pcp_key_t *s); /** Verify a signature. @@ -89,7 +89,7 @@ unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t \return If the signature verifies return the raw message with the signature removed (size: siglen - crypto_sign_BYTES), returns NULL in case of errors. Check fatals_if_any(). */ -unsigned char *pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey_t *p); +byte *pcp_ed_verify(byte *signature, size_t siglen, pcp_pubkey_t *p); /** Verify a signature using the mastersecret. @@ -106,7 +106,7 @@ unsigned char *pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey \return If the signature verifies return the raw message with the signature removed (size: siglen - crypto_sign_BYTES), returns NULL in case of errors. Check fatals_if_any(). */ -unsigned char *pcp_ed_verify_key(unsigned char *signature, size_t siglen, pcp_pubkey_t *p); +byte *pcp_ed_verify_key(byte *signature, size_t siglen, pcp_pubkey_t *p); /** Sign a stream in 32k block mode. diff --git a/include/pcp/key.h b/include/pcp/key.h index 696f605..f86b0f3 100644 --- a/include/pcp/key.h +++ b/include/pcp/key.h @@ -342,9 +342,9 @@ char *pcp_getpubkeyid(pcp_pubkey_t *k); \param[in] k The public key structure. - \return Returns a pointer to an 32 byte unsigned char. + \return Returns a pointer to an 32 byte byte. */ -unsigned char *pcppubkey_getchecksum(pcp_pubkey_t *k); +byte *pcppubkey_getchecksum(pcp_pubkey_t *k); /** Calculate a checksum of a public key part of the given secret key. @@ -352,9 +352,9 @@ unsigned char *pcppubkey_getchecksum(pcp_pubkey_t *k); \param[in] k The secret key structure. - \return Returns a pointer to an 32 byte unsigned char. + \return Returns a pointer to an 32 byte byte. */ -unsigned char *pcpkey_getchecksum(pcp_key_t *k); +byte *pcpkey_getchecksum(pcp_key_t *k); /** Checks if a secret key structure is registered in the secret key hash. @@ -396,14 +396,14 @@ pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k); functions. It allocates the memory and the caller is responsible to clear and free() it after use. - \return Returns a pointer to a 24 byte unsigned char array. + \return Returns a pointer to a 24 byte byte array. */ -unsigned char * pcp_gennonce(); +byte * pcp_gennonce(); /* use scrypt() to create a key from a passphrase and a nonce FIXME: use pure scrypt() instead. */ -unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce); +byte *pcp_derivekey(char *passphrase, byte *nonce); /* FIXME: abandon and use Buffer instead */ void pcp_seckeyblob(void *blob, pcp_key_t *k); diff --git a/include/pcp/mac.h b/include/pcp/mac.h index 8e000b0..38d811f 100644 --- a/include/pcp/mac.h +++ b/include/pcp/mac.h @@ -31,6 +31,7 @@ #include #include #include +#include "defines.h" #include "pad.h" #include "mem.h" @@ -55,11 +56,11 @@ \return Returns the size of \a cipher. */ -size_t pcp_sodium_mac(unsigned char **cipher, - unsigned char *cleartext, +size_t pcp_sodium_mac(byte **cipher, + byte *cleartext, size_t clearsize, - unsigned char *nonce, - unsigned char *key); + byte *nonce, + byte *key); /** Decrypt a symmetrically encrypted message. @@ -79,11 +80,11 @@ size_t pcp_sodium_mac(unsigned char **cipher, \return Returns 0 in case of success of -1 in case of an error. Check fatals_if_any(). */ -int pcp_sodium_verify_mac(unsigned char **cleartext, - unsigned char* message, +int pcp_sodium_verify_mac(byte **cleartext, + byte* message, size_t messagesize, - unsigned char *nonce, - unsigned char *key); + byte *nonce, + byte *key); diff --git a/include/pcp/mem.h b/include/pcp/mem.h index ea049b2..fe43ad9 100644 --- a/include/pcp/mem.h +++ b/include/pcp/mem.h @@ -25,6 +25,7 @@ #include #include +#include "defines.h" #include "platform.h" /* simple malloc() wrapper */ diff --git a/include/pcp/mgmt.h b/include/pcp/mgmt.h index f2ec3a6..521005a 100644 --- a/include/pcp/mgmt.h +++ b/include/pcp/mgmt.h @@ -298,12 +298,12 @@ Buffer *pcp_export_c_pub(pcp_key_t *sk); */ Buffer *pcp_export_secret(pcp_key_t *sk, char *passphrase); -pcp_ks_bundle_t *pcp_import_pub(unsigned char *raw, size_t rawsize); +pcp_ks_bundle_t *pcp_import_pub(byte *raw, size_t rawsize); pcp_ks_bundle_t *pcp_import_pub_rfc(Buffer *blob); pcp_ks_bundle_t *pcp_import_pub_pbp(Buffer *blob); /* import secret key */ -pcp_key_t *pcp_import_secret(unsigned char *raw, size_t rawsize, char *passphrase); +pcp_key_t *pcp_import_secret(byte *raw, size_t rawsize, char *passphrase); pcp_key_t *pcp_import_secret_native(Buffer *cipher, char *passphrase); #endif // _HAVE_PCP_MGMT_H diff --git a/include/pcp/pad.h b/include/pcp/pad.h index d9c7cf6..d12ff09 100644 --- a/include/pcp/pad.h +++ b/include/pcp/pad.h @@ -59,13 +59,13 @@ /* sample call: */ /* */ /* char unpadded[] = {0xef, 0xa5}; */ -/* unsigned char *padded; */ +/* byte *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, +void pcp_pad_prepend(byte **padded, byte *unpadded, size_t padlen, size_t unpadlen); /* removes zero's of a binary stream, which is */ @@ -86,12 +86,12 @@ void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded, /* sample call: */ /* */ /* char padded[] = {0x0, 0x0, 0x0, 0x0, 0xef, 0xa5}; */ -/* unsigned char *unpadded; */ +/* byte *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, +void pcp_pad_remove(byte **unpadded, byte *padded, size_t padlen, size_t unpadlen); diff --git a/include/pcp/scrypt.h b/include/pcp/scrypt.h index b0d44d0..c07c76b 100644 --- a/include/pcp/scrypt.h +++ b/include/pcp/scrypt.h @@ -36,7 +36,7 @@ #include "mem.h" #include "defines.h" -unsigned char * pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen); +byte * pcp_scrypt(char *passwd, size_t passwdlen, byte *nonce, size_t noncelen); #endif /* _HAVE_PCP_SCRYPT_H */ diff --git a/include/pcp/uthash.h b/include/pcp/uthash.h index 72acf11..0952631 100755 --- a/include/pcp/uthash.h +++ b/include/pcp/uthash.h @@ -59,7 +59,7 @@ do { /* a number of the hash function use uint32_t which isn't defined on win32 */ #ifdef _MSC_VER typedef unsigned int uint32_t; -typedef unsigned char uint8_t; +typedef byte uint8_t; #else #include /* uint32_t */ #endif @@ -416,7 +416,7 @@ do { #define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \ do { \ unsigned _hj_i,_hj_j,_hj_k; \ - unsigned char *_hj_key=(unsigned char*)(key); \ + byte *_hj_key=(byte*)(key); \ hashv = 0xfeedbeef; \ _hj_i = _hj_j = 0x9e3779b9; \ _hj_k = (unsigned)(keylen); \ @@ -467,7 +467,7 @@ do { #endif #define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \ do { \ - unsigned char *_sfh_key=(unsigned char*)(key); \ + byte *_sfh_key=(byte*)(key); \ uint32_t _sfh_tmp, _sfh_len = keylen; \ \ int _sfh_rem = _sfh_len & 3; \ diff --git a/include/pcp/util.h b/include/pcp/util.h index b9ad053..42decb3 100644 --- a/include/pcp/util.h +++ b/include/pcp/util.h @@ -37,7 +37,7 @@ #include #include - +#include "defines.h" /** Convert a char array to lowercase. @@ -74,7 +74,7 @@ char *_lc(char *in); \return Returns the offset or -1 of the offset were not found. */ -size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hlen); +size_t _findoffset(byte *bin, size_t binlen, char *sigstart, size_t hlen); /** XOR an input buffer with another buffer. @@ -87,7 +87,7 @@ size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hle \param[in] xlen The size of the buffers (they must have the same size). */ -void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen); +void _xorbuf(byte *iv, byte *buf, size_t xlen); /** Dump binary data as hex to stderr. @@ -97,7 +97,7 @@ void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen); \param[in] s Size of d. */ -void _dump(char *n, unsigned char *d, size_t s); +void _dump(char *n, byte *d, size_t s); #endif /* _HAVE_PCP_UTIL_H */ diff --git a/include/pcp/vault.h b/include/pcp/vault.h index fef5cc6..46dc91c 100644 --- a/include/pcp/vault.h +++ b/include/pcp/vault.h @@ -240,7 +240,7 @@ int pcpvault_copy(vault_t *tmp, vault_t *vault); void pcpvault_unlink(vault_t *tmp); /* calculate the vault checksum */ -unsigned char *pcpvault_create_checksum(vault_t *vault); +byte *pcpvault_create_checksum(vault_t *vault); /* write the new checksum to the header of the current vault */ void pcpvault_update_checksum(vault_t *vault); diff --git a/libpcp/buffer.c b/libpcp/buffer.c index 4fc4dc0..bf8c11c 100644 --- a/libpcp/buffer.c +++ b/libpcp/buffer.c @@ -98,7 +98,7 @@ void buffer_add_str(Buffer *b, const char * fmt, ...) { void buffer_add_hex(Buffer *b, void *data, size_t len) { size_t i; - unsigned char *d = data; + byte *d = data; for(i=0; iend > 0) return b->buf; else @@ -136,7 +136,7 @@ size_t buffer_get_chunk(Buffer *b, void *buf, size_t len) { return len; } -unsigned char *buffer_get_remainder(Buffer *b) { +byte *buffer_get_remainder(Buffer *b) { void *buf = ucmalloc(b->end - b->offset); if(buffer_get_chunk(b, buf, b->end - b->offset) == 0) { free(buf); diff --git a/libpcp/crypto.c b/libpcp/crypto.c index 531b479..d8ee7bf 100644 --- a/libpcp/crypto.c +++ b/libpcp/crypto.c @@ -22,15 +22,15 @@ #include "crypto.h" -size_t pcp_sodium_box(unsigned char **cipher, - unsigned char *cleartext, +size_t pcp_sodium_box(byte **cipher, + byte *cleartext, size_t clearsize, - unsigned char *nonce, - unsigned char *secret, - unsigned char *pub) { + byte *nonce, + byte *secret, + byte *pub) { - unsigned char *pad_clear; - unsigned char *pad_cipher; + byte *pad_clear; + byte *pad_cipher; size_t ciphersize = (clearsize + crypto_box_ZEROBYTES) - crypto_box_BOXZEROBYTES; @@ -52,16 +52,16 @@ 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) { +int pcp_sodium_verify_box(byte **cleartext, byte* message, + size_t messagesize, byte *nonce, + byte *secret, byte *pub) { /* verify/decrypt the box */ - unsigned char *pad_cipher; - unsigned char *pad_clear; + byte *pad_cipher; + byte *pad_clear; int success = -1; pcp_pad_prepend(&pad_cipher, message, crypto_box_BOXZEROBYTES, messagesize); - pad_clear = (unsigned char *)ucmalloc((crypto_box_ZEROBYTES+ messagesize)); + pad_clear = (byte *)ucmalloc((crypto_box_ZEROBYTES+ messagesize)); /* crypto_box_open(m,c,clen,n,pk,sk); */ if (crypto_box_open(pad_clear, pad_cipher, @@ -81,13 +81,13 @@ int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message, -unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, - unsigned char *message, size_t messagesize, +byte *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, + byte *message, size_t messagesize, size_t *csize) { - unsigned char *nonce = pcp_gennonce(); + byte *nonce = pcp_gennonce(); - unsigned char *cipher; + byte *cipher; size_t es = pcp_sodium_box(&cipher, message, messagesize, nonce, secret->secret, pub->pub); @@ -104,7 +104,7 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, /* fprintf(stderr, " nonce: "); pcpprint_bin(stderr, nonce, crypto_secretbox_NONCEBYTES); fprintf(stderr, "\n"); */ /* put nonce and cipher together */ - unsigned char *combined = ucmalloc(es + crypto_secretbox_NONCEBYTES); + byte *combined = ucmalloc(es + crypto_secretbox_NONCEBYTES); memcpy(combined, nonce, crypto_secretbox_NONCEBYTES); memcpy(&combined[crypto_secretbox_NONCEBYTES], cipher, es); @@ -124,14 +124,14 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub, } -unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub, - unsigned char *cipher, size_t ciphersize, +byte *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub, + byte *cipher, size_t ciphersize, size_t *dsize) { - unsigned char *message = NULL; + byte *message = NULL; - unsigned char *nonce = ucmalloc(crypto_secretbox_NONCEBYTES); - unsigned char *cipheronly = ucmalloc(ciphersize - crypto_secretbox_NONCEBYTES); + byte *nonce = ucmalloc(crypto_secretbox_NONCEBYTES); + byte *cipheronly = ucmalloc(ciphersize - crypto_secretbox_NONCEBYTES); memcpy(nonce, cipher, crypto_secretbox_NONCEBYTES); memcpy(cipheronly, &cipher[crypto_secretbox_NONCEBYTES], @@ -161,21 +161,22 @@ unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub, return NULL; } -size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, unsigned char *symkey, int verify) { +size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, byte *symkey, int verify) { pcp_pubkey_t *cur = NULL; pcp_pubkey_t *sender = NULL; - unsigned char *reccipher = NULL; - int nrec, recmatch; + byte *reccipher = NULL; + int nrec, recmatch, self; uint32_t lenrec; byte head[1]; size_t cur_bufsize, rec_size; - unsigned char rec_buf[PCP_ASYM_RECIPIENT_SIZE]; + byte rec_buf[PCP_ASYM_RECIPIENT_SIZE]; #ifdef PCP_ASYM_ADD_SENDER_PUB - unsigned char *senderpub; + byte *senderpub; #endif - int self = 0; + + nrec = recmatch = self = 0; if(ps_tell(in) == 1) { /* header has already been determined outside the lib */ @@ -238,7 +239,7 @@ size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, unsigned recmatch = 0; pcphash_iteratepub(cur) { - unsigned char *recipient; + byte *recipient; recipient = pcp_box_decrypt(s, cur, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size); if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) { /* found a match */ @@ -278,9 +279,9 @@ size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, unsigned } size_t pcp_encrypt_stream(Pcpstream *in, Pcpstream *out, pcp_key_t *s, pcp_pubkey_t *p, int sign) { - unsigned char *symkey; + byte *symkey; int recipient_count; - unsigned char *recipients_cipher; + byte *recipients_cipher; pcp_pubkey_t *cur, *t; size_t es; int nrec; @@ -307,7 +308,7 @@ size_t pcp_encrypt_stream(Pcpstream *in, Pcpstream *out, pcp_key_t *s, pcp_pubke nrec = 0; HASH_ITER(hh, p, cur, t) { - unsigned char *rec_cipher; + byte *rec_cipher; rec_cipher = pcp_box_encrypt(s, cur, symkey, crypto_secretbox_KEYBYTES, &es); if(es != rec_size) { fatal("invalid rec_size, expected %dl, got %dl\n", rec_size, es); @@ -388,20 +389,20 @@ size_t pcp_encrypt_stream(Pcpstream *in, Pcpstream *out, pcp_key_t *s, pcp_pubke -size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream *out, unsigned char *symkey, int havehead, pcp_rec_t *recsign) { +size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream *out, byte *symkey, int havehead, pcp_rec_t *recsign) { /* havehead = 0: write the whole thing from here havehead = 1: no header, being called from asym... */ - unsigned char *buf_nonce; - unsigned char *buf_cipher; - unsigned char in_buf[PCP_BLOCK_SIZE]; + byte *buf_nonce; + byte *buf_cipher; + byte in_buf[PCP_BLOCK_SIZE]; size_t cur_bufsize = 0; size_t out_size = 0; size_t es; crypto_generichash_state *st = NULL; - unsigned char *hash = NULL; + byte *hash = NULL; byte head[1]; if(recsign != NULL) { @@ -424,8 +425,8 @@ size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream *out, unsigned char *symk /* 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); + byte *iv = urmalloc(PCP_BLOCK_SIZE); + byte *ivpad = urmalloc(PCP_BLOCK_SIZE_IN - PCP_BLOCK_SIZE); ps_write(out, ivpad, PCP_BLOCK_SIZE_IN - PCP_BLOCK_SIZE); ps_write(out, iv, PCP_BLOCK_SIZE); @@ -478,7 +479,7 @@ size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream *out, unsigned char *symk crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX); /* generate the actual signature */ - unsigned char *signature = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, recsign->secret); + byte *signature = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, recsign->secret); size_t siglen = crypto_sign_BYTES + crypto_generichash_BYTES_MAX; /* encrypt it as well */ @@ -503,27 +504,27 @@ size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream *out, unsigned char *symk free(st); free(hash); } - return NULL; + return 0; } -size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symkey, pcp_rec_t *recverify) { - unsigned char *buf_nonce; - unsigned char *buf_cipher; - unsigned char *buf_clear; +size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, byte *symkey, pcp_rec_t *recverify) { + byte *buf_nonce; + byte *buf_cipher; + byte *buf_clear; size_t out_size, cur_bufsize, es; size_t ciphersize = (PCP_BLOCK_SIZE_IN) - crypto_secretbox_NONCEBYTES; - unsigned char in_buf[PCP_BLOCK_SIZE_IN]; + byte in_buf[PCP_BLOCK_SIZE_IN]; buf_nonce = ucmalloc(crypto_secretbox_NONCEBYTES); buf_cipher = ucmalloc(ciphersize); out_size = 0; - unsigned char *signature = NULL; - unsigned char *signature_cr = NULL; + byte *signature = NULL; + byte *signature_cr = NULL; size_t siglen = crypto_sign_BYTES + crypto_generichash_BYTES_MAX; size_t siglen_cr = siglen + PCP_CRYPTO_ADD + crypto_secretbox_NONCEBYTES; crypto_generichash_state *st = NULL; - unsigned char *hash = NULL; + byte *hash = NULL; if(recverify != NULL) { st = ucmalloc(sizeof(crypto_generichash_state)); @@ -533,7 +534,7 @@ size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symk } #ifdef PCP_CBC - unsigned char *iv = NULL; /* will be filled during 1st loop */ + byte *iv = NULL; /* will be filled during 1st loop */ #endif while(!ps_end(in)) { @@ -612,7 +613,7 @@ size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symk crypto_generichash_update(st, recverify->cipher, recverify->ciphersize); crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX); - unsigned char *verifiedhash = NULL; + byte *verifiedhash = NULL; verifiedhash = pcp_ed_verify(signature, siglen, recverify->pub); if(verifiedhash == NULL) out_size = 0; @@ -639,7 +640,7 @@ size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symk } -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(byte *cipher, size_t clen, pcp_key_t *secret, pcp_pubkey_t *pub) { pcp_rec_t *r = ucmalloc(sizeof(pcp_rec_t)); r->cipher = ucmalloc(clen); memcpy(r->cipher, cipher, clen); diff --git a/libpcp/ed.c b/libpcp/ed.c index 12055c9..c1f608c 100644 --- a/libpcp/ed.c +++ b/libpcp/ed.c @@ -21,8 +21,8 @@ #include "ed.h" -unsigned char * pcp_ed_verify_key(unsigned char *signature, size_t siglen, pcp_pubkey_t *p) { - unsigned char *message = ucmalloc(siglen - crypto_sign_BYTES); +byte * pcp_ed_verify_key(byte *signature, size_t siglen, pcp_pubkey_t *p) { + byte *message = ucmalloc(siglen - crypto_sign_BYTES); unsigned long long mlen; if(crypto_sign_open(message, &mlen, signature, siglen, p->masterpub) != 0) { @@ -37,8 +37,8 @@ unsigned char * pcp_ed_verify_key(unsigned char *signature, size_t siglen, pcp_p return NULL; } -unsigned char * pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey_t *p) { - unsigned char *message = ucmalloc(siglen); /* we alloc the full size, the resulting len will be returned by nacl anyway - crypto_sign_BYTES); */ +byte * pcp_ed_verify(byte *signature, size_t siglen, pcp_pubkey_t *p) { + byte *message = ucmalloc(siglen); /* we alloc the full size, the resulting len will be returned by nacl anyway - crypto_sign_BYTES); */ unsigned long long mlen; if(crypto_sign_open(message, &mlen, signature, siglen, p->edpub) != 0) { @@ -53,18 +53,18 @@ unsigned char * pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubke return NULL; } -unsigned char *pcp_ed_sign_key(unsigned char *message, size_t messagesize, pcp_key_t *s) { +byte *pcp_ed_sign_key(byte *message, size_t messagesize, pcp_key_t *s) { unsigned long long mlen = messagesize + crypto_sign_BYTES; - unsigned char *signature = ucmalloc(mlen); + byte *signature = ucmalloc(mlen); crypto_sign(signature, &mlen, message, messagesize, s->mastersecret); return signature; } -unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t *s) { +byte *pcp_ed_sign(byte *message, size_t messagesize, pcp_key_t *s) { unsigned long long mlen = messagesize + crypto_sign_BYTES; - unsigned char *signature = ucmalloc(mlen); + byte *signature = ucmalloc(mlen); crypto_sign(signature, &mlen, message, messagesize, s->edsecret); @@ -72,11 +72,11 @@ unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t } size_t pcp_ed_sign_buffered(Pcpstream *in, Pcpstream* out, pcp_key_t *s, int z85) { - unsigned char in_buf[PCP_BLOCK_SIZE]; + byte in_buf[PCP_BLOCK_SIZE]; size_t cur_bufsize = 0; size_t outsize = 0; crypto_generichash_state *st = ucmalloc(sizeof(crypto_generichash_state)); - unsigned char hash[crypto_generichash_BYTES_MAX]; + byte hash[crypto_generichash_BYTES_MAX]; crypto_generichash_init(st, NULL, 0, 0); @@ -101,13 +101,13 @@ size_t pcp_ed_sign_buffered(Pcpstream *in, Pcpstream* out, pcp_key_t *s, int z85 crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX); - unsigned char *signature = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, s); + byte *signature = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, s); size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX; if(z85) { ps_print(out, "\r\n%s\r\n~ Version: PCP v%d.%d.%d ~\r\n\r\n", PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); size_t zlen; - char *z85encoded = pcp_z85_encode((unsigned char*)signature, mlen, &zlen); + char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen); ps_print(out, "%s\r\n%s\r\n", z85encoded, PCP_SIG_END); } else { @@ -121,9 +121,9 @@ size_t pcp_ed_sign_buffered(Pcpstream *in, Pcpstream* out, pcp_key_t *s, int z85 } pcp_pubkey_t *pcp_ed_verify_buffered(Pcpstream *in, pcp_pubkey_t *p) { - unsigned char in_buf[PCP_BLOCK_SIZE/2]; - unsigned char in_next[PCP_BLOCK_SIZE/2]; - unsigned char in_full[PCP_BLOCK_SIZE]; + byte in_buf[PCP_BLOCK_SIZE/2]; + byte in_next[PCP_BLOCK_SIZE/2]; + byte in_full[PCP_BLOCK_SIZE]; size_t cur_bufsize = 0; size_t next_bufsize = 0; @@ -132,14 +132,14 @@ pcp_pubkey_t *pcp_ed_verify_buffered(Pcpstream *in, pcp_pubkey_t *p) { int z85 = 0; int gotsig = 0; - unsigned char hash[crypto_generichash_BYTES_MAX]; + byte hash[crypto_generichash_BYTES_MAX]; char zhead[] = PCP_SIG_HEADER; size_t hlen = strlen(PCP_SIG_HEADER); size_t hlen2 = 17; /* " hash: blake2\r\n\r\n" FIXME: parse and calculate */ size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX; size_t zlen = 262; /* FIXME: calculate */ - unsigned char z85encoded[zlen]; - unsigned char sighash[mlen]; + byte z85encoded[zlen]; + byte sighash[mlen]; char z85sigstart[] = "\n" PCP_SIG_START; /* FIXME: verifies, but it misses the \r! */ char binsigstart[] = PCP_SIGPREFIX; char sigstart[] = PCP_SIG_START; @@ -259,7 +259,7 @@ pcp_pubkey_t *pcp_ed_verify_buffered(Pcpstream *in, pcp_pubkey_t *p) { goto errvb1; size_t dstlen; - unsigned char *z85decoded = pcp_z85_decode(z85block, &dstlen); + byte *z85decoded = pcp_z85_decode(z85block, &dstlen); if(dstlen != mlen) { fatal("z85 decoded signature didn't result in a proper signed hash(got: %ld, expected: %ld)\n", dstlen, mlen); goto errvb1; @@ -269,7 +269,7 @@ pcp_pubkey_t *pcp_ed_verify_buffered(Pcpstream *in, pcp_pubkey_t *p) { /* else: if unarmored, sighash is already filled */ /* huh, how did we made it til here? */ - unsigned char *verifiedhash = NULL; + byte *verifiedhash = NULL; if(p == NULL) { pcphash_iteratepub(p) { verifiedhash = pcp_ed_verify(sighash, mlen, p); @@ -300,11 +300,11 @@ pcp_pubkey_t *pcp_ed_verify_buffered(Pcpstream *in, pcp_pubkey_t *p) { } size_t pcp_ed_detachsign_buffered(Pcpstream *in, Pcpstream *out, pcp_key_t *s) { - unsigned char in_buf[PCP_BLOCK_SIZE]; + byte in_buf[PCP_BLOCK_SIZE]; size_t cur_bufsize = 0; size_t outsize = 0; crypto_generichash_state *st = ucmalloc(sizeof(crypto_generichash_state)); - unsigned char hash[crypto_generichash_BYTES_MAX]; + byte hash[crypto_generichash_BYTES_MAX]; crypto_generichash_init(st, NULL, 0, 0); @@ -318,13 +318,13 @@ size_t pcp_ed_detachsign_buffered(Pcpstream *in, Pcpstream *out, pcp_key_t *s) { crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX); - unsigned char *signature = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, s); + byte *signature = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, s); size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX; ps_print(out, "\r\n%s\r\n~ Version: PCP v%d.%d.%d ~\r\n\r\n", PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); size_t zlen; - char *z85encoded = pcp_z85_encode((unsigned char*)signature, mlen, &zlen); + char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen); ps_print(out, "%s\r\n%s\r\n", z85encoded, PCP_SIG_END); free(st); @@ -333,11 +333,11 @@ size_t pcp_ed_detachsign_buffered(Pcpstream *in, Pcpstream *out, pcp_key_t *s) { } pcp_pubkey_t *pcp_ed_detachverify_buffered(Pcpstream *in, Pcpstream *sigfd, pcp_pubkey_t *p) { - unsigned char in_buf[PCP_BLOCK_SIZE]; + byte in_buf[PCP_BLOCK_SIZE]; size_t cur_bufsize = 0; size_t outsize = 0; crypto_generichash_state *st = ucmalloc(sizeof(crypto_generichash_state)); - unsigned char hash[crypto_generichash_BYTES_MAX]; + byte hash[crypto_generichash_BYTES_MAX]; size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX; crypto_generichash_init(st, NULL, 0, 0); @@ -353,19 +353,19 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(Pcpstream *in, Pcpstream *sigfd, pcp_ crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX); /* read the sig */ - unsigned char *sig = NULL; + byte *sig = NULL; size_t inputBufSize = 0; - unsigned char byte[1]; + byte onebyte[1]; while(!ps_end(sigfd)) { - if(!ps_read(sigfd, &byte, 1)) + if(!ps_read(sigfd, &onebyte, 1)) break; /* if(!fread(&byte, 1, 1, sigfd)) break;*/ - unsigned char *tmp = realloc(sig, inputBufSize + 1); + byte *tmp = realloc(sig, inputBufSize + 1); sig = tmp; - memmove(&sig[inputBufSize], byte, 1); + memmove(&sig[inputBufSize], onebyte, 1); inputBufSize ++; } @@ -380,7 +380,7 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(Pcpstream *in, Pcpstream *sigfd, pcp_ goto errdea2; size_t clen; - unsigned char *sighash = pcp_z85_decode(z85block, &clen); + byte *sighash = pcp_z85_decode(z85block, &clen); if(sighash == NULL) goto errdea3; @@ -389,7 +389,7 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(Pcpstream *in, Pcpstream *sigfd, pcp_ goto errdea4; } - unsigned char *verifiedhash = NULL; + byte *verifiedhash = NULL; if(p == NULL) { pcphash_iteratepub(p) { verifiedhash = pcp_ed_verify(sighash, mlen, p); diff --git a/libpcp/key.c b/libpcp/key.c index 2ac38a0..c00bfa3 100644 --- a/libpcp/key.c +++ b/libpcp/key.c @@ -28,15 +28,15 @@ * derivation function. However, I create a hash from the pcp_scrypt() * result anyway because I need a cure25519 secret. */ -unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) { - unsigned char *key = ucmalloc(crypto_secretbox_KEYBYTES); +byte *pcp_derivekey(char *passphrase, byte *nonce) { + byte *key = ucmalloc(crypto_secretbox_KEYBYTES); size_t plen = strnlen(passphrase, 255); /* create the scrypt hash */ - unsigned char *scrypted = pcp_scrypt(passphrase, plen, nonce, crypto_secretbox_NONCEBYTES); + byte *scrypted = pcp_scrypt(passphrase, plen, nonce, crypto_secretbox_NONCEBYTES); /* make a hash from the scrypt() result */ - crypto_hash_sha256(key, (unsigned char*)scrypted, 64); + crypto_hash_sha256(key, (byte*)scrypted, 64); /* turn the 32byte hash into a secret key */ key[0] &= 248; @@ -136,21 +136,21 @@ pcp_key_t * pcpkey_new () { return key; } -unsigned char * pcp_gennonce() { - unsigned char *nonce = ucmalloc(crypto_secretbox_NONCEBYTES); +byte * pcp_gennonce() { + byte *nonce = ucmalloc(crypto_secretbox_NONCEBYTES); arc4random_buf(nonce, crypto_secretbox_NONCEBYTES); return nonce; } pcp_key_t *pcpkey_encrypt(pcp_key_t *key, char *passphrase) { if(key->nonce[0] == 0) { - unsigned char *nonce = pcp_gennonce(); + byte *nonce = pcp_gennonce(); memcpy (key->nonce, nonce, crypto_secretbox_NONCEBYTES); } - unsigned char *encryptkey = pcp_derivekey(passphrase, key->nonce); + byte *encryptkey = pcp_derivekey(passphrase, key->nonce); - unsigned char *encrypted; + byte *encrypted; size_t es; Buffer *both = buffer_new(128, "keypack"); @@ -184,9 +184,9 @@ pcp_key_t *pcpkey_encrypt(pcp_key_t *key, char *passphrase) { } pcp_key_t *pcpkey_decrypt(pcp_key_t *key, char *passphrase) { - unsigned char *encryptkey = pcp_derivekey(passphrase, key->nonce); + byte *encryptkey = pcp_derivekey(passphrase, key->nonce); - unsigned char *decrypted; + byte *decrypted; size_t es; es = pcp_sodium_verify_mac(&decrypted, key->encrypted, 176, key->nonce, encryptkey); @@ -235,14 +235,14 @@ char *pcpkey_get_art(pcp_key_t *k) { return r; } -unsigned char *pcppubkey_getchecksum(pcp_pubkey_t *k) { - unsigned char *hash = ucmalloc(32); +byte *pcppubkey_getchecksum(pcp_pubkey_t *k) { + byte *hash = ucmalloc(32); crypto_hash_sha256(hash, k->pub, 32); return hash; } -unsigned char *pcpkey_getchecksum(pcp_key_t *k) { - unsigned char *hash = ucmalloc(32); +byte *pcpkey_getchecksum(pcp_key_t *k) { + byte *hash = ucmalloc(32); crypto_hash_sha256(hash, k->pub, 32); return hash; } @@ -253,7 +253,7 @@ pcp_key_t * key2be(pcp_key_t *k) { return k; #else uint32_t version = k->version; - unsigned char* p = (unsigned char*)&version; + byte* p = (byte*)&version; if(p[0] != 0) { k->version = htobe32(k->version); k->serial = htobe32(k->serial); @@ -279,7 +279,7 @@ pcp_pubkey_t * pubkey2be(pcp_pubkey_t *k) { return k; #else uint32_t version = k->version; - unsigned char* p = (unsigned char*)&version; + byte* p = (byte*)&version; if(p[0] != 0) { k->version = htobe32(k->version); k->serial = htobe32(k->serial); diff --git a/libpcp/keysig.c b/libpcp/keysig.c index 489e349..6f4afea 100644 --- a/libpcp/keysig.c +++ b/libpcp/keysig.c @@ -27,7 +27,7 @@ pcp_keysig_t * keysig2be(pcp_keysig_t *s) { return s; #else uint32_t size = s->size; - unsigned char* p = (unsigned char*)&size; + byte* p = (byte*)&size; if(p[0] != 0) { s->size = htobe32(s->size); } diff --git a/libpcp/mac.c b/libpcp/mac.c index d059458..d66228c 100644 --- a/libpcp/mac.c +++ b/libpcp/mac.c @@ -24,13 +24,13 @@ -size_t pcp_sodium_mac(unsigned char **cipher, - unsigned char *cleartext, +size_t pcp_sodium_mac(byte **cipher, + byte *cleartext, size_t clearsize, - unsigned char *nonce, - unsigned char *key) { - unsigned char *pad_clear; - unsigned char *pad_cipher; + byte *nonce, + byte *key) { + byte *pad_clear; + byte *pad_cipher; pad_cipher = ucmalloc(crypto_secretbox_ZEROBYTES + clearsize); @@ -48,17 +48,17 @@ size_t pcp_sodium_mac(unsigned char **cipher, return (clearsize + crypto_secretbox_ZEROBYTES) - crypto_secretbox_BOXZEROBYTES; } -int pcp_sodium_verify_mac(unsigned char **cleartext, unsigned char* message, - size_t messagesize, unsigned char *nonce, - unsigned char *key) { +int pcp_sodium_verify_mac(byte **cleartext, byte* message, + size_t messagesize, byte *nonce, + byte *key) { /* verify the mac */ - unsigned char *pad_cipher; - unsigned char *pad_clear; + byte *pad_cipher; + byte *pad_clear; int success = -1; pcp_pad_prepend(&pad_cipher, message, crypto_secretbox_BOXZEROBYTES, messagesize); - pad_clear = (unsigned char *)ucmalloc((crypto_secretbox_ZEROBYTES + messagesize)); + pad_clear = (byte *)ucmalloc((crypto_secretbox_ZEROBYTES + messagesize)); if (crypto_secretbox_open(pad_clear, pad_cipher, diff --git a/libpcp/mem.c b/libpcp/mem.c index badd5d0..5734954 100644 --- a/libpcp/mem.c +++ b/libpcp/mem.c @@ -28,7 +28,7 @@ void *ucmalloc(size_t s) { if (s == 0) return NULL; - size_t size = s * sizeof(unsigned char); + size_t size = s * sizeof(byte); void *value = malloc (size); if (value == NULL) { @@ -53,11 +53,11 @@ void *urmalloc(size_t s) { void *ucrealloc(void *d, size_t oldlen, size_t newlen) { - newlen = newlen * sizeof(unsigned char); + newlen = newlen * sizeof(byte); /* we're using a 1 byte sized pointer, so that we can memset(zero) it after resizing */ - unsigned char *value = realloc (d, newlen); + byte *value = realloc (d, newlen); if (value == NULL) { err(errno, "Cannot reallocate %ld bytes of memory", newlen); diff --git a/libpcp/mgmt.c b/libpcp/mgmt.c index c7f907e..8718ee6 100644 --- a/libpcp/mgmt.c +++ b/libpcp/mgmt.c @@ -111,7 +111,7 @@ int _check_hash_keysig(Buffer *blob, pcp_pubkey_t *p, pcp_keysig_t *sk) { size_t blobstop = blob->offset; size_t sigsize = crypto_sign_BYTES + crypto_generichash_BYTES_MAX; - unsigned char *signature = ucmalloc(sigsize); + byte *signature = ucmalloc(sigsize); if(buffer_get_chunk(blob, signature, sigsize) == 0) goto chker1; @@ -128,13 +128,13 @@ int _check_hash_keysig(Buffer *blob, pcp_pubkey_t *p, pcp_keysig_t *sk) { buffer_get_chunk(blob, sk->blob, sk->size); /* verify the signature */ - unsigned char *verifyhash = pcp_ed_verify_key(signature, sigsize, p); + byte *verifyhash = pcp_ed_verify_key(signature, sigsize, p); if(verifyhash == NULL) goto chker1; /* re-calculate the hash */ crypto_generichash_state *st = ucmalloc(sizeof(crypto_generichash_state)); - unsigned char *hash = ucmalloc(crypto_generichash_BYTES_MAX); + byte *hash = ucmalloc(crypto_generichash_BYTES_MAX); crypto_generichash_init(st, NULL, 0, 0); crypto_generichash_update(st, sk->blob, sk->size); crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX); @@ -170,9 +170,9 @@ int _check_hash_keysig(Buffer *blob, pcp_pubkey_t *p, pcp_keysig_t *sk) { } -pcp_ks_bundle_t *pcp_import_pub(unsigned char *raw, size_t rawsize) { +pcp_ks_bundle_t *pcp_import_pub(byte *raw, size_t rawsize) { size_t clen; - unsigned char *bin = NULL; + byte *bin = NULL; char *z85 = NULL; if(rawsize == 0) { @@ -284,7 +284,7 @@ pcp_ks_bundle_t *pcp_import_pub_pbp(Buffer *blob) { char *date = ucmalloc(19); char *ignore = ucmalloc(46); char *parts = NULL; - unsigned char *sig = ucmalloc(crypto_sign_BYTES);; + byte *sig = ucmalloc(crypto_sign_BYTES);; int pnum; pbp_pubkey_t *b = ucmalloc(sizeof(pbp_pubkey_t)); pcp_pubkey_t *tmp = ucmalloc(sizeof(pcp_pubkey_t)); @@ -345,7 +345,7 @@ pcp_ks_bundle_t *pcp_import_pub_pbp(Buffer *blob) { /* edpub used for signing, might differ */ memcpy(tmp->edpub, b->sigpub, crypto_sign_PUBLICKEYBYTES); - unsigned char *verify = pcp_ed_verify(buffer_get(blob), buffer_size(blob), tmp); + byte *verify = pcp_ed_verify(buffer_get(blob), buffer_size(blob), tmp); free(tmp); pcp_ks_bundle_t *bundle = ucmalloc(sizeof(pcp_ks_bundle_t)); @@ -451,8 +451,8 @@ Buffer *pcp_export_perl_pub(pcp_key_t *sk) { return b; } -void pcp_export_c_pub_var(Buffer *b, char *var, unsigned char *d, size_t len) { - buffer_add_str(b, "unsigned char %s[%ld] = {\n ", var, len); +void pcp_export_c_pub_var(Buffer *b, char *var, byte *d, size_t len) { + buffer_add_str(b, "byte %s[%ld] = {\n ", var, len); size_t i; for(i=0; iarmor = 1; @@ -280,7 +280,7 @@ size_t ps_read_decodeOLD(Pcpstream *stream, Buffer *cache, void *buf, size_t buf /* finally, decode it and put into cache */ size_t binlen, outlen; - unsigned char *bin = pcp_z85_decode(buffer_get_str(z), &binlen); + byte *bin = pcp_z85_decode(buffer_get_str(z), &binlen); if(bin == NULL) { /* it's not z85 encoded, so threat it as binary */ stream->armor = 1; diff --git a/libpcp/scrypt.c b/libpcp/scrypt.c index 046023d..1cad7a4 100644 --- a/libpcp/scrypt.c +++ b/libpcp/scrypt.c @@ -21,7 +21,7 @@ #include "scrypt.h" -unsigned char* pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen) { +byte* pcp_scrypt(char *passwd, size_t passwdlen, byte *nonce, size_t noncelen) { uint8_t *dk = ucmalloc(64); /* resulting hash */ /* constants */ diff --git a/libpcp/util.c b/libpcp/util.c index 3715143..45a18ce 100644 --- a/libpcp/util.c +++ b/libpcp/util.c @@ -31,7 +31,7 @@ char *_lc(char *in) { } /* find the offset of the beginning of a certain string within binary data */ -size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hlen) { +size_t _findoffset(byte *bin, size_t binlen, char *sigstart, size_t hlen) { size_t i; size_t offset = 0; int m = 0; @@ -52,14 +52,14 @@ size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hle } /* xor 2 likesized buffers */ -void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen) { +void _xorbuf(byte *iv, byte *buf, size_t xlen) { size_t i; for (i = 0; i < xlen; ++i) buf[i] = iv[i] ^ buf[i]; } /* print some binary data to stderr */ -void _dump(char *n, unsigned char *d, size_t s) { +void _dump(char *n, byte *d, size_t s) { int l = strlen(n) + 9; fprintf(stderr, "%s (%04ld): ", n, s); size_t i; diff --git a/libpcp/vault.c b/libpcp/vault.c index cead11b..463e804 100644 --- a/libpcp/vault.c +++ b/libpcp/vault.c @@ -134,7 +134,7 @@ int pcpvault_additem(vault_t *vault, void *item, size_t itemsize, uint8_t type) header->type = type; header->size = itemsize; - crypto_hash_sha256((unsigned char*)header->checksum, item, itemsize); + crypto_hash_sha256((byte*)header->checksum, item, itemsize); ih2be(header); fwrite(header, sizeof(vault_item_header_t), 1, vault->fd); @@ -255,7 +255,7 @@ int pcpvault_writeall(vault_t *vault) { } void pcpvault_update_checksum(vault_t *vault) { - unsigned char *checksum = pcpvault_create_checksum(vault); + byte *checksum = pcpvault_create_checksum(vault); vault_header_t *header = ucmalloc(sizeof(vault_header_t)); header->fileid = PCP_VAULT_ID; @@ -270,14 +270,14 @@ void pcpvault_update_checksum(vault_t *vault) { fseek(vault->fd, 0, SEEK_END); } -unsigned char *pcpvault_create_checksum(vault_t *vault) { +byte *pcpvault_create_checksum(vault_t *vault) { int numskeys = pcphash_count(); int numpkeys = pcphash_countpub(); size_t datasize = ((PCP_RAW_KEYSIZE) * numskeys) + ((PCP_RAW_PUBKEYSIZE) * numpkeys); - unsigned char *data = ucmalloc(datasize); - unsigned char *checksum = ucmalloc(32); + byte *data = ucmalloc(datasize); + byte *checksum = ucmalloc(32); size_t datapos = 0; pcp_key_t *k = NULL; @@ -317,7 +317,7 @@ int pcpvault_copy(vault_t *tmp, vault_t *vault) { fseek(tmp->fd, 0, SEEK_END); int tmpsize = ftell(tmp->fd); fseek(tmp->fd, 0, SEEK_SET); - unsigned char *in = ucmalloc(tmpsize); + byte *in = ucmalloc(tmpsize); fread(in, tmpsize, 1, tmp->fd); /* and put it into the new file */ @@ -339,7 +339,7 @@ int pcpvault_copy(vault_t *tmp, vault_t *vault) { void pcpvault_unlink(vault_t *tmp) { int i, tmpsize; - unsigned char *r; + byte *r; fseek(tmp->fd, 0, SEEK_END); tmpsize = ftell(tmp->fd); r = ucmalloc(tmpsize); @@ -489,7 +489,7 @@ int pcpvault_fetchall(vault_t *vault) { goto err; } - unsigned char *checksum = NULL; + byte *checksum = NULL; checksum = pcpvault_create_checksum(vault); /* printf(" calc checksum: "); pcpprint_bin(stdout, checksum, 32); printf("\n"); diff --git a/src/encryption.c b/src/encryption.c index a69ca31..59f2035 100644 --- a/src/encryption.c +++ b/src/encryption.c @@ -26,7 +26,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i FILE *in = NULL; FILE *out = NULL; pcp_key_t *secret = NULL; - unsigned char *symkey = NULL; + byte *symkey = NULL; size_t dlen; uint8_t head; @@ -53,7 +53,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i if(!feof(in) && !ferror(in)) { if(head == PCP_SYM_CIPHER) { /* symetric mode */ - unsigned char *salt = ucmalloc(90); + byte *salt = ucmalloc(90); char stsalt[] = PBP_COMPAT_SALT; memcpy(salt, stsalt, 90); @@ -143,7 +143,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec pcp_pubkey_t *tmp = NULL; pcp_pubkey_t *pub = NULL; pcp_key_t *secret = NULL; - unsigned char *symkey = NULL; + byte *symkey = NULL; int self = 0; if(id == NULL && recipient == NULL) { @@ -158,7 +158,7 @@ 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 */ + byte *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); diff --git a/src/keymgmt.c b/src/keymgmt.c index a79a355..520c972 100644 --- a/src/keymgmt.c +++ b/src/keymgmt.c @@ -429,7 +429,7 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int int pcp_importsecret (vault_t *vault, FILE *in, char *passwd) { - unsigned char *buf = ucmalloc(2048); + byte *buf = ucmalloc(2048); size_t buflen = fread(buf, 1, 2048, in); pcp_key_t *sk = NULL; @@ -511,7 +511,7 @@ int pcp_importsecret (vault_t *vault, FILE *in, char *passwd) { } int pcp_importpublic (vault_t *vault, FILE *in) { - unsigned char *buf = ucmalloc(2048); + byte *buf = ucmalloc(2048); size_t buflen = fread(buf, 1, 2048, in); pcp_keysig_t *sk = NULL; pcp_pubkey_t *pub = NULL; diff --git a/src/keymgmt.h b/src/keymgmt.h index 06e95d9..4ee6e98 100644 --- a/src/keymgmt.h +++ b/src/keymgmt.h @@ -62,6 +62,6 @@ int pcp_importsecret (vault_t *vault, FILE *in, char *passwd); void pcpdelete_key(char *keyid); char *pcp_find_id_byrec(char *recipient); - +void pcpedit_key(char *keyid); #endif /* _HAVE_KEYMGMT_H */ diff --git a/src/keyprint.c b/src/keyprint.c index 528c81d..39e09da 100644 --- a/src/keyprint.c +++ b/src/keyprint.c @@ -57,7 +57,7 @@ int pcptext_infile(char *infile) { } size_t clen; - unsigned char *bin = pcp_z85_decode((char *)z85, &clen); + byte *bin = pcp_z85_decode((char *)z85, &clen); free(z85); if(bin == NULL) { @@ -159,7 +159,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) { c->tm_year+1900, c->tm_mon+1, c->tm_mday, c->tm_hour, c->tm_min, c->tm_sec); - unsigned char *hash = pcppubkey_getchecksum(key); + byte *hash = pcppubkey_getchecksum(key); fprintf(out, " Checksum: "); int i; @@ -311,7 +311,7 @@ void pcpexport_yaml(char *outfile) { } } -void pcpprint_bin(FILE *out, unsigned char *data, size_t len) { +void pcpprint_bin(FILE *out, byte *data, size_t len) { int i; for ( i = 0;i < len;++i) fprintf(out, "%02x", (unsigned int) data[i]); diff --git a/src/keyprint.h b/src/keyprint.h index b0d2672..a594265 100644 --- a/src/keyprint.h +++ b/src/keyprint.h @@ -45,6 +45,6 @@ void pcptext_vault(vault_t *vault); int pcptext_infile(char *infile); void pcpexport_yaml(char *outfile); -void pcpprint_bin(FILE *out, unsigned char *data, size_t len); +void pcpprint_bin(FILE *out, byte *data, size_t len); #endif /* _HAVE_PCP_KEYPRINT_H */ diff --git a/src/z85util.c b/src/z85util.c index 96b06d5..f786def 100644 --- a/src/z85util.c +++ b/src/z85util.c @@ -44,16 +44,16 @@ int pcpz85_encode(char *infile, char *outfile) { } } - unsigned char *input = NULL; + byte *input = NULL; size_t inputBufSize = 0; - unsigned char byte[1]; + byte onebyte[1]; while(!feof(in)) { - if(!fread(&byte, 1, 1, in)) + if(!fread(&onebyte, 1, 1, in)) break; - unsigned char *tmp = realloc(input, inputBufSize + 1); + byte *tmp = realloc(input, inputBufSize + 1); input = tmp; - memmove(&input[inputBufSize], byte, 1); + memmove(&input[inputBufSize], onebyte, 1); inputBufSize ++; } fclose(in); @@ -115,7 +115,7 @@ int pcpz85_decode(char *infile, char *outfile) { goto errdz1; size_t clen; - unsigned char *decoded = pcp_z85_decode(encoded, &clen); + byte *decoded = pcp_z85_decode(encoded, &clen);