Optimized for encrypt/decrypt using same function