split core elgamal impl to lib