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-level random #839

Merged
merged 2 commits into from
Mar 4, 2022
Merged

Crypto-level random #839

merged 2 commits into from
Mar 4, 2022

Conversation

qinglin89
Copy link
Contributor

Description

math/rand is the fastest for applications that don’t need crypto-level or security-related random data generation. crypto.rand is suited for secure and crypto-ready usage, but it’s slower. In the admin cli, the random number has been used on the nonce generation.

Rationale

Replace math.rand with crypto.rand which generate random integer within 0~2147483647

Changes

Notable changes:

  • Change math.rand to crypto.rand

@qinglin89 qinglin89 changed the title Ar 220215 01 Crypto-level random Feb 28, 2022
@qinglin89 qinglin89 changed the base branch from develop to pre-opensource March 2, 2022 02:49
admin/client.go Outdated
rand.Seed(time.Now().UnixNano())
nonce := strconv.Itoa(rand.Int())
nTmp, _ := rand.Int(rand.Reader, big.NewInt(randMax))
nonce := nTmp.Bytes()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to handle the error? If there is an error, will nTmp be nil?
Can we change nTmp to a more meaningful name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Yes, it may fail due to a variety of reasons, will return error message to cli.
  • Sure

@forcodedancing forcodedancing merged commit 22e53d4 into pre-opensource Mar 4, 2022
@unclezoro unclezoro deleted the ar-220215-01 branch May 10, 2022 06:16
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