Skip to content

Commit

Permalink
scrypt: add Params::n method (#544)
Browse files Browse the repository at this point in the history
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();
```
  • Loading branch information
sorairolake authored Dec 10, 2024
1 parent dbc051a commit eeefe4b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scrypt/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eeefe4b

Please sign in to comment.