Skip to content

Allow Android to import EC private scalar only keys - #135024

Open
vcsjones wants to merge 6 commits into
dotnet:mainfrom
vcsjones:android-ec-pub-key
Open

vcsjones wants to merge 6 commits into
dotnet:mainfrom
vcsjones:android-ec-pub-key

Conversation

@vcsjones

@vcsjones vcsjones commented Oct 1, 2026

Copy link
Copy Markdown
Member

Android was our last platform that did not support importing only the private scalar d for EC keys without Q.

This change allows Android to import ECParameters that contain only D. Android already supported this - what it did not do was make it straight forward to ask the private key "what is your public key". This meant that importing a D-only key would fail to export the public key.

This makes it work by importing the private key D, then performing a PKCS#8 export on it, which gives us back Q.

This also removes CanDeriveNewPublicKey since every platform now has it as true, except for browser, which don't run the EC tests anyway.

@vcsjones vcsjones added this to the 12.0.0 milestone Oct 1, 2026
@vcsjones vcsjones self-assigned this Oct 1, 2026
@vcsjones
vcsjones deployed to copilot-pat-pool October 1, 2026 14:39 — with GitHub Actions Active
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The native cryptography changes are significant, and approval-readiness assessments are mixed; final human review is warranted.

Review effort: Lite
Findings: None

What changed in this PR

Enables Android to import EC keys containing only the private scalar D by recovering the public point through PKCS#8 export.

Changes:

  • Adds Android EC private-key PKCS#8 export and public-key recovery.
  • Supports constructing key pairs without an initial public key.
  • Removes obsolete EC public-key derivation capability gating and updates tests.
File Description
src/​native/​libs/​System.Security.Cryptography.Native.Android/​pal_misc.h Allows nullable key components.
src/​native/​libs/​System.Security.Cryptography.Native.Android/​pal_ecc_import_export.h Declares PKCS#8 export support.
src/​native/​libs/​System.Security.Cryptography.Native.Android/​pal_ecc_import_export.c Implements D-only key creation and private-key export.
src/​libraries/​System.Security.Cryptography/​tests/​ECDsaTestRegistration.OpenSsl.cs Removes obsolete capability gating.
src/​libraries/​System.Security.Cryptography/​tests/​ECDsaTestRegistration.Default.cs Removes obsolete capability gating.
src/​libraries/​System.Security.Cryptography/​tests/​ECDsaTestRegistration.Cng.cs Removes obsolete capability gating.
src/​libraries/​System.Security.Cryptography/​tests/​EcDiffieHellmanOpenSslProvider.cs Removes obsolete capability gating.
src/​libraries/​System.Security.Cryptography/​tests/​ECDiffieHellmanCngProvider.cs Removes obsolete capability gating.
src/​libraries/​System.Security.Cryptography/​tests/​DefaultECDiffieHellmanProvider.Windows.cs Removes obsolete capability gating.
src/​libraries/​System.Security.Cryptography/​tests/​DefaultECDiffieHellmanProvider.Unix.cs Removes obsolete capability gating.
src/​libraries/​System.Security.Cryptography/​tests/​DefaultECDiffieHellmanProvider.Browser.cs Updates provider test configuration.
src/​libraries/​System.Security.Cryptography/​tests/​DefaultECDiffieHellmanProvider.Android.cs Updates Android provider test configuration.
src/​libraries/​Common/​tests/​System/​Security/​Cryptography/​AlgorithmImplementations/​ECDsa/​ECDsaImportExport.cs Expands EC import/export coverage.
src/​libraries/​Common/​tests/​System/​Security/​Cryptography/​AlgorithmImplementations/​ECDiffieHellman/​ECDiffieHellmanTests.ImportExport.cs Expands D-only import/export coverage.
src/​libraries/​Common/​tests/​System/​Security/​Cryptography/​AlgorithmImplementations/​ECDiffieHellman/​ECDiffieHellmanProvider.cs Removes obsolete capability plumbing.
src/​libraries/​Common/​tests/​System/​Security/​Cryptography/​AlgorithmImplementations/​ECDiffieHellman/​ECDhKeyFileTests.cs Updates key-file tests.
src/​libraries/​Common/​tests/​System/​Security/​Cryptography/​AlgorithmImplementations/​EC/​ECKeyFileTests.LimitedPrivate.cs Updates limited-private-key tests.
src/​libraries/​Common/​tests/​System/​Security/​Cryptography/​AlgorithmImplementations/​EC/​ECKeyFileTests.cs Removes obsolete derivation gating.
src/​libraries/​Common/​src/​System/​Security/​Cryptography/​ECAndroid.ImportExport.cs Recovers public parameters for D-only imports.
src/​libraries/​Common/​src/​Interop/​Android/​System.Security.Cryptography.Native.Android/​Interop.EcDsa.ImportExport.cs Adds managed PKCS#8 export interop.

@vcsjones

vcsjones commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-android

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

This branch was successfully deployed

1 active deployment
copilot-pat-pool — 5d49c672 Deployed Oct 1, 2026 by vcsjones via conclusion #9466
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