class TPM::TPublic

Section 12.2.4 in trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf

Constants

BN_BASE
BYTE_LENGTH
CURVE_TPM_TO_OPENSSL
ECC_UNCOMPRESSED_POINT_INDICATOR
RSA_KEY_DEFAULT_PUBLIC_EXPONENT

Public Instance Methods

ecc?() click to toggle source
# File lib/tpm/t_public.rb, line 53
def ecc?
  alg_type == TPM::ALG_ECC
end
key() click to toggle source
# File lib/tpm/t_public.rb, line 57
def key
  if parameters.symmetric == TPM::ALG_NULL
    if ecc?
      ecc_key
    elsif rsa?
      rsa_key
    else
      raise "Type #{alg_type} not supported"
    end
  end
end
openssl_curve_name() click to toggle source
# File lib/tpm/t_public.rb, line 69
def openssl_curve_name
  if ecc?
    CURVE_TPM_TO_OPENSSL[parameters.curve_id] || raise("Unknown curve #{parameters.curve_id}")
  end
end
rsa?() click to toggle source
# File lib/tpm/t_public.rb, line 49
def rsa?
  alg_type == TPM::ALG_RSA
end

Private Instance Methods

bn(data) click to toggle source
# File lib/tpm/t_public.rb, line 102
def bn(data)
  if data
    OpenSSL::BN.new(data, BN_BASE)
  end
end
ecc_key() click to toggle source
# File lib/tpm/t_public.rb, line 77
def ecc_key
  if parameters.scheme == TPM::ALG_ECDSA
    group = OpenSSL::PKey::EC::Group.new(openssl_curve_name)

    key = OpenSSL::PKey::EC.new(group)
    key.public_key = OpenSSL::PKey::EC::Point.new(group, bn(ECC_UNCOMPRESSED_POINT_INDICATOR + unique.buffer.value))

    key
  end
end
rsa_key() click to toggle source
# File lib/tpm/t_public.rb, line 88
def rsa_key
  case parameters.scheme
  when TPM::ALG_RSASSA, TPM::ALG_RSAPSS, TPM::ALG_NULL
    n = unique.buffer.value

    if parameters.key_bits / BYTE_LENGTH == n.size
      key = OpenSSL::PKey::RSA.new(parameters.key_bits.value)
      key.set_key(bn(n), bn(RSA_KEY_DEFAULT_PUBLIC_EXPONENT), nil)

      key.public_key
    end
  end
end