In am learning the SSH RFC
An encryption algorithm and a key will be negotiated during the key exchange. When encryption is in effect, the packet length, padding length, payload, and padding fields of each packet MUST be encrypted with the given algorithm.
So the structure of the packet would be like that. How does the SSH server or client know the real length of the encrypted data?
payload [byte[packet_length - padding_length - 1]] ^ | packet_length | mac (Message Authentication Code - MAC) [uint32] | [byte[mac_length]] ^ | ^ | | | | | | +-------+--------------------------------------------------------------------+ | | | | ssh | | | | +----------------------------------------------------------------+ | | | |-----------------------------------------------------| | | | | | || | | | | | || | | | | tcp | || | | | | | || | | | | | || + | + | + + | + || + | | | | || | | | | | | || | | | | |-----------------------------------------------------| | | | | |----------------------------------------------------------------+ | +-------+--------------------------------------------------------------------+ | | | | | | | | | v | v [byte] | [byte[padding_length]] padding_length | random padding | | | | | | | v encrypted_data