&(zck->chunk_hash_type)))
goto hash_error;
if(zck->comp.data_loc > 0) {
- if(!hash_update(zck, &(zck->check_full_hash), zck->comp.data,
- zck->comp.data_loc))
- goto hash_error;
+ if(!zck->has_uncompressed_source) {
+ if(!hash_update(zck, &(zck->check_full_hash), zck->comp.data,
+ zck->comp.data_loc))
+ goto hash_error;
+ }
if(!hash_update(zck, &(zck->check_chunk_hash), zck->comp.data,
zck->comp.data_loc))
goto hash_error;
if(!hash_init(zck, &(zck->check_chunk_hash),
&(zck->chunk_hash_type)))
goto hash_error;
- if(!hash_update(zck, &(zck->check_full_hash), src, rb) ||
- !hash_update(zck, &(zck->check_chunk_hash), src, rb) ||
+ if(!zck->has_uncompressed_source) {
+ if(!hash_update(zck, &(zck->check_full_hash), src, rb))
+ goto read_error;
+ }
+ if(!hash_update(zck, &(zck->check_chunk_hash), src, rb) ||
!comp_add_to_data(zck, &(zck->comp), src, rb))
goto read_error;
}
zck_log(ZCK_LOG_DEBUG, "No more data");
if(!hash_update(zck, &(zck->check_chunk_hash), buf, rsize))
return 0;
- if(!hash_update(zck, &(zck->check_full_hash), buf, rsize))
- return 0;
+ if(!zck->has_uncompressed_source) {
+ if(!hash_update(zck, &(zck->check_full_hash), buf, rsize))
+ return 0;
+ }
rlen += rsize;
}
int valid_chunk = validate_chunk(idx, bad_checksums);
int validate_file(zckCtx *zck, zck_log_type bad_checksums) {
VALIDATE_BOOL(zck);
+ if(zck->has_uncompressed_source) {
+ zck_log(
+ ZCK_LOG_DEBUG,
+ "Skipping full file validation since uncompressed source flag is set"
+ );
+ return 1;
+ }
char *digest = hash_finalize(zck, &(zck->check_full_hash));
if(digest == NULL) {
set_error(zck, "Unable to calculate full file checksum");
int ZCK_PUBLIC_API zck_validate_data_checksum(zckCtx *zck) {
VALIDATE_READ_BOOL(zck);
+ if(zck->has_uncompressed_source) {
+ zck_log(
+ ZCK_LOG_DEBUG,
+ "Skipping full file validation since uncompressed source flag is set"
+ );
+ return 1;
+ }
+
if(!seek_data(zck, zck->data_offset, SEEK_SET))
return 0;
if(!hash_init(zck, &(zck->check_full_hash), &(zck->hash_type)))
if(zck->full_hash_digest == NULL)
return false;
+ /* Set hash to 0s if has_uncompressed_source is set */
+ if(zck->has_uncompressed_source)
+ memset(zck->full_hash_digest, 0, zck->hash_type.digest_size);
+
/* Set initial malloc size */
index_malloc = MAX_COMP_SIZE * 2;
if(comp_size == 0)
return true;
- if(!hash_update(zck, &(zck->full_hash), data, comp_size))
- return false;
+ if(!zck->has_uncompressed_source) {
+ if(!hash_update(zck, &(zck->full_hash), data, comp_size))
+ return false;
+ }
if(!hash_update(zck, &(zck->work_index_hash), data, comp_size))
return false;
} else if(option == ZCK_UNCOMP_HEADER) {
zck->has_uncompressed_source = 1;
+ /* Uncompressed source requires chunk checksums to be a minimum of SHA-256 */
+ if(zck->chunk_hash_type.type == ZCK_HASH_SHA1 ||
+ zck->chunk_hash_type.type == ZCK_HASH_SHA512_128) {
+ if(!set_chunk_hash_type(zck, ZCK_HASH_SHA256))
+ return false;
+ }
+
/* Hash options */
} else if(option < 100) {
/* Currently no hash options other than setting hash type, so bail */
0 = SHA-1
1 = SHA-256
+ Note: if the file has flag 2 (uncompressed source) set, the total data
+ checksum must not be checked and should not be generated. Also, the
+ chunk checksum must not be SHA-1 or SHA-512/128, since there is no total
+ data checksum.
+
Header size:
This is an integer containing the size of the header, not including the lead
Current flags are:
bit 0: File has data streams
bit 1: File has optional elements
- bit 2: EXPERIMENTAL: File may be applied against an uncompressed source
+ bit 2: File may be applied against an uncompressed source
Compression type
This is an integer containing the type of compression used to compress dict and
This is the checksum of the compressed chunk, used to detect whether any two
chunks are identical.
-EXPERIMENTAL: NOTE: Uncompressed chunk checksum will only exist if flag 2 is set
- to 1
+NOTE: Uncompressed chunk checksum will only exist if flag 2 is set to 1
Uncompressed chunk checksum
This is the checksum of the uncompressed chunk, used to detect whether a chunk
from an uncompressed source is identical to the compressed chunk