From: Andre Noll Date: Wed, 19 Apr 2017 13:12:44 +0000 (+0200) Subject: Prepare hash_function() for multiple hash algorithms. X-Git-Tag: v0.2.0~4^2~2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=6811bf3ef3f157e82c189f22e0b5cedd8a8ba1db;p=osl.git Prepare hash_function() for multiple hash algorithms. In order to transparently support more than one hash function in the future, we now pass the table version to hash_function(). The version is always one at the moment, and only the sha1 hash is implemented so far. --- diff --git a/fsck.c b/fsck.c index 8a32aba..42312d9 100644 --- a/fsck.c +++ b/fsck.c @@ -718,7 +718,7 @@ static int check_disk_storage_presence(struct osl_table *t) ret = get_mapped_object(t, dsnc, i, &obj); if (ret < 0) return ret; - hash_object(&obj, hashes + i * HASH_SIZE); + hash_object(t, &obj, hashes + i * HASH_SIZE); hash_obj.data = hashes + i * HASH_SIZE; osl_add_row(hash_tree_table, &hash_obj); ds_name = disk_storage_name_of_hash(t, hashes + i * HASH_SIZE); @@ -1041,7 +1041,7 @@ static int dump_row(struct osl_table *t, unsigned row_num, const char *row_dir) ret = get_mapped_object(t, dsnc, row_num, &obj); if (ret < 0) return ret; - hash_object(&obj, hash); + hash_object(t, &obj, hash); ds_name = disk_storage_name_of_hash(t, hash); FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) { filename = disk_storage_path(t, i, ds_name); diff --git a/hash.h b/hash.h index 6244d08..0815338 100644 --- a/hash.h +++ b/hash.h @@ -16,8 +16,12 @@ void sha1_hash(const char *data, unsigned long len, unsigned char *sha1); -/** Our own sha1 implementation, see sha1.c. */ -#define hash_function sha1_hash +static inline void hash_function(uint8_t table_version, const char *data, + unsigned long len, unsigned char *result) +{ + assert(table_version == 1); + sha1_hash(data, len, result); +} /** * Compare two hashes. diff --git a/osl.c b/osl.c index 40b0a24..8e19bc4 100644 --- a/osl.c +++ b/osl.c @@ -168,7 +168,7 @@ static char *disk_storage_name_of_object(const struct osl_table *t, const struct osl_object *obj) { HASH_TYPE hash[HASH_SIZE]; - hash_object(obj, hash); + hash_object(t, obj, hash); return disk_storage_name_of_hash(t, hash); } @@ -186,9 +186,10 @@ static int disk_storage_name_of_row(const struct osl_table *t, return -E_OSL_NOMEM; } -static void column_name_hash(const char *col_name, HASH_TYPE *hash) +static void column_name_hash(const struct osl_table *t, const char *col_name, + HASH_TYPE *hash) { - hash_function(col_name, strlen(col_name), hash); + hash_function(t->version, col_name, strlen(col_name), hash); } static int init_column_descriptions(struct osl_table *t) @@ -553,7 +554,7 @@ __export int osl_create_table(const struct osl_table_description *desc) if (ret < 0) goto out; } - column_name_hash(cd->name, t->columns[i].name_hash); + column_name_hash(t, cd->name, t->columns[i].name_hash); ret = -E_OSL_NOMEM; filename = column_filename(t, i); if (!filename) @@ -724,7 +725,7 @@ int map_table(struct osl_table *t, enum map_table_flags flags) FOR_EACH_COLUMN(i, t->desc, cd) { if (cd->storage_type == OSL_NO_STORAGE) continue; - column_name_hash(cd->name, t->columns[i].name_hash); + column_name_hash(t, cd->name, t->columns[i].name_hash); if (num_rows > 0 && cd->storage_type == OSL_MAPPED_STORAGE) { ret = map_column(t, i); if (ret < 0) diff --git a/osl_core.h b/osl_core.h index 9879b1e..91489c9 100644 --- a/osl_core.h +++ b/osl_core.h @@ -456,12 +456,14 @@ _static_inline_ struct osl_row *get_row_pointer(const struct rb_node *node, /** * Compute a cryptographic hash of an osl object. * + * \param t Determines the hash function to use. * \param obj the Object to compute the hash value from. * \param hash Result is returned here. */ -_static_inline_ void hash_object(const struct osl_object *obj, HASH_TYPE *hash) +_static_inline_ void hash_object(const struct osl_table *t, + const struct osl_object *obj, HASH_TYPE *hash) { - hash_function(obj->data, obj->size, hash); + hash_function(t->version, obj->data, obj->size, hash); } /**