Module: HrrRbSsh::Transport::KexAlgorithm::IvComputable

Included in:
DiffieHellman, DiffieHellmanGroupExchange, EllipticCurveDiffieHellman
Defined in:
lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb

Instance Method Summary collapse

Instance Method Details

#build_key(_k, h, _x, session_id, key_length) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb', line 12

def build_key(_k, h, _x, session_id, key_length)
  k = DataType::Mpint.encode _k
  x = DataType::Byte.encode _x

  key = OpenSSL::Digest.digest(self.class::DIGEST, k + h + x + session_id)

  while key.length < key_length
    key = key + OpenSSL::Digest.digest(self.class::DIGEST, k + h + key )
  end

  key[0, key_length]
end

#iv_c_to_s(transport, encryption_algorithm_c_to_s_name) ⇒ Object



25
26
27
28
# File 'lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb', line 25

def iv_c_to_s transport, encryption_algorithm_c_to_s_name
  key_length = EncryptionAlgorithm[encryption_algorithm_c_to_s_name]::IV_LENGTH
  build_key(shared_secret, hash(transport), 'A'.ord, transport.session_id, key_length)
end

#iv_s_to_c(transport, encryption_algorithm_s_to_c_name) ⇒ Object



30
31
32
33
# File 'lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb', line 30

def iv_s_to_c transport, encryption_algorithm_s_to_c_name
  key_length = EncryptionAlgorithm[encryption_algorithm_s_to_c_name]::IV_LENGTH
  build_key(shared_secret, hash(transport), 'B'.ord, transport.session_id, key_length)
end

#key_c_to_s(transport, encryption_algorithm_c_to_s_name) ⇒ Object



35
36
37
38
# File 'lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb', line 35

def key_c_to_s transport, encryption_algorithm_c_to_s_name
  key_length = EncryptionAlgorithm[encryption_algorithm_c_to_s_name]::KEY_LENGTH
  build_key(shared_secret, hash(transport), 'C'.ord, transport.session_id, key_length)
end

#key_s_to_c(transport, encryption_algorithm_s_to_c_name) ⇒ Object



40
41
42
43
# File 'lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb', line 40

def key_s_to_c transport, encryption_algorithm_s_to_c_name
  key_length = EncryptionAlgorithm[encryption_algorithm_s_to_c_name]::KEY_LENGTH
  build_key(shared_secret, hash(transport), 'D'.ord, transport.session_id, key_length)
end

#mac_c_to_s(transport, mac_algorithm_c_to_s_name) ⇒ Object



45
46
47
48
# File 'lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb', line 45

def mac_c_to_s transport, mac_algorithm_c_to_s_name
  key_length = MacAlgorithm[mac_algorithm_c_to_s_name]::KEY_LENGTH
  build_key(shared_secret, hash(transport), 'E'.ord, transport.session_id, key_length)
end

#mac_s_to_c(transport, mac_algorithm_s_to_c_name) ⇒ Object



50
51
52
53
# File 'lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb', line 50

def mac_s_to_c transport, mac_algorithm_s_to_c_name
  key_length = MacAlgorithm[mac_algorithm_s_to_c_name]::KEY_LENGTH
  build_key(shared_secret, hash(transport), 'F'.ord, transport.session_id, key_length)
end