Skip to content

Commit 0262c5a

Browse files
authored
argon2: followups to #247 (#333)
- Bump version to `0.5.0-pre` (#247 contained breaking changes) - Use pointer casts to convert `Block` integer array to byte array - Rename `permutate!` to `permute!` (former isn't in OED, latter is)
1 parent e8f0194 commit 0262c5a

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

argon2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "argon2"
3-
version = "0.4.1"
3+
version = "0.5.0-pre"
44
description = """
55
Pure Rust implementation of the Argon2 password hashing function with support
66
for the Argon2d, Argon2i, and Argon2id algorithmic variants

argon2/src/block.rs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,36 @@ use zeroize::Zeroize;
1111

1212
const TRUNC: u64 = u32::MAX as u64;
1313

14-
macro_rules! permutate_step {
14+
#[rustfmt::skip]
15+
macro_rules! permute_step {
1516
($a:expr, $b:expr, $c:expr, $d:expr) => {
16-
$a =
17-
(Wrapping($a) + Wrapping($b) + (Wrapping(2) * Wrapping(($a & TRUNC) * ($b & TRUNC)))).0;
17+
$a = (Wrapping($a) + Wrapping($b) + (Wrapping(2) * Wrapping(($a & TRUNC) * ($b & TRUNC)))).0;
1818
$d = ($d ^ $a).rotate_right(32);
19-
$c =
20-
(Wrapping($c) + Wrapping($d) + (Wrapping(2) * Wrapping(($c & TRUNC) * ($d & TRUNC)))).0;
19+
$c = (Wrapping($c) + Wrapping($d) + (Wrapping(2) * Wrapping(($c & TRUNC) * ($d & TRUNC)))).0;
2120
$b = ($b ^ $c).rotate_right(24);
2221

23-
$a =
24-
(Wrapping($a) + Wrapping($b) + (Wrapping(2) * Wrapping(($a & TRUNC) * ($b & TRUNC)))).0;
22+
$a = (Wrapping($a) + Wrapping($b) + (Wrapping(2) * Wrapping(($a & TRUNC) * ($b & TRUNC)))).0;
2523
$d = ($d ^ $a).rotate_right(16);
26-
$c =
27-
(Wrapping($c) + Wrapping($d) + (Wrapping(2) * Wrapping(($c & TRUNC) * ($d & TRUNC)))).0;
24+
$c = (Wrapping($c) + Wrapping($d) + (Wrapping(2) * Wrapping(($c & TRUNC) * ($d & TRUNC)))).0;
2825
$b = ($b ^ $c).rotate_right(63);
2926
};
3027
}
3128

32-
macro_rules! permutate {
29+
macro_rules! permute {
3330
(
3431
$v0:expr, $v1:expr, $v2:expr, $v3:expr,
3532
$v4:expr, $v5:expr, $v6:expr, $v7:expr,
3633
$v8:expr, $v9:expr, $v10:expr, $v11:expr,
3734
$v12:expr, $v13:expr, $v14:expr, $v15:expr,
3835
) => {
39-
permutate_step!($v0, $v4, $v8, $v12);
40-
permutate_step!($v1, $v5, $v9, $v13);
41-
permutate_step!($v2, $v6, $v10, $v14);
42-
permutate_step!($v3, $v7, $v11, $v15);
43-
permutate_step!($v0, $v5, $v10, $v15);
44-
permutate_step!($v1, $v6, $v11, $v12);
45-
permutate_step!($v2, $v7, $v8, $v13);
46-
permutate_step!($v3, $v4, $v9, $v14);
36+
permute_step!($v0, $v4, $v8, $v12);
37+
permute_step!($v1, $v5, $v9, $v13);
38+
permute_step!($v2, $v6, $v10, $v14);
39+
permute_step!($v3, $v7, $v11, $v15);
40+
permute_step!($v0, $v5, $v10, $v15);
41+
permute_step!($v1, $v6, $v11, $v12);
42+
permute_step!($v2, $v7, $v8, $v13);
43+
permute_step!($v3, $v4, $v9, $v14);
4744
};
4845
}
4946

@@ -57,15 +54,11 @@ impl Block {
5754
pub const SIZE: usize = 1024;
5855

5956
pub(crate) fn as_bytes(&self) -> &[u8; Self::SIZE] {
60-
let ptr = self.0.as_ptr() as *const u8;
61-
let slice = unsafe { core::slice::from_raw_parts(ptr, Self::SIZE) };
62-
slice.try_into().unwrap()
57+
unsafe { &*(self.0.as_ptr() as *const [u8; Self::SIZE]) }
6358
}
6459

6560
pub(crate) fn as_mut_bytes(&mut self) -> &mut [u8; Self::SIZE] {
66-
let ptr = self.0.as_mut_ptr() as *mut u8;
67-
let slice = unsafe { core::slice::from_raw_parts_mut(ptr, Self::SIZE) };
68-
slice.try_into().unwrap()
61+
unsafe { &mut *(self.0.as_mut_ptr() as *mut [u8; Self::SIZE]) }
6962
}
7063

7164
pub(crate) fn compress(rhs: &Self, lhs: &Self) -> Self {
@@ -75,7 +68,7 @@ impl Block {
7568
let mut q = r;
7669
for chunk in q.0.chunks_exact_mut(16) {
7770
#[rustfmt::skip]
78-
permutate!(
71+
permute!(
7972
chunk[0], chunk[1], chunk[2], chunk[3],
8073
chunk[4], chunk[5], chunk[6], chunk[7],
8174
chunk[8], chunk[9], chunk[10], chunk[11],
@@ -88,7 +81,7 @@ impl Block {
8881
let b = i * 2;
8982

9083
#[rustfmt::skip]
91-
permutate!(
84+
permute!(
9285
q.0[b], q.0[b + 1],
9386
q.0[b + 16], q.0[b + 17],
9487
q.0[b + 32], q.0[b + 33],

argon2/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#![no_std]
2-
// TODO(tarcieri): safe parallel implementation
3-
// See: https://github.com/RustCrypto/password-hashes/issues/154
42
#![cfg_attr(docsrs, feature(doc_cfg))]
53
#![doc = include_str!("../README.md")]
64
#![doc(

0 commit comments

Comments
 (0)