diff options
author | Christophe Fergeau <teuf@gnome.org> | 2007-09-27 17:55:21 +0000 |
---|---|---|
committer | Christophe Fergeau <teuf@gnome.org> | 2007-09-27 17:55:21 +0000 |
commit | 9a2a5fd8fb42f334131a5a98fe0db9a88714224a (patch) | |
tree | ef98c66879450777cc38444d0d30948ab61f0193 | |
parent | 7f0adc14e2eb6a28f6b54d96a72f6caf72c08ccc (diff) | |
download | libgpod-9a2a5fd8fb42f334131a5a98fe0db9a88714224a.tar.gz libgpod-9a2a5fd8fb42f334131a5a98fe0db9a88714224a.tar.xz libgpod-9a2a5fd8fb42f334131a5a98fe0db9a88714224a.zip |
* src/itdb_itunesdb.c: (calculate_db_checksum),
(itdb_write_checksum):
* src/itdb_sha1.c: (itdb_compute_hash):
* src/itdb_sha1.h: propagate the calculated checksum length as an out
parameter to the checksumming functions, fixes a bug where a partial
checksum would be written if it contained a \0
* tests/test-checksum.c: (calculate_db_checksum): update test program
to that API change
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1702 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/itdb_itunesdb.c | 10 | ||||
-rw-r--r-- | src/itdb_sha1.c | 14 | ||||
-rw-r--r-- | src/itdb_sha1.h | 2 | ||||
-rw-r--r-- | tests/test-checksum.c | 2 |
5 files changed, 28 insertions, 11 deletions
@@ -1,3 +1,14 @@ +2007-09-27 Christophe,,, <teuf@atchoum> + + * src/itdb_itunesdb.c: (calculate_db_checksum), + (itdb_write_checksum): + * src/itdb_sha1.c: (itdb_compute_hash): + * src/itdb_sha1.h: propagate the calculated checksum length as an out + parameter to the checksumming functions, fixes a bug where a partial + checksum would be written if it contained a \0 + * tests/test-checksum.c: (calculate_db_checksum): update test program + to that API change + 2007-09-26 Jorg Schuler <jcsjcs at users.sourceforge.net> * src/itdb_device.c: remove "read only" notice on Nano Video diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c index a411052..35b01c5 100644 --- a/src/itdb_itunesdb.c +++ b/src/itdb_itunesdb.c @@ -4944,7 +4944,7 @@ gboolean itdb_write_file (Itdb_iTunesDB *itdb, const gchar *filename, } static unsigned char * -calculate_db_checksum (const char *itdb_path, guint64 fwid) +calculate_db_checksum (const char *itdb_path, guint64 fwid, gsize *len) { int fd; struct stat stat_buf; @@ -4985,7 +4985,7 @@ calculate_db_checksum (const char *itdb_path, guint64 fwid) memset(itdb_data+0x32, 0, 20); memset(itdb_data+0x58, 0, 20); - checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size); + checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size, len); munmap (itdb_data, stat_buf.st_size); close (fd); @@ -5023,6 +5023,7 @@ static gboolean itdb_write_checksum (Itdb_iTunesDB *db) guint64 fwid; char *itdb_path; unsigned char *checksum; + gsize len; gboolean result; if (db->device == NULL) { @@ -5035,15 +5036,14 @@ static gboolean itdb_write_checksum (Itdb_iTunesDB *db) } itdb_path = itdb_get_itunesdb_path (itdb_get_mountpoint (db)); - checksum = calculate_db_checksum (itdb_path, fwid); + checksum = calculate_db_checksum (itdb_path, fwid, &len); if (checksum == NULL) { g_free (itdb_path); return FALSE; } - result = itdb_write_checksum_to_file (itdb_path, checksum, - strlen ((char *)checksum)); + result = itdb_write_checksum_to_file (itdb_path, checksum, len); g_free (itdb_path); { diff --git a/src/itdb_sha1.c b/src/itdb_sha1.c index 5ad8751..0ec6c54 100644 --- a/src/itdb_sha1.c +++ b/src/itdb_sha1.c @@ -211,13 +211,15 @@ static unsigned char *generate_key (guint64 fwid) unsigned char *itdb_compute_hash (guint64 firewire_id, const unsigned char *itdb, - unsigned long size) + unsigned long size, + gsize *len) { unsigned char *key; unsigned char *hash; SHA_INFO context; int i; - + const gsize CHECKSUM_LEN = 20; + key = generate_key(firewire_id); /* hmac sha1 */ @@ -227,7 +229,7 @@ unsigned char *itdb_compute_hash (guint64 firewire_id, } /* 20 bytes for the checksum, and 1 trailing \0 */ - hash = g_new0 (unsigned char, 21); + hash = g_new0 (unsigned char, CHECKSUM_LEN + 1); sha_init(&context); sha_update(&context, key, 64); sha_update(&context, itdb, size); @@ -238,10 +240,14 @@ unsigned char *itdb_compute_hash (guint64 firewire_id, sha_init(&context); sha_update(&context, key, 64); - sha_update(&context, hash, 20); + sha_update(&context, hash, CHECKSUM_LEN); sha_final(hash, &context); g_free (key); + if (len != NULL) { + *len = CHECKSUM_LEN; + } + return hash; } diff --git a/src/itdb_sha1.h b/src/itdb_sha1.h index 1effb8b..d89918b 100644 --- a/src/itdb_sha1.h +++ b/src/itdb_sha1.h @@ -33,5 +33,5 @@ unsigned char *itdb_compute_hash (guint64 firewire_id, const unsigned char *itdb, - unsigned long size); + unsigned long size, gsize *len); #endif diff --git a/tests/test-checksum.c b/tests/test-checksum.c index 3f9ef85..70086cd 100644 --- a/tests/test-checksum.c +++ b/tests/test-checksum.c @@ -93,7 +93,7 @@ calculate_db_checksum (const char *itdb_path, guint64 fwid) memset(itdb_data+0x32, 0, 20); memset(itdb_data+0x58, 0, 20); - checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size); + checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size, NULL); munmap (itdb_data, stat_buf.st_size); close (fd); |