hectorbst / libhash Goto Github PK
View Code? Open in Web Editor NEWSmall library coming from a personal student study on different SHA algorithms.
License: MIT License
Small library coming from a personal student study on different SHA algorithms.
License: MIT License
Functions sha512_compute and sha256_compute generate wrong padding when message length is greater than pad block length. The bug is last param of memset
(length) which should be multiple of sizeof(word_t)
, i.e.: sizeof(word_t) * BLOCKSIZE - sizeof(word_t) * PADBLOCKSIZE
, since the result
var is of type word_t
and not 8-bit byte type. The sha512_compute function also has wrong condition for the case when an additional block should be generated. Should be datalength < BLOCK_SIZE - 16
due to SHA-512 padding block is 128 bit -> 16 bytes.
Test vector for SHA384:
msg = f419494c3c6d0727b3395a483a2167182a7252f4fd099c2d4b71b053f94bb8b3adf3b51e8460cfec084ce9415c95798fbae4975c208c544645b54c44d2b97f2ecfce5c805be61f5ba1d35dcc07afdd51a87baa990506668cf710e18be9b0ebf943f366fa29c69f7a6616de72a3353b66
md384 = aead8688c58c6ba4e9cadb4756b465dce0fb06f1cfaa478197f2ea89414e47e9572034adfed160703c79b82b3fd7ab78
Here's an example fix for sha512_compute
:
result[i++] = 0x80;
if (datalength > BLOCK_SIZE - 16) {
while (i < BLOCK_SIZE) {
result[i++] = 0;
}
sha512_compress(result, state);
memset(result, 0, sizeof(result));
}
else {
while (i < BLOCK_SIZE - 16) {
result[i++] = 0;
}
}
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.