Fix crypto BIO

Addresses various problems, fixes tests.

/cc @bnoordhuis @isaacs.