From eeefe4b5d0b8f55d1c7b09dc4fc811e132aed7ae Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Wed, 11 Dec 2024 03:08:02 +0900 Subject: [PATCH] scrypt: add `Params::n` method (#544) Currently, the `N` parameter can be obtained by raising 2 to the power of `Params::log_n`. ```rust // example of raising 2 to the power of `Params::log_n` let n = 1 << params.log_n(); ``` It's easier to read to use a method which gets the `N` parameter directly instead of this way. ```rust let n = params.n(); ``` --- scrypt/src/params.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scrypt/src/params.rs b/scrypt/src/params.rs index d957a017..449f758b 100644 --- a/scrypt/src/params.rs +++ b/scrypt/src/params.rs @@ -102,11 +102,20 @@ impl Params { /// logâ‚‚ of the Scrypt parameter `N`, the work factor. /// - /// Memory and CPU usage scale linearly with `N`. + /// Memory and CPU usage scale linearly with `N`. If you need `N`, use + /// [`Params::n`] instead. pub const fn log_n(&self) -> u8 { self.log_n } + /// `N` parameter: the work factor. + /// + /// This method returns 2 to the power of [`Params::log_n`]. Memory and CPU + /// usage scale linearly with `N`. + pub const fn n(&self) -> u64 { + 1 << self.log_n + } + /// `r` parameter: resource usage. /// /// scrypt iterates 2*r times. Memory and CPU time scale linearly