Skip to content

Migrate block mode crates#2

Merged
newpavlov merged 1 commit intomasterfrom
migrate
Feb 10, 2022
Merged

Migrate block mode crates#2
newpavlov merged 1 commit intomasterfrom
migrate

Conversation

@newpavlov
Copy link
Member

@newpavlov newpavlov commented Nov 9, 2021

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

Closes #5
Closes #6

TODO:

  • Add test vectors for IGE and PCBC
  • Impl IvState for CFB
  • Impl zeroizing Drop for CTR
  • Add examples to crate docs

@newpavlov newpavlov merged commit d4583ba into master Feb 10, 2022
@newpavlov newpavlov deleted the migrate branch February 10, 2022 12:14
@M1cha
Copy link

M1cha commented Feb 10, 2022

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

@newpavlov
Copy link
Member Author

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

@M1cha
Copy link

M1cha commented Feb 10, 2022

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
Copy link
Member Author

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
Copy link

where is Ecb<Aes128, Pkcs7>

@newpavlov
Copy link
Member Author

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

@liyongjing
Copy link

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
Copy link
Member Author

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.

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

Successfully merging this pull request may close these issues.

block-modes: add opaque Debug implementations Intermediate IV exposing for save/restore APIs

3 participants