Skip to content

ECDSA and ECDH over P-256, P-384, P-521 and secp256k1 #162

In review

Description

@WingZer0o

Summary

cas-lib's only classical signatures are RSA and Ed25519, and its only key exchange is X25519. The NIST curves are what most protocols and platforms still require: ECDSA P-256 is ES256 (JWT, WebAuthn/passkeys, Apple and Android keystores, AWS KMS), P-384/P-521 are needed for CNSA and FIPS profiles, and secp256k1 is used by Bitcoin and Ethereum. ECDH over the same curves is needed for interop with WebCrypto, TLS and most HSMs.

Upstream

Scope

  • ECDSA P-256 / SHA-256 (ES256): keygen, sign, verify
  • ECDSA P-384 / SHA-384 (ES384)
  • ECDSA P-521 / SHA-512 (ES512)
  • ECDSA secp256k1 / SHA-256 (ES256K)
  • Signature encodings: fixed-size (IEEE P1363 / JOSE) and ASN.1 DER
  • ECDH on P-256, P-384, P-521 and secp256k1

Implementation notes

  • Follow the module pattern: trait in cas_<module>.rs, impl in <algorithm>.rs, declared in src/lib.rs (no top-level re-exports).
  • Return CasResult<T> and never panic (a panic across the FFI boundary is UB); add CasError variants only by appending (stable ABI codes).
  • Zeroize intermediate secret buffers with zeroize::Zeroizing; structs holding secrets get a redacting Debug impl (see src/pqc/cas_pqc.rs).
  • Keys are PEM per the data conventions: PKCS#8 private keys and SPKI public keys (accept SEC1 EC PRIVATE KEY too if cheap).
  • Sign deterministically (RFC 6979). Reject high-S signatures for secp256k1 if a strict mode is offered; document the choice.
  • ECDH: validate the peer public key (on-curve, not identity) and return the shared secret in a Zeroizing buffer; recommend passing it through HKDF rather than using it as a key.
  • Put signatures and ECDH in one new module (e.g. ecc) or split across signatures / key_exchange; follow whichever keeps the trait-per-module pattern.

Tests

  • Wycheproof: ecdsa_secp256r1_sha256_test.json, ecdsa_secp384r1_sha384_test.json, ecdsa_secp521r1_sha512_test.json, ecdsa_secp256k1_sha256_test.json (and the _p1363 variants where present), ecdh_secp256r1_test.json, ecdh_secp384r1_test.json, ecdh_secp521r1_test.json, ecdh_secp256k1_test.json.
  • NIST CAVP ECDSA SigVer / KAS ECC KATs under tests/data/.

Docs

  • Add a complete, runnable fn main() example for each new API to docs/EXAMPLES.md and keep its Table of Contents in sync.

Activity

  1. added
    enhancement
    on Nov 27, 2026
  2. WingZer0o commented on Nov 27, 2026

    @WingZer0o
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions