diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-09-03 11:03:06 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-09-03 11:03:06 (GMT) |
commit | 6d5c2726dad7f1b0539ffba19c726d10ad579430 (patch) | |
tree | 022b4360d76899ebb08392417636e0b8fc918fd8 | |
parent | 3656cf3e03003c2c84738408e5d2780f4a404f83 (diff) |
Release 1.4
MAJOR: Changed block ID numbers
Fix bug when determining endianness.
Added alt_hash and signature to block header (not read or
written yet)
-rw-r--r-- | Doxyfile.in | 2 | ||||
-rw-r--r-- | example_files/tng_example.tng | bin | 2531 -> 2531 bytes | |||
-rw-r--r-- | include/tng_io.h | 20 | ||||
-rw-r--r-- | src/lib/tng_io.c | 78 |
4 files changed, 47 insertions, 53 deletions
diff --git a/Doxyfile.in b/Doxyfile.in index 84b5770..7e6426f 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -32,7 +32,7 @@ PROJECT_NAME = "TNG API" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = "1.3" +PROJECT_NUMBER = "1.4" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/example_files/tng_example.tng b/example_files/tng_example.tng Binary files differindex 38ef819..82c64a4 100644 --- a/example_files/tng_example.tng +++ b/example_files/tng_example.tng diff --git a/include/tng_io.h b/include/tng_io.h index acf73cc..7ddae0e 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -1,6 +1,6 @@ /* This code is part of the tng binary trajectory format. * - * VERSION 1.3 + * VERSION 1.4 * * Written by Magnus Lundborg * Copyright (c) 2012, The GROMACS development team. @@ -25,7 +25,7 @@ * Each block can contain MD5 hashes to verify data integrity and the file * can be signed by the user to ensure that the origin is correct. * - * This is version 1.3 of the TNG API. The intention is that this version of + * This is version 1.4 of the TNG API. The intention is that this version of * the API and ABI should be stable, but it is still possible that future * changes might make that impossible, in which case that will be clarified. * @@ -76,6 +76,9 @@ * * Revisions * + * v. 1.4 - More flexible support for digital signatures in header. + * - Block ID numbers changed. + * * v. 1.3 - Second stable release of the API. * * - Added multiplication factor for coordinate units to general info. @@ -348,7 +351,7 @@ typedef unsigned long long int uint64_t; /** The version of this TNG build */ -#define TNG_VERSION 3 /* TNG_VERSION 3 => Api version 1.3 */ +#define TNG_VERSION 4 /* TNG_VERSION 4 => Api version 1.4 */ /** Flag to indicate frame dependent data. */ #define TNG_FRAME_DEPENDENT 1 @@ -358,7 +361,7 @@ typedef unsigned long long int uint64_t; /** The maximum length of a date string */ #define TNG_MAX_DATE_STR_LEN 24 /** The length of an MD5 hash */ -#define TNG_HASH_LEN 16 +#define TNG_MD5_HASH_LEN 16 /** The maximum allowed length of a string */ #define TNG_MAX_STR_LEN 1024 @@ -397,19 +400,24 @@ typedef enum {TNG_UNCOMPRESSED, TNG_XTC_COMPRESSION, TNG_TNG_COMPRESSION, TNG_GZIP_COMPRESSION} tng_compression; + +/** Hash types */ +typedef enum {TNG_NO_HASH, + TNG_MD5, + TNG_SHA256} tng_hash_type; /** Non trajectory blocks come before the first frame set block */ typedef enum {TNG_NON_TRAJECTORY_BLOCK, TNG_TRAJECTORY_BLOCK} tng_block_type; /** Block IDs of standard non trajectory blocks. */ -typedef enum {TNG_GENERAL_INFO, +typedef enum {TNG_GENERAL_INFO = 0x0000000000000000L, TNG_MOLECULES, TNG_TRAJECTORY_FRAME_SET, TNG_PARTICLE_MAPPING} tng_non_trajectory_block_ids; /** Block IDs of standard trajectory blocks. Box shape and partial charges can * be either trajectory blocks or non-trajectory blocks */ -typedef enum {TNG_TRAJ_BOX_SHAPE = 10000, +typedef enum {TNG_TRAJ_BOX_SHAPE = 0x0000000010000000L, TNG_TRAJ_POSITIONS, TNG_TRAJ_VELOCITIES, TNG_TRAJ_FORCES, diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index d2b5acb..c682a92 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -113,11 +113,17 @@ struct tng_gen_block { /** The ID of the block to determine its type */ int64_t id; /** The MD5 hash of the block to verify integrity */ - char hash[TNG_HASH_LEN]; + char md5_hash[TNG_MD5_HASH_LEN]; /** The name of the block */ char *name; /** The library version used to write the block */ int64_t block_version; + int64_t alt_hash_type; + int64_t alt_hash_len; + char *alt_hash; + int64_t signature_type; + int64_t signature_len; + char *signature; /** The full block header contents */ char *header_contents; /** The full block contents */ @@ -592,34 +598,34 @@ static tng_function_status tng_swap_byte_order_little_endian_64 * @param block is a general block container. * @return TNG_SUCCESS (0) if successful. */ -static tng_function_status tng_block_hash_generate(tng_gen_block_t block) +static tng_function_status tng_block_md5_hash_generate(tng_gen_block_t block) { md5_state_t md5_state; md5_init(&md5_state); md5_append(&md5_state, (md5_byte_t *)block->block_contents, block->block_contents_size); - md5_finish(&md5_state, (md5_byte_t *)block->hash); + md5_finish(&md5_state, (md5_byte_t *)block->md5_hash); return(TNG_SUCCESS); } -/** Compare the current block hash (e.g. read from file) with the hash +/** Compare the current block md5 hash (e.g. read from file) with the md5 hash * calculated from the current contents. - * If the current hash is not set skip the comparison. + * If the current md5 hash is not set skip the comparison. * @param block is a general block container. * @param results If the hashes match results is set to TNG_TRUE, otherwise it is * set to TNG_FALSE. If the hash was not set results is set to TNG_TRUE. * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (1) if the hash was not * set. */ -static tng_function_status hash_match_verify(tng_gen_block_t block, - tng_bool *results) +static tng_function_status tng_md5_hash_match_verify(tng_gen_block_t block, + tng_bool *results) { md5_state_t md5_state; - char hash[TNG_HASH_LEN]; + char hash[TNG_MD5_HASH_LEN]; - if(strncmp(block->hash, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) == 0) + if(strncmp(block->md5_hash, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) == 0) { *results = TNG_TRUE; return(TNG_FAILURE); @@ -629,29 +635,9 @@ static tng_function_status hash_match_verify(tng_gen_block_t block, block->block_contents_size); md5_finish(&md5_state, (md5_byte_t *)hash); - if(strncmp(block->hash, hash, 16) != 0) + if(strncmp(block->md5_hash, hash, 16) != 0) { *results = TNG_FALSE; -// int i; -// printf("Hash in file: "); -// for(i = 0; i<16; i++) -// { -// printf("%hhX ", block->hash[i]); -// } -// printf("\n"); -// printf("Expected hash: "); -// for(i = 0; i<16; i++) -// { -// printf("%hhX ", hash[i]); -// } -// printf("\n"); -// if(block->block_contents_size < 100) -// { -// for(i = 0; i < block->block_contents_size; i++) -// { -// printf("%hhX ", block->block_contents[i]); -// } -// } } else { @@ -739,8 +725,8 @@ static tng_function_status tng_block_init(struct tng_gen_block **block_p) block = *block_p; block->id = -1; - /* Reset the hash */ - memcpy(block->hash, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", TNG_HASH_LEN); + /* Reset the md5_hash */ + memcpy(block->md5_hash, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", TNG_MD5_HASH_LEN); block->name = 0; block->block_version = TNG_VERSION; block->header_contents = 0; @@ -820,7 +806,7 @@ static tng_function_status tng_block_header_read { /* File is little endian */ if ( *(const uint8_t*)&block->header_contents_size != 0x00 && - *(const uint8_t*)(&block->header_contents_size + 7) == 0x00) + *((const uint8_t*)(&block->header_contents_size) + 7) == 0x00) { /* If the architecture endianness is little endian no byte swap * will be needed. Otherwise use the functions to swap to little @@ -945,8 +931,8 @@ static tng_function_status tng_block_header_read offset += sizeof(block->id); - memcpy(block->hash, block->header_contents+offset, TNG_HASH_LEN); - offset += TNG_HASH_LEN; + memcpy(block->md5_hash, block->header_contents+offset, TNG_MD5_HASH_LEN); + offset += TNG_MD5_HASH_LEN; if(block->name && strcmp(block->name, block->header_contents+offset) != 0) { @@ -1061,7 +1047,7 @@ static tng_function_status tng_block_header_write if(hash_mode == TNG_USE_HASH) { - tng_block_hash_generate(block); + tng_block_md5_hash_generate(block); } /* Calculate the size of the header to write */ @@ -1069,7 +1055,7 @@ static tng_function_status tng_block_header_write sizeof(block->block_contents_size) + sizeof(block->id) + sizeof(block->block_version) + - TNG_HASH_LEN + + TNG_MD5_HASH_LEN + name_len; if(block->header_contents) @@ -1128,8 +1114,8 @@ static tng_function_status tng_block_header_write } offset += sizeof(block->id); - memcpy(block->header_contents+offset, block->hash, TNG_HASH_LEN); - offset += TNG_HASH_LEN; + memcpy(block->header_contents+offset, block->md5_hash, TNG_MD5_HASH_LEN); + offset += TNG_MD5_HASH_LEN; strncpy(block->header_contents+offset, block->name, name_len); offset += name_len; @@ -1205,7 +1191,7 @@ static tng_function_status tng_general_info_block_read if(hash_mode == TNG_USE_HASH) { - hash_match_verify(block, &same_hash); + tng_md5_hash_match_verify(block, &same_hash); if(same_hash != TNG_TRUE) { printf("General info block contents corrupt. Hashes do not match. " @@ -2130,7 +2116,7 @@ static tng_function_status tng_molecules_block_read if(hash_mode == TNG_USE_HASH) { - hash_match_verify(block, &same_hash); + tng_md5_hash_match_verify(block, &same_hash); if(same_hash != TNG_TRUE) { printf("Molecules block contents corrupt. Hashes do not match. " @@ -2943,7 +2929,7 @@ static tng_function_status tng_frame_set_block_read if(hash_mode == TNG_USE_HASH) { - hash_match_verify(block, &same_hash); + tng_md5_hash_match_verify(block, &same_hash); if(same_hash != TNG_TRUE) { printf("Frame set block contents corrupt. File pos %d Hashes do not match. " @@ -3487,7 +3473,7 @@ static tng_function_status tng_trajectory_mapping_block_read if(hash_mode == TNG_USE_HASH) { - hash_match_verify(block, &same_hash); + tng_md5_hash_match_verify(block, &same_hash); if(same_hash != TNG_TRUE) { printf("Particle mapping block contents corrupt. Hashes do not match. " @@ -5968,7 +5954,7 @@ static tng_function_status tng_data_block_contents_read if(hash_mode == TNG_USE_HASH) { - hash_match_verify(block, &same_hash); + tng_md5_hash_match_verify(block, &same_hash); if(same_hash != TNG_TRUE) { printf("'%s' data block contents corrupt. Hashes do not match. %s: %d\n", @@ -6169,11 +6155,11 @@ static tng_function_status tng_md5_hash_update(tng_trajectory_t tng_data, return(TNG_CRITICAL); } - tng_block_hash_generate(block); + tng_block_md5_hash_generate(block); fseek(tng_data->output_file, header_start_pos + 3 * sizeof(int64_t), SEEK_SET); - fwrite(block->hash, TNG_HASH_LEN, 1, tng_data->output_file); + fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file); return(TNG_SUCCESS); } |