Hashed-TCP connection
---------------------

At present this is just "implemented", however, a proper design would
probably result in it being done with ASN.1.

Server                       Client
-----------------            -------------------
waiting                      waiting
                  <--------  makes connection
accept connection -------->


SERVER
======

+---------+
| waiting +-----<--------------------+
+----+----+                          |
     |                               |
+----+----+                          |
| receive |                          |
| hashing |                          |
| funciton|                          |
|  request|                          |
+----+----+                          |
     |                               |
+----+----+                    +-----+-----+
| valid   |                    | send back |
| hash fn +----No--------->----+ error     |
|    ?    |                    | message   |
+----+----+                    +-----------+
     |
    Yes
     |
+----+----+
| send an |
| ACK     |
+----+----+
     |
+----+----+
| waiting +-----<--------------------+
+----+----+                          |
     |                               |
+----+----+                          |
| receive |                          |
| crypto  |                          |
| funciton|                          |
|  request|                          |
+----+----+                          |
     |                               |
+----+----+                    +-----+-----+
| valid   |                    | send back |
|crypto fn+----No--------->----+ error     |
|    ?    |                    | message   |
+----+----+                    +-----------+
     |
    Yes
     |
+----+----+
| send an |
| ACK     |
+----+----+
     |
     |
+----+----+
| using a |
| hash fn?|-----No----------->------------------------->------------------+
+----+----+                                                               |
     |                                                                    |
    Yes                                                                   |
     |                                                                    |
+----+------+                                                             |
| send nonce|                                                             |
+-----+-----+                                                             |
      |                                                                   |
      |                                                                   |
+-----+-----+                                                             |
|  receive  |                                                             |
|   remote  |                                                             |
|   nonce   |                                                             |
+-----+-----+                                                             |
      |                                                                   |
      |                                                                   |
+-----+-----+                                                             |
|  receive  |                                                             |
|remote hash|                                                             |
+-----+-----+                                                             |
      |                                                                   |
      |                                                                   |
+-----------+                +------------+     +-----------------+       |
| is hash   +--->---NO--->---| send error |-----+ drop connection |       |
|   valid ? |                +------------+     +-----------------+       |
+-----------+                                                             |
      |                                                                   |
      |                                                                   |
+-----+-----+                                                             |
| wait for  +-------------<---------------------------<-------------------+
| message   |
+-----------+

*******************************************************************************

CLIENT
======

+-----------+
|  waiting  |
+-----+-----+
      |
      |
+-----+-----+
| send hash |
| function  |----<--------------------------+
|  request  |                               |
+-----+-----+                               |
      |                                     |
      |                             +-------+-------+
+-----+-----+                       | chose another |
|  waiting  |-->--receive error-->--| hash function |
+-----+-----+                       +---------------+
      |
      |
  receive ACK
      |
      |
+-----+-----+
|send crypto|
| function  |----<--------------------------+
|  request  |                               |
+-----+-----+                               |
      |                                     |
      |                             +-------+-------+
+-----+-----+                       | chose another |
|  waiting  |-->--receive error-->--|crypto function|
+-----+-----+                       +---------------+
      |
      |
  receive ACK
      |
      |
+-----+-----+
| send nonce|
+-----+-----+
      |
      |
+-----+-----+
|  receive  |
|   remote  |
|   nonce   |
+-----+-----+
      |
      |
+-----+-----+
| calculate |
| h(n1,n2,s)|
+-----+-----+
      |
      |
+-----+-----+
| send hash |
+-----------+
      |
      |
+-----+-----+
|  receive  |
|remote hash|
+-----+-----+
      |
      |
+-----------+                +------------+     +-----------------+
| is hash   +--->---NO--->---| send error |-----+ drop connection |
|   valid ? |                +------------+     +-----------------+
+-----------+
