I want to perform a modular reduction using Solinas prime value as q = 2^383-2^33+1. How can I efficiently compute it taking advantage of q being Solinas prime?
1 Answer
$\begingroup$
$\endgroup$
The rough idea is:
- start with the highest non-zero word,
- multiply each non-zero term in the Solinas number (for example, -1 at 33'rd bit and 1 at lowest bit)
- subtract the multiplied term from the number twice - the second time is to ensure any carry in the highest non-zero word is cleared.
- repeat the process for the next highest word until the number is less than the modulus.
I've an implementation of this you can reference, it's written for the modulus of the P-256 curve.