Encryption

0. Derive shared secret

sharedSecret: uint8[64]

1. Initialization Vector (IV)

AlgorithmKeyPadding
AES CBCsharedSecret[16..32]None

Content

TypeName
uint64SessionId
uint32SequenceNumber
uint16FragmentIndex
uint16FragmentCount

2. Encrypt message payload

AlgorithmKeyPadding
AES CBCsharedSecret[0..16]PKCS7

Content

TypeName
uint32PayloadSize
uint8[PayloadSize]RawPayload

3. Adjust header

  • Add SessionEncrypted and HasHMAC flags
  • Adjust message length to encrypted payload

4. Calc HMAC

AlgorithmKey
Sha256sharedSecret[32..64]
  • Append HMAC
  • Increase message length by Hmac-Size.