Class: Linzer::MLDSA::GemKey
Overview
ML-DSA signing/verification backed by the ml_dsa gem (a C
extension bundling the PQClean implementation).
Supports all three FIPS 204 parameter sets. Optional: not required
by linzer.rb itself, and not a runtime dependency of the gemspec,
callers who want this backend must add ml_dsa to their own
Gemfile and require "linzer/ml_dsa/gem_key" themselves, which
requires ml_dsa in turn.
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
Attributes inherited from Key
Instance Method Summary collapse
-
#backend ⇒ Symbol
:ml_dsa -- which backend produced this key.
-
#initialize(material, params = {}) ⇒ GemKey
constructor
A new instance of GemKey.
-
#sign(data) ⇒ String
Signs an RFC 9421 signature base with an empty FIPS 204 context.
-
#validate_signature_parameters(parameters) ⇒ true
Validates that the HTTP
algparameter matches this key's parameter set. -
#verify(signature, data) ⇒ Boolean
Verifies an RFC 9421 signature base with an empty FIPS 204 context.
Methods inherited from Key
Constructor Details
#initialize(material, params = {}) ⇒ GemKey
Returns a new instance of GemKey.
32 33 34 35 |
# File 'lib/linzer/ml_dsa/gem_key.rb', line 32 def initialize(material, params = {}) @algorithm = String(params.fetch(:algorithm)) super end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
30 31 32 |
# File 'lib/linzer/ml_dsa/gem_key.rb', line 30 def algorithm @algorithm end |
Instance Method Details
#backend ⇒ Symbol
Returns :ml_dsa -- which backend produced this key.
79 80 81 |
# File 'lib/linzer/ml_dsa/gem_key.rb', line 79 def backend :ml_dsa end |
#sign(data) ⇒ String
Signs an RFC 9421 signature base with an empty FIPS 204 context.
55 56 57 58 59 60 |
# File 'lib/linzer/ml_dsa/gem_key.rb', line 55 def sign(data) validate_signing_key material.sign(data, context: "") rescue MlDsa::Error => e raise SigningError, e., cause: e end |
#validate_signature_parameters(parameters) ⇒ true
Validates that the HTTP alg parameter matches this key's parameter set.
42 43 44 45 46 47 48 |
# File 'lib/linzer/ml_dsa/gem_key.rb', line 42 def validate_signature_parameters(parameters) supplied_algorithm = parameters["alg"] || parameters[:alg] return true if supplied_algorithm.nil? || supplied_algorithm == algorithm raise VerifyError, "Signature algorithm #{supplied_algorithm} does not match key algorithm #{algorithm}" end |
#verify(signature, data) ⇒ Boolean
Verifies an RFC 9421 signature base with an empty FIPS 204 context.
68 69 70 71 72 73 74 75 76 |
# File 'lib/linzer/ml_dsa/gem_key.rb', line 68 def verify(signature, data) validate_verify_key return false unless signature.is_a?(String) return false unless signature.bytesize == parameter_set.signature_bytes verification_material.verify(data, signature, context: "") rescue MlDsa::Error, ArgumentError, TypeError false end |