changed all occurrences of unsigned char to byte (defined in defines.h) to make the code more precise about sizes.

This commit is contained in:
git@daemon.de
2014-02-25 11:09:58 +01:00
parent cbc45f5fa1
commit 3b1db06529
31 changed files with 243 additions and 240 deletions

View File

@@ -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; i<len; ++i) {
buffer_add_str(b, "%02x", d[i]);
}
@@ -117,7 +117,7 @@ void buffer_resize(Buffer *b, size_t len) {
}
}
unsigned char *buffer_get(Buffer *b) {
byte *buffer_get(Buffer *b) {
if(b->end > 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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -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);

View File

@@ -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; i<len-1; ++i) {
buffer_add_str(b, "0x%02x, ", (unsigned int)d[i]);
@@ -492,7 +492,7 @@ Buffer *pcp_export_c_pub(pcp_key_t *sk) {
Buffer *pcp_export_pbp_pub(pcp_key_t *sk) {
struct tm *v, *c;
unsigned char *signature = NULL;
byte *signature = NULL;
char *date = NULL;
Buffer *out = buffer_new(320, "pbp01");
@@ -627,14 +627,14 @@ Buffer *pcp_export_rfc_pub (pcp_key_t *sk) {
/* create a hash from the PK material and the raw signature packet */
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, buffer_get(raw), buffer_size(raw));
crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX);
/* sign the hash */
unsigned char *sig = pcp_ed_sign_key(hash, crypto_generichash_BYTES_MAX, sk);
byte *sig = pcp_ed_sign_key(hash, crypto_generichash_BYTES_MAX, sk);
/* append the signature packet to the output */
buffer_add(out, buffer_get(raw), buffer_size(raw));
@@ -653,9 +653,9 @@ Buffer *pcp_export_rfc_pub (pcp_key_t *sk) {
}
Buffer *pcp_export_secret(pcp_key_t *sk, char *passphrase) {
unsigned char *nonce = NULL;
unsigned char *symkey = NULL;
unsigned char *cipher = NULL;
byte *nonce = NULL;
byte *symkey = NULL;
byte *cipher = NULL;
size_t es;
Buffer *raw = buffer_new(512, "secretbuf");
@@ -704,9 +704,9 @@ Buffer *pcp_export_secret(pcp_key_t *sk, char *passphrase) {
return out;
}
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) {
size_t clen;
unsigned char *bin = NULL;
byte *bin = NULL;
char *z85 = NULL;
if(rawsize == 0) {
@@ -738,9 +738,9 @@ pcp_key_t *pcp_import_secret(unsigned char *raw, size_t rawsize, char *passphras
pcp_key_t *pcp_import_secret_native(Buffer *cipher, char *passphrase) {
pcp_key_t *sk = ucmalloc(sizeof(pcp_key_t));
unsigned char *nonce = ucmalloc(crypto_secretbox_NONCEBYTES);
unsigned char *symkey = NULL;
unsigned char *clear = NULL;
byte *nonce = ucmalloc(crypto_secretbox_NONCEBYTES);
byte *symkey = NULL;
byte *clear = NULL;
size_t cipherlen = 0;
size_t minlen = (64 * 2) + (32 * 4) + 8 + 4 + 4;
uint16_t notationlen = 0;

View File

@@ -22,10 +22,10 @@
#include "pad.h"
void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded,
void pcp_pad_prepend(byte **padded, byte *unpadded,
size_t padlen, size_t unpadlen) {
*padded = ucmalloc(unpadlen + padlen);
unsigned char *tmp = ucmalloc(unpadlen + padlen);
byte *tmp = ucmalloc(unpadlen + padlen);
/* pcp_append orig */
int i;
@@ -37,10 +37,10 @@ void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded,
free(tmp);
}
void pcp_pad_remove(unsigned char **unpadded, unsigned char *padded,
void pcp_pad_remove(byte **unpadded, byte *padded,
size_t padlen, size_t unpadlen) {
*unpadded = ucmalloc(unpadlen * sizeof(unsigned char));
unsigned char *tmp = ucmalloc(unpadlen);
*unpadded = ucmalloc(unpadlen * sizeof(byte));
byte *tmp = ucmalloc(unpadlen);
int i;
for(i=0; i<unpadlen; ++i) {
@@ -57,12 +57,12 @@ int main(int argc, char **argv) {
size_t unpadlen;
int padlen = strtol(argv[2], NULL, 0);
unpadlen = strlen(argv[1]);
unsigned char *dst;
byte *dst;
pcp_pad_prepend(&dst, argv[1], padlen, unpadlen);
/* printf(" prev: %s\n after: %s\n", argv[1], dst); */
unsigned char *reverse;
byte *reverse;
pcp_pad_remove(&reverse, dst, padlen, unpadlen);
/* printf("reverse: %s\n", reverse); */

View File

@@ -229,7 +229,7 @@ size_t ps_read_decode(Pcpstream *stream, Buffer *cache, void *buf, size_t bufsiz
/* 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;
@@ -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;

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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");