I want to calculate the modulus of a square: n^2 % m, where both n and m are large numbers (but less than the maximum of a 64 bits integer). The problem arrises when n^2 gets larger than the 64 bits maximum.
Is there an algorithm available to do this calculation? I know n^2 % m = (n % m)^2 %m, but this doesn't help me when m > n.