Skip to content

Commit 40b0048

Browse files
authored
argon2: check p_cost < Params::MIN_P_COST before m_cost < p_cost * 8 (#745)
`p_cost * 8` overflows for `p_cost` values larger than `u32::MAX / 8`, which can trigger panic with enabled overflow checks.
1 parent 2b86d70 commit 40b0048

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

argon2/src/params.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@ impl Params {
114114
return Err(Error::MemoryTooLittle);
115115
}
116116

117-
// Note: we don't need to check `MAX_M_COST`, since it's `u32::MAX`
118-
119-
if m_cost < p_cost * 8 {
120-
return Err(Error::MemoryTooLittle);
121-
}
122-
123-
if t_cost < Params::MIN_T_COST {
124-
return Err(Error::TimeTooSmall);
125-
}
126-
127117
// Note: we don't need to check `MAX_T_COST`, since it's `u32::MAX`
128118

129119
if p_cost < Params::MIN_P_COST {
@@ -134,6 +124,16 @@ impl Params {
134124
return Err(Error::ThreadsTooMany);
135125
}
136126

127+
// Note: we don't need to check `MAX_M_COST`, since it's `u32::MAX`
128+
129+
if m_cost < p_cost * 8 {
130+
return Err(Error::MemoryTooLittle);
131+
}
132+
133+
if t_cost < Params::MIN_T_COST {
134+
return Err(Error::TimeTooSmall);
135+
}
136+
137137
if let Some(len) = output_len {
138138
if len < Params::MIN_OUTPUT_LEN {
139139
return Err(Error::OutputTooShort);

0 commit comments

Comments
 (0)