Skip to content

Commit 3eca225

Browse files
Initial KBKDF implementation (#108)
Specification: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-108r1.pdf --------- Co-authored-by: Arthur Gautier <[email protected]>
1 parent 02c319c commit 3eca225

File tree

16 files changed

+166809
-11
lines changed

16 files changed

+166809
-11
lines changed

.github/workflows/kbkdf.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: kbkdf
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "kbkdf/**"
7+
- "Cargo.*"
8+
push:
9+
branches: master
10+
11+
defaults:
12+
run:
13+
working-directory: kbkdf
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.81.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 --target ${{ matrix.target }}
38+
39+
minimal-versions:
40+
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
41+
with:
42+
working-directory: ${{ github.workflow }}
43+
44+
test:
45+
runs-on: ubuntu-latest
46+
strategy:
47+
matrix:
48+
rust:
49+
- 1.81.0 # MSRV
50+
- stable
51+
steps:
52+
- uses: actions/checkout@v4
53+
- uses: RustCrypto/actions/cargo-cache@master
54+
- uses: dtolnay/rust-toolchain@master
55+
with:
56+
toolchain: ${{ matrix.rust }}
57+
- run: cargo check --all-features
58+
- run: cargo test --no-default-features
59+
- run: cargo test
60+
- run: cargo test --all-features

Cargo.lock

+81-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"hkdf",
66
"concat-kdf",
77
"ansi-x963-kdf",
8+
"kbkdf",
89
]
910

1011
[profile.dev]

kbkdf/Cargo.toml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "kbkdf"
3+
version = "0.1.0"
4+
edition = "2018"
5+
authors = ["RustCrypto Developers"]
6+
license = "MIT OR Apache-2.0"
7+
homepage = "https://github.com/RustCrypto/KDFs/"
8+
repository = "https://github.com/RustCrypto/KDFs/"
9+
description = "Key Derivation Using Pseudorandom Function (KBKDF)"
10+
keywords = ["crypto", "KBKDF", "KDF"]
11+
categories = ["cryptography", "no-std"]
12+
readme = "README.md"
13+
rust-version = "1.81"
14+
exclude = ["/tests/*"]
15+
16+
[dependencies]
17+
digest = { version = "0.11.0-pre.9", default-features = false, features = ["mac"] }
18+
19+
[dev-dependencies]
20+
hex-literal = "0.4"
21+
hex = "0.4"
22+
hmac = { version = "0.13.0-pre.4", default-features = false }
23+
sha2 = { version = "0.11.0-pre.2", default-features = false }
24+
sha1 = { version = "0.11.0-pre.2", default-features = false }
25+
cmac = "0.8.0-pre.2"
26+
aes = "0.9.0-pre.2"
27+
28+
[package.metadata.docs.rs]
29+
all-features = true
30+
rustdoc-args = ["--cfg", "docsrs"]

kbkdf/README.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# RustCrypto: KBKDF
2+
3+
[![crate][crate-image]][crate-link]
4+
[![Docs][docs-image]][docs-link]
5+
![Apache2/MIT licensed][license-image]
6+
![Rust Version][rustc-image]
7+
[![Project Chat][chat-image]][chat-link]
8+
[![Build Status][build-image]][build-link]
9+
10+
Pure Rust implementation of the Key Based Key Derivation Function (KBKDF).
11+
This function is described in section 4 of [NIST SP 800-108r1, Recommendation
12+
for Key Derivation Using Pseudorandom Functions](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-108r1.pdf).
13+
14+
# Usage
15+
16+
The most common way to use KBKDF is as follows: you generate a shared secret with other party
17+
(e.g. via Diffie-Hellman algorithm) and use key derivation function to derive a shared key.
18+
19+
```rust
20+
use hex_literal::hex;
21+
use hmac::Hmac;
22+
use kbkdf::{Counter, Kbkdf, Params};
23+
use sha2::Sha256;
24+
25+
type HmacSha256 = Hmac<Sha256>;
26+
let counter = Counter::<HmacSha256, HmacSha256>::default();
27+
let key = counter
28+
.derive(Params::builder(b"secret").with_label(b"label").build())
29+
.unwrap();
30+
assert_eq!(
31+
key,
32+
hex!(
33+
"ff6a1e505e0f2546eae8f1e11ab95ff6"
34+
"47b78bb2182a835c7c1f8054ae7cfea5"
35+
"8182da6b978c411fa840326ebbe07bfc"
36+
"aaef01c090bb6f8e9c1da9dedf40bc3e"
37+
)
38+
);
39+
```
40+
41+
## Minimum Supported Rust Version
42+
43+
Rust **1.81** or higher.
44+
45+
Minimum supported Rust version can be changed in the future, but it will be
46+
done with a minor version bump.
47+
48+
## SemVer Policy
49+
50+
- All on-by-default features of this library are covered by SemVer
51+
- MSRV is considered exempt from SemVer as noted above
52+
53+
## License
54+
55+
Licensed under either of:
56+
57+
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
58+
* [MIT license](http://opensource.org/licenses/MIT)
59+
60+
at your option.
61+
62+
### Contribution
63+
64+
Unless you explicitly state otherwise, any contribution intentionally submitted
65+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
66+
dual licensed as above, without any additional terms or conditions.
67+
68+
[crate-image]: https://img.shields.io/crates/v/kbkdf.svg
69+
[crate-link]: https://crates.io/crates/kbkdf
70+
[docs-image]: https://docs.rs/kbkdf/badge.svg
71+
[docs-link]: https://docs.rs/kbkdf/
72+
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
73+
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
74+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
75+
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260043-KDFs
76+
[build-image]: https://github.com/RustCrypto/KDFs/workflows/kbkdf/badge.svg?branch=master&event=push
77+
[build-link]: https://github.com/RustCrypto/KDFs/actions?query=workflow:kbkdf

0 commit comments

Comments
 (0)