rewritten crypto subsystem implementation