Skip to content

Post-Quantum (PQ) and Post-Quantum/Traditional (PQ/T) hybrid signatures for VCs #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 187 commits into
base: main
Choose a base branch
from

Conversation

AleCla97
Copy link

@AleCla97 AleCla97 commented Mar 31, 2025

Description of change

Integration of Post-Quantum (PQ) and Post-Quantum/Traditional (PQ/T) hybrid signatures for VCs

  • New features: pqc for PQ related code, hybrid for hybrid related code, pqc-liboqs for the pq signatures implementation based on liboqs, hybrid-liboqs for the hybrid signatures implementation, based on this draft
  • JwkStoragePQ: Extension of the JwkStorage for pq keys and Memstore implementation
  • Algorithm Key Pair (AKP), new Jwktype for PQ JWKs based on ML-DSA for JOSE and COSE
    draft
  • CompositeAlgId: Hybrid keytype MLDSA44/65-ED25519
  • DID JWK extension: create a new DID JWK with traditional, pq, hybrid and zk keys
  • DIDCompositeJWK, did method for hybrid keys and his relative resolver
  • JwtCredentialValidatorHybrid and JwtPresentationValidatorHybrid, hybrid signature validators
  • PQCJwsVerifier, verifier for PQ signatures with an implementation based on liboqs
  • New examples: pq and hybrid
  • Wasm: bindings of the new functions
  • Wasm: new examples: pq and hybrid
  • Wasm: JwkPqMemStore and PQJwsVerifier implementation of JwkStorage and IJwsVerifier with noble post quantum for ML-DSA

Other changes

  • Bump zkryptium and json proof token version to match the latest BBS and JPT drafts

Type of change

Add an x to the boxes that are relevant to your changes.

  • Bug fix (a non-breaking change which fixes an issue)
  • Enhancement (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Fix

How the change has been tested

  • cargo test --release to see that there were no incompatibilities.
  • the new features were tested through the new pq and hybrid tests( both rust and wasm.)
  • the update of zkryptium and json proof token was also tested by running the zkp tests

Change checklist

Add an x to the boxes that are relevant to your changes.

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@eike-hass eike-hass added Wasm Related to Wasm bindings. Becomes part of the Wasm changelog Added A new feature that requires a minor release. Part of "Added" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. labels Apr 17, 2025
@eike-hass eike-hass force-pushed the main branch 2 times, most recently from bb21207 to 42fc734 Compare April 22, 2025 16:04
@AleCla97 AleCla97 marked this pull request as ready for review April 23, 2025 14:03
@AleCla97 AleCla97 requested a review from a team as a code owner April 23, 2025 14:03
Copy link
Contributor

@UMR1352 UMR1352 left a comment

Choose a reason for hiding this comment

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

Thank you for your outstanding effort 🙇! I went through your changes, leaving some comments here and there.
What's left to do now is:

  • address the comments and review again;
  • format the code accordingly to our formatting rules;
  • resolve merge conflicts and adapt this to work with the latest version of the library;
  • harmonize the licence headers (for files that you guys edited I'd remove the additional modification comment and instead add the LINKS foundation name next to ours);

As always, let us now how much you want to be involved in the aforementioned steps.

Comment on lines +29 to +31
json-proof-token = { version = "0.4.1" }
zkryptium = { version = "0.4.0", default-features = false, features = ["bbsplus"] }
oqs = {version = "0.10.0", default-features = false, features = ["sigs", "std", "vendored"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless it's really needed, let's try to avoid pinning dependencies to a specific patch version. For instance:
oqs = { version = "0.10.0", ... } should be oqs = { version = "0.10", ... }


use crate::jwk::Jwk;

/// Mame of algorithms used to generate the hybrid signature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Mame of algorithms used to generate the hybrid signature.
/// Algorithms used to generate hybrid signatures.

Comment on lines +10 to +18
pub enum CompositeAlgId {
/// DER encoded value in hex = 060B6086480186FA6B5008013E
#[serde(rename = "id-MLDSA44-Ed25519")]
IdMldsa44Ed25519,
/// DER encoded value in hex = 060B6086480186FA6B50080147
#[serde(rename = "id-MLDSA65-Ed25519")]
IdMldsa65Ed25519,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance that more algorithms will be added in the close-ish future? If that's so we might want to annotate this enum with the #[non_exhaustive] attribute to allow extending the list without causing breaking changes.

Comment on lines +29 to +48
/// Represent a combination of a traditional public key and a post-quantum public key both in Jwk format.
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct CompositeJwk {
#[serde(rename = "algId")]
alg_id: CompositeAlgId,
#[serde(rename = "traditionalPublicKey")]
traditional_public_key: Jwk,
#[serde(rename = "pqPublicKey")]
pq_public_key: Jwk,
}

impl CompositeJwk {
/// Create a new CompositePublicKey structure.
pub fn new(alg_id: CompositeAlgId, traditional_public_key: Jwk, pq_public_key: Jwk) -> Self {
Self {
alg_id,
traditional_public_key,
pq_public_key,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a slight issue with this definition of CompositeJwk. The current API doesn't prevent its users from misusing it. For instance, one could create a CompositeJwk providing a non-post-quantum JWK for pq_public_key.
To enhance type correctness we could define a struct PostQuantumJwk(Jwk) that upholds this invariant - i.e. post quantum key encoded as JWK. Such a type, equipped with the right methods and traits implementation would make it seamlessly work with Jwk while strengthening the correctness of our API.

The same argument would be made for the fact that the passed JWKs might be private keys instead of public ones, though in this instance we can simply make sure to clear out the private components of the passed keys before creating a CompositeJwk.

Comment on lines +27 to +31
impl Default for JwkParamsAKP {
fn default() -> Self {
Self::new()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be derived.

use crate::jose::IJwkParams;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[wasm_bindgen(js_name = CompositeJwk, inspectable)]
Copy link
Contributor

Choose a reason for hiding this comment

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

inspectable doens't do anything as there are no public fields.

}

/// Returns the JSON WEB KEY (JWK) encoded inside this `did:jwk`.
#[wasm_bindgen]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[wasm_bindgen]
#[wasm_bindgen(js_name = compositeJwk)]

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure we want to expose these JWT/Credential handling utilities?

Comment on lines +31 to +38
pub struct CompositeJwk {
#[serde(rename = "algId")]
alg_id: CompositeAlgId,
#[serde(rename = "traditionalPublicKey")]
traditional_public_key: Jwk,
#[serde(rename = "pqPublicKey")]
pq_public_key: Jwk,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub struct CompositeJwk {
#[serde(rename = "algId")]
alg_id: CompositeAlgId,
#[serde(rename = "traditionalPublicKey")]
traditional_public_key: Jwk,
#[serde(rename = "pqPublicKey")]
pq_public_key: Jwk,
}
#[serde(rename_all = "camelCase")]
pub struct CompositeJwk {
alg_id: CompositeAlgId,
traditional_public_key: Jwk,
pq_public_key: Jwk,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

wasm_bindgen supports async functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Added A new feature that requires a minor release. Part of "Added" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. Wasm Related to Wasm bindings. Becomes part of the Wasm changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants