Tls refactor

Auto-testing passed on Linux and Windows.
Normal mode tested on Linux and Windows/Linux.

I consider this ready to merge but would like at least one other person to try a couple of tests as a sanity check.

This new structure will make implementing TLS1.1 easier, as well as making code auditing easier.

There is still more general refactoring (not specifically TLS) that could be done (more sensible module organisation, in particular).