From 4da9824ab07c62250b34e3f3d3be06389172f4ba Mon Sep 17 00:00:00 2001 From: gardners Date: Sun, 27 May 2012 14:44:53 +0200 Subject: [PATCH] fixed bug in storing file that could cause entertaining file hash problems. --- rhizome_database.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rhizome_database.c b/rhizome_database.c index 4172409d..cebceef2 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -857,11 +857,11 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key) { int n=RHIZOME_CRYPT_PAGE_SIZE; if (i+n>m->fileLength) n=m->fileLength-i; - SHA512_Update(&context, &addr[i], count); + SHA512_Update(&context, &addr[i], n); if (key) { /* calculate block nonce */ int j; for(j=0;j<8;j++) nonce[i]=(i>>(j*8))&0xff; - crypto_stream_xsalsa20_xor(&addr[i],&buffer[0],count, + crypto_stream_xsalsa20_xor(&addr[i],&buffer[0],n, nonce,key); if (sqlite3_blob_write(blob,&buffer[0],n,i) !=SQLITE_OK) dud++; } @@ -877,6 +877,7 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key) if (strcasecmp(hash_out,hash)) { + WHYF("Computed hash = %s",hash_out); return WHY("File hash does not match -- has file been modified while being stored?"); }