MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / MontgomeryReduce

Function MontgomeryReduce

extra/yassl/taocrypt/src/integer.cpp:3735–3745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3733// U[N] --- multiplicative inverse of M mod 2**(WORD_BITS*N)
3734
3735void 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

Callers 2

AddMethod · 0.85
ConvertOutMethod · 0.85

Calls 3

MultiplyBottomFunction · 0.85
MultiplyTopFunction · 0.85
CopyWordsFunction · 0.85

Tested by

no test coverage detected