From ae64d2602befd5589c8c0141a6d812841fdfb232 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Apr 2008 14:04:39 +0000 Subject: more code policing to stop warnings when built with -W -Wall git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17048 a1c6a512-1295-4272-9138-f99709370657 --- tools/creative.c | 6 +++--- tools/descramble.c | 10 +++++----- tools/hmac-sha1.c | 48 +++++++++++++++++++----------------------------- tools/hmac-sha1.h | 13 +++---------- 4 files changed, 30 insertions(+), 47 deletions(-) diff --git a/tools/creative.c b/tools/creative.c index 6e0e468411..5b8f15abc0 100644 --- a/tools/creative.c +++ b/tools/creative.c @@ -52,7 +52,7 @@ extern unsigned int le2int(unsigned char* buf); static int make_ciff_file(unsigned char *inbuf, int length, unsigned char *outbuf, int device) { - char key[20]; + unsigned char key[20]; memcpy(outbuf, "FFIC", 4); int2le(length+90, &outbuf[4]); memcpy(&outbuf[8], "FNIC", 4); @@ -68,8 +68,8 @@ static int make_ciff_file(unsigned char *inbuf, int length, memcpy(&outbuf[0x98+length], "LLUN", 4); int2le(20, &outbuf[0x98+length+4]); /* Do checksum */ - hmac_sha((char *)devices[device].null, strlen(devices[device].null), - (char *)outbuf, 0x98+length, key, 20); + hmac_sha((unsigned char *)devices[device].null, strlen(devices[device].null), + outbuf, 0x98+length, key, 20); memcpy(&outbuf[0x98+length+8], key, 20); return length+0x90+0x1C+8; } diff --git a/tools/descramble.c b/tools/descramble.c index 3d09bfad75..42bc9cee6c 100644 --- a/tools/descramble.c +++ b/tools/descramble.c @@ -157,13 +157,13 @@ int main (int argc, char** argv) length |= header[10] << 16 | header[11] << 24; /* calculate the xor string used */ - for (i=0; i j) + if (src > (int)j) src -= 0x1000; for (x=0; x + #include "hmac-sha1.h" /* @@ -386,35 +388,20 @@ void SHA1PadMessage(SHA1Context *context) #define SHA_BLOCKSIZE 64 -static void truncate -( - char* d1, /* data to be truncated */ - char* d2, /* truncated data */ - int len /* length in bytes to keep */ -) -{ - int i ; - for (i = 0 ; i < len ; i++) d2[i] = d1[i]; -} - - /* Function to compute the digest */ void -hmac_sha -( - char* k, /* secret key */ - int lk, /* length of the key in bytes */ - char* d, /* data */ - int ld, /* length of data in bytes */ - char* out, /* output buffer, at least "t" bytes */ - int t -) +hmac_sha(unsigned char* k, /* secret key */ + int lk, /* length of the key in bytes */ + unsigned char* d, /* data */ + int ld, /* length of data in bytes */ + unsigned char* out, /* output buffer, at least "t" bytes */ + int t) { SHA1Context ictx, octx ; - char isha[SHA_DIGESTSIZE], osha[SHA_DIGESTSIZE] ; - char key[SHA_DIGESTSIZE] ; - char buf[SHA_BLOCKSIZE] ; - int i ; + unsigned char isha[SHA_DIGESTSIZE], osha[SHA_DIGESTSIZE] ; + unsigned char key[SHA_DIGESTSIZE] ; + unsigned char buf[SHA_BLOCKSIZE] ; + int i ; if (lk > SHA_BLOCKSIZE) { @@ -433,8 +420,11 @@ hmac_sha SHA1Reset(&ictx) ; /* Pad the key for inner digest */ - for (i = 0 ; i < lk ; ++i) buf[i] = k[i] ^ 0x36 ; - for (i = lk ; i < SHA_BLOCKSIZE ; ++i) buf[i] = 0x36 ; + for (i = 0 ; i < lk ; ++i) + buf[i] = k[i] ^ 0x36 ; + + for (i = lk ; i < SHA_BLOCKSIZE ; ++i) + buf[i] = 0x36 ; SHA1Input(&ictx, buf, SHA_BLOCKSIZE) ; SHA1Input(&ictx, d, ld) ; @@ -456,8 +446,8 @@ hmac_sha SHA1Result(&octx, osha) ; - /* truncate and print the results */ + /* truncate the results */ t = t > SHA_DIGESTSIZE ? SHA_DIGESTSIZE : t ; - truncate(osha, out, t) ; + memcpy(out, osha, t); } diff --git a/tools/hmac-sha1.h b/tools/hmac-sha1.h index 149b5bac46..e5be1cfc38 100644 --- a/tools/hmac-sha1.h +++ b/tools/hmac-sha1.h @@ -70,15 +70,8 @@ int SHA1Input( SHA1Context *, int SHA1Result( SHA1Context *, uint8_t Message_Digest[SHA1HashSize]); -void -hmac_sha -( - char* k, - int lk, - char* d, - int ld, - char* out, - int t -); +void hmac_sha(unsigned char* k, int lk, + unsigned char* d, int ld, + unsigned char* out, int t); #endif -- cgit v1.2.3