Skip to content

Commit 62f2f9d

Browse files
authored
Proper implementation of processor count handling in argon2id
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent d829a0a commit 62f2f9d

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

HashifyNet/Algorithms/Argon2id/Argon2id_Implementation.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,10 @@ public Argon2id_Implementation(IArgon2idConfig config)
6969
throw new ArgumentOutOfRangeException($"{nameof(config)}.{nameof(config.Iterations)}", config.Iterations, "Iterations must be at least 1.");
7070
}
7171

72-
int maxProcessors;
73-
#if NET8_0_OR_GREATER
74-
if (OperatingSystem.IsBrowser())
75-
#else
76-
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Create("Browser")))
77-
#endif
78-
{
79-
// TODO: Review this.
80-
maxProcessors = int.MaxValue; // Just assume we can use as many as we want in WASM.
81-
}
82-
else
83-
{
84-
maxProcessors = Environment.ProcessorCount;
85-
}
86-
72+
int maxProcessors = Math.Max(1, Environment.ProcessorCount);
8773
if (_config.DegreeOfParallelism < 1 || _config.DegreeOfParallelism > maxProcessors)
8874
{
89-
throw new ArgumentOutOfRangeException($"{nameof(config)}.{nameof(config.DegreeOfParallelism)}", config.DegreeOfParallelism, $"Degree of parallelism must be at least 1 and smaller or equal to processor count '{Environment.ProcessorCount}'.");
75+
throw new ArgumentOutOfRangeException($"{nameof(config)}.{nameof(config.DegreeOfParallelism)}", config.DegreeOfParallelism, $"Degree of parallelism must be at least 1 and smaller or equal to processor count '{maxProcessors}'.");
9076
}
9177

9278
if (_config.MemorySize < 8 * _config.DegreeOfParallelism)

0 commit comments

Comments
 (0)