Skip to content

Commit de86d9c

Browse files
committed
Merge pull request #110 from GuillaumeGomez/master
Few fixes and updates
2 parents 2e8512a + e7b025a commit de86d9c

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "rust-crypto"
33
version = "0.1.0"
44
authors = []
55

6-
[[lib]]
6+
[lib]
77
name = "rust-crypto"
88
path = "src/rust-crypto/lib.rs"
99

src/rust-crypto/blockmodes.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,10 @@ mod test {
11431143
use std::rand;
11441144
use std::rand::Rng;
11451145

1146-
let mut rng1: rand::StdRng = rand::SeedableRng::from_seed(&[1, 2, 3, 4]);
1147-
let mut rng2: rand::StdRng = rand::SeedableRng::from_seed(&[1, 2, 3, 4]);
1148-
let mut rng3: rand::StdRng = rand::SeedableRng::from_seed(&[1, 2, 3, 4]);
1146+
let tmp : &[_] = &[1, 2, 3, 4];
1147+
let mut rng1: rand::StdRng = rand::SeedableRng::from_seed(tmp);
1148+
let mut rng2: rand::StdRng = rand::SeedableRng::from_seed(tmp);
1149+
let mut rng3: rand::StdRng = rand::SeedableRng::from_seed(tmp);
11491150
let max_size = cmp::max(test.get_plain().len(), test.get_cipher().len());
11501151

11511152
let r1 = || {

src/rust-crypto/util.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ pub fn supports_aesni() -> bool {
2525
asm!("")
2626
}
2727

28-
return (flags & 0x02000000) != 0;
28+
(flags & 0x02000000) != 0
2929
}
3030

3131
#[cfg(target_arch = "x86")]
3232
#[cfg(target_arch = "x86_64")]
3333
#[allow(dead_assignment)]
34+
#[allow(unused_variable)]
3435
unsafe fn fixed_time_eq_asm(mut lhsp: *const u8, mut rhsp: *const u8, mut count: uint) -> bool {
3536
let mut result: u8 = 0;
3637

@@ -53,7 +54,7 @@ unsafe fn fixed_time_eq_asm(mut lhsp: *const u8, mut rhsp: *const u8, mut count:
5354
: "volatile" // flags
5455
);
5556

56-
return result == 0;
57+
result == 0
5758
}
5859

5960
#[cfg(target_arch = "arm")]
@@ -81,25 +82,24 @@ unsafe fn fixed_time_eq_asm(mut lhsp: *const u8, mut rhsp: *const u8, mut count:
8182
: "volatile" // flags
8283
);
8384

84-
return result == 0;
85+
result == 0
8586
}
8687

8788
/// Compare two vectors using a fixed number of operations. If the two vectors are not of equal
8889
/// length, the function returns false immediately.
8990
pub fn fixed_time_eq(lhs: &[u8], rhs: &[u8]) -> bool {
9091
if lhs.len() != rhs.len() {
91-
return false;
92-
}
93-
if lhs.len() == 0 {
94-
return true;
95-
}
96-
97-
let count = lhs.len();
98-
99-
unsafe {
100-
let lhsp = lhs.unsafe_get(0);
101-
let rhsp = rhs.unsafe_get(0);
102-
return fixed_time_eq_asm(lhsp, rhsp, count);
92+
false
93+
} else if lhs.len() == 0 {
94+
true
95+
} else {
96+
let count = lhs.len();
97+
98+
unsafe {
99+
let lhsp = lhs.unsafe_get(0);
100+
let rhsp = rhs.unsafe_get(0);
101+
fixed_time_eq_asm(lhsp, rhsp, count)
102+
}
103103
}
104104
}
105105

0 commit comments

Comments
 (0)