cryptopals

Matasano's cryptopals challenges (cryptopals.com).
Log | Files | Refs | README | LICENSE

commit f3f35c242f9cad7a9550ce9ab21a4ae0f944733e
parent f603a013e7f2e75b58b5a6ff90c3c8e1bcec385e
Author: Jared Tobin <jared@jtobin.ca>
Date:   Thu, 31 Aug 2017 16:40:59 +1200

Typo.

Diffstat:
Msrc/s2c11.rs | 18++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/s2c11.rs b/src/s2c11.rs @@ -31,23 +31,21 @@ pub fn black_box_encrypter(message: &[u8]) -> Vec<u8> { let between = Range::new(5, 11); let prepend_size = between.ind_sample(&mut rng); let append_size = between.ind_sample(&mut rng); + let prepend = gen_bytes(prepend_size); + let append = gen_bytes(append_size); - let prepend = gen_bytes(prepend_size); - let append = gen_bytes(append_size); + let m_size = prepend_size + message.len() + append_size; + let c_size = m_size + BLOCK_SIZE - m_size % BLOCK_SIZE; - let message_size = prepend_size + message.len() + append_size; - let ciphertext_size = - message_size + BLOCK_SIZE - message_size % BLOCK_SIZE; - - let mut ciphertext = Vec::with_capacity(ciphertext_size); - - let key = gen_bytes(KEY_SIZE); + let mut ciphertext = Vec::with_capacity(c_size); ciphertext.extend_from_slice(&prepend); ciphertext.extend_from_slice(message); ciphertext.extend_from_slice(&append); - ciphertext = pkcs(&ciphertext, ciphertext_size); + ciphertext = pkcs(&ciphertext, c_size); + + let key = gen_bytes(KEY_SIZE); if rng.gen() { aes_128_ecb_crypt(Mode::Encrypt, &key, &ciphertext)