Repository: RustCrypto/password-hashes (language: rust)

Issue:
Argon2: Max params
* Max m_cost is (2^32)-1 "4 TiB" but it's defined as (2^28)-1 "256 GiB":
https://github.com/RustCrypto/password-hashes/blob/7ff9080a4ead680037acd43928f4815d0bb13f7c/argon2/src/params.rs#L15-L18 vs https://github.com/RustCrypto/password-hashes/blob/7ff9080a4ead680037acd43928f4815d0bb13f7c/argon2/src/params.rs#L49

* Max p_cost is (2^24)-1 but it's stated as 255:
https://github.com/RustCrypto/password-hashes/blob/7ff9080a4ead680037acd43928f4815d0bb13f7c/argon2/src/params.rs#L25-L28 vs https://github.com/RustCrypto/password-hashes/blob/7ff9080a4ead680037acd43928f4815d0bb13f7c/argon2/src/params.rs#L67


Discussion / hints:

Fix patch:
diff --git a/argon2/src/params.rs b/argon2/src/params.rs
index 9db5a3f5..81464d5d 100644
--- a/argon2/src/params.rs
+++ b/argon2/src/params.rs
@@ -22,9 +22,9 @@ pub struct Params {
     /// Value is an integer in decimal (1 to 10 digits).
     t_cost: u32,
 
-    /// Degree of parallelism, between 1 and 255.
+    /// Degree of parallelism, between 1 and (2^24)-1.
     ///
-    /// Value is an integer in decimal (1 to 3 digits).
+    /// Value is an integer in decimal (1 to 8 digits).
     p_cost: u32,
 
     /// Key identifier.
@@ -46,7 +46,7 @@ impl Params {
     pub const MIN_M_COST: u32 = 2 * SYNC_POINTS as u32; // 2 blocks per slice
 
     /// Maximum number of 1 KiB memory blocks.
-    pub const MAX_M_COST: u32 = 0x0FFFFFFF;
+    pub const MAX_M_COST: u32 = u32::MAX;
 
     /// Default number of iterations (i.e. "time").
     pub const DEFAULT_T_COST: u32 = 2;
@@ -433,9 +433,7 @@ impl ParamsBuilder {
             return Err(Error::MemoryTooLittle);
         }
 
-        if self.m_cost > Params::MAX_M_COST {
-            return Err(Error::MemoryTooMuch);
-        }
+        // Note: we don't need to check `MAX_M_COST`, since it's `u32::MAX`
 
         if self.m_cost < self.p_cost * 8 {
             return Err(Error::MemoryTooLittle);
@@ -520,10 +518,6 @@ mod tests {
             ParamsBuilder::new().m_cost(Params::MIN_M_COST - 1).build(),
             Err(Error::MemoryTooLittle)
         );
-        assert_eq!(
-            ParamsBuilder::new().m_cost(Params::MAX_M_COST + 1).build(),
-            Err(Error::MemoryTooMuch)
-        );
         assert_eq!(
             ParamsBuilder::new().t_cost(Params::MIN_T_COST - 1).build(),
             Err(Error::TimeTooSmall)


Test patch: