Giter Site home page Giter Site logo

nanpuyue / sha256 Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 3.0 16 KB

A Pure Rust Implementation of SHA-256 Algorithm

Home Page: https://blog.nanpuyue.com/2019/049.html

License: Apache License 2.0

Rust 100.00%
sha-256 cryptography hash algorithm rust

sha256's Introduction

sha256's People

Contributors

nanpuyue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sha256's Issues

Does not pass SHA256 Test Vector Known Answer Tests (KAT)

There are two bugs in the implementation that prevent the KAT from passing.
First, the main compression function is implemented incorrectly. Lines 77-84 update the primary state after each of the 64 rounds of the algorithm, however this is incorrect. The state is not to be updated until AFTER all 64 rounds - see NIST FIPS 180-4 6.2.2 steps 2 and 4. In step 2, a copy of the previous round state is put into temporary variables, then the copies of the state are updated in each round in step 3. In step 4, the new state is created from the old state and the copies of the state variables (a, b, c,...).

The second problem is in the length construction. Use of the update function creates problems as a full block is not create. The final method needs to handle the length construction to input a full block into the compression function. In some cases this requires a new block to be created because there are not 65 bits leftover in the buffer. The whole final function needs to be rewritten.

I have made both fixes in my private area and now pass the KAT tests. See the KAT tests here: https://www.di-mgt.com.au/sha_testvectors.html

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.