Skip to content

ECDsa.Create(ECParameters) behavior is not consistent across platforms with a public/private key mismatch #27830

@bartonjs

Description

@bartonjs

Create an ECParameters for secp256r1 (ECCurve.NamedCurves.nistP256) with

D = 9F9BD156374FB78F3D69EFF10DEF8C296EC4F03EACA42F4257130D0CE9316FCD,
Q.X = 6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296
Q.Y = 4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5

(That X/Y pair is for the curve point G, not the key point Q)

On Linux (via OpenSSL)

Unhandled Exception: Interop+Crypto+OpenSslCryptographicException: error:100B107B:elliptic curve routines:EC_KEY_check_key:invalid private key
at System.Security.Cryptography.ECOpenSsl.ImportParameters(ECParameters parameters)

On Windows, success (the Q value seems to be rederived from D).

Since it's probably hard to make Linux and macOS coerce Q, it's probably more practical to make Windows throw (theoretical process: NCryptImportKey, then NCryptExportKey and compare the target Q value, then dispose the new key handle and throw before replacing the existing key handle).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions