Skip to content

crypto/cipher: ExampleNewGCM_encrypt should use NonceSize to generate nonce. #48372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
najeira opened this issue Sep 14, 2021 · 1 comment · May be fixed by #48373
Closed

crypto/cipher: ExampleNewGCM_encrypt should use NonceSize to generate nonce. #48372

najeira opened this issue Sep 14, 2021 · 1 comment · May be fixed by #48373
Labels
Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@najeira
Copy link
Contributor

najeira commented Sep 14, 2021

ExampleNewGCM_encrypt should use AEAD.NonceSize to generate nonce.

Current:

nonce := make([]byte, 12)

12 is hard-coded to make nonce buffer.

Better:

nonce := make([]byte, aesgcm.NonceSize())

Use AEAD.NonceSize. AEAD has NonceSize that returns the size of the nonce.

najeira added a commit to najeira/go that referenced this issue Sep 14, 2021
…he example

The existing example uses hard-coded constant to make nonce buffer.
Using AEAD.NonceSize makes it a more portable and appropriate example.

Fixes: golang#48372
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/349603 mentions this issue: crypto/cipher: use AEAD.NonceSize to make nonce in the example

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 15, 2021
@seankhliao seankhliao added the Documentation Issues describing a change to documentation. label Aug 20, 2022
@seankhliao seankhliao added this to the Unplanned milestone Aug 20, 2022
@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Apr 16, 2025
@dmitshur dmitshur modified the milestones: Unplanned, Go1.25 Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants