Index: src/OFHashes.h ================================================================== --- src/OFHashes.h +++ src/OFHashes.h @@ -10,12 +10,12 @@ */ #import "OFObject.h" #import "OFString.h" -#define MD5_DIGEST_SIZE 16 -#define SHA1_DIGEST_SIZE 20 +#define OF_MD5_DIGEST_SIZE 16 +#define OF_SHA1_DIGEST_SIZE 20 extern int _OFHashing_reference; /** * The OFMD5Hash class provides functions to create an MD5 hash. @@ -44,11 +44,11 @@ */ - updateWithBuffer: (const char*)buf ofSize: (size_t)size; /** - * \return A buffer containing the hash (MD5_DIGEST_SIZE = 16 bytes). + * \return A buffer containing the hash (OF_MD5_DIGEST_SIZE = 16 bytes). * The buffer is part of object's memory pool. */ - (uint8_t*)digest; @end @@ -58,11 +58,11 @@ @interface OFSHA1Hash: OFObject { uint32_t state[5]; uint64_t count; char buffer[64]; - uint8_t digest[SHA1_DIGEST_SIZE]; + uint8_t digest[OF_SHA1_DIGEST_SIZE]; BOOL calculated; } /** @@ -80,11 +80,11 @@ */ - updateWithBuffer: (const char*)buf ofSize: (size_t)size; /** - * \return A buffer containing the hash (SHA1_DIGEST_SIZE = 20 bytes). + * \return A buffer containing the hash (OF_SHA1_DIGEST_SIZE = 20 bytes). * The buffer is part of object's memory pool. */ - (uint8_t*)digest; @end Index: src/OFHashes.m ================================================================== --- src/OFHashes.m +++ src/OFHashes.m @@ -18,13 +18,13 @@ #import "OFExceptions.h" #import "OFMacros.h" int _OFHashing_reference; -/******* - * MD5 * - *******/ +/* + * MD5 + */ /* The four MD5 core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) #define F2(x, y, z) F1(z, x, y) #define F3(x, y, z) (x ^ y ^ z) @@ -246,13 +246,13 @@ #undef F2 #undef F3 #undef F4 #undef MD5STEP -/******** - * SHA1 * - ********/ +/* + * SHA1 + */ /* blk0() and blk() perform the initial expand. */ #ifndef OF_BIG_ENDIAN #define blk0(i) \ (block->l[i] = (OF_ROL(block->l[i], 24) & 0xFF00FF00) | \ @@ -408,13 +408,15 @@ while ((count & 504) != 448) sha1_update(state, &count, buffer, "\0", 1); /* Should cause a sha1_transform() */ sha1_update(state, &count, buffer, finalcount, 8); - for (i = 0; i < SHA1_DIGEST_SIZE; i++) + for (i = 0; i < OF_SHA1_DIGEST_SIZE; i++) digest[i] = (char)((state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); + + calculated = YES; return digest; } @end Index: tests/OFHashes/OFHashes.m ================================================================== --- tests/OFHashes/OFHashes.m +++ tests/OFHashes/OFHashes.m @@ -15,13 +15,13 @@ #include #import "OFHashes.h" #import "OFFile.h" -const uint8_t testfile_md5[MD5_DIGEST_SIZE] = +const uint8_t testfile_md5[OF_MD5_DIGEST_SIZE] = "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; -const uint8_t testfile_sha1[SHA1_DIGEST_SIZE] = +const uint8_t testfile_sha1[OF_SHA1_DIGEST_SIZE] = "\xC9\x9A\xB8\x7E\x1E\xC8\xEC\x65\xD5\xEB\xE4\x2E\x0D\xA6\x80\x96\xF5" "\x94\xE7\x17"; int main() @@ -42,22 +42,22 @@ [sha1 updateWithBuffer: buf ofSize: len]; } [f close]; - if (!memcmp([md5 digest], testfile_md5, MD5_DIGEST_SIZE)) { + if (!memcmp([md5 digest], testfile_md5, OF_MD5_DIGEST_SIZE)) { fputs("\r\033[1;33mTests successful: 1/2\033[0m", stdout); fflush(stdout); } else { puts("\r\033[K\033[1;31mTest 1/2 failed!\033[0m"); return 1; } - if (!memcmp([sha1 digest], testfile_sha1, SHA1_DIGEST_SIZE)) + if (!memcmp([sha1 digest], testfile_sha1, OF_SHA1_DIGEST_SIZE)) puts("\r\033[1;32mTests successful: 2/2\033[0m"); else { puts("\r\033[K\033[1;31mTest 2/2 failed!\033[0m"); return 1; } return 0; }