diff --git a/Cargo.toml b/Cargo.toml index e3a43cf..629cb23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,10 @@ get-info-full = [] large-blobs = [] third-party-payment = [] +backend-dilithium2 = [] +backend-dilithium3 = [] +backend-dilithium5 = [] + log-all = [] log-none = [] log-info = [] diff --git a/src/webauthn.rs b/src/webauthn.rs index 48d4dc6..072b929 100644 --- a/src/webauthn.rs +++ b/src/webauthn.rs @@ -158,9 +158,40 @@ pub enum UnknownPKCredentialParam { pub const ES256: i32 = -7; /// EdDSA pub const ED_DSA: i32 = -8; - -pub const COUNT_KNOWN_ALGS: usize = 2; -pub const KNOWN_ALGS: [i32; COUNT_KNOWN_ALGS] = [ES256, ED_DSA]; +/// Dilithium2 +#[cfg(feature = "backend-dilithium2")] +pub const DILITHIUM2: i32 = -87; +#[cfg(feature = "backend-dilithium3")] +pub const DILITHIUM3: i32 = -88; +#[cfg(feature = "backend-dilithium5")] +pub const DILITHIUM5: i32 = -89; + +// Dynamically calculate the number of different known algorithms +pub const COUNT_KNOWN_ALGS: usize = + 2 + (if cfg!(feature = "backend-dilithium2") { + 1 + } else { + 0 + }) + (if cfg!(feature = "backend-dilithium3") { + 1 + } else { + 0 + }) + (if cfg!(feature = "backend-dilithium5") { + 1 + } else { + 0 + }); + +pub const KNOWN_ALGS: [i32; COUNT_KNOWN_ALGS] = [ + ES256, + ED_DSA, + #[cfg(feature = "backend-dilithium2")] + DILITHIUM2, + #[cfg(feature = "backend-dilithium3")] + DILITHIUM3, + #[cfg(feature = "backend-dilithium5")] + DILITHIUM5, +]; impl TryFrom for KnownPublicKeyCredentialParameters { type Error = UnknownPKCredentialParam;