crypt: Move implementation-independent code to separate file.