Giter Site home page Giter Site logo

hectorbst / libhash Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 6.0 19 KB

Small library coming from a personal student study on different SHA algorithms.

License: MIT License

C 94.21% Makefile 5.79%
hash hashing sha sha512 sha512sum sha256 sha256sum sha224 sha224sum sha384

libhash's People

Contributors

hectorbst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

libhash's Issues

Wrong padding when l > BLOCKSIZE - 1 - PADBLOCKLEN

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;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.