Private/Crypto/Invoke-SecretSharingCipherRoundFunction.ps1
|
function Invoke-SecretSharingCipherRoundFunction { <# .SYNOPSIS Computes one round's Feistel round function, F(i, R), for the master-secret cipher. .DESCRIPTION F = PBKDF2-HMAC-SHA256(password = [RoundIndex] + Passphrase, salt = SaltPrefix + R, iterations = (BaseIterationCount << IterationExponent) / RoundCount, dklen = R.Length). #> [CmdletBinding()] [OutputType([byte[]], [System.Object[]])] param( [Parameter(Mandatory)] [byte]$RoundIndex, [Parameter(Mandatory)] [AllowEmptyCollection()] [byte[]]$Passphrase, [Parameter(Mandatory)] [AllowEmptyCollection()] [byte[]]$SaltPrefix, [Parameter(Mandatory)] [byte[]]$R, [Parameter(Mandatory)] [ValidateRange(0, 15)] [int]$IterationExponent ) $constant = Get-SecretSharingCipherConstant $password = [byte[]](@($RoundIndex) + $Passphrase) $salt = [byte[]]($SaltPrefix + $R) $iterations = [int](($constant.BaseIterationCount -shl $IterationExponent) / $constant.RoundCount) $pbkdf2 = [System.Security.Cryptography.Rfc2898DeriveBytes]::new($password, $salt, $iterations, [System.Security.Cryptography.HashAlgorithmName]::SHA256) try { return , $pbkdf2.GetBytes($R.Length) } finally { $pbkdf2.Dispose() } } |