diff --git a/include/pcp/defines.h b/include/pcp/defines.h index 651e412..31c2a2b 100644 --- a/include/pcp/defines.h +++ b/include/pcp/defines.h @@ -82,6 +82,8 @@ 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_RECIPIENT_RSIZE (PCP_ASYM_RECIPIENT_SIZE + 1) + /* #define PCP_ASYM_ADD_SENDER_PUB */ /* used for self encryption only */ diff --git a/libpcp/crypto.c b/libpcp/crypto.c index 8f1194e..95775bf 100644 --- a/libpcp/crypto.c +++ b/libpcp/crypto.c @@ -171,7 +171,7 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey byte head[1]; size_t cur_bufsize, rec_size; - unsigned char rec_buf[PCP_ASYM_RECIPIENT_SIZE]; + unsigned char rec_buf[PCP_ASYM_RECIPIENT_RSIZE]; #ifdef PCP_ASYM_ADD_SENDER_PUB unsigned char *senderpub; @@ -224,20 +224,27 @@ size_t pcp_decrypt_file(FILE *in, FILE* out, pcp_key_t *s, unsigned char *symkey lenrec = be32toh(lenrec); if(verify) { - reccipher = ucmalloc(lenrec * PCP_ASYM_RECIPIENT_SIZE); + reccipher = ucmalloc(lenrec * PCP_ASYM_RECIPIENT_RSIZE); } + + /* step 4, fetch recipient list and try to decrypt it for us */ + unsigned char *recip = ucmalloc(PCP_ASYM_RECIPIENT_SIZE); for(nrec=0; nrecpub, b->pub, crypto_box_PUBLICKEYBYTES); memcpy(pub->edpub, b->edpub, crypto_sign_PUBLICKEYBYTES); memcpy(pub->id, pcp_getpubkeyid(pub), 17); + _lc(pub->owner); /* edpub used for signing, might differ */ memcpy(tmp->edpub, b->sigpub, crypto_sign_PUBLICKEYBYTES);