class Net::SSH::Transport::CipherFactory

Implements a factory of OpenSSL cipher algorithms.

def self.get(name, options = {})

value of the +encrypt+ parameter.
cipher will be put into encryption or decryption mode, based on the
iv, key, shared, hash and digester values. Additionally, the
will be initialized using an iv and key generated from the given
Retrieves a new instance of the named algorithm. The new instance
def self.get(name, options = {})
  klass = SSH_TO_CLASS[name]
  unless klass.nil?
    key_len = klass.key_length
    key = Net::SSH::Transport::KeyExpander.expand_key(key_len, options[:key], options)
    return klass.new(encrypt: options[:encrypt], key: key)
  end
  ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
  return IdentityCipher if ossl_name == "none"
  cipher = OpenSSL::Cipher.new(ossl_name)
  cipher.send(options[:encrypt] ? :encrypt : :decrypt)
  cipher.padding = 0
  cipher.extend(Net::SSH::Transport::OpenSSLCipherExtensions)
  if name =~ /-ctr(@openssh.org)?$/
    if ossl_name !~ /-ctr/
      cipher.extend(Net::SSH::Transport::CTR)
    else
      cipher = Net::SSH::Transport::OpenSSLAESCTR.new(cipher)
    end
  end
  cipher.iv = Net::SSH::Transport::KeyExpander.expand_key(cipher.iv_len, options[:iv], options)
  key_len = cipher.key_len
  cipher.key_len = key_len
  cipher.key = Net::SSH::Transport::KeyExpander.expand_key(key_len, options[:key], options)
  return cipher
end

def self.get_lengths(name, options = {})

if :iv_len option is supplied the third return value will be ivlen
of the tuple.
algorithm is unknown, or is "none", 0 is returned for both elements
block-size ] for the named cipher algorithm. If the cipher
Returns a two-element array containing the [ key-length,
def self.get_lengths(name, options = {})
  klass = SSH_TO_CLASS[name]
  return [klass.key_length, klass.block_size] unless klass.nil?
  ossl_name = SSH_TO_OSSL[name]
  if ossl_name.nil? || ossl_name == "none"
    result = [0, 0]
    result << 0 if options[:iv_len]
  else
    cipher = OpenSSL::Cipher.new(ossl_name)
    key_len = cipher.key_len
    cipher.key_len = key_len
    block_size =
      case ossl_name
      when /\-ctr/
        Net::SSH::Transport::OpenSSLAESCTR.block_size
      else
        cipher.block_size
      end
    result = [key_len, block_size]
    result << cipher.iv_len if options[:iv_len]
  end
  result
end

def self.supported?(name)

and false otherwise.
Returns true if the underlying OpenSSL library supports the given cipher,
def self.supported?(name)
  return true if SSH_TO_CLASS.key?(name)
  ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
  return true if ossl_name == "none"
  return SSH_TO_CLASS.key?(name) || OpenSSL::Cipher.ciphers.include?(ossl_name)
end