I need to compute the product of two BigIntegers raised to BigIntegers modular a prime.
I'm computing - y^r * r^s (mod p).
The code I'm using works, but I can't help feeling that it is performing unnecessary calculations, which are pretty expensive when large BigIntegers are involved.
BigInteger v1A = y.modPow(r, p);
BigInteger v1B = r.modPow(s, p);
BigInteger v1 = v1A.multiply(v1B).mod(p);
Ideally I'd like a way to calculate v1 in one go. Is this possible?
Assuming that the methods that you're using are efficient, I don't see a faster way to do this, but I'm no expert. Of course, you could consolidate your code to:
but that's the exact same as your code.