Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

API Gap: KeyWrapper, KeyUwrapper

Open
#150 1 comment 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bcgit/bc-rust

All issues in bcgit/bc-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.