Private/Field/Get-SecretSharingFieldTable.ps1
|
function Get-SecretSharingFieldTable { <# .SYNOPSIS Returns the GF(256) exponent/logarithm lookup tables used by field arithmetic. .DESCRIPTION Builds, once per module session, the base-3 exponent and logarithm tables over GF(256) reduced by the Rijndael irreducible polynomial x^8 + x^4 + x^3 + x + 1 (0x11B) - the same field AES and SLIP-0039 use. 3 (i.e. x + 1) is used as the generator because it is a primitive element of this field, so it cycles through all 255 nonzero field elements before repeating. .OUTPUTS PSCustomObject with a 255-entry Exp [int[]] and a 256-entry Log [int[]]. #> [CmdletBinding()] [OutputType([PSCustomObject])] param() if ($script:SecretSharingFieldTable) { return $script:SecretSharingFieldTable } $exp = [int[]]::new(255) $log = [int[]]::new(256) [int]$value = 1 for ($i = 0; $i -lt 255; $i++) { $exp[$i] = $value $log[$value] = $i # multiply by the generator (3 = x + 1), then reduce mod the field polynomial $value = ($value -shl 1) -bxor $value if ($value -band 0x100) { $value = $value -bxor 0x11B } } $script:SecretSharingFieldTable = [PSCustomObject]@{ Exp = $exp Log = $log } return $script:SecretSharingFieldTable } |