Class: Melos::Crypto::CipherSuite::EC

Inherits:
Object
  • Object
show all
Defined in:
lib/melos/crypto.rb

Direct Known Subclasses

P256, P384, P521

Class Method Summary collapse

Class Method Details

.deserialize_private_encapsulation_key(raw) ⇒ Object



75
76
77
# File 'lib/melos/crypto.rb', line 75

def self.deserialize_private_encapsulation_key(raw)
  self.deserialize_private_key(raw)
end

.deserialize_private_key(secret) ⇒ Object

also would like to depend on HPKE gem…



53
54
55
56
57
58
59
60
61
# File 'lib/melos/crypto.rb', line 53

def self.deserialize_private_key(secret)
  asn1_seq = OpenSSL::ASN1.Sequence([
    OpenSSL::ASN1.Integer(1),
    OpenSSL::ASN1.OctetString(secret),
    OpenSSL::ASN1.ObjectId(curve_name, 0, :EXPLICIT)
  ])

  OpenSSL::PKey.read(asn1_seq.to_der)
end

.deserialize_private_signature_key(raw) ⇒ Object



78
79
80
# File 'lib/melos/crypto.rb', line 78

def self.deserialize_private_signature_key(raw)
  self.deserialize_private_key(raw)
end

.deserialize_public_encapsulation_key(raw) ⇒ Object



81
82
83
# File 'lib/melos/crypto.rb', line 81

def self.deserialize_public_encapsulation_key(raw)
  self.deserialize_public_key(raw)
end

.deserialize_public_key(serialized_pk) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/melos/crypto.rb', line 63

def self.deserialize_public_key(serialized_pk)
  asn1_seq = OpenSSL::ASN1.Sequence([
    OpenSSL::ASN1.Sequence([
      OpenSSL::ASN1.ObjectId("id-ecPublicKey"),
      OpenSSL::ASN1.ObjectId(curve_name)
    ]),
    OpenSSL::ASN1.BitString(serialized_pk)
  ])

  OpenSSL::PKey.read(asn1_seq.to_der)
end

.deserialize_public_signature_key(raw) ⇒ Object



84
85
86
# File 'lib/melos/crypto.rb', line 84

def self.deserialize_public_signature_key(raw)
  self.deserialize_public_key(raw)
end