fix(cipher/diffiehellman): use valid random private keys in key-exchange test#804
Open
rajpreetcodes wants to merge 1 commit into
Open
Conversation
…nge test The key-exchange test generated "random" private keys via rsa.GenerateKey(rand.Reader, 31) and read .D.Int64(). Go 1.24 added a minimum RSA key size of 1024 bits, so GenerateKey now returns "rsa: key too small" and a nil key. The test ignored that error and dereferenced the nil key, causing a nil-pointer panic on Go >= 1.24 (the version CI's "^1.18" spec resolves to). Generate the private keys directly with crypto/rand in the valid Diffie-Hellman range [1, primeNumber-1] instead. This removes the broken RSA dependency and also makes the test meaningful: the previous .D.Int64() could be negative, which drove modularExponentiation down a degenerate path so the assertion held even for invalid inputs.
Not up to standards ⛔
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
The Diffie-Hellman key-exchange test produced its "random" private keys by calling
rsa.GenerateKey(rand.Reader, 31)and reading.D.Int64().Go 1.24 introduced a minimum RSA key size of 1024 bits, so
rsa.GenerateKeywith a 31-bit size now returns the errorrsa: key too smalland anilkey. The test ignored that error (alicePrvKey, _ := ...) and then dereferenced the nil key (alicePrvKey.D.Int64()), producing a nil-pointer panic:Because the CI workflow uses
setup-gowithgo-version: '^1.18'(which resolves to the latest Go release), this breaks the build on Go ≥ 1.24.This change generates the private keys directly with
crypto/randin the valid Diffie-Hellman range[1, primeNumber-1], removing the RSA dependency. It also makes the test more meaningful: the old.D.Int64()value could be negative, which sentmodularExponentiationdown a degenerate path where the equality assertion held even for invalid inputs.Verification:
go test ./cipher/diffiehellman/passes (ran with-count=20, not flaky)go test ./...is greengo vet ./...cleangofmtcleanChecklist
Notes: Fixes a nil-pointer panic in the Diffie-Hellman key-exchange test on Go ≥ 1.24 (
rsa: key too small).