added support for authenticated hashes

This commit is contained in:
TLINDEN
2015-07-21 14:18:03 +02:00
parent 95ab61b3cb
commit 362f7dff6b
14 changed files with 906 additions and 930 deletions

View File

@@ -360,9 +360,19 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
return 1;
}
void pcpchecksum(char **files, int filenum) {
void pcpchecksum(char **files, int filenum, char *key) {
int i;
byte *checksum = ucmalloc(crypto_generichash_BYTES_MAX);
byte *keyhash = NULL;
size_t hashlen = 0;
if(key != NULL) {
keyhash = ucmalloc(crypto_generichash_BYTES);
crypto_generichash(keyhash, crypto_generichash_BYTES,
(byte *)key, strlen(key),
NULL, crypto_generichash_BYTES);
hashlen = crypto_generichash_BYTES;
}
for(i=0; i<filenum; i++) {
FILE *in;
@@ -377,9 +387,9 @@ void pcpchecksum(char **files, int filenum) {
}
}
Pcpstream *pin = ps_new_file(in);
if(pcp_checksum(ptx, pin, checksum) > 0) {
if(pcp_checksum(ptx, pin, checksum, keyhash, hashlen) > 0) {
char *hex = _bin2hex(checksum, crypto_generichash_BYTES_MAX);
fprintf(stdout, "BLAKE2 (%s) = %s\n", files[i], hex);
fprintf(stdout, "BLAKE2b (%s) = %s\n", files[i], hex);
free(hex);
}
else
@@ -387,4 +397,7 @@ void pcpchecksum(char **files, int filenum) {
}
free(checksum);
if(keyhash != NULL)
free(keyhash);
}