Chargement…
Chargement…
With R=256 and an odd modulus m<=255, the block returns x*y*R^-1 mod m. Inputs satisfy 0<=x,y<m. This is a Montgomery product, not directly x*y mod m unless operands were prepared for that domain.
Initialize t=0. For each of the eight bits of x, least-significant first: add y to t when the bit is 1; when t is odd, add m; then divide t by two. After the eighth step, subtract m if t>=m.
For m=251, R^-1=201. The testbench checks several products, values close to the modulus, and zero.