Skip to content

Commit cdd2fb3

Browse files
committed
[WIP] kdf crate
Traits which provide an API for interacting with Key Derivation Functions. We have several of these located at https://github.com/rustcrypto/kdfs and password-based KDFs at https://github.com/RustCrypto/password-hashes but the APIs for using these are typically just free functions, whereas traits could provide a common API.
1 parent baf8d73 commit cdd2fb3

File tree

8 files changed

+167
-0
lines changed

8 files changed

+167
-0
lines changed

.github/workflows/kdf.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: kdf
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "kdf/**"
7+
- "Cargo.*"
8+
push:
9+
branches: master
10+
11+
defaults:
12+
run:
13+
working-directory: kdf
14+
15+
env:
16+
CARGO_INCREMENTAL: 0
17+
RUSTFLAGS: "-Dwarnings"
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
rust:
25+
- 1.85.0 # MSRV
26+
- stable
27+
target:
28+
- thumbv7em-none-eabi
29+
- wasm32-unknown-unknown
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: RustCrypto/actions/cargo-cache@master
33+
- uses: dtolnay/rust-toolchain@master
34+
with:
35+
toolchain: ${{ matrix.rust }}
36+
targets: ${{ matrix.target }}
37+
- run: cargo build --no-default-features --release --target ${{ matrix.target }}
38+
39+
test:
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
rust:
44+
- 1.85.0 # MSRV
45+
- stable
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: RustCrypto/actions/cargo-cache@master
49+
- uses: dtolnay/rust-toolchain@master
50+
with:
51+
toolchain: ${{ matrix.rust }}
52+
- run: cargo check --all-features
53+
- run: cargo test
54+
- run: cargo test --release

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"crypto-common",
99
"digest",
1010
"elliptic-curve",
11+
"kdf",
1112
"kem",
1213
"password-hash",
1314
"universal-hash",

kdf/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "kdf"
3+
version = "0.0.0"
4+
authors = ["RustCrypto Developers"]
5+
edition = "2024"
6+
rust-version = "1.85"
7+
documentation = "https://docs.rs/kdf"
8+
readme = "README.md"
9+
repository = "https://github.com/RustCrypto/traits"
10+
license = "Apache-2.0 OR MIT"
11+
keywords = ["crypto"]
12+
categories = ["cryptography", "no-std"]
13+
description = "Traits for Key Derivation Functions"

kdf/LICENSE-APACHE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2021 RustCrypto Developers
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

kdf/LICENSE-MIT

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2025 RustCrypto Developers
2+
3+
Permission is hereby granted, free of charge, to any
4+
person obtaining a copy of this software and associated
5+
documentation files (the "Software"), to deal in the
6+
Software without restriction, including without
7+
limitation the rights to use, copy, modify, merge,
8+
publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software
10+
is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice
14+
shall be included in all copies or substantial portions
15+
of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.

kdf/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# [RustCrypto]: Key Derivation Functions (KDFs)
2+
3+
[![crate][crate-image]][crate-link]
4+
[![Docs][docs-image]][docs-link]
5+
[![Build Status][build-image]][build-link]
6+
![Apache2/MIT licensed][license-image]
7+
![Rust Version][rustc-image]
8+
[![Project Chat][chat-image]][chat-link]
9+
10+
## License
11+
12+
Licensed under either of
13+
14+
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
15+
* [MIT license](http://opensource.org/licenses/MIT)
16+
17+
at your option.
18+
19+
### Contribution
20+
21+
Unless you explicitly state otherwise, any contribution intentionally submitted
22+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
23+
dual licensed as above, without any additional terms or conditions.
24+
25+
[//]: # (badges)
26+
27+
[crate-image]: https://img.shields.io/crates/v/kdf.svg
28+
[crate-link]: https://crates.io/crates/kdf
29+
[docs-image]: https://docs.rs/kdf/badge.svg
30+
[docs-link]: https://docs.rs/kdf/
31+
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
32+
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
33+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
34+
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/channel/260043-KDFs
35+
[build-image]: https://github.com/RustCrypto/traits/actions/workflows/kdf.yml/badge.svg?branch=master
36+
[build-link]: https://github.com/RustCrypto/traits/actions/workflows/kdf.yml?query=branch:master
37+
38+
[//]: # (links)
39+
40+
[RustCrypto]: https://github.com/RustCrypto
41+
[1]: https://en.wikipedia.org/wiki/Key_encapsulation

kdf/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![doc = include_str!("../README.md")]
2+
#![no_std]
3+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4+
#![doc(
5+
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
6+
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
7+
)]
8+
#![forbid(unsafe_code)]
9+
#![warn(missing_docs, unused_qualifications, missing_debug_implementations)]
10+
11+
/// Use the KDF to derive the given amount of output.
12+
pub trait Derive {
13+
/// Consumes the KDF instance and derives as much data as will fit in `out`,
14+
/// overwriting its contents.
15+
fn derive(self, out: &mut [u8]);
16+
}

0 commit comments

Comments
 (0)