Skip to content

Commit

Permalink
Update cng/hkdf.go
Browse files Browse the repository at this point in the history
Co-authored-by: Davis Goodin <[email protected]>
  • Loading branch information
qmuntal and dagood authored Oct 10, 2023
1 parent bc373e0 commit 576c2f6
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions cng/hkdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 576c2f6

Please sign in to comment.