RustCrypto / RustCrypto/traits

add trait for length-preserving encryption

Open
#1,332 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cipher
Dominant language
Rust
Stars
755
Forks
256
Avg merge
1h 27m
Merged PRs (30d)
2

Description

Sort of similar to https://github.com/RustCrypto/traits/issues/177 and https://github.com/RustCrypto/block-ciphers/issues/48, but for tweakable SPRPs like HCTR2.

If accepted, I can provide an implementation of HCTR2.

Sample API, trait names are TBD:

pub trait Lpe {
    /// Encrypts `src` into `dst` using `tweak`
    ///
    /// In is an error if `dst` is not at least as long as `src` or if either are less
    /// than [`BLOCK_SIZE`] bytes long.
    fn seal(&self, dst: &mut [u8], src: &[u8], tweak: &[u8]) -> Result<(), Error> {
        if dst.len() < src.len() { ... }
        dst[..src.len()].copy_from_slice(src);
        match self.seal_in_place(dst, tweak) {
            Ok(()) => Ok(()),
            Err(err) => {
                    // This isn't strictly necessary, but there isn't any
                    // harm in doing it.
                    dst[..src.len()].zeroize();
                    Err(err)
            }
        }
    }

    fn open(&self, dst: &mut [u8], src: &[u8], tweak: &[u8]) -> Result<(), Error> {
         // etc
    }

    fn seal_in_place(&self, data: &mut [u8], tweak: &[u8]) -> Result<(), Error>;
    fn open_in_place(&self, data: &mut [u8], tweak: &[u8]) -> Result<(), Error>;
}
pub trait LpeMut { ... }

Some thoughts:

  1. I don't like how the API returns a Result, but I'm not sure how else to express that there must be at least one block of plaintext without requiring Block, panicking, or a lot of typenum gymnastics.
  2. I don't know if all LPE algorithms require the length of the plaintext to be at least one block, but I assume most do.
  3. seal and open aren't strictly necessary, but encrypting from src to dst is very common and it would be a shame if doing that always required copying the entire input.

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start by comparing the linked RustCrypto traits and block-ciphers issues, then read the HCTR2 paper linked in the issue. Resolve whether the proposed Lpe and LpeMut APIs, error handling, minimum length, and buffer-copying methods fit the project. Done means the trait design is accepted and its open questions have an agreed resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.