Modular multiplication (source code)

= Modular multiplication

Computing the <remainder> $ab\bmod m$ while working with bounded <integer> representatives. Repeated doubling and addition can avoid forming an overflowing product: process the <binary digits> of $b$, double the current contribution <modulo> $m$, and add it to the result whenever the current <binary digit> is 1. The additions themselves must also use an overflow-safe implementation.