Skip to content

Commit 4459f60

Browse files
authored
cipher: followups to #1482 (#1483)
The branch was never tested against the block ciphers repo located at https://github.com/rustcrypto/block-ciphers There were various errors and missed changes in macros which were required to get everything to compile. This includes fixes and has been tested against the downstream repo.
1 parent 7ae1519 commit 4459f60

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

cipher/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ macro_rules! impl_simple_block_encdec {
626626
type BlockSize = $block_size;
627627
}
628628

629-
impl<$($N$(:$b0$(+$b)*)?),*> $crate:BlockEncryptt for $cipher<$($N),*> {
629+
impl<$($N$(:$b0$(+$b)*)?),*> $crate::BlockCipherEncrypt for $cipher<$($N),*> {
630630
fn encrypt_with_backend(&self, f: impl $crate::BlockClosure<BlockSize = $block_size>) {
631631
struct EncBack<'a, $($N$(:$b0$(+$b)*)?),* >(&'a $cipher<$($N),*>);
632632

@@ -653,7 +653,7 @@ macro_rules! impl_simple_block_encdec {
653653
}
654654
}
655655

656-
impl<$($N$(:$b0$(+$b)*)?),*> $crate:BlockDecryptt for $cipher<$($N),*> {
656+
impl<$($N$(:$b0$(+$b)*)?),*> $crate::BlockCipherDecrypt for $cipher<$($N),*> {
657657
fn decrypt_with_backend(&self, f: impl $crate::BlockClosure<BlockSize = $block_size>) {
658658
struct DecBack<'a, $($N$(:$b0$(+$b)*)?),* >(&'a $cipher<$($N),*>);
659659

cipher/src/dev/block.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ macro_rules! block_cipher_test {
77
#[test]
88
fn $name() {
99
use cipher::{
10-
array::Array, blobby::Blob3Iterator, typenum::Unsigned, BlockDecryptMut,
11-
BlockEncryptMut, BlockSizeUser, KeyInit,
10+
array::Array, blobby::Blob3Iterator, typenum::Unsigned, BlockCipherDecrypt,
11+
BlockCipherEncrypt, BlockSizeUser, KeyInit,
1212
};
1313

1414
fn run_test(key: &[u8], pt: &[u8], ct: &[u8]) -> bool {
1515
let mut state = <$cipher as KeyInit>::new_from_slice(key).unwrap();
1616

1717
let mut block = Array::clone_from_slice(pt);
18-
state.encrypt_block_mut(&mut block);
18+
state.encrypt_block(&mut block);
1919
if ct != block.as_slice() {
2020
return false;
2121
}
2222

23-
state.decrypt_block_mut(&mut block);
23+
state.decrypt_block(&mut block);
2424
if pt != block.as_slice() {
2525
return false;
2626
}
@@ -43,19 +43,19 @@ macro_rules! block_cipher_test {
4343

4444
// check that `encrypt_blocks` and `encrypt_block`
4545
// result in the same ciphertext
46-
state.encrypt_blocks_mut(&mut blocks1);
46+
state.encrypt_blocks(&mut blocks1);
4747
for b in blocks2.iter_mut() {
48-
state.encrypt_block_mut(b);
48+
state.encrypt_block(b);
4949
}
5050
if blocks1 != blocks2 {
5151
return false;
5252
}
5353

5454
// check that `encrypt_blocks` and `encrypt_block`
5555
// result in the same plaintext
56-
state.decrypt_blocks_mut(&mut blocks1);
56+
state.decrypt_blocks(&mut blocks1);
5757
for b in blocks2.iter_mut() {
58-
state.decrypt_block_mut(b);
58+
state.decrypt_block(b);
5959
}
6060
if blocks1 != blocks2 {
6161
return false;
@@ -102,7 +102,7 @@ macro_rules! block_mode_enc_test {
102102
fn $name() {
103103
use cipher::{
104104
array::Array, blobby::Blob4Iterator, inout::InOutBuf, typenum::Unsigned,
105-
BlockEncryptMut, BlockSizeUser, KeyIvInit,
105+
BlockCipherEncrypt, BlockSizeUser, KeyIvInit,
106106
};
107107

108108
fn run_test(key: &[u8], iv: &[u8], pt: &[u8], ct: &[u8]) -> bool {
@@ -160,7 +160,7 @@ macro_rules! block_mode_dec_test {
160160
fn $name() {
161161
use cipher::{
162162
array::Array, blobby::Blob4Iterator, inout::InOutBuf, typenum::Unsigned,
163-
BlockDecryptMut, BlockSizeUser, KeyIvInit,
163+
BlockCipherDecrypt, BlockSizeUser, KeyIvInit,
164164
};
165165

166166
fn run_test(key: &[u8], iv: &[u8], pt: &[u8], ct: &[u8]) -> bool {
@@ -214,10 +214,10 @@ macro_rules! block_mode_dec_test {
214214
#[macro_export]
215215
macro_rules! iv_state_test {
216216
($name:ident, $cipher:ty, encrypt $(,)?) => {
217-
$crate::iv_state_test!($name, $cipher, encrypt_blocks_mut);
217+
$crate::iv_state_test!($name, $cipher, encrypt_blocks);
218218
};
219219
($name:ident, $cipher:ty, decrypt $(,)?) => {
220-
$crate::iv_state_test!($name, $cipher, decrypt_blocks_mut);
220+
$crate::iv_state_test!($name, $cipher, decrypt_blocks);
221221
};
222222
($name:ident, $cipher:ty, apply_ks $(,)?) => {
223223
$crate::iv_state_test!($name, $cipher, apply_keystream_blocks);
@@ -289,14 +289,14 @@ macro_rules! block_encryptor_bench {
289289
($init:block, $cipher:ty, $block_name:ident, $blocks_name:ident $(,)? ) => {
290290
#[bench]
291291
pub fn $block_name(bh: &mut test::Bencher) {
292-
use cipher::BlockEncryptMut;
292+
use cipher::BlockCipherEncrypt;
293293

294294
let mut cipher = $init;
295295
let mut blocks = vec![Default::default(); 1024];
296296

297297
bh.iter(|| {
298298
for block in blocks.iter_mut() {
299-
cipher.encrypt_block_mut(block);
299+
cipher.encrypt_block(block);
300300
}
301301
test::black_box(&blocks);
302302
});
@@ -305,13 +305,13 @@ macro_rules! block_encryptor_bench {
305305

306306
#[bench]
307307
pub fn $blocks_name(bh: &mut test::Bencher) {
308-
use cipher::BlockEncryptMut;
308+
use cipher::BlockCipherEncrypt;
309309

310310
let mut cipher = $init;
311311
let mut blocks = vec![Default::default(); 1024];
312312

313313
bh.iter(|| {
314-
cipher.encrypt_blocks_mut(&mut blocks);
314+
cipher.encrypt_blocks(&mut blocks);
315315
test::black_box(&blocks);
316316
});
317317
bh.bytes = (blocks.len() * blocks[0].len()) as u64;
@@ -350,14 +350,14 @@ macro_rules! block_decryptor_bench {
350350
($init:block, $cipher:ty, $block_name:ident, $blocks_name:ident $(,)? ) => {
351351
#[bench]
352352
pub fn $block_name(bh: &mut test::Bencher) {
353-
use cipher::BlockDecryptMut;
353+
use cipher::BlockCipherDecrypt;
354354

355355
let mut cipher = $init;
356356
let mut blocks = vec![Default::default(); 1024];
357357

358358
bh.iter(|| {
359359
for block in blocks.iter_mut() {
360-
cipher.decrypt_block_mut(block);
360+
cipher.decrypt_block(block);
361361
}
362362
test::black_box(&blocks);
363363
});
@@ -366,13 +366,13 @@ macro_rules! block_decryptor_bench {
366366

367367
#[bench]
368368
pub fn $blocks_name(bh: &mut test::Bencher) {
369-
use cipher::BlockDecryptMut;
369+
use cipher::BlockCipherDecrypt;
370370

371371
let mut cipher = $init;
372372
let mut blocks = vec![Default::default(); 1024];
373373

374374
bh.iter(|| {
375-
cipher.decrypt_blocks_mut(&mut blocks);
375+
cipher.decrypt_blocks(&mut blocks);
376376
test::black_box(&blocks);
377377
});
378378
bh.bytes = (blocks.len() * blocks[0].len()) as u64;

0 commit comments

Comments
 (0)