summaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-08-07 20:10:48 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-08-07 20:10:48 +0200
commit1a7d30cebf76ff9ed057d05c03afabbaf36ebff6 (patch)
tree0aa60bc8d3b135681992a4983c50572e43fffe97 /src/image.c
parentea52c0509aac90a6d97d84ecf076d65eb9514a40 (diff)
download0xFFFF-1a7d30cebf76ff9ed057d05c03afabbaf36ebff6.tar.bz2
image: Implement image_hash_from_data
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/image.c b/src/image.c
index c59577a..224468f 100644
--- a/src/image.c
+++ b/src/image.c
@@ -223,9 +223,8 @@ struct image * image_alloc_from_shared_fd(int fd, size_t size, size_t offset, ui
if ( image->hash != hash ) {
fprintf(stderr, "Error: Image hash mishmash (expected %#04x)\n", image->hash);
-// image_free(image);
-// return NULL;
- image->hash = hash;
+ image_free(image);
+ return NULL;
}
return image;
@@ -352,12 +351,27 @@ void image_list_del(struct image_list * list) {
}
+static uint16_t do_hash(uint16_t * b, int len) {
+
+ uint16_t result = 0;
+
+ for ( len >>= 1; len--; b = b+1 )
+ result^=b[0];
+
+ return result;
+
+}
uint16_t image_hash_from_data(struct image * image) {
- /* TODO */
- printf("image_hash_from_data is not implemented\n");
+ unsigned char buf[0x20000];
+ uint16_t hash = 0;
+ int ret;
+
+ while ( ( ret = image_read(image, &buf, sizeof(buf)) ) )
+ hash ^= do_hash((uint16_t *)&buf, ret);
+ return hash;
}
static const char * image_types[] = {