Giter Club home page Giter Club logo

rust-hmac-sha256's Introduction

rust-hmac-sha256

A small, self-contained SHA256, HMAC-SHA256, and HKDF-SHA256 implementation in Rust.

Optional features:

  • traits: enable support for the Digest trait from the digest crate.
  • opt_size: enable size optimizations. Based on benchmarks, the .text section size is reduced by 75%, at the cost of approximately 16% performance.

rust-hmac-sha256's People

Stargazers

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

Watchers

 avatar  avatar  avatar

rust-hmac-sha256's Issues

Need help to choose SHA256 implementation

I'm looking for SHA256 implementation for embedded and can't choose the proper one of several.

There are 4 no_std SHA256 implementations:

  1. Yours.
  2. DoumanAsh lhash - https://github.com/DoumanAsh/lhash/blob/master/src/sha256.rs
  3. DaGenix rust-crypto - https://github.com/DaGenix/rust-crypto/blob/master/src/sha2.rs
  4. RustCrypto hashes - https://github.com/RustCrypto/hashes/blob/master/sha2/src/sha256/soft.rs

Could you please tell what pros and cons does your implementation have compared to others?

HKDF::Extract and RFC 5869

Is HKDF::Extract mean to apply RFC 5869 with SHA-256 as the hash function? I am getting unexpected outputs using HKDF::extract.

From https://datatracker.ietf.org/doc/html/rfc5869 HKDF-Extract is defined as (with HASH=SHA-256)

HKDF-Extract(salt, IKM) -> PRK
where
PRK = HKDF-Extract(salt, IKM) = HMAC-Hash(salt, IKM) = HMAC-SHA-256(salt, IKM)

But this is not the result I get. Instead the code as defined does not even use it as a MAC, and instead:

pub fn extract(salt: impl AsRef<[u8]>, ikm: impl AsRef<[u8]>) -> [u8; 32] {
        let mut h = Hash::new();
        h.update(ikm);
        h.update(salt);
        h.finalize()
    }

I would expect it to be something like.

pub fn extract(salt: impl AsRef<[u8]>, ikm: impl AsRef<[u8]>) -> [u8; 32] {
       let mut hmac = HMAC::new(&salt);
       hmac .update(ikm);
       hmac.finalize()
    }

or even simpler:

pub fn extract(salt: impl AsRef<[u8]>, ikm: impl AsRef<[u8]>) -> [u8; 32] {
       HMAC::mac(ikm, salt)
    }

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.