Module: PQCrypto::Signature

Defined in:
lib/pq_crypto/signature.rb

Defined Under Namespace

Classes: Keypair, PublicKey, SecretKey

Constant Summary collapse

CANONICAL_ALGORITHM =
:ml_dsa_65
DETAILS =
{
  CANONICAL_ALGORITHM => {
    name: CANONICAL_ALGORITHM,
    family: Serialization.algorithm_to_family(CANONICAL_ALGORITHM),
    oid: Serialization.algorithm_to_oid(CANONICAL_ALGORITHM),
    public_key_bytes: SIGN_PUBLIC_KEY_BYTES,
    secret_key_bytes: SIGN_SECRET_KEY_BYTES,
    signature_bytes: SIGN_BYTES,
    description: "ML-DSA-65 signature primitive (FIPS 204).",
  }.freeze,
}.freeze

Class Method Summary collapse

Class Method Details

.details(algorithm) ⇒ Object



62
63
64
# File 'lib/pq_crypto/signature.rb', line 62

def details(algorithm)
  DETAILS.fetch(resolve_algorithm!(algorithm)).dup
end

.generate(algorithm = CANONICAL_ALGORITHM) ⇒ Object



22
23
24
25
26
# File 'lib/pq_crypto/signature.rb', line 22

def generate(algorithm = CANONICAL_ALGORITHM)
  resolve_algorithm!(algorithm)
  public_key, secret_key = PQCrypto.__send__(:native_sign_keypair)
  Keypair.new(PublicKey.new(algorithm, public_key), SecretKey.new(algorithm, secret_key))
end

.public_key_from_bytes(algorithm, bytes) ⇒ Object



28
29
30
31
# File 'lib/pq_crypto/signature.rb', line 28

def public_key_from_bytes(algorithm, bytes)
  resolve_algorithm!(algorithm)
  PublicKey.new(algorithm, bytes)
end

.public_key_from_pqc_container_der(der, algorithm = nil) ⇒ Object



38
39
40
41
42
# File 'lib/pq_crypto/signature.rb', line 38

def public_key_from_pqc_container_der(der, algorithm = nil)
  resolved_algorithm, bytes = Serialization.public_key_from_pqc_container_der(algorithm, der)
  resolve_algorithm!(resolved_algorithm)
  PublicKey.new(resolved_algorithm, bytes)
end

.public_key_from_pqc_container_pem(pem, algorithm = nil) ⇒ Object



44
45
46
47
48
# File 'lib/pq_crypto/signature.rb', line 44

def public_key_from_pqc_container_pem(pem, algorithm = nil)
  resolved_algorithm, bytes = Serialization.public_key_from_pqc_container_pem(algorithm, pem)
  resolve_algorithm!(resolved_algorithm)
  PublicKey.new(resolved_algorithm, bytes)
end

.secret_key_from_bytes(algorithm, bytes) ⇒ Object



33
34
35
36
# File 'lib/pq_crypto/signature.rb', line 33

def secret_key_from_bytes(algorithm, bytes)
  resolve_algorithm!(algorithm)
  SecretKey.new(algorithm, bytes)
end

.secret_key_from_pqc_container_der(der, algorithm = nil) ⇒ Object



50
51
52
53
54
# File 'lib/pq_crypto/signature.rb', line 50

def secret_key_from_pqc_container_der(der, algorithm = nil)
  resolved_algorithm, bytes = Serialization.secret_key_from_pqc_container_der(algorithm, der)
  resolve_algorithm!(resolved_algorithm)
  SecretKey.new(resolved_algorithm, bytes)
end

.secret_key_from_pqc_container_pem(pem, algorithm = nil) ⇒ Object



56
57
58
59
60
# File 'lib/pq_crypto/signature.rb', line 56

def secret_key_from_pqc_container_pem(pem, algorithm = nil)
  resolved_algorithm, bytes = Serialization.secret_key_from_pqc_container_pem(algorithm, pem)
  resolve_algorithm!(resolved_algorithm)
  SecretKey.new(resolved_algorithm, bytes)
end

.supportedObject



66
67
68
# File 'lib/pq_crypto/signature.rb', line 66

def supported
  DETAILS.keys.dup
end