Skip to content

Comments

Fix BenchmarkChacha20Poly1305: arg nonceSize shadowed package var#143

Merged
qmuntal merged 1 commit intomainfrom
dev/dagood/fix-shadow-bench
Feb 21, 2026
Merged

Fix BenchmarkChacha20Poly1305: arg nonceSize shadowed package var#143
qmuntal merged 1 commit intomainfrom
dev/dagood/fix-shadow-bench

Conversation

@dagood
Copy link
Member

@dagood dagood commented Feb 19, 2026

The nonceSize arg shadows package const nonceSize = 12, causing the switch to always hit the first case. This raises a panic (rather than skipping) because the nonce is the wrong size.

const (
	nonceSize  = 12
	nonceSizeX = 24
)
...
func benchmarkChaCha20Poly1305Seal(b *testing.B, buf []byte, nonceSize int) {
...
	var nonce = make([]byte, nonceSize)
...
	switch len(nonce) {
	case nonceSize:
		aead, _ = cng.NewChaCha20Poly1305(key[:])
	case nonceSizeX:
		b.Skip("SizeX not supported")
	}

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical variable shadowing bug in two ChaCha20-Poly1305 benchmark functions where the parameter name nonceSize shadowed the package-level constant nonceSize = 12. This caused the switch statement logic to always match the first case, leading to panics when benchmarks were run with nonce size 24 (the X variant) because the wrong AEAD constructor was used.

Changes:

  • Renamed the nonceSize parameter to testNonceSize in benchmarkChaCha20Poly1305Seal and benchmarkChaCha20Poly1305Open functions
  • Updated all usages of the parameter within these functions to use the new name

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dagood dagood requested a review from a team February 20, 2026 23:29
Copy link
Member

@qmuntal qmuntal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@qmuntal qmuntal merged commit 7f762f5 into main Feb 21, 2026
32 checks passed
@qmuntal qmuntal deleted the dev/dagood/fix-shadow-bench branch February 21, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants