stbrumme / hash-library Goto Github PK
View Code? Open in Web Editor NEWPortable C++ hashing library
Home Page: https://create.stephan-brumme.com/hash-library/
License: zlib License
Portable C++ hashing library
Home Page: https://create.stephan-brumme.com/hash-library/
License: zlib License
There is a memory leak, please add delete[] buffer;
to line 64 (before return)
Lines 60 to 65 in f77b564
It seems OSX has no endian.h
, but it also looks like it is not needed.
Possible solution to make sha256.cpp
compile on OSX:
Replace
Lines 9 to 12 in a8a88f8
with
#if !defined(_MSC_VER) && !defined(__APPLE__)
#include <endian.h>
#endif
I have build it from source using command
g++ -O3 digest.cpp crc32.cpp md5.cpp sha1.cpp sha256.cpp keccak.cpp sha3.cpp -o digest
Calculate the keccak256 for string 5aaeb6053f3e94c9b9a09f33669435e7ef1beaed
Actual hash: Keccak/256: d2a614d1f92994cd6f3e75fd233d568867fcdc638ab04a4dac5a719d7792ee6d
Expected hash: Keccak/256: d385650ce8fdc6db7ee3a091d34814dbc4ce18219ffae52182efff4034d707e5
I can see proper value at "Keccak and SHA3 Live Test" but when I try to use digest it produces different value.
Hello, thanks for this library! I didnt see a getHash(unsigned char buffer[HashBytes]) function in SHA3, wasn't sure why. Can you please let me know? Thanks!
Keccak sha3(Keccak::Keccak256);
std::cout << sha3("") << std::endl;
expected: a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a
actual : c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
Let me know if I'm missing something.
Is there a way you could add the funcs in the SHA3 class, that would allow to use it with hmac ?
https://github.com/stbrumme/hash-library/blob/master/sha256.cpp#L293 is reporting a buffer overrun warning.
Suggested changed in bold.
// process full blocks
while (numBytes >= BlockSize)
{
processBlock(current);
current += BlockSize;
m_numBytes += BlockSize;
numBytes -= BlockSize;
}
// keep remaining bytes in buffer
//while (numBytes > 0)
while (numBytes > 0 && m_bufferSize < BlockSize)
{
m_buffer[m_bufferSize++] = *current++;
numBytes--;
}
}
This is not an issue per se, but I couldn't think of another way to approach this.
I was looking for a "small" (i.e. not libopenssl) hashing library in C, but didn't find anything. This library is perfect, but is, obviously, in C++.
So, I have ported the code back to C with as few changes as I could. I have not yet ported the tests, but running digest
against a set of random files yields the same checksums from both the original and C version which gives me some confidence that I didn't introduce any glaring bugs.
The code retains all copyright notices and statements that Stephan is the original author/owner.
I was considering posting this to github, and realize that the license allows for this but wanted to get your blessing before doing so. If you were interested in adding the repo to github.com/stbrumme, that would also be great.
Hexadecimal string 72a5f501151ca974002f34
returns the wrong hash value. Actually any string which starts with 72a5f501151ca974
returns a wrong hash. Maybe related to 64-bit data type?
Calling Keccak::getHash() repeatedly produces different hashes, SHA3 could be affected, too
int main(int argc, char *argv[]) {
Keccak k;
std::string temp("hello world");
k.add(&temp[0], temp.size());
std::cout << k.getHash() << std::endl;
std::cout << k.getHash() << std::endl;
std::cout << k.getHash() << std::endl;
return 0;
}
returns
47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad
c82cad59277af8d880d6ccbbddf0bbed8359fdfaa7491960e1f2397011bf5ae5
d165ecff4927241ce0fa7184b3ad53b4116f7fea6a8b2e1f509e75d087bcfead
Hi, can you add sha224?
The LICENSE file in the repository describes a Zlib license, but the license inside the actual source code is maximally restrictive. When the author reserves all rights, it means that nobody can use the code in any way, not for commercial use, not for personal. They can't modify it or redistribute.
Consider copy-pasting contents of LICENSE into all source files.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.