Add Debug implementation for EcGroup{,Ref}#2548
Merged
botovq merged 1 commit intorust-openssl:masterfrom Dec 21, 2025
Merged
Conversation
botovq
reviewed
Dec 21, 2025
f019854 to
9b5551b
Compare
This allows deriving Debug on user-defined structs that contain
instances of EcGroup.
For standard groups, the debug output will look something like this:
EcGroup { curve_name: "secp521r1" }
For groups not based on a standard curve, the Debug impl will try to
extract and print the curve's components, such that:
let mut p = BigNum::new().unwrap();
let mut a = BigNum::new().unwrap();
let mut b = BigNum::new().unwrap();
let mut ctx = BigNumContext::new().unwrap();
EcGroup::from_curve_name(Nid::SECP224R1)
.unwrap()
.components_gfp(&mut p, &mut a, &mut b, &mut ctx)
.unwrap();
// reconstruct the group from its components
let group = EcGroup::from_components(p, a, b, &mut ctx).unwrap();
println!("{:#?}", group);
will print:
EcGroup {
p: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",
a: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE",
b: "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4",
}
If EcGroup::components_gfp() fails, or if any other error occurs, we'll
instead print only:
EcGroup
Calling EcGroup::components_gfp() on a curve over GF(2^m) unexpectedly
works, and there does not seem to be an explicit way to distinguish
custom curves over GF(2^m) from custom curves over GF(p), and so, custom
curves over GF(2^m) will be Debug'd by the same logic. (rust-openssl
does not allow constructing custom curves over GF(2^m), so we can't add
test cases for this.)
9b5551b to
925af89
Compare
botovq
approved these changes
Dec 21, 2025
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.
This allows deriving Debug on user-defined structs that contain
instances of EcGroup.
For standard groups, the debug output will look something like this:
For groups not based on a standard curve, the Debug impl will try to
extract and print the curve's components, such that:
will print:
If EcGroup::components_gfp() fails, or if any other error occurs, we'll
instead print only:
Calling EcGroup::components_gfp() on a curve over GF(2^m) unexpectedly
works, and there does not seem to be an explicit way to distinguish
custom curves over GF(2^m) from custom curves over GF(p), and so, custom
curves over GF(2^m) will be Debug'd by the same logic. (rust-openssl
does not allow constructing custom curves over GF(2^m), so we can't add
test cases for this.)