mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
added -C to generate a blake2 checksum of one or more files
This commit is contained in:
@@ -66,6 +66,12 @@ NEXT
|
|||||||
|
|
||||||
added option -X (read passphrase from file).
|
added option -X (read passphrase from file).
|
||||||
|
|
||||||
|
Symmetric decryption doesn't require a vault
|
||||||
|
anymore.
|
||||||
|
|
||||||
|
Added -C: create a blake2 checksum of one or
|
||||||
|
more files.
|
||||||
|
|
||||||
0.2.4 fixed compiler macro misplacement (github#4).
|
0.2.4 fixed compiler macro misplacement (github#4).
|
||||||
|
|
||||||
fixed invalid free (github#5).
|
fixed invalid free (github#5).
|
||||||
|
|||||||
6
INSTALL
6
INSTALL
@@ -1,7 +1,7 @@
|
|||||||
Installation Instructions
|
Installation Instructions
|
||||||
*************************
|
*************************
|
||||||
|
|
||||||
Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
|
Copyright (C) 1994-1996, 1999-2002, 2004-2012 Free Software Foundation,
|
||||||
Inc.
|
Inc.
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
Copying and distribution of this file, with or without modification,
|
||||||
@@ -12,8 +12,8 @@ without warranty of any kind.
|
|||||||
Basic Installation
|
Basic Installation
|
||||||
==================
|
==================
|
||||||
|
|
||||||
Briefly, the shell command `./configure && make && make install'
|
Briefly, the shell commands `./configure; make; make install' should
|
||||||
should configure, build, and install this package. The following
|
configure, build, and install this package. The following
|
||||||
more-detailed instructions are generic; see the `README' file for
|
more-detailed instructions are generic; see the `README' file for
|
||||||
instructions specific to this package. Some packages provide this
|
instructions specific to this package. Some packages provide this
|
||||||
`INSTALL' file but do not implement all of the features documented
|
`INSTALL' file but do not implement all of the features documented
|
||||||
|
|||||||
8
TODO
8
TODO
@@ -10,8 +10,6 @@ malloc() new pointers in functions only if not NULL, e.g. pcp_gennonce()
|
|||||||
|
|
||||||
check pub key count in pcp.c before calling verify signature, croak if count==0
|
check pub key count in pcp.c before calling verify signature, croak if count==0
|
||||||
|
|
||||||
Update pod key format spec.
|
|
||||||
|
|
||||||
vault checksum: add keysigs as well
|
vault checksum: add keysigs as well
|
||||||
|
|
||||||
Add newlines to headers in define.h, so strlen() later catches the whole length.
|
Add newlines to headers in define.h, so strlen() later catches the whole length.
|
||||||
@@ -19,11 +17,5 @@ Add newlines to headers in define.h, so strlen() later catches the whole length.
|
|||||||
Check is_utf8 license.
|
Check is_utf8 license.
|
||||||
also found in https://gd.meizo.com/_files/lpc/ext/utf8.c
|
also found in https://gd.meizo.com/_files/lpc/ext/utf8.c
|
||||||
|
|
||||||
Symmetric decrypt mode tries to open vault
|
|
||||||
|
|
||||||
pcp_find_primary_secret() makes a copy ???
|
|
||||||
|
|
||||||
c++ destructor double free mess
|
c++ destructor double free mess
|
||||||
|
|
||||||
cpptest 0 uses same Context for encryptor and decryptor,
|
|
||||||
must be another one for the latter!
|
|
||||||
@@ -7,6 +7,7 @@ extern "C" {
|
|||||||
|
|
||||||
#include "pcp/config.h"
|
#include "pcp/config.h"
|
||||||
#include "pcp/buffer.h"
|
#include "pcp/buffer.h"
|
||||||
|
#include "pcp/config.h"
|
||||||
#include "pcp/context.h"
|
#include "pcp/context.h"
|
||||||
#include "pcp/crypto.h"
|
#include "pcp/crypto.h"
|
||||||
#include "pcp/defines.h"
|
#include "pcp/defines.h"
|
||||||
|
|||||||
@@ -325,7 +325,15 @@ int pcp_sodium_verify_mac(byte **cleartext,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Create a blake2 checksum of an input stream.
|
||||||
|
|
||||||
|
\param[in] ptx pcp context.
|
||||||
|
\param[in] in stream to read data from.
|
||||||
|
\param[out] checksum output buffer containing resulting checksum.
|
||||||
|
|
||||||
|
\return Returns 0 on error.
|
||||||
|
*/
|
||||||
|
int pcp_checksum(PCPCTX *ptx, Pcpstream *in, byte *checksum);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -811,3 +811,29 @@ TODO: how to go past 64 bits:
|
|||||||
http://mrob.com/pub/math/int128.c.txt
|
http://mrob.com/pub/math/int128.c.txt
|
||||||
http://locklessinc.com/articles/256bit_arithmetic/
|
http://locklessinc.com/articles/256bit_arithmetic/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int pcp_checksum(PCPCTX *ptx, Pcpstream *in, byte *checksum) {
|
||||||
|
crypto_generichash_state *st = ucmalloc(sizeof(crypto_generichash_state));
|
||||||
|
byte *buf = ucmalloc(PCP_BLOCK_SIZE);
|
||||||
|
size_t bufsize = 0;
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
|
crypto_generichash_init(st, NULL, 0, 0);
|
||||||
|
|
||||||
|
while(!ps_end(in)) {
|
||||||
|
bufsize = ps_read(in, buf, PCP_BLOCK_SIZE);
|
||||||
|
crypto_generichash_update(st, buf, bufsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto_generichash_final(st, checksum, crypto_generichash_BYTES_MAX);
|
||||||
|
|
||||||
|
if(ps_err(in)) {
|
||||||
|
ret = 0;
|
||||||
|
fatal(ptx, "Error while reading file!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
free(st);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|||||||
@@ -131,4 +131,9 @@
|
|||||||
Use -I and -O respectively, otherwise it
|
Use -I and -O respectively, otherwise it
|
||||||
uses stdin/stdout
|
uses stdin/stdout
|
||||||
|
|
||||||
|
Misc Options:
|
||||||
|
-C --checksum Calculate a Blake2 checksum of one or more files.
|
||||||
|
Use -I to specify one file or put multiple file
|
||||||
|
names after -C like "pcp1 -C file1 file2 file3".
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -359,3 +359,30 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pcpchecksum(char **files, int filenum) {
|
||||||
|
int i;
|
||||||
|
byte *checksum = ucmalloc(crypto_generichash_BYTES_MAX);
|
||||||
|
|
||||||
|
for(i=0; i<filenum; i++) {
|
||||||
|
FILE *in;
|
||||||
|
if(files[i] == NULL)
|
||||||
|
in = stdin;
|
||||||
|
else {
|
||||||
|
if((in = fopen(files[i], "rb")) == NULL) {
|
||||||
|
fatal(ptx, "Could not open input file %s\n", files[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Pcpstream *pin = ps_new_file(in);
|
||||||
|
if(pcp_checksum(ptx, pin, checksum) > 0) {
|
||||||
|
char *hex = _bin2hex(checksum, crypto_generichash_BYTES_MAX);
|
||||||
|
fprintf(stdout, "BLAKE2 (%s) = %s\n", files[i], hex);
|
||||||
|
free(hex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(checksum);
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,5 +40,6 @@
|
|||||||
|
|
||||||
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, int verify);
|
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, int verify);
|
||||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt, int armor, int anon);
|
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt, int armor, int anon);
|
||||||
|
void pcpchecksum(char **files, int filenum);
|
||||||
|
|
||||||
#endif /* _HAVE_ENCRYPTION_H */
|
#endif /* _HAVE_ENCRYPTION_H */
|
||||||
|
|||||||
31
src/pcp.c
31
src/pcp.c
@@ -114,6 +114,7 @@ int main (int argc, char **argv) {
|
|||||||
{ "decrypt", no_argument, NULL, 'd' },
|
{ "decrypt", no_argument, NULL, 'd' },
|
||||||
{ "anonymous", no_argument, NULL, 'A' },
|
{ "anonymous", no_argument, NULL, 'A' },
|
||||||
{ "add-myself", no_argument, NULL, 'M' },
|
{ "add-myself", no_argument, NULL, 'M' },
|
||||||
|
{ "checksum", no_argument, NULL, 'C' },
|
||||||
|
|
||||||
/* encoding */
|
/* encoding */
|
||||||
{ "z85-encode", no_argument, NULL, 'z' },
|
{ "z85-encode", no_argument, NULL, 'z' },
|
||||||
@@ -135,7 +136,7 @@ int main (int argc, char **argv) {
|
|||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcmf:b1F:0KAMX:j",
|
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcmf:b1F:0KAMX:jC",
|
||||||
longopts, NULL)) != -1) {
|
longopts, NULL)) != -1) {
|
||||||
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
@@ -230,6 +231,9 @@ int main (int argc, char **argv) {
|
|||||||
mode += PCP_MODE_VERIFY;
|
mode += PCP_MODE_VERIFY;
|
||||||
usevault = 1;
|
usevault = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
mode += PCP_MODE_CHECKSUM;
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
sigfile = ucmalloc(strlen(optarg)+1);
|
sigfile = ucmalloc(strlen(optarg)+1);
|
||||||
strncpy(sigfile, optarg, strlen(optarg)+1);
|
strncpy(sigfile, optarg, strlen(optarg)+1);
|
||||||
@@ -433,6 +437,14 @@ int main (int argc, char **argv) {
|
|||||||
|
|
||||||
if(usevault == 1) {
|
if(usevault == 1) {
|
||||||
vault = pcpvault_init(ptx, vaultfile);
|
vault = pcpvault_init(ptx, vaultfile);
|
||||||
|
/* special case: ignore vault error in decrypt mode. sym decrypt doesn't
|
||||||
|
need it and asym will just fail without keys. */
|
||||||
|
if(vault == NULL && mode == PCP_MODE_DECRYPT) {
|
||||||
|
/* use an empty one */
|
||||||
|
vault = pcpvault_init(ptx, "/dev/null");
|
||||||
|
fatals_reset(ptx);
|
||||||
|
}
|
||||||
|
|
||||||
if(vault != NULL) {
|
if(vault != NULL) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case PCP_MODE_KEYGEN:
|
case PCP_MODE_KEYGEN:
|
||||||
@@ -595,6 +607,23 @@ int main (int argc, char **argv) {
|
|||||||
pcpvault_close(ptx, vault);
|
pcpvault_close(ptx, vault);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PCP_MODE_CHECKSUM:
|
||||||
|
if(infile == NULL) {
|
||||||
|
if(argc == 0) {
|
||||||
|
char *list[1];
|
||||||
|
list[0] = NULL;
|
||||||
|
pcpchecksum(list, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pcpchecksum(argv, argc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char *list[1];
|
||||||
|
list[0] = infile;
|
||||||
|
pcpchecksum(list, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* mode params mixed */
|
/* mode params mixed */
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
#define PCP_MODE_ZDECODE 0x00000962
|
#define PCP_MODE_ZDECODE 0x00000962
|
||||||
#define PCP_MODE_SIGN 0x00000FF6
|
#define PCP_MODE_SIGN 0x00000FF6
|
||||||
#define PCP_MODE_VERIFY 0x00001B25
|
#define PCP_MODE_VERIFY 0x00001B25
|
||||||
#define PCP_MODE_YAML 0x00002E27
|
#define PCP_MODE_CHECKSUM 0x00002E27
|
||||||
|
|
||||||
/*
|
/*
|
||||||
0x00001B25
|
0x00001B25
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ Signature Options:
|
|||||||
|
|
||||||
Encoding Options:
|
Encoding Options:
|
||||||
-z --z85-encode Armor with Z85 encoding.
|
-z --z85-encode Armor with Z85 encoding.
|
||||||
|
-Z --z85-decode Decode Z85 encodeded input.
|
||||||
|
-a --armor --textmode same as -z
|
||||||
|
|
||||||
|
Misc Options:
|
||||||
|
-C --checksum calculate a Blake2 checksum of one or more files.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
Extra arguments after options are treated as filenames or
|
Extra arguments after options are treated as filenames or
|
||||||
|
|||||||
Reference in New Issue
Block a user