Skip to content

add parsing of ECC group from ECC parameters#5532

Merged
randombit merged 1 commit into
randombit:masterfrom
falko-strenzke:falko/ecc-key-group-from-param
Jul 18, 2026
Merged

add parsing of ECC group from ECC parameters#5532
randombit merged 1 commit into
randombit:masterfrom
falko-strenzke:falko/ecc-key-group-from-param

Conversation

@falko-strenzke

@falko-strenzke falko-strenzke commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Tasks:

  • integrate new test vectors into new test in the test_ecdh.cpp

@falko-strenzke falko-strenzke mentioned this pull request Apr 15, 2026
5 tasks
@randombit

Copy link
Copy Markdown
Owner

Change looks fine, needs some test cases though

Comment thread src/tests/test_pubkey.cpp Outdated
Comment thread src/tests/test_pubkey.cpp Outdated
Comment thread src/tests/test_pubkey.cpp Outdated
#include <botan/x509_key.h>
#include <botan/internal/fmt.h>
#include <botan/internal/stl_util.h>
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is not an appropriate file for this test - test_pubkey.cpp is test infrastructure for public key algorithms

For example it would be appropriate in this file to add PK_Private_Key_Decoding_Test base class and then deriving it somewhere for your actual test.

Considering the test is already hard coded to ECDH keys might as well be in test_ecdh.cpp I suppose.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Actually we already have exactly such a generic test - PK_Key_Decoding_Test which doesn't even need to be derived from it just reads from src/tests/data/pubkey/key_encoding.vec

The only issue is that right now this test only handles valid keys and not invalid. This should be easy to extend by adding a [Valid] header for the current test data plus [Invalid] which inverts the success/fail logic.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually we already have exactly such a generic test - PK_Key_Decoding_Test which doesn't even need to be derived from it just reads from src/tests/data/pubkey/key_encoding.vec

The existing test is different. It decodes a complete private key info structure, that is not working for the intended test. I will thus create a new one in the test_ecdh.cpp.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@randombit
I think I addressed all your review comments now. Could you check it again?

Comment thread src/tests/test_pubkey.cpp Outdated
Comment thread src/tests/test_pubkey.cpp Outdated
@falko-strenzke

Copy link
Copy Markdown
Collaborator Author

@randombit
I am further wondering about the way that

EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id,
                             std::span<const uint8_t> key_bits,
                             bool with_modular_inverse)

handles the alg_id: it never looks at the OID, only checks for the presence of parameters. A caller that calls the function with a specific algorithm identifier might expect the function to check that alg_id actually denotes a valid ECC key. Should we add a check for alg_id indicating either an ECDSA or an ECDH key?

I also think that to make the interface clearer, passing alg_id should be optional. Getting the group from the encoded key might be what the caller intends.

@randombit

Copy link
Copy Markdown
Owner

Should we add a check for alg_id indicating either an ECDSA or an ECDH key?

Not helpful since this is generic across algorithms this could also be SM2, ECKCDSA, GOST, ...

@falko-strenzke
falko-strenzke force-pushed the falko/ecc-key-group-from-param branch from a68b2fb to 9d15494 Compare May 26, 2026 14:28
@falko-strenzke
falko-strenzke requested a review from randombit May 26, 2026 14:30
@falko-strenzke
falko-strenzke force-pushed the falko/ecc-key-group-from-param branch 3 times, most recently from 41f78dd to c107b1d Compare May 27, 2026 14:01
@falko-strenzke
falko-strenzke force-pushed the falko/ecc-key-group-from-param branch from c107b1d to 54200e6 Compare June 3, 2026 11:46
@randombit
randombit merged commit 7566931 into randombit:master Jul 18, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants