Class: Linzer::MLDSA::OpenSSLKey
- Defined in:
- lib/linzer/ml_dsa/openssl_key.rb
Overview
Requires OpenSSL 3.5+ with ML-DSA signature algorithms enabled. Some distributions ship OpenSSL 3.5+ with these disabled by crypto policy (see https://github.com/ruby/openssl/issues/1075), so callers should be prepared for OpenSSL::PKey::PKeyError on unsupported builds even when the OpenSSL version alone looks sufficient.
ML-DSA (FIPS 204) signing/verification backed directly by OpenSSL 3.5+, with no additional gem dependency. Supports all three parameter sets (ML-DSA-44/65/87).
Like Ed25519, ML-DSA is a "pure"/digest-less signature scheme: the RFC 9421 signature base is signed directly, with no prehashing.
Instance Attribute Summary collapse
-
#algorithm ⇒ String
readonly
The FIPS 204 parameter set this key was constructed for, e.g.
Attributes inherited from Key
Instance Method Summary collapse
-
#backend ⇒ Symbol
:openssl -- which backend produced this key.
-
#initialize(material, params = {}) ⇒ OpenSSLKey
constructor
A new instance of OpenSSLKey.
-
#sign(data) ⇒ String
Signs data using the ML-DSA private key.
-
#validate_signature_parameters(parameters) ⇒ true
Validates that the HTTP
algparameter matches this key's algorithm. -
#verify(signature, data) ⇒ Boolean
Verifies a signature using the ML-DSA public key.
Methods inherited from Key
Constructor Details
#initialize(material, params = {}) ⇒ OpenSSLKey
Returns a new instance of OpenSSLKey.
73 74 75 76 |
# File 'lib/linzer/ml_dsa/openssl_key.rb', line 73 def initialize(material, params = {}) @algorithm = String(params.fetch(:algorithm)) super end |
Instance Attribute Details
#algorithm ⇒ String (readonly)
Returns The FIPS 204 parameter set this key was
constructed for, e.g. "ml-dsa-44".
66 67 68 |
# File 'lib/linzer/ml_dsa/openssl_key.rb', line 66 def algorithm @algorithm end |
Instance Method Details
#backend ⇒ Symbol
Returns :openssl -- which backend produced this key.
113 114 115 |
# File 'lib/linzer/ml_dsa/openssl_key.rb', line 113 def backend :openssl end |
#sign(data) ⇒ String
Signs data using the ML-DSA private key.
96 97 98 99 |
# File 'lib/linzer/ml_dsa/openssl_key.rb', line 96 def sign(data) validate_signing_key material.sign(nil, data) end |
#validate_signature_parameters(parameters) ⇒ true
Validates that the HTTP alg parameter matches this key's algorithm.
83 84 85 86 87 88 89 |
# File 'lib/linzer/ml_dsa/openssl_key.rb', line 83 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 a signature using the ML-DSA public key.
107 108 109 110 |
# File 'lib/linzer/ml_dsa/openssl_key.rb', line 107 def verify(signature, data) validate_verify_key material.verify(nil, signature, data) end |