From 576c2f6cb4f1eb2cc808c6b039d861863baff2bb Mon Sep 17 00:00:00 2001 From: Quim Muntal Date: Tue, 10 Oct 2023 09:23:34 +0200 Subject: [PATCH] Update cng/hkdf.go Co-authored-by: Davis Goodin --- cng/hkdf.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cng/hkdf.go b/cng/hkdf.go index 3989139..6f164ce 100644 --- a/cng/hkdf.go +++ b/cng/hkdf.go @@ -83,11 +83,8 @@ func (c *hkdf) Read(p []byte) (int, error) { // It is common to derive multiple equally sized keys from the same HKDF instance. // Optimize this case by allocating a buffer large enough to hold // at least 3 of such keys each time there is not enough data. - blocks := bytesNeeded / c.hashLen - if bytesNeeded%c.hashLen != 0 { - // Round up to the next multiple of hashLen. - blocks += 1 - } + // Round up to the next multiple of hashLen. + blocks := (bytesNeeded-1)/c.hashLen + 1 const minBlocks = 3 if blocks < minBlocks { blocks = minBlocks