| 3733 | // U[N] --- multiplicative inverse of M mod 2**(WORD_BITS*N) |
| 3734 | |
| 3735 | void MontgomeryReduce(word *R, word *T, const word *X, const word *M, |
| 3736 | const word *U, unsigned int N) |
| 3737 | { |
| 3738 | MultiplyBottom(R, T, X, U, N); |
| 3739 | MultiplyTop(T, T+N, X, R, M, N); |
| 3740 | word borrow = Subtract(T, X+N, T, N); |
| 3741 | // defend against timing attack by doing this Add even when not needed |
| 3742 | word carry = Add(T+N, T, M, N); |
| 3743 | (void)carry; // shut up compiler |
| 3744 | CopyWords(R, T + (borrow ? N : 0), N); |
| 3745 | } |
| 3746 | |
| 3747 | // R[N] ----- result = A inverse mod 2**(WORD_BITS*N) |
| 3748 | // T[3*N/2] - temporary work space |
no test coverage detected