Add randomized tests exercising the streams in normal operation

This revealed a bug: the server private key buffer was too small. This was due to confusion
between the length of the seed from which the public and private keys are derived and the
length of the private key itself.
Switch a series of 'if's to a switch

(to make stepping in the debugger less tedious)