RustCrypto / block-modes

Collection of generic block mode algorithms written in pure Rust
64 stars 13 forks source link

Migrate block mode crates #2

Closed newpavlov closed 2 years ago

newpavlov commented 3 years ago

Depends on RustCrypto/utils#566, RustCrypto/traits#727, and RustCrypto/block-ciphers#284.

Closes #5 Closes #6

TODO:

M1cha commented 2 years ago

why didn't this include ecb? It was deleted from block-ciphers but not imported into this crate.

newpavlov commented 2 years ago

ECB is implemented by block cipher types themselves, i.e. instead of Ecb<Aes128> you can use Aes128 directly.

M1cha commented 2 years ago

Thanks, but I currently use block_modes::Ecb<aes::Aes128, block_modes::block_padding::NoPadding> and I don't see any padding options in aes 0.8

newpavlov commented 2 years ago

With the new versions you now specify padding on encryption/decryption methods, not on a block mode type. For example, see cbc docs. For ECB instead of cbc::Encryptor<aes::Aes128> you would simply use aes::Aes128.

liyongjing commented 2 years ago

where is Ecb<Aes128, Pkcs7>

newpavlov commented 2 years ago

ECB is "implemented" by block ciphers directly, i.e. you can use methods like encrypt_padded on Aes128.

liyongjing commented 2 years ago

aes = "0.7.0" block-modes = "0.8.1" AES/ECB/PKCS5Padding impl on old-version

    use aes::Aes128;
    use block_modes::block_padding::Pkcs7;
    use block_modes::{BlockMode, Ecb};

    type Aes128Ecb = Ecb<Aes128, Pkcs7>;
    let cipher = Aes128Ecb::new_from_slices(&key, &key).unwrap();
    let mut buffer = [0u8; 32];
    let pos = plaintext.len();
    buffer[..pos].copy_from_slice(plaintext);
    let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
newpavlov commented 2 years ago

Use the linked methods directly on Aes128 (ee docs for BlockEncrypt and BlockDecrypt). You do not need Ecb with the new crate versions. Padding is passed as a type argument to the padding-based methods.