Skip to content
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

crypto/rand: Documentation for errors #54980

Closed
Deleplace opened this issue Sep 9, 2022 · 6 comments
Closed

crypto/rand: Documentation for errors #54980

Deleplace opened this issue Sep 9, 2022 · 6 comments
Labels
Documentation Issues describing a change to documentation. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@Deleplace
Copy link
Contributor

The 3 exported funcs Int, Prime, Read return an error, but the current documentation doesn't say why and when errors might occur. Also their is no guidance about how to deal with a non-nil error: would a caller-side retry policy make sense?

I suggest we write a short explanation about why errors are part of the API at all, what such errors would look like, and how to deal with them.

@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Sep 9, 2022
@mknyszek mknyszek added this to the Backlog milestone Sep 9, 2022
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 9, 2022
@mknyszek
Copy link
Contributor

mknyszek commented Sep 9, 2022

CC @golang/security

@Deleplace
Copy link
Contributor Author

Prime does mention that its errors comes from rand.Read.

It may be confusing to figure out if we're likely to have errors "because CSPRNGs inherently use system calls that may fail", or "because we're accepting any custom io.Reader in Int and Prime", or if "Reader cannot return errors, but we still want to stick to the io.Reader interface".

@ericlagergren
Copy link
Contributor

would a caller-side retry policy make sense?

In general, there is no safe non-nil error result from rand.Reader or rand.Read.

@bwesterb
Copy link

I would be in favour of having crypto/rand.[Reader.]Read never return an error, and completely fill the provided slice. (And have it panic if the underlying system call errors.)

@jfrech
Copy link

jfrech commented Apr 28, 2024

Cf. #66821

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/602497 mentions this issue: crypto/rand: crash program if Read would return an error

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 7, 2024
@dmitshur dmitshur modified the milestones: Backlog, Go1.24 Oct 7, 2024
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. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants