fixed z85 encoding overflow bug, fixed signature code on big-endian systems.

This commit is contained in:
TLINDEN
2013-11-19 17:17:30 +01:00
parent 314dbde0b9
commit 80ec5014a8
17 changed files with 203 additions and 153 deletions

View File

@@ -32,7 +32,7 @@ size_t pcp_sodium_box(unsigned char **cipher,
unsigned char *pad_clear;
unsigned char *pad_cipher;
size_t ciphersize = (clearsize + crypto_box_ZEROBYTES) - crypto_box_BOXZEROBYTES; // $s + 32 -16
size_t ciphersize = (clearsize + crypto_box_ZEROBYTES) - crypto_box_BOXZEROBYTES;
pad_cipher = ucmalloc(crypto_box_ZEROBYTES + clearsize);
pcp_pad_prepend(&pad_clear, cleartext, crypto_box_ZEROBYTES, clearsize);

View File

@@ -72,20 +72,28 @@ pcp_sig_t *pcp_ed_newsig(unsigned char *hash, char *id) {
pcp_sig_t *sig = ucmalloc(sizeof(pcp_sig_t));
sig->version = PCP_SIG_VERSION;
sig->ctime = (long)time(0);
memcpy(sig->edsig, hash, crypto_hash_sha256_BYTES + crypto_sign_BYTES);
memcpy(sig->edsig, hash, crypto_sign_BYTES);
memcpy(sig->id, id, 17);
return sig;
}
pcp_sig_t *sig2native(pcp_sig_t *s) {
#ifdef __BIG_ENDIAN
return s;
#else
s->version = be32toh(s->version);
s->ctime = be64toh(s->ctime);
return s;
#endif
}
pcp_sig_t *sig2be(pcp_sig_t *s) {
#ifdef __BIG_ENDIAN
return s;
#else
s->version = htobe32(s->version);
s->ctime = htobe64(s->ctime);
return s;
#endif
}

View File

@@ -102,22 +102,47 @@ char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen) {
char *z85 = ucmalloc(zlen);
z85 = zmq_z85_encode(z85, padded, outlen);
// make it a 72 chars wide block
blocklen = strlen(z85) + ((strlen(z85) / 72) * 2) + 1;
blocklen = (zlen + ((zlen / 72) * 2)) + 1;
char *z85block = ucmalloc(blocklen);
//fprintf(stderr, "zlen: %d, outlen: %d, srclen: %d, blocklen: %d\n",
// zlen, outlen, srclen, blocklen);
pos = b = 0;
/*
for(i=0; i<zlen; ++i) {
if(pos >= 71) {
z85block[b++] = '\r';
z85block[b++] = '\n';
*z85block++ = '\r';
*z85block++ = '\n';
pos = 1;
}
else {
pos++;
}
z85block[b++] = z85[i];
*z85block++ = z85[i];
}
*/
char *z = &z85[0];
char *B = &z85block[0];
while(*z != '\0') {
if(pos >= 71) {
*B++ = '\r';
*B++ = '\n';
pos = 1;
}
else {
pos++;
}
*B++ = *z++;
}
*B = '\0';
//fprintf(stderr, "z85block len: %d\n", blocklen, strlen(z85block));
//fprintf(stderr, "z85block: <%s>\n", z85block);
*dstlen = blocklen;
free(z85);