Make names (of session_key and message_index) more consistent. Use our own protobuf tags rather than trying to piggyback on the one-to-one structure.
I want to be able to use this functionality from elsewhere, so factor it out to its own file.