From 98ece8c1caeb3cfc26213863d08f26612a9e1ef5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 8 Aug 2009 15:15:27 +0000 Subject: [PATCH] made sha1.cpp build in sunpro --- src/sha1.cpp | 54 +++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/sha1.cpp b/src/sha1.cpp index a7ea67113..3495c6ac3 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -18,30 +18,32 @@ changelog at the end of the file. // if you don't want boost // replace with // #include +// typedef uint32_t u32; +// typedef uint8_t u8; #include -using boost::uint32_t; -using boost::uint8_t; +typedef boost::uint32_t u32; +typedef boost::uint8_t u8; #include "libtorrent/config.hpp" struct TORRENT_EXPORT SHA_CTX { - uint32_t state[5]; - uint32_t count[2]; - uint8_t buffer[64]; + u32 state[5]; + u32 count[2]; + u8 buffer[64]; }; TORRENT_EXPORT void SHA1_Init(SHA_CTX* context); -TORRENT_EXPORT void SHA1_Update(SHA_CTX* context, uint8_t const* data, uint32_t len); -TORRENT_EXPORT void SHA1_Final(uint8_t* digest, SHA_CTX* context); +TORRENT_EXPORT void SHA1_Update(SHA_CTX* context, u8 const* data, u32 len); +TORRENT_EXPORT void SHA1_Final(u8* digest, SHA_CTX* context); namespace { union CHAR64LONG16 { - uint8_t c[64]; - uint32_t l[16]; + u8 c[64]; + u32 l[16]; }; #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) @@ -50,7 +52,7 @@ namespace // I got the idea of expanding during the round function from SSLeay struct little_endian_blk0 { - static uint32_t apply(CHAR64LONG16* block, int i) + static u32 apply(CHAR64LONG16* block, int i) { return block->l[i] = (rol(block->l[i],24)&0xFF00FF00) | (rol(block->l[i],8)&0x00FF00FF); @@ -59,7 +61,7 @@ namespace struct big_endian_blk0 { - static uint32_t apply(CHAR64LONG16* block, int i) + static u32 apply(CHAR64LONG16* block, int i) { return block->l[i]; } @@ -78,13 +80,13 @@ namespace // Hash a single 512-bit block. This is the core of the algorithm. template - void SHA1Transform(uint32_t state[5], uint8_t const buffer[64]) + void SHA1Transform(u32 state[5], u8 const buffer[64]) { using namespace std; - uint32_t a, b, c, d, e; + u32 a, b, c, d, e; CHAR64LONG16* block; - uint8_t workspace[64]; + u8 workspace[64]; block = (CHAR64LONG16*)workspace; memcpy(block, buffer, 64); @@ -136,10 +138,10 @@ namespace } template - void internal_update(SHA_CTX* context, uint8_t const* data, uint32_t len) + void internal_update(SHA_CTX* context, u8 const* data, u32 len) { using namespace std; - uint32_t i, j; // JHB + u32 i, j; // JHB #ifdef VERBOSE SHAPrintContext(context, "before"); @@ -169,8 +171,8 @@ namespace bool is_big_endian() { - uint32_t test = 1; - return *reinterpret_cast(&test) == 0; + u32 test = 1; + return *reinterpret_cast(&test) == 0; } } @@ -190,7 +192,7 @@ void SHA1_Init(SHA_CTX* context) // Run your data through this. -void SHA1_Update(SHA_CTX* context, uint8_t const* data, uint32_t len) +void SHA1_Update(SHA_CTX* context, u8 const* data, u32 len) { #if defined __BIG_ENDIAN__ internal_update(context, data, len); @@ -209,24 +211,24 @@ void SHA1_Update(SHA_CTX* context, uint8_t const* data, uint32_t len) // Add padding and return the message digest. -void SHA1_Final(uint8_t* digest, SHA_CTX* context) +void SHA1_Final(u8* digest, SHA_CTX* context) { - uint8_t finalcount[8]; + u8 finalcount[8]; - for (uint32_t i = 0; i < 8; ++i) + for (u32 i = 0; i < 8; ++i) { // Endian independent - finalcount[i] = static_cast( + finalcount[i] = static_cast( (context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); } - SHA1_Update(context, (uint8_t const*)"\200", 1); + SHA1_Update(context, (u8 const*)"\200", 1); while ((context->count[0] & 504) != 448) - SHA1_Update(context, (uint8_t const*)"\0", 1); + SHA1_Update(context, (u8 const*)"\0", 1); SHA1_Update(context, finalcount, 8); // Should cause a SHA1Transform() - for (uint32_t i = 0; i < 20; ++i) + for (u32 i = 0; i < 20; ++i) { digest[i] = static_cast( (context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);