Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serpent with 32 bytes key #315

Closed
Antidote1911 opened this issue Apr 23, 2022 · 2 comments
Closed

Serpent with 32 bytes key #315

Antidote1911 opened this issue Apr 23, 2022 · 2 comments

Comments

@Antidote1911
Copy link

It's possible to use Serpent in CTR with a 32 bytes key ?
In this example decryption work with 16 bytes key but not 32.
(Same result if i try to encrypt with RustCrypto)

// does not ensure ciphertexts are authentic! Thus ciphertext integrity
// is not verified, which can lead to serious vulnerabilities!

use serpent::Serpent;
use serpent::cipher::{KeyIvInit, StreamCipher };
use serpent::cipher::generic_array::GenericArray;
use rand::{Rng, rngs::OsRng};

const KEYLEN:  usize = 32;
const NONCELEN:usize = 16;

type SerpentCtr = ctr::Ctr64BE<Serpent>;

fn main() {
    let plaintext=*b"super secret data to encrypt";
    let mut buf = plaintext.to_vec();

    let mut key_bytes = [0; KEYLEN];
    OsRng.fill(&mut key_bytes);

    let mut nonce_bytes = [0; NONCELEN];
    OsRng.fill(&mut nonce_bytes);

    let key = GenericArray::from_slice(&key_bytes);
    let iv = GenericArray::from_slice(&nonce_bytes);

    // encrypt with botan
    let engine = botan::Cipher::new("CTR-BE(Serpent)", botan::CipherDirection::Encrypt).unwrap();
    engine.set_key(&key).unwrap();
    engine.start(&iv).unwrap();
    let mut test = engine.finish(&mut buf).unwrap();

    // decrypt with rustcrypto
    let mut cipher = SerpentCtr::new(&key, &iv); // not work with 32 bytes key. left: `32`,right: `16`'
    cipher.apply_keystream(&mut test);

    assert_eq!(plaintext[..], test);
}

Thanks for RustCrypto, and for your work !

@tarcieri
Copy link
Member

tarcieri commented May 2, 2022

The current implementation only has support for 128-bit (16-byte) keys

@Antidote1911
Copy link
Author

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants