Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit e27ad91

Browse files
sosthene-nitrokeyrobin-nitrokey
authored andcommitted
Add HPKE extension
This will be useful for PIV encryption, working together with trussed-dev/trussed-auth#41 This implements the standard HPKE from [RFC 9180](https://www.rfc-editor.org/rfc/rfc9180.html). This uses a custom implmentation instead of the `hpke` crate because this crate seals the trait to implement custom ciphers, and we want to use `ChaCha8` and not `ChaCha20`. The implementation is tested against the RFC test vectors for `ChaCha20`, and is made generic so that the same code can be used for `ChaCha8` in the backend. For ChaCha8Poly1305 AEAD ID, I used a custom `0xFFFE`, which is probably unused. I need to look if there is somewhere someone already using ChaCha8Poly1305 for HPKE and if there is a specified ID.
1 parent 72b0820 commit e27ad91

File tree

7 files changed

+1253
-4
lines changed

7 files changed

+1253
-4
lines changed

Cargo.toml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
# SPDX-License-Identifier: CC0-1.0
33

44
[workspace]
5-
members = ["extensions/chunked", "extensions/fs-info", "extensions/hkdf", "extensions/manage", "extensions/wrap-key-to-file"]
5+
members = [
6+
"extensions/chunked",
7+
"extensions/fs-info",
8+
"extensions/hkdf",
9+
"extensions/hpke",
10+
"extensions/manage",
11+
"extensions/wrap-key-to-file",
12+
]
613

714
[workspace.package]
815
authors = ["Nitrokey GmbH <info@nitrokey.com>"]
@@ -35,15 +42,20 @@ hkdf = { version = "0.12", optional = true }
3542
rand_core = { version = "0.6.4", default-features = false }
3643
sha2 = { version = "0.10", default-features = false, optional = true }
3744
littlefs2 = "0.4.0"
45+
salty = { version = "0.3.0", default-features = false }
46+
digest = { version = "0.10.7", default-features = false }
47+
hex-literal = { version = "0.4.0", optional = true }
48+
aead = { version = "0.5.2", optional = true, default-features = false }
3849

3950
trussed-chunked = { version = "0.1.0", optional = true }
4051
trussed-hkdf = { version = "0.2.0", optional = true }
52+
trussed-hpke = { version = "0.1.0", optional = true }
4153
trussed-manage = { version = "0.1.0", optional = true }
4254
trussed-wrap-key-to-file = { version = "0.1.0", optional = true }
4355
trussed-fs-info = { version = "0.1.0", optional = true }
4456

4557
[dev-dependencies]
46-
hex-literal = "0.3.4"
58+
hex-literal = "0.4.0"
4759
hmac = "0.12.0"
4860
trussed = { workspace = true, features = ["virt"] }
4961

@@ -52,8 +64,9 @@ default = []
5264

5365
chunked = ["trussed-chunked", "chacha20poly1305/stream"]
5466
hkdf = ["trussed-hkdf", "dep:hkdf", "dep:sha2"]
67+
hpke = ["trussed-hpke", "dep:hkdf", "dep:sha2", "dep:hex-literal", "dep:aead", "dep:chacha20poly1305"]
5568
manage = ["trussed-manage"]
56-
wrap-key-to-file = ["chacha20poly1305", "trussed-wrap-key-to-file"]
69+
wrap-key-to-file = ["dep:chacha20poly1305", "trussed-wrap-key-to-file"]
5770
fs-info = ["trussed-fs-info"]
5871

5972
virt = ["std", "trussed/virt"]
@@ -68,11 +81,12 @@ log-warn = []
6881
log-error = []
6982

7083
[patch.crates-io]
71-
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "a055e4f79a10122c8c0c882161442e6e02f0c5c6" }
84+
trussed = { git = "https://github.com/nitrokey/trussed.git", rev = "540ad725ef44f0d6d3d2da7dd6ec0bacffaeb5bf" }
7285
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "960e57d9fc0d209308c8e15dc26252bbe1ff6ba8" }
7386

7487
trussed-chunked = { path = "extensions/chunked" }
7588
trussed-hkdf = { path = "extensions/hkdf" }
89+
trussed-hpke = { path = "extensions/hpke" }
7690
trussed-manage = { path = "extensions/manage" }
7791
trussed-wrap-key-to-file = { path = "extensions/wrap-key-to-file" }
7892
trussed-fs-info= { path = "extensions/fs-info" }

extensions/hpke/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (C) Nitrokey GmbH
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
[package]
5+
name = "trussed-hpke"
6+
version = "0.1.0"
7+
authors.workspace = true
8+
edition.workspace = true
9+
repository.workspace = true
10+
license.workspace = true
11+
12+
[dependencies]
13+
serde.workspace = true
14+
trussed.workspace = true
15+
serde-byte-array = "0.1.2"

0 commit comments

Comments
 (0)