Skip to content

Commit 734248d

Browse files
committed
Merge pull request #290 from rustyhorde/master
Fixes for change introduced by rust-lang/rust#23860
2 parents f952013 + 75fbe76 commit 734248d

25 files changed

+167
-146
lines changed

src/aes.rs

+1-1
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

+4
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

+5-5
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

+2
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

+3-3
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

+5-5
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

+1-1
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

+5-3
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

+12-12
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

+2
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 {

src/curve25519.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9].
1111
Bounds on each t[i] vary depending on context.
1212
*/
1313

14-
#[derive(Copy)]
14+
#[derive(Clone, Copy)]
1515
pub struct Fe(pub [i32; 10]);
1616

1717
impl PartialEq for Fe {
@@ -1062,37 +1062,37 @@ impl Fe {
10621062
}
10631063
}
10641064

1065-
#[derive(Copy)]
1065+
#[derive(Clone, Copy)]
10661066
pub struct GeP2 {
10671067
x: Fe,
10681068
y: Fe,
10691069
z: Fe,
10701070
}
10711071

1072-
#[derive(Copy)]
1072+
#[derive(Clone, Copy)]
10731073
pub struct GeP3 {
10741074
x: Fe,
10751075
y: Fe,
10761076
z: Fe,
10771077
t: Fe,
10781078
}
10791079

1080-
#[derive(Copy)]
1080+
#[derive(Clone, Copy)]
10811081
pub struct GeP1P1 {
10821082
x: Fe,
10831083
y: Fe,
10841084
z: Fe,
10851085
t: Fe,
10861086
}
10871087

1088-
#[derive(Copy)]
1088+
#[derive(Clone, Copy)]
10891089
pub struct GePrecomp {
10901090
y_plus_x: Fe,
10911091
y_minus_x: Fe,
10921092
xy2d: Fe,
10931093
}
10941094

1095-
#[derive(Copy)]
1095+
#[derive(Clone, Copy)]
10961096
pub struct GeCached {
10971097
y_plus_x: Fe,
10981098
y_minus_x: Fe,

src/fortuna.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* is designed to be timing-attack resistant. The speed hit from this
2121
* is in line with a "safety first" API, but be aware of it.
2222
*
23-
* Fortuna was originally described in
23+
* Fortuna was originally described in
2424
* Practical Cryptography, Niels Ferguson and Bruce Schneier.
2525
* John Wiley & Sons, 2003.
2626
*
@@ -147,7 +147,7 @@ impl FortunaGenerator {
147147

148148

149149
/// A single entropy pool (not public)
150-
#[derive(Copy)]
150+
#[derive(Clone, Copy)]
151151
struct Pool {
152152
state: Sha256,
153153
count: usize
@@ -194,7 +194,7 @@ impl Fortuna {
194194
}
195195
}
196196

197-
/// Adds a random event `e` from source `s` to entropy pool `i` (PC 9.5.6)
197+
/// Adds a random event `e` from source `s` to entropy pool `i` (PC 9.5.6)
198198
pub fn add_random_event(&mut self, s: u8, i: usize, e: &[u8]) {
199199
assert!(i <= NUM_POOLS);
200200
// These restrictions (and `s` in [0, 255]) are part of the Fortuna spec.
@@ -352,7 +352,7 @@ mod tests {
352352
50, 68, 236, 107, 133, 18, 217, 219, 46, 134,
353353
169, 156, 211, 74, 163, 17, 100, 173, 26, 70,
354354
246, 193, 57, 164, 167, 175, 233, 220, 160, 114,
355-
2, 200, 215, 80, 207, 218, 85, 58, 235, 117,
355+
2, 200, 215, 80, 207, 218, 85, 58, 235, 117,
356356
177, 223, 87, 192, 50, 251, 61, 65, 141, 100,
357357
59, 228, 23, 215, 58, 107, 248, 248, 103, 57,
358358
127, 31, 241, 91, 230, 33, 0, 164, 77, 46];
@@ -411,7 +411,7 @@ mod tests {
411411

412412
// from Crypto.Random.Fortuna import FortunaAccumulator
413413
// x = FortunaAccumulator.FortunaAccumulator()
414-
// x.add_random_event(0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
414+
// x.add_random_event(0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
415415
// x.add_random_event(0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
416416
// x.add_random_event(1, 0, "\1\2")
417417
// x.add_random_event(1, 1, "\1\2")
@@ -433,7 +433,7 @@ mod tests {
433433
f.add_random_event(0, 0, &[0; 32]);
434434
f.add_random_event(0, 0, &[0; 32]);
435435

436-
// x.add_random_event(0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
436+
// x.add_random_event(0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
437437
// x.add_random_event(0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
438438
// print list(bytearray(x.random_data(100)))
439439
let expected = [101, 123, 175, 157, 142, 202, 211, 47, 149, 214,
@@ -513,4 +513,3 @@ mod bench {
513513
bh.bytes = bytes.len() as u64;
514514
}
515515
}
516-

0 commit comments

Comments
 (0)