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

Add crypto GenerateEntropy() and GenerateHexNonce() #57

Merged
merged 7 commits into from
Feb 21, 2024

Conversation

KendallWeihe
Copy link
Contributor

Closes #51

crypto/entropy.go Outdated Show resolved Hide resolved
crypto/entropy_test.go Outdated Show resolved Hide resolved
crypto/entropy_test.go Outdated Show resolved Hide resolved
@mistermoe
Copy link
Contributor

mistermoe commented Feb 20, 2024

@KendallWeihe thoughts on doing the following for the argument passed to GenerateEntropy and also allowing it to be passed to GenerateNonce?

type EntropySize int

const (
    // Directly set the sizes according to NIST recommendations for entropy
    // defined here: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf
    Entropy112Bits EntropySize = 112 / 8 // 14 bytes
    Entropy128Bits             = 128 / 8 // 16 bytes
    Entropy192Bits             = 192 / 8 // 24 bytes
    Entropy256Bits             = 256 / 8 // 32 bytes
)

this way we can call either function like so:

crypto.GenerateEntropy(Entropy128Bits)
crypto.GenerateNonce(Entropy128Bits)

This provides consumers with easy access to recommended values. wish we could use iota for this but recommended sizes does not increment by a consistent amount that would easily map to iota's default behavior

could also leave off Bits e.g.

const (
    // Directly set the sizes according to NIST recommendations for entropy
    // defined here: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf
    Entropy112 EntropySize = 112 / 8 // 14 bytes
    Entropy128             = 128 / 8 // 16 bytes
    Entropy192             = 192 / 8 // 24 bytes
    Entropy256             = 256 / 8 // 32 bytes
)

@KendallWeihe
Copy link
Contributor Author

@mistermoe awesome idea! Done ✅ And also added additional test coverage for custom size, and nonce error case, as well as a doc comment for GenerateEntropy()

crypto/entropy_test.go Outdated Show resolved Hide resolved
Co-authored-by: Diane Huxley <[email protected]>
@KendallWeihe KendallWeihe merged commit 5902a6c into main Feb 21, 2024
3 checks passed
@KendallWeihe KendallWeihe deleted the kendallw/gen-nonce branch February 27, 2024 13:35
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.

Add nonce generation to crypto package
4 participants