Dustin-Ray / capyCRYPT

An experimental high-performance cryptosystem.
MIT License
12 stars 1 forks source link

fix: remove security parameter from calls to decrypt and verify #15

Closed Dustin-Ray closed 1 year ago

Dustin-Ray commented 1 year ago

decryption and signature verification both assume well-formed input, so no need to request d for these operations

Dustin-Ray commented 1 year ago

This:

msg.pw_encrypt(&pw, 512);
msg.pw_decrypt(&pw, 512);

Should look like this:

msg.pw_encrypt(&pw, 512);
msg.pw_decrypt(&pw);
Dustin-Ray commented 1 year ago

This issue links to https://github.com/drcapybara/capyCRYPT/issues/27

Decryption and signature verification should -> Err if Message.d is not a supported value or not set.

Dustin-Ray commented 1 year ago

This can be solved by simply adding a d parameter to the Message struct, and setting it in every function that accepts d as a parameter.

For Example, in pw_encrypt

fn pw_encrypt(&mut self, pw: &[u8], d: u64) {
    self.d = Some(d);
    ...
    ...
}

Then, in pw_decrypt:

fn pw_decrypt(&mut self, pw: &[u8]) {
    let mut z_pw = self.sym_nonce.clone().unwrap();
    z_pw.append(&mut pw.to_owned());
    let ke_ka = kmac_xof(&mut z_pw, &vec![], 1024, "S", &self.d);
    ...
    ...
}

The we can call like this:

msg.pw_encrypt(&pw, 512);
msg.pw_decrypt(&pw);

We might run into the borrow checker with this one. .clone() on d isnt a terrible solution since d isnt large but using immutable references to d should be preferred.