API Gap: KeyWrapper, KeyUwrapper
@roy-basmacier is already working on this.
Since Sep 22, 2026.
Assessment
This issue has not been assessed yet.
Description
These are also on the OpenSSL list with the driving specifications being SP 800-38F "Recommendation for Block Cipher Modes of Operation: Methods for Key Wrapping" and RFC 5649.
Primarily the algorithms described are for AES and TDES, however Aria and Camellia (and I think SM4, not 100% sure....) support the same algorithms.
The algorithms require the full material being wrapped to be passed in.
Typing all this into Opus resulted in a suggestion looking like this:
pub trait KeyWrapper<const KEK_LEN: usize>: Algorithm {
/// Half the underlying block cipher's block size, in bytes -- "semiblock", Sec. 4.1.
/// 8 for KW and KWP (128-bit block); 4 for TKW (TDEA, 64-bit block).
const SEMIBLOCK_LEN: usize;
/// Wraps `key` under `kek`. `CT_LEN` is determined by `KEY_LEN` and checked at compile time.
///
/// # Errors
/// Rejects a KEK whose [`KeyType`] is not [`KeyType::SymmetricCipherKey`], and one whose
/// security strength is below that of the key being wrapped (Appendix A.2), both as
/// [`KeyWrapError::KeyMaterialError`].
fn wrap_key<const KEY_LEN: usize, const CT_LEN: usize>(
kek: &KeyMaterial<KEK_LEN>,
key: &KeyMaterial<KEY_LEN>,
) -> Result<[u8; CT_LEN], KeyWrapError>;
/// As [`wrap_key`](Self::wrap_key), writing into a caller-provided buffer. Returns the number
/// of bytes written, which is always `CT_LEN`.
fn wrap_key_out<const KEY_LEN: usize, const CT_LEN: usize>(
kek: &KeyMaterial<KEK_LEN>,
key: &KeyMaterial<KEY_LEN>,
ciphertext: &mut [u8; CT_LEN],
) -> Result<usize, KeyWrapError> {
*ciphertext = Self::wrap_key(kek, key)?;
Ok(CT_LEN)
}
}
With an equivalent trait for KeyUnwrapper. I note KeyWrapErrror is also new.
Also of note is that these algorithms (especially the KWP (padded) format), get used for things other than symmetric and private keys. So while the suggestion above shows KeyMaterial going in (mostly correct) input as [u8] might be better.
- Dominant language
- Rust
- Stars
- 25
- Forks
- 18
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bcgit/bc-rust
-
good first issue refactor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
documentation
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
n0-computer/iroh#4550 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
paritytech/zombienet-sdk#591 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
farion1231/cc-switch#7638 · 1 comment ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100