Collection of Key Derivation Functions written in pure Rust

Overview

RustCrypto: Key Derivation Functions

Project Chat dependency status Apache2/MIT licensed

Collection of Key Derivation Functions (KDF) written in pure Rust.

Supported Algorithms

Algorithm Crate Crates.io Documentation MSRV
HKDF hkdf crates.io Documentation MSRV 1.41

NOTE: for password-based KDFs (e.g. Argon2, PBKDF2, scrypt), please see RustCrypto/password-hashes

Minimum Supported Rust Version (MSRV) Policy

MSRV bumps are considered breaking changes and will be performed only with minor version bump.

License

All crates licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Comments
  • add 0.7.1 tag?

    add 0.7.1 tag?

    It looks like we got an 0.7.1 release on crates.io (yay!), but there's no tag on the git repo. The version was updated in 87659b14, but was the release made from that, or from a subsequent commit?

    We should compare the crates.io tarball against the last four commits, and add a hkdf-0.7.1 tag to the right one.

    opened by warner 5
  • hkdf v0.9.0-alpha.0

    hkdf v0.9.0-alpha.0

    We're trying to complete RustCrypto upgrades against some of our projects which use the new releases of things like digest and hmac and this is one of the crates we're blocked on (for crates we'd like to publish ASAP as it were, so we can't rely on a git dependency).

    I'm not sure what additional work you'd like to do before a final release (e.g. landing #34), but hopefully it's OK to cut an alpha release with the upgrades in the interim?

    opened by tarcieri 4
  • Implemented multipart features for HKDF-Extract and HKDF-Expand

    Implemented multipart features for HKDF-Extract and HKDF-Expand

    Background

    It is not uncommon to use concatenation in the ikm parameter of HKDF-Extract and info parameter of HKDF-Expand to achieve context binding. See for example, the use of the LabeledExtract and LabeledExpand functions in the HPKE specfication and HKDF-Expand-Label function in the MLS and TLS 1.3 specifications.

    Problem

    Some of these labeled methods take inputs of arbitrary length, which requires me to allocate on every call, given the current Hkdf API. Concretely, if I wanted to HKDF-Extract with ikm = "mycontextstr" || input where input is some user-inputted, arbitrary-length string, I would have to compute Hkdf::extract(None, &[b"mycontextstr", input].concat()), which is an allocation of unbounded size.

    Obviously, this is extremely undesirable if I want to make HPKE work on embedded devices. In fact, as of right now, this issue is the only thing preventing rust-hpke from being alloc-free.

    Solution

    Implement streaming support for HKDF-Extract and HKDF-Expand.

    For HKDF-Extract, we can do proper iterative streaming, since the underlying MAC supports this kind of streaming. This is implemented using the new HkdfExtract struct.

    Due to the structure of HKDF-Expand, streaming with iterators isn't possible. At the very least, one needs an iterator that can be cycled an arbitrary number of times. I chose to represent this as a simple slice over bytestrings, but you may want to generalize to an input that is Iterator<Item = &[u8]> + Clone. If you'd prefer this, let me know and I'll make the change.

    opened by rozbb 4
  • expand without extract

    expand without extract

    It would be nice if your API made it easier to perform the expand without the initial extract phase. This is what I do now:

        let hk = Hkdf::<Sha256>{
            prk: *GenericArray::from_slice(prk),
        };
    

    Possibly there should be a constructor that does this from_slice method call on the u8 slice.

    opened by david415 4
  • Support HKDF-Expand with different sized PRKs

    Support HKDF-Expand with different sized PRKs

    Add support for HKDF with PRK lengths >= Digest::OutputSize. This is allowed in RFC 5869 (see section 2.3 for Extend operation input requirements and section 3.3 WRT using PRKs that were not generated from the Extract step). Unfortunately the current API does not support this (since Hkdf.prk is a fixed sized array) so breaking changes were required.

    opened by nlordell 4
  • omitting HKDF salt is hard to get right

    omitting HKDF salt is hard to get right

    We've seen one (brief) bug in https://github.com/warner/magic-wormhole.rs in which our protocol requires calling HKDF without a salt, and the initial code used Hkdf::<Sha256>::extract(&[], key) to express this. But the HKDF definition (RFC 5869) says that when the salt is omitted, "it is set to a string of HashLen zeros". Passing an empty salt string is not the same as omitting the salt (i.e. passing 32 zero bytes), causing a protocol mismatch.

    To properly omit the salt, you must use something like extract(&[0; Sha256::OutputSize], key) or something that I'm not even sure would compile. Manually setting the salt size feels error-prone.

    The python HKDF library lets you pass None as the salt value, and it will do the right thing.

    Should we consider changing the extract() API to take an Option<&[u8]> for the salt value?

    Can Rust do some kind of polymorphic thing that might let us have two different extract() methods, with different type signatures (one with &[u8], the other with Option) to enable backwards compability?

    opened by warner 4
  • Reduce heap allocation, remove unnecessary mut, derive Clone

    Reduce heap allocation, remove unnecessary mut, derive Clone

    This improves usability and marginally improves performance:

    Before:

    test sha256_10 ... bench:       4,176 ns/iter (+/- 88) = 2 MB/s
    test sha256_1k ... bench:      68,458 ns/iter (+/- 2,005) = 14 MB/s
    test sha256_8k ... bench:     520,298 ns/iter (+/- 14,572) = 15 MB/s
    

    After:

    test sha256_10 ... bench:       4,113 ns/iter (+/- 535) = 2 MB/s
    test sha256_1k ... bench:      66,892 ns/iter (+/- 8,179) = 15 MB/s
    test sha256_8k ... bench:     506,935 ns/iter (+/- 57,681) = 15 MB/s
    
    opened by Ralith 4
  • update dependencies: digest-0.7, hmac-0.5

    update dependencies: digest-0.7, hmac-0.5

    This involves a few internal API changes. Applications or libraries which use hkdf will almost certainly need to depend on e.g. sha2-0.7 instead of sha2-0.6, so when this change is released, we should bump the hkdf version number (from the current 0.2.1 to something like 0.3.0).

    opened by warner 4
  • switch to RustCrypto traits, change API

    switch to RustCrypto traits, change API

    This moves away from rust-crypto to RustCrypto, which my rust+crypto friends tell me is the preferred approach these days. It modifies the HKDF API to instantiate the Hkdf object around a Digest trait, so instead of passing in "sha256" as a string, you use sha2::Sha256 and then create Hkdf::<Sha256:>>new(&ikm, &salt).

    It also adds test vectors for SHA1.

    Due to the API change, this should not be landed until #3 is done, and an old-API 0.1.1 has been released.

    opened by warner 4
  • hkdf: simplify trait bounds

    hkdf: simplify trait bounds

    Initially reported in Zulip.

    Right now if function uses HKDF and wants to be generic over hash functions, trait bounds look quite scary:

    fn hkdf<H: CoreProxy>()
    where
        <H as CoreProxy>::Core: HashMarker
            + UpdateCore
            + FixedOutputCore
            + BufferKindUser<BufferKind = Eager>
            + Default
            + Clone,
        <<H as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
        Le<<<H as CoreProxy>::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
    {
        Hkdf::<H>::new(None, &[]);
    }
    

    It could be worth to simplify the bounds somehow. Also it may be worth to allow hkdf to use the SimpleHmac in addition to Hmac. It probably will involve introducing a helper trait or two in hmac.

    opened by newpavlov 3
  • Bump `hmac` dependency to v0.10

    Bump `hmac` dependency to v0.10

    There shouldn't be any changes that actually impact hkdf.

    This version uses a newer crypto-mac release which has a new optional cipher feature that uses the new cipher crate.

    opened by tarcieri 3
Owner
Rust Crypto
Cryptographic algorithms written in pure Rust
Rust Crypto
Martinez is vNext Ethereum implementation written in pure Rust with Erigon architecture as design.

?? Martinez ?? Next-generation implementation of Ethereum protocol ("client") written in Rust, based on Erigon architecture. Why run Martinez? Look at

Arthur·Thomas 23 Jul 3, 2022
Parity-bridges-common - Collection of Useful Bridge Building Tools 🏗️

Parity Bridges Common This is a collection of components for building bridges. These components include Substrate pallets for syncing headers, passing

Parity Technologies 223 Jan 4, 2023
Cryptocurrencies trend-following trading bot sandbox written in Rust.

Trend trading bot Experiments repo about (crypto) trend trading. By "trend" I mean trading following the trend using technical indicators (vs other ki

Julien 6 Oct 2, 2022
Blockchain written with educational purpose

Blockchain written with educational purpose

Learn Together 18 Jan 1, 2023
A Rust library for working with Bitcoin SV

Rust-SV A library to build Bitcoin SV applications in Rust. Documentation Features P2P protocol messages (construction and serialization) Address enco

Brenton Gunning 51 Oct 13, 2022
Coinbase pro client for Rust

Coinbase pro client for Rust Supports SYNC/ASYNC/Websocket-feed data support Features private and public API sync and async support websocket-feed sup

null 126 Dec 30, 2022
Custom Ethereum vanity address generator made in Rust

ethaddrgen Custom Ethereum address generator Get a shiny ethereum address and stand out from the crowd! Disclaimer: Do not use the private key shown i

Jakub Hlusička 153 Dec 27, 2022
The new, performant, and simplified version of Holochain on Rust (sometimes called Holochain RSM for Refactored State Model)

Holochain License: This repository contains the core Holochain libraries and binaries. This is the most recent and well maintained version of Holochai

Holochain 737 Dec 28, 2022
DEPRECATED. The Holochain framework implemented in rust with a redux style internal state-model.

Holochain-rust Travis: Circle CI: Codecov: License: This code is loosely based on the previous Golang prototype. Code Status: This Rust version is alp

Holochain 1k Jan 3, 2023
IBC modules and relayer - Formal specifications and Rust implementation

ibc-rs Rust implementation of the Inter-Blockchain Communication (IBC) protocol. This project comprises primarily four crates: The ibc crate defines t

Informal Systems 296 Jan 4, 2023
A Rust implementation of BIP-0039

bip39-rs A Rust implementation of BIP0039 Changes See the changelog file, or the Github releases for specific tags. Documentation Add bip39 to your Ca

Infincia LLC 49 Dec 9, 2022
Rust Ethereum 2.0 Client

Lighthouse: Ethereum 2.0 An open-source Ethereum 2.0 client, written in Rust and maintained by Sigma Prime. Documentation Overview Lighthouse is: Read

Sigma Prime 2.1k Jan 1, 2023
Official Rust implementation of the Nimiq protocol

Nimiq Core implementation in Rust (core-rs) Rust implementation of the Nimiq Blockchain Core Nimiq is a frictionless payment protocol for the web. Thi

Nimiq 72 Sep 23, 2022
Rust implementation of Zcash protocol

The Parity Zcash client. Gitter Blog: Parity teams up with Zcash Foundation for Parity Zcash client Installing from source Installing the snap Running

Parity Technologies 183 Sep 8, 2022
rust client libraries to deal with the current cardano mainnet (byron / cardano-sl)

Rust implementation of Cardano primitives, helpers, and related applications Cardano Rust is a modular toolbox of Cardano’s cryptographic primitives,

Input Output 275 Oct 9, 2022
Tendermint in Rust!

tendermint.rs Tendermint in Rust with TLA+ specifications. Tendermint is a high-performance blockchain consensus engine for Byzantine fault tolerant a

Informal Systems 439 Jan 1, 2023
A Rust library for generating cryptocurrency wallets

Table of Contents 1. Overview 2. Build Guide 2.1 Install Rust 2.2a Build from Homebrew 2.2b Build from Crates.io 2.2c Build from Source Code 3. Usage

Aleo 554 Dec 31, 2022
Rust port of the Terry Davis' (RIP) "god says" program

RIP Terry A. Davis 1969-2018 god says Rust port of the programmer Terry Davis' "god says" (AKA GodSpeaks) program. Terrence Andrew Davis (December 15,

Orhun Parmaksız 54 Dec 26, 2022
Implementation of the Kademlia DHT protocol in Rust

kademlia-dht Simple implementation of the Kademlia DHT protocol in Rust with state dumping features for educational purposes (not production-ready). T

Leonardo Folgoni 18 Sep 24, 2022