Skip to content

Commit ce25028

Browse files
committed
pbkdf2: Use checked_add() instead of implementing it by hand
1 parent b06ff02 commit ce25028

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/rust-crypto/pbkdf2.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111

1212
use std::io::IoResult;
13-
use std::num::Bounded;
1413
use std::rand::{OsRng, Rng};
1514
use std::slice::MutableCloneableVector;
1615

@@ -94,12 +93,9 @@ pub fn pbkdf2<M: Mac>(mac: &mut M, salt: &[u8], c: u32, output: &mut [u8]) {
9493
let mut idx: u32 = 0;
9594

9695
for chunk in output.mut_chunks(os) {
97-
if idx == Bounded::max_value() {
98-
fail!("PBKDF2 size limit exceeded.");
99-
} else {
100-
// The block index starts at 1. So, this is supposed to run on the first execution.
101-
idx += 1;
102-
}
96+
// The block index starts at 1. So, this is supposed to run on the first execution.
97+
idx = idx.checked_add(&1).expect("PBKDF2 size limit exceeded.");
98+
10399
if chunk.len() == os {
104100
calculate_block(mac, salt, c, idx, scratch.as_mut_slice(), chunk);
105101
} else {

0 commit comments

Comments
 (0)