diff options
author | Clifford Wolf <clifford@clifford.at> | 2014-11-20 09:26:33 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2014-11-20 09:26:33 +0100 |
commit | 263f672a3fc89ebc7e8ddf64f51c0285db056559 (patch) | |
tree | 86f2df90d1b2e84a82a34acb6f636b61fc673925 /libs/sha1/sha1.h | |
parent | 87333f3ae236555ac1efb38b5e99b5f067900ddd (diff) | |
parent | 4aae465867cd1221e47eaaa7550f1eb9aa2f5863 (diff) | |
download | yosys-263f672a3fc89ebc7e8ddf64f51c0285db056559.tar.gz yosys-263f672a3fc89ebc7e8ddf64f51c0285db056559.tar.bz2 yosys-263f672a3fc89ebc7e8ddf64f51c0285db056559.zip |
Merge pull request #42 from slowriot/master
SHA1 library: fixing incorrect buffer size allocation, and unsafe integer size type
Diffstat (limited to 'libs/sha1/sha1.h')
-rw-r--r-- | libs/sha1/sha1.h | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/libs/sha1/sha1.h b/libs/sha1/sha1.h index 15edee12e..f6a03e735 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 <steve@edmweb.com> Small changes to fit into bglibs -- Bruce Guenter <bruce@untroubled.org> Translation to simpler C++ Code -- Volker Grabsch <vog@notjusthosting.com> + Fixing bugs and improving style + -- Eugene Hopkinson <slowriot at voxelstorm dot com> */ - + #ifndef SHA1_HPP #define SHA1_HPP - - + + #include <iostream> #include <string> - + class SHA1 { public: @@ -30,28 +32,25 @@ 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]; + + uint32_t digest[DIGEST_INTS]; std::string buffer; - uint64 transforms; - + uint64_t 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); + 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_t block[BLOCK_INTS]); }; - + std::string sha1(const std::string &string); - - - + + + #endif /* SHA1_HPP */ |