The Miller-Rabin test assumes that any odd number can be written in the form: p-1 = 2^k * m. and that: m must be odd or p is not prime.
a = chosen base
Then you calculate B0 = a^m * mod(p)
if B0 = 1 or -1 (p-1) then it is probably prime, however if not then you calculate B1, B2... until you get 1 or -1 (p-1)
This is done by:
Bn = (Bn-1)^2*mod(p)
So, my question is: Is there a way to calculate the maximum number of B iterations you must calculate in order to get 1 or -1 (p-1) for a given value of p, and if so, what is it?