Skip to content

Commit 7dd955a

Browse files
committed
Merge pull request #290 from rustyhorde/master
Fixes for change introduced by rust-lang/rust#23860
2 parents c6df44e + 0b37181 commit 7dd955a

25 files changed

+167
-146
lines changed

src/aes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use symmetriccipher::{Encryptor, Decryptor, SynchronousStreamCipher};
1414
use util;
1515

1616
/// AES key size
17-
#[derive(Copy)]
17+
#[derive(Clone, Copy)]
1818
pub enum KeySize {
1919
KeySize128,
2020
KeySize192,

src/aesni.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ pub struct AesNiEncryptor {
1414
round_keys: [u8; 240]
1515
}
1616

17+
impl Clone for AesNiEncryptor { fn clone(&self) -> AesNiEncryptor { *self } }
18+
1719
#[derive(Copy)]
1820
pub struct AesNiDecryptor {
1921
rounds: u8,
2022
round_keys: [u8; 240]
2123
}
2224

25+
impl Clone for AesNiDecryptor { fn clone(&self) -> AesNiDecryptor { *self } }
26+
2327
/// The number of rounds as well as a function to setup an appropriately sized key.
2428
type RoundSetupInfo = (u8, fn(&[u8], KeyType, &mut [u8]));
2529

src/aessafe.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ macro_rules! define_aes_struct(
139139
$name:ident,
140140
$rounds:expr
141141
) => (
142-
#[derive(Copy)]
142+
#[derive(Clone, Copy)]
143143
pub struct $name {
144144
sk: [Bs8State<u16>; ($rounds + 1)]
145145
}
@@ -227,7 +227,7 @@ macro_rules! define_aes_struct_x8(
227227
$name:ident,
228228
$rounds:expr
229229
) => (
230-
#[derive(Copy)]
230+
#[derive(Clone, Copy)]
231231
pub struct $name {
232232
sk: [Bs8State<u32x4>; ($rounds + 1)]
233233
}
@@ -453,7 +453,7 @@ fn decrypt_core<S: AesOps + Copy>(state: &S, sk: &[S]) -> S {
453453
tmp
454454
}
455455

456-
#[derive(Copy)]
456+
#[derive(Clone, Copy)]
457457
struct Bs8State<T>(T, T, T, T, T, T, T, T);
458458

459459
impl <T: Copy> Bs8State<T> {
@@ -634,7 +634,7 @@ impl <T: Not<Output = T> + Copy> Bs8State<T> {
634634
}
635635
}
636636

637-
#[derive(Copy)]
637+
#[derive(Clone, Copy)]
638638
struct Bs4State<T>(T, T, T, T);
639639

640640
impl <T: Copy> Bs4State<T> {
@@ -658,7 +658,7 @@ impl <T: BitXor<Output = T> + Copy> Bs4State<T> {
658658
}
659659
}
660660

661-
#[derive(Copy)]
661+
#[derive(Clone, Copy)]
662662
struct Bs2State<T>(T, T);
663663

664664
impl <T> Bs2State<T> {

src/blake2b.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub struct Blake2b {
5252
computed: bool, // whether the final digest has been computed
5353
}
5454

55+
impl Clone for Blake2b { fn clone(&self) -> Blake2b { *self } }
56+
5557
struct Blake2bParam {
5658
digest_length: u8,
5759
key_length: u8,

src/blockmodes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait PaddingProcessor {
4242

4343
/// The BlockEngine is implemented as a state machine with the following states. See comments in the
4444
/// BlockEngine code for more information on the states.
45-
#[derive(Copy)]
45+
#[derive(Clone, Copy)]
4646
enum BlockEngineState {
4747
FastMode,
4848
NeedInput,
@@ -417,7 +417,7 @@ impl <P: BlockProcessor, X: PaddingProcessor> BlockEngine<P, X> {
417417
}
418418

419419
/// No padding mode for ECB and CBC encryption
420-
#[derive(Copy)]
420+
#[derive(Clone, Copy)]
421421
pub struct NoPadding;
422422

423423
impl PaddingProcessor for NoPadding {
@@ -426,7 +426,7 @@ impl PaddingProcessor for NoPadding {
426426
}
427427

428428
/// PKCS padding mode for ECB and CBC encryption
429-
#[derive(Copy)]
429+
#[derive(Clone, Copy)]
430430
pub struct PkcsPadding;
431431

432432
// This class implements both encryption padding, where padding is added, and decryption padding,

src/blowfish.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use cryptoutil::{read_u32v_be, write_u32_be};
88
use symmetriccipher::{BlockEncryptor, BlockDecryptor};
99
use step_by::RangeExt;
1010

11-
#[derive(Copy)]
11+
#[derive(Clone,Copy)]
1212
pub struct Blowfish {
1313
s: [[u32; 256]; 4],
1414
p: [u32; 18]
@@ -240,7 +240,7 @@ impl Blowfish {
240240
}
241241
}
242242
}
243-
243+
244244
// Bcrypt key schedule.
245245
pub fn salted_expand_key(&mut self, salt: &[u8], key: &[u8]) {
246246
let mut key_pos = 0;
@@ -264,7 +264,7 @@ impl Blowfish {
264264
r = new_r;
265265
self.s[i][j] = l;
266266
self.s[i][j+1] = r;
267-
267+
268268
let (new_l, new_r) = self.encrypt(l ^ next_u32_wrap(salt, &mut salt_pos), r ^ next_u32_wrap(salt, &mut salt_pos));
269269
l = new_l;
270270
r = new_r;
@@ -533,7 +533,7 @@ mod test {
533533
assert!(test.ciphertext[..] == output[..]);
534534
}
535535
}
536-
536+
537537
#[test]
538538
fn decrypt_eay_test_vectors() {
539539
let tests = eay_test_vectors();
@@ -558,7 +558,7 @@ mod bench {
558558
let plaintext = [1u8; 8];
559559
let state = Blowfish::new(&key);
560560
let mut ciphertext = [0u8; 8];
561-
561+
562562
bh.iter(|| {
563563
state.encrypt_block(&plaintext, &mut ciphertext);
564564
});

src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::cmp;
88

99
use cryptoutil;
1010

11-
#[derive(Copy)]
11+
#[derive(Clone,Copy)]
1212
pub enum BufferResult {
1313
BufferUnderflow,
1414
BufferOverflow

src/chacha20.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use symmetriccipher::{Encryptor, Decryptor, SynchronousStreamCipher, SymmetricCi
1010
use cryptoutil::{read_u32_le, symm_enc_or_dec, write_u32_le, xor_keystream};
1111
use simd::u32x4;
1212

13-
#[derive(Copy)]
13+
#[derive(Clone,Copy)]
1414
struct ChaChaState {
1515
a: u32x4,
1616
b: u32x4,
@@ -25,6 +25,8 @@ pub struct ChaCha20 {
2525
offset : usize,
2626
}
2727

28+
impl Clone for ChaCha20 { fn clone(&self) -> ChaCha20 { *self } }
29+
2830
macro_rules! swizzle{
2931
($b: expr, $c: expr, $d: expr) => {{
3032
let u32x4(b10, b11, b12, b13) = $b;
@@ -69,7 +71,7 @@ macro_rules! round{
6971

7072
macro_rules! rotate {
7173
($a: expr, $b: expr, $c:expr) => {{
72-
let v = $a ^ $b;
74+
let v = $a ^ $b;
7375
let r = S32 - $c;
7476
let right = v >> r;
7577
$a = (v << $c) ^ right
@@ -112,7 +114,7 @@ impl ChaCha20 {
112114
}
113115

114116
fn expand(key: &[u8], nonce: &[u8]) -> ChaChaState {
115-
117+
116118
let constant = match key.len() {
117119
16 => b"expand 16-byte k",
118120
32 => b"expand 32-byte k",

src/chacha20poly1305.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use poly1305::Poly1305;
1212
use mac::Mac;
1313
use cryptoutil::{write_u64_le};
1414
use util::fixed_time_eq;
15-
#[derive(Copy)]
15+
#[derive(Clone, Copy)]
1616
pub struct ChaCha20Poly1305 {
1717
cipher : ChaCha20,
1818
mac: Poly1305,
@@ -99,7 +99,7 @@ mod test {
9999
aad: Vec<u8>,
100100
tag: Vec<u8>
101101
}
102-
102+
103103
#[test]
104104
fn test_chacha20_256_poly1305_boringssl_vectors_encrypt() {
105105

@@ -748,17 +748,17 @@ mod bench {
748748
bh.iter( || {
749749
let mut cipher = ChaCha20Poly1305::new(&[0; 32], &[0; 8], &aad);
750750
let mut decipher = ChaCha20Poly1305::new(&[0; 32], &[0; 8], &aad);
751-
751+
752752
let mut output = [0u8; 10];
753753
let mut tag = [0u8; 16];
754754
let mut output2 = [0u8; 10];
755755
cipher.encrypt(&input, &mut output, &mut tag);
756756
decipher.decrypt(&output, &mut output2, &tag);
757-
757+
758758
});
759759
bh.bytes = 10u64;
760760
}
761-
761+
762762

763763
#[bench]
764764
pub fn chacha20poly1305_1k(bh: & mut Bencher) {
@@ -767,16 +767,16 @@ mod bench {
767767
bh.iter( || {
768768
let mut cipher = ChaCha20Poly1305::new(&[0; 32], &[0; 8], &aad);
769769
let mut decipher = ChaCha20Poly1305::new(&[0; 32], &[0; 8], &aad);
770-
770+
771771
let mut output = [0u8; 1024];
772772
let mut tag = [0u8; 16];
773773
let mut output2 = [0u8; 1024];
774-
774+
775775
cipher.encrypt(&input, &mut output, &mut tag);
776776
decipher.decrypt(&output, &mut output2, &tag);
777777
});
778778
bh.bytes = 1024u64;
779-
779+
780780
}
781781

782782
#[bench]
@@ -786,16 +786,16 @@ mod bench {
786786
bh.iter( || {
787787
let mut cipher = ChaCha20Poly1305::new(&[0; 32], &[0; 8], &aad);
788788
let mut decipher = ChaCha20Poly1305::new(&[0; 32], &[0; 8], &aad);
789-
789+
790790
let mut output = [0u8; 65536];
791791
let mut tag = [0u8; 16];
792792
let mut output2 = [0u8; 65536];
793-
793+
794794
cipher.encrypt(&input, &mut output, &mut tag);
795795
decipher.decrypt(&output, &mut output2, &tag);
796796

797797
});
798798
bh.bytes = 65536u64;
799-
799+
800800
}
801-
}
801+
}

src/cryptoutil.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ pub struct FixedBuffer64 {
446446
buffer_idx: usize,
447447
}
448448

449+
impl Clone for FixedBuffer64 { fn clone(&self) -> FixedBuffer64 { *self } }
450+
449451
impl FixedBuffer64 {
450452
/// Create a new buffer
451453
pub fn new() -> FixedBuffer64 {

0 commit comments

Comments
 (0)