| | | 1 | | namespace ArturRios.Util.Hashing; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Configuration values for controlling Argon2id hashing cost parameters. |
| | | 5 | | /// </summary> |
| | | 6 | | /// <param name="degreeOfParallelism">Number of threads (lanes) to use; defaults to <see cref="DefaultDegreeOfParallelis |
| | | 7 | | /// <param name="numberOfIterations">Number of iterations; defaults to <see cref="DefaultNumberOfIterations"/>.</param> |
| | | 8 | | /// <param name="memoryToUseInKb">Memory size in kilobytes; defaults to <see cref="DefaultMemoryToUseInKb"/>.</param> |
| | 8 | 9 | | public class HashConfiguration( |
| | 8 | 10 | | int? degreeOfParallelism = null, |
| | 8 | 11 | | int? numberOfIterations = null, |
| | 8 | 12 | | int? memoryToUseInKb = null) |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Default parallelism (threads) used when unspecified. |
| | | 16 | | /// </summary> |
| | | 17 | | public const int DefaultDegreeOfParallelism = 16; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Default recommended minimum iteration count. |
| | | 21 | | /// </summary> |
| | | 22 | | public const int DefaultNumberOfIterations = 4; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Default memory cost (600 MB) expressed in kilobytes. |
| | | 26 | | /// </summary> |
| | | 27 | | public const int DefaultMemoryToUseInKb = 600000; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the configured degree of parallelism. |
| | | 31 | | /// </summary> |
| | 16 | 32 | | public int DegreeOfParallelism { get; } = degreeOfParallelism ?? DefaultDegreeOfParallelism; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the configured number of iterations. |
| | | 36 | | /// </summary> |
| | 16 | 37 | | public int NumberOfIterations { get; } = numberOfIterations ?? DefaultNumberOfIterations; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the configured memory usage in kilobytes. |
| | | 41 | | /// </summary> |
| | 16 | 42 | | public int MemoryToUseInKb { get; } = memoryToUseInKb ?? DefaultMemoryToUseInKb; |
| | | 43 | | } |