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

Migrate block mode crates #2

Merged
merged 1 commit into from Feb 10, 2022
Merged

Migrate block mode crates #2

merged 1 commit into from Feb 10, 2022

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

@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