Refactor: Generalize the SEC.1 decoder#5356
Open
reneme wants to merge 3 commits intorandombit:masterfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors SEC1-encoded point parsing by extracting the decoding logic into a dedicated, testable sec1_decode() function. The new implementation separates format parsing from context-specific operations like point decompression and curve validation, making the code more maintainable and reusable.
Changes:
- Introduced
sec1_decode()function and associated SEC1 data structures (SEC1_Identity,SEC1_Compressed,SEC1_Full) - Added comprehensive test coverage for SEC1 point parsing with valid and invalid test cases
- Unified hybrid format handling across all call sites
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/pubkey/ec_group/ec_sec1.h | New header defining SEC1 decoding function and data structures |
| src/tests/test_ec_group.cpp | Added test class for SEC1 parsing validation |
| src/tests/data/pubkey/ecc_point_parsing.vec | Test vectors covering various SEC1 encoding scenarios |
| src/lib/pubkey/ec_group/legacy_ec_point/ec_point.cpp | Refactored OS2ECP functions to use sec1_decode |
| src/lib/pubkey/ec_group/ec_inner_data.cpp | Updated params_match to use sec1_decode |
| src/lib/pubkey/ec_group/ec_group.cpp | Refactored base point decoding in BER_decode_EC_group |
| src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h | Updated point deserialization to use sec1_decode |
| src/lib/math/pcurves/pcurves_generic/pcurves_generic.cpp | Refactored GenericAffinePoint deserialization |
| src/bogo_shim/bogo_shim.cpp | Removed obsolete error mapping for deprecated format error |
| src/lib/pubkey/ec_group/info.txt | Added ec_sec1.h to internal headers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0c555d9 to
3e205df
Compare
3e205df to
fc5a2e1
Compare
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.
As promised a few weeks ago. This decomposes SEC1-parsing from the context-specific interpretation of the values (point decompression, point-on-curve check, ...).
There's now an individually testable
sec1_decode()function that passes an instance ofSEC1_Identity,SEC1_Compressed, orSEC1_Fullto a user-provided handler function. Call sites can conveniently use theBotan::overloaded{}helper to implement this handler.This also centralizes the handling of the deprecated "hybrid" format. Before this was supported in some places but not everywhere. I would argue that keeping support for it might now not even be a real maintenance burden anymore.