Skip to content

Commit b18eabc

Browse files
Perf: use SHA256.HashData for seeded key derivation (#50)
Replaces disposable SHA256 instance with the static SHA256.HashData API in the seeded keypair path. Reduces per-call allocations.
1 parent b5c4f0e commit b18eabc

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

src/functions/public/New-SodiumKeyPair.ps1

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@
9797
switch ($PSCmdlet.ParameterSetName) {
9898
'SeededKeyPair' {
9999
$seedBytes = [System.Text.Encoding]::UTF8.GetBytes($Seed)
100-
$sha256 = [System.Security.Cryptography.SHA256]::Create()
101-
try {
102-
$derivedSeed = $sha256.ComputeHash($seedBytes)
103-
} finally {
104-
$sha256.Dispose()
105-
}
100+
$derivedSeed = [System.Security.Cryptography.SHA256]::HashData($seedBytes)
106101
$result = [PSModule.Sodium]::crypto_box_seed_keypair($publicKey, $privateKey, $derivedSeed)
107102
break
108103
}

0 commit comments

Comments
 (0)