fixed catching of header string

This commit is contained in:
TLINDEN
2014-02-09 15:49:52 +01:00
parent ce73950920
commit 6829ea6fbc
8 changed files with 65 additions and 63 deletions

View File

@@ -7,6 +7,7 @@ extern "C" {
#include "pcp/base85.h" #include "pcp/base85.h"
#include "pcp/buffer.h" #include "pcp/buffer.h"
#include "pcp/config.h"
#include "pcp/crypto.h" #include "pcp/crypto.h"
#include "pcp/defines.h" #include "pcp/defines.h"
#include "pcp/digital_crc32.h" #include "pcp/digital_crc32.h"

View File

@@ -68,7 +68,6 @@ void buffer_resize(Buffer *b, size_t len) {
if((b->end > 0 && b->end + len > b->size) || (b->end == 0 && len > b->size) ) { if((b->end > 0 && b->end + len > b->size) || (b->end == 0 && len > b->size) ) {
/* increase by buf blocksize */ /* increase by buf blocksize */
size_t newsize = (((len / b->blocksize) +1) * b->blocksize) + b->size; size_t newsize = (((len / b->blocksize) +1) * b->blocksize) + b->size;
fprintf(stderr, "[buffer %s] resizing from %ld to %ld\n", b->name, b->size, newsize);
b->buf = ucrealloc(b->buf, b->size, newsize); b->buf = ucrealloc(b->buf, b->size, newsize);
b->size = newsize; b->size = newsize;
} }

View File

@@ -73,10 +73,21 @@ unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) {
} }
} }
binlen = strlen (z85) * 4 / 5; binlen = strlen (z85) * 4 / 5;
bin = ucmalloc(binlen); bin = ucmalloc(binlen);
bin = zmq_z85_decode(bin, z85); bin = zmq_z85_decode(bin, z85);
if(bin == NULL) {
free(z85);
fatal("zmq_z85_decode() failed, input size ! % 5");
return NULL;
}
_dump("bin", bin, binlen);
fwrite(bin, 1, binlen, stderr);
unsigned char *raw = NULL; unsigned char *raw = NULL;
if(bin != NULL) { if(bin != NULL) {
raw = pcp_unpadfour(bin, binlen, &outlen); raw = pcp_unpadfour(bin, binlen, &outlen);
@@ -224,7 +235,7 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) {
} }
} }
if(buffer_size(line) > 0) { if(buffer_size(line) > 0 && end != 1) {
/* something left in line buffer, probably /* something left in line buffer, probably
newline at eof missing or no multiline input */ newline at eof missing or no multiline input */
buffer_add_buf(z, line); buffer_add_buf(z, line);
@@ -238,8 +249,6 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) {
out = ucmalloc(buffer_size(z)+1); out = ucmalloc(buffer_size(z)+1);
strncpy(out, buffer_get_str(z), buffer_size(z)+1); strncpy(out, buffer_get_str(z), buffer_size(z)+1);
fprintf(stderr, "got: \n<%s>\n", out);
buffer_free(z); buffer_free(z);
buffer_free(line); buffer_free(line);

View File

@@ -561,35 +561,24 @@ a couple of modifications (portability, readability etc).
To fulfil the requirements of the ZeroMQ Z85 functions, B<pcp1> To fulfil the requirements of the ZeroMQ Z85 functions, B<pcp1>
does some additional preparations of raw input before actually doing the does some additional preparations of raw input before actually doing the
encoding, since the input for zmq_z85_encode() must be divisible by 4: encoding, since the input for zmq_z85_encode() must be divisible by 4. Therefore
we pad the input with zeroes and remove them after decoding.
Expand the input so that the resulting size is divisible by 4.
Fill the added bytes with zeroes.
Prepend the input with a one byte value which holds the number of zeroes
added in the previous step.
Example:
Raw input:
hello\0
Here, the input size is 6, which is insufficient, therefore it has to be expanded
to be 8. After the process the input looks like this:
1hello\0\0
So, we padded the input with 1 zero (makes 7 bytes) and preprended it with the
value 1 (the number of zeros added): makes 8 bytes total.
After decoding Z85 input the process will be reversed.
B<Trying to use another tool to decode an Z85 encoded string produced B<Trying to use another tool to decode an Z85 encoded string produced
by z85, might not work therefore, unless the tool takes the padding scheme by z85, might not work therefore, unless the tool takes the padding scheme
outlined above into account>. outlined above into account>.
Z85 encoding and decoding can be used separately as well to work with
files. Examples:
Encode some file to Z85 encoding:
pcp1 -z -I file -O file.z85
Reverse the process:
pcp1 -Z -I file.z85 -O file
=head2 PBP COMPATIBILITY =head2 PBP COMPATIBILITY
PCP tries to be fully compatible with PBP (https://github.com/stef/pbp). Encrypted PCP tries to be fully compatible with PBP (https://github.com/stef/pbp). Encrypted

View File

@@ -107,11 +107,13 @@
against using -I as well (plus -f <sigfile>). against using -I as well (plus -f <sigfile>).
Encoding Options: Encoding Options:
-z --z85-encode Encode something to Z85 encoding. Use -z --z85-encode Encode (armor) something to Z85 encoding.
-I and -O respectively, otherwise it If used with encryption or singing operation
encode its output. Otherwise encode a plain
file. Use -I and -O respectively, otherwise it
stdin/stdout. stdin/stdout.
-Z --z85-decode Decode something from Z85 encoding. Use -Z --z85-decode Decode (dearmor) something from Z85 encoding.
-I and -O respectively, otherwise it Use -I and -O respectively, otherwise it
stdin/stdout stdin/stdout

View File

@@ -162,11 +162,13 @@ Pretty Curved Privacy - File encryption using eliptic curve cryptography.
against using -I as well (plus -f <sigfile>). against using -I as well (plus -f <sigfile>).
Encoding Options: Encoding Options:
-z --z85-encode Encode something to Z85 encoding. Use -z --z85-encode Encode (armor) something to Z85 encoding.
-I and -O respectively, otherwise it If used with encryption or singing operation
encode its output. Otherwise encode a plain
file. Use -I and -O respectively, otherwise it
stdin/stdout. stdin/stdout.
-Z --z85-decode Decode something from Z85 encoding. Use -Z --z85-decode Decode (dearmor) something from Z85 encoding.
-I and -O respectively, otherwise it Use -I and -O respectively, otherwise it
stdin/stdout stdin/stdout
@@ -805,35 +807,24 @@ a couple of modifications (portability, readability etc).
To fulfil the requirements of the ZeroMQ Z85 functions, B<pcp1> To fulfil the requirements of the ZeroMQ Z85 functions, B<pcp1>
does some additional preparations of raw input before actually doing the does some additional preparations of raw input before actually doing the
encoding, since the input for zmq_z85_encode() must be divisible by 4: encoding, since the input for zmq_z85_encode() must be divisible by 4. Therefore
we pad the input with zeroes and remove them after decoding.
Expand the input so that the resulting size is divisible by 4.
Fill the added bytes with zeroes.
Prepend the input with a one byte value which holds the number of zeroes
added in the previous step.
Example:
Raw input:
hello\0
Here, the input size is 6, which is insufficient, therefore it has to be expanded
to be 8. After the process the input looks like this:
1hello\0\0
So, we padded the input with 1 zero (makes 7 bytes) and preprended it with the
value 1 (the number of zeros added): makes 8 bytes total.
After decoding Z85 input the process will be reversed.
B<Trying to use another tool to decode an Z85 encoded string produced B<Trying to use another tool to decode an Z85 encoded string produced
by z85, might not work therefore, unless the tool takes the padding scheme by z85, might not work therefore, unless the tool takes the padding scheme
outlined above into account>. outlined above into account>.
Z85 encoding and decoding can be used separately as well to work with
files. Examples:
Encode some file to Z85 encoding:
pcp1 -z -I file -O file.z85
Reverse the process:
pcp1 -Z -I file.z85 -O file
=head2 PBP COMPATIBILITY =head2 PBP COMPATIBILITY
PCP tries to be fully compatible with PBP (https://github.com/stef/pbp). Encrypted PCP tries to be fully compatible with PBP (https://github.com/stef/pbp). Encrypted

View File

@@ -183,7 +183,7 @@ int main (int argc, char **argv) {
armor = 1; armor = 1;
break; break;
case 'Z': case 'Z':
armor = 1; armor = 2;
break; break;
case 'b': case 'b':
pbpcompat = 1; pbpcompat = 1;
@@ -248,8 +248,17 @@ int main (int argc, char **argv) {
if(mode == 0) { if(mode == 0) {
version(); /* turn -z|-Z into a mode if there's nothing else specified */
return 1; if(armor == 1) {
mode = PCP_MODE_ZENCODE;
}
else if(armor == 2) {
mode = PCP_MODE_ZDECODE;
}
else {
version();
return 1;
}
} }
if(mode == PCP_MODE_ENCRYPT + PCP_MODE_SIGN) { if(mode == PCP_MODE_ENCRYPT + PCP_MODE_SIGN) {

View File

@@ -117,6 +117,8 @@ int pcpz85_decode(char *infile, char *outfile) {
size_t clen; size_t clen;
unsigned char *decoded = pcp_z85_decode(encoded, &clen); unsigned char *decoded = pcp_z85_decode(encoded, &clen);
if(decoded == NULL) if(decoded == NULL)
goto errdz2; goto errdz2;