MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / DivideByPower2Mod

Function DivideByPower2Mod

src/cryptlib/integer.cpp:1075–1090  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1073// M[N] - modulus
1074
1075void DivideByPower2Mod(word *R, const word *A, unsigned int k, const word *M, unsigned int N)
1076{
1077 CopyWords(R, A, N);
1078
1079 while (k--)
1080 {
1081 if (R[0]%2==0)
1082 ShiftWordsRightByBits(R, N, 1);
1083 else
1084 {
1085 word carry = Add(R, R, M, N);
1086 ShiftWordsRightByBits(R, N, 1);
1087 R[N-1] += carry<<(WORD_BITS-1);
1088 }
1089 }
1090}
1091
1092// R[N] - result = A*(2^k) mod M
1093// A[N] - input

Callers 2

InverseModMethod · 0.85
MultiplicativeInverseMethod · 0.85

Calls 2

CopyWordsFunction · 0.85
ShiftWordsRightByBitsFunction · 0.85

Tested by

no test coverage detected