I have been reading Bleichenbacher's 1998 paper on a forged message attack on RSA. The paper assumes access to an Oracle that takes a ciphertext $c$ and will check the decrypted text for valid PKCS #1 padding and returns the validity of the padding. This side-channel can be used for an attack since we can send a forged ciphertext by selecting random integers $s$ and compute:
$c' = cs^{e}\, \mbox{mod}\, n$
If $c'$ is PKCS conforming we know that the two most significant bytes of $ ms = c'^{d} \mbox{mod}\,n$ were equal to 0x00 0x02. If we define
$B=2^{8(k-2)}$
where $k$ is the length of $n$ in bytes, then we know
$2B\leq ms\,\mbox{mod}\,n<3B $
Now we have a range $M_{0}$ in which we know $ms$ to lie:
$M_{0} = {[2B, 3B-1]}$
The attack now proceeds by iteratively generating more valid forged ciphertexts for integers $s_{i}$ and with the gained knowledge reduce the range of $M_{i}$
I am having trouble understanding Step 3 in the paper which deals with narrowing the set of solutions:
$M_{i} \leftarrow \cup_{a, b, r} \lbrace [\mbox{max}(a, [\frac{2B+rn}{s_{i}}]), \mbox{min}(b, [\frac{3B-1+rn}{s_{i}}])]\rbrace$
for all $[a,b] \in M_{i-1}$ and $\frac{as_{i}-3B+1}{n}\leq r< \frac{bs_{i}-2B}{n}$
How would this be implemented in code? It looks to me that we would need to compute each range for every $r$ within the specified bounds e.g.:
for (r=r_min; r<r_max; ++r)
max(a, x);
min(b, y);
However this seems to be intractable to me and I think I am making an error in trying to convert the math to code. Anyone maybe see where I am going wrong?