Skip to content

Commit 2f4f74f

Browse files
committed
[WIP] pkcs5: encryption
Implements PKCS#5 encryption support, presently targeting only support for PBES2 with PBKDF2-SHA-256 and AES-CBC (with 128 or 256-bit key size) Note that these are presently the best options supported by PKCS#5 v2.1. Support for legacy algorithms like DES, 3DES, MD2, and SHA-1 is deliberately ommitted. We can revisit potentially adding these upon request if there is demand, however since these algorithms are insecure we don't support them in this initial implementation.
1 parent 2a2cdb7 commit 2f4f74f

File tree

13 files changed

+471
-36
lines changed

13 files changed

+471
-36
lines changed

.github/workflows/pkcs5.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
rust:
28-
- 1.47.0 # MSRV
28+
- 1.49.0 # MSRV
2929
- stable
3030
target:
3131
- thumbv7em-none-eabi
@@ -38,14 +38,15 @@ jobs:
3838
toolchain: ${{ matrix.rust }}
3939
target: ${{ matrix.target }}
4040
override: true
41-
- run: cargo build --release --target ${{ matrix.target }}
41+
- run: cargo build --target ${{ matrix.target }} --release
42+
- run: cargo build --target ${{ matrix.target }} --release --features pbes2
4243

4344
test:
4445
runs-on: ubuntu-latest
4546
strategy:
4647
matrix:
4748
rust:
48-
- 1.47.0 # MSRV
49+
- 1.49.0 # MSRV
4950
- stable
5051
steps:
5152
- uses: actions/checkout@v1
@@ -55,3 +56,4 @@ jobs:
5556
toolchain: ${{ matrix.rust }}
5657
override: true
5758
- run: cargo test --release
59+
- run: cargo test --release --all-features

.github/workflows/workspace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v1
1717
- uses: actions-rs/toolchain@v1
1818
with:
19-
toolchain: 1.46.0 # MSRV
19+
toolchain: 1.49.0 # Highest MSRV in repo
2020
components: clippy
2121
override: true
2222
profile: minimal

Cargo.lock

Lines changed: 131 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ members = [
1616
"pkcs8",
1717
"spki",
1818
]
19+
20+
[patch.crates-io]
21+
aes = { git = "https://github.com/RustCrypto/block-ciphers" }
22+
block-modes = { git = "https://github.com/RustCrypto/block-ciphers" }

base64ct/src/encoding.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ impl<T: Variant> Encoding for T {
231231

232232
fn encoded_len(bytes: &[u8]) -> usize {
233233
// TODO: replace with `unwrap_or` on stabilization
234+
#[allow(clippy::manual_unwrap_or)]
234235
match encoded_len_inner(bytes.len(), T::PADDED) {
235236
Some(v) => v,
236237
None => 0,

pkcs5/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@ readme = "README.md"
1717
der = { version = "0.2.7", features = ["oid"], path = "../der" }
1818
spki = { version = "0.2", path = "../spki" }
1919

20+
aes = { version = "=0.7.0-pre", optional = true }
21+
block-modes = { version = "=0.8.0-pre", optional = true, default-features = false }
22+
hmac = { version = "0.10", optional = true, default-features = false }
23+
pbkdf2 = { version = "0.7", optional = true, default-features = false }
24+
sha2 = { version = "0.9", optional = true, default-features = false }
25+
2026
[dev-dependencies]
2127
hex-literal = "0.3"
2228

29+
[features]
30+
pbes2 = ["aes", "block-modes", "hmac", "pbkdf2", "sha2"]
31+
2332
[package.metadata.docs.rs]
2433
all-features = true
2534
rustdoc-args = ["--cfg", "docsrs"]

pkcs5/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dual licensed as above, without any additional terms or conditions.
3434
[docs-image]: https://docs.rs/pkcs5/badge.svg
3535
[docs-link]: https://docs.rs/pkcs5/
3636
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
37-
[rustc-image]: https://img.shields.io/badge/rustc-1.47+-blue.svg
37+
[rustc-image]: https://img.shields.io/badge/rustc-1.49+-blue.svg
3838
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
3939
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260052-utils
4040
[build-image]: https://github.com/RustCrypto/utils/workflows/pkcs5/badge.svg?branch=master&event=push

0 commit comments

Comments
 (0)