mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
fixed catching of header string
This commit is contained in:
@@ -7,6 +7,7 @@ extern "C" {
|
||||
|
||||
#include "pcp/base85.h"
|
||||
#include "pcp/buffer.h"
|
||||
#include "pcp/config.h"
|
||||
#include "pcp/crypto.h"
|
||||
#include "pcp/defines.h"
|
||||
#include "pcp/digital_crc32.h"
|
||||
|
||||
@@ -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) ) {
|
||||
/* increase by buf blocksize */
|
||||
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->size = newsize;
|
||||
}
|
||||
|
||||
15
libpcp/z85.c
15
libpcp/z85.c
@@ -73,10 +73,21 @@ unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
binlen = strlen (z85) * 4 / 5;
|
||||
bin = ucmalloc(binlen);
|
||||
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;
|
||||
if(bin != NULL) {
|
||||
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
|
||||
newline at eof missing or no multiline input */
|
||||
buffer_add_buf(z, line);
|
||||
@@ -238,8 +249,6 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) {
|
||||
out = ucmalloc(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(line);
|
||||
|
||||
|
||||
@@ -561,35 +561,24 @@ a couple of modifications (portability, readability etc).
|
||||
|
||||
To fulfil the requirements of the ZeroMQ Z85 functions, B<pcp1>
|
||||
does some additional preparations of raw input before actually doing the
|
||||
encoding, since the input for zmq_z85_encode() must be divisible by 4:
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
PCP tries to be fully compatible with PBP (https://github.com/stef/pbp). Encrypted
|
||||
|
||||
@@ -107,11 +107,13 @@
|
||||
against using -I as well (plus -f <sigfile>).
|
||||
|
||||
Encoding Options:
|
||||
-z --z85-encode Encode something to Z85 encoding. Use
|
||||
-I and -O respectively, otherwise it
|
||||
-z --z85-encode Encode (armor) something to Z85 encoding.
|
||||
If used with encryption or singing operation
|
||||
encode its output. Otherwise encode a plain
|
||||
file. Use -I and -O respectively, otherwise it
|
||||
stdin/stdout.
|
||||
-Z --z85-decode Decode something from Z85 encoding. Use
|
||||
-I and -O respectively, otherwise it
|
||||
-Z --z85-decode Decode (dearmor) something from Z85 encoding.
|
||||
Use -I and -O respectively, otherwise it
|
||||
stdin/stdout
|
||||
|
||||
|
||||
|
||||
47
man/pcp1.pod
47
man/pcp1.pod
@@ -162,11 +162,13 @@ Pretty Curved Privacy - File encryption using eliptic curve cryptography.
|
||||
against using -I as well (plus -f <sigfile>).
|
||||
|
||||
Encoding Options:
|
||||
-z --z85-encode Encode something to Z85 encoding. Use
|
||||
-I and -O respectively, otherwise it
|
||||
-z --z85-encode Encode (armor) something to Z85 encoding.
|
||||
If used with encryption or singing operation
|
||||
encode its output. Otherwise encode a plain
|
||||
file. Use -I and -O respectively, otherwise it
|
||||
stdin/stdout.
|
||||
-Z --z85-decode Decode something from Z85 encoding. Use
|
||||
-I and -O respectively, otherwise it
|
||||
-Z --z85-decode Decode (dearmor) something from Z85 encoding.
|
||||
Use -I and -O respectively, otherwise it
|
||||
stdin/stdout
|
||||
|
||||
|
||||
@@ -805,35 +807,24 @@ a couple of modifications (portability, readability etc).
|
||||
|
||||
To fulfil the requirements of the ZeroMQ Z85 functions, B<pcp1>
|
||||
does some additional preparations of raw input before actually doing the
|
||||
encoding, since the input for zmq_z85_encode() must be divisible by 4:
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
PCP tries to be fully compatible with PBP (https://github.com/stef/pbp). Encrypted
|
||||
|
||||
11
src/pcp.c
11
src/pcp.c
@@ -183,7 +183,7 @@ int main (int argc, char **argv) {
|
||||
armor = 1;
|
||||
break;
|
||||
case 'Z':
|
||||
armor = 1;
|
||||
armor = 2;
|
||||
break;
|
||||
case 'b':
|
||||
pbpcompat = 1;
|
||||
@@ -248,9 +248,18 @@ int main (int argc, char **argv) {
|
||||
|
||||
|
||||
if(mode == 0) {
|
||||
/* turn -z|-Z into a mode if there's nothing else specified */
|
||||
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) {
|
||||
mode = PCP_MODE_ENCRYPT;
|
||||
|
||||
@@ -117,6 +117,8 @@ int pcpz85_decode(char *infile, char *outfile) {
|
||||
size_t clen;
|
||||
unsigned char *decoded = pcp_z85_decode(encoded, &clen);
|
||||
|
||||
|
||||
|
||||
if(decoded == NULL)
|
||||
goto errdz2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user