From 76cc2bf7b43140698618e9dbb87a219c3bd7d32f Mon Sep 17 00:00:00 2001 From: SlowRiot Date: Thu, 20 Nov 2014 01:58:57 +0000 Subject: fixing incorrect buffer size allocation, and unsafe integer size type --- libs/sha1/sha1.h | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'libs/sha1/sha1.h') diff --git a/libs/sha1/sha1.h b/libs/sha1/sha1.h index 15edee12e..898575d6c 100644 --- a/libs/sha1/sha1.h +++ b/libs/sha1/sha1.h @@ -1,27 +1,29 @@ /* sha1.h - header of - + ============ SHA-1 in C++ ============ - + 100% Public Domain. - + Original C Code -- Steve Reid Small changes to fit into bglibs -- Bruce Guenter Translation to simpler C++ Code -- Volker Grabsch + Fixing bugs and improving style + -- Eugene Hopkinson */ - + #ifndef SHA1_HPP #define SHA1_HPP - - + + #include #include - + class SHA1 { public: @@ -30,28 +32,28 @@ public: void update(std::istream &is); std::string final(); static std::string from_file(const std::string &filename); - + private: typedef unsigned long int uint32; /* just needs to be at least 32bit */ typedef unsigned long long uint64; /* just needs to be at least 64bit */ - + static const unsigned int DIGEST_INTS = 5; /* number of 32bit integers per SHA1 digest */ static const unsigned int BLOCK_INTS = 16; /* number of 32bit integers per SHA1 block */ static const unsigned int BLOCK_BYTES = BLOCK_INTS * 4; - + uint32 digest[DIGEST_INTS]; std::string buffer; uint64 transforms; - + void reset(); void transform(uint32 block[BLOCK_BYTES]); - - static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_BYTES]); - static void read(std::istream &is, std::string &s, int max); + + static void read(std::istream &is, std::string &s, size_t max); + static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_INTS]); }; - + std::string sha1(const std::string &string); - - - + + + #endif /* SHA1_HPP */ -- cgit v1.2.3 From 4aae465867cd1221e47eaaa7550f1eb9aa2f5863 Mon Sep 17 00:00:00 2001 From: SlowRiot Date: Thu, 20 Nov 2014 02:03:08 +0000 Subject: switching from unreliable typedefs to precisely sized uint32_t and uint64_t --- libs/sha1/sha1.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'libs/sha1/sha1.h') diff --git a/libs/sha1/sha1.h b/libs/sha1/sha1.h index 898575d6c..f6a03e735 100644 --- a/libs/sha1/sha1.h +++ b/libs/sha1/sha1.h @@ -34,22 +34,19 @@ public: static std::string from_file(const std::string &filename); private: - typedef unsigned long int uint32; /* just needs to be at least 32bit */ - typedef unsigned long long uint64; /* just needs to be at least 64bit */ - static const unsigned int DIGEST_INTS = 5; /* number of 32bit integers per SHA1 digest */ static const unsigned int BLOCK_INTS = 16; /* number of 32bit integers per SHA1 block */ static const unsigned int BLOCK_BYTES = BLOCK_INTS * 4; - uint32 digest[DIGEST_INTS]; + uint32_t digest[DIGEST_INTS]; std::string buffer; - uint64 transforms; + uint64_t transforms; void reset(); - void transform(uint32 block[BLOCK_BYTES]); + void transform(uint32_t block[BLOCK_BYTES]); static void read(std::istream &is, std::string &s, size_t max); - static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_INTS]); + static void buffer_to_block(const std::string &buffer, uint32_t block[BLOCK_INTS]); }; std::string sha1(const std::string &string); -- cgit v1.2.3