Skip to content

Commit 6f70786

Browse files
authored
yescrypt: lint and code cleanups (#665)
1 parent e888cc4 commit 6f70786

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

yescrypt/src/common.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,26 @@
1-
#![allow(
2-
dead_code,
3-
mutable_transmutes,
4-
non_camel_case_types,
5-
non_snake_case,
6-
non_upper_case_globals,
7-
unused_assignments,
8-
unused_mut
9-
)]
10-
11-
pub(crate) unsafe fn blkcpy(mut dst: *mut u32, mut src: *const u32, mut count: usize) {
1+
pub(crate) unsafe fn blkcpy(dst: *mut u32, src: *const u32, count: usize) {
122
dst.copy_from(src, count);
133
}
144

15-
pub(crate) unsafe fn blkxor(mut dst: *mut u32, mut src: *const u32, mut count: usize) {
5+
pub(crate) unsafe fn blkxor(dst: *mut u32, src: *const u32, count: usize) {
166
for i in 0..count {
177
*dst.add(i) ^= *src.add(i);
188
}
199
}
2010

21-
pub(crate) unsafe fn integerify(mut B: *const u32, mut r: usize) -> u64 {
22-
let mut X: *const u32 = B.add(
11+
pub(crate) unsafe fn integerify(b: *const u32, r: usize) -> u64 {
12+
let x: *const u32 = b.add(
2313
(2usize)
2414
.wrapping_mul(r)
2515
.wrapping_sub(1usize)
2616
.wrapping_mul(16usize),
2717
);
28-
((*X.add(13) as u64) << 32).wrapping_add(*X as u64)
29-
}
30-
31-
unsafe fn memxor(mut dst: *mut u8, mut src: *mut u8, mut size: usize) {
32-
for i in 0..size {
33-
*dst.add(i) ^= *src.add(i);
34-
}
18+
((*x.add(13) as u64) << 32).wrapping_add(*x as u64)
3519
}
3620

3721
pub(crate) fn prev_power_of_two(mut x: u64) -> u64 {
38-
let mut y = 0;
22+
let mut y;
23+
3924
loop {
4025
y = x & x.wrapping_sub(1);
4126
if y == 0 {

yescrypt/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,18 @@
1010
//clippy::cast_possible_truncation,
1111
clippy::cast_possible_wrap,
1212
clippy::cast_precision_loss,
13-
//clippy::cast_sign_loss,
13+
clippy::cast_sign_loss,
1414
clippy::checked_conversions,
1515
clippy::implicit_saturating_sub,
1616
clippy::panic,
1717
clippy::panic_in_result_fn,
18-
//missing_docs,
18+
missing_docs,
1919
rust_2018_idioms,
2020
unused_lifetimes,
2121
unused_qualifications
2222
)]
2323
// Temporary lint overrides while C code is being translated
24-
#![allow(
25-
clippy::cast_possible_wrap,
26-
clippy::too_many_arguments,
27-
clippy::toplevel_ref_arg,
28-
clippy::unwrap_used,
29-
unsafe_op_in_unsafe_fn
30-
)]
24+
#![allow(clippy::too_many_arguments, unsafe_op_in_unsafe_fn)]
3125

3226
// Adapted from the yescrypt reference implementation available at:
3327
// <https://github.com/openwall/yescrypt>

yescrypt/src/params.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,44 @@ bitflags::bitflags! {
44
/// Flags for controlling the operation of `yescrypt`.
55
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
66
pub struct Flags: u32 {
7-
const WORM = 0x001;
8-
const RW = 0x002;
9-
const ROUNDS_3 = 0b000;
10-
const ROUNDS_6 = 0x004;
11-
const GATHER_4 = 0x010;
12-
const SIMPLE_2 = 0x020;
13-
const SBOX_12K = 0x080;
7+
/// Write once read many
8+
const WORM = 0x001;
9+
10+
/// Read/write
11+
const RW = 0x002;
12+
13+
/// 3 rounds
14+
const ROUNDS_3 = 0b000;
15+
16+
/// 6 rounds
17+
const ROUNDS_6 = 0x004;
18+
19+
/// Gather 4
20+
const GATHER_4 = 0x010;
21+
22+
/// Simple 2
23+
const SIMPLE_2 = 0x020;
24+
25+
/// SBox 12k
26+
const SBOX_12K = 0x080;
27+
28+
/// Use shared preallocated memory
1429
const SHARED_PREALLOCATED = 0x10000;
15-
const MODE_MASK = 0x3;
16-
const RW_FLAVOR_MASK = 0x3fc;
17-
const INIT_SHARED = 0x01000000;
18-
const ALLOC_ONLY = 0x08000000;
19-
const PREHASH = 0x10000000;
30+
31+
/// Mode mask value
32+
const MODE_MASK = 0x3;
33+
34+
/// Read/write flavor mask value
35+
const RW_FLAVOR_MASK = 0x3fc;
36+
37+
/// Initialize shared memory
38+
const INIT_SHARED = 0x01000000;
39+
40+
/// Allocate only
41+
const ALLOC_ONLY = 0x08000000;
42+
43+
/// Prehash
44+
const PREHASH = 0x10000000;
2045
}
2146
}
2247

0 commit comments

Comments
 (0)