turn B;: A = (A * A)% n;
goto s2;
}
2. ext128.cpp
// ==================== 128 bits ariphmetics ================= =
// ===================== 23.05.01 ==== 20.42 =========== =======
// =================== (c) 2001 by A.Bashmakov ============= = Data ​​p>
{a [2]; long b;
} point;
// ---------------------------------------- ------------------------ Mult16 (unsigned *, unsigned *, unsigned *); Div16 (unsigned *, unsigned *, unsigned *, unsigned *) ; Sum16 (unsigned *, unsigned *, unsigned *); Razn16 (unsigned *, unsigned *, unsigned *); Pow_N (unsigned *, unsigned *, unsigned *, unsigned *); ModN (unsigned *, unsigned *);
// ---------------------------------------- ------------------------ Mult16 (unsigned a [9], unsigned b [9], unsigned rez [18])
{//a * b = rez; a & b max 128 bit, rez - 256 bit
unsigned st16 = 0U;
unsigned ml16 = 0U;
unsigned long temp = 0L;
for (int j = 0; j <16; j + +) rez [j] = 0U;
a [8] = 0;
b [8] = 0;
for (j = 0; j <9; j + +)
{
for (int i = 0; i <9; i + +)
{
if (i == 0)
{
rez [9 + j] = st16;
st16 = 0;
}
point.b = (unsigned long) a [i] * (unsigned long) b [j];
ml16 = point.a [0];
temp = (unsigned long) rez [i + j] + (unsigned long) ml16 + st16;
rez [i + j] + = ml16 + st16;
st16 = point.a [1] + (unsigned) (temp>> 16);
if ((j == 8) && (i == 8)) rez [i + j +1] = st16;
}
}
}
// ---------------------------------------- ------------------------ Sum16 (unsigned a [16], unsigned b [16], unsigned rez [16])
{//a + b = rez;
unsigned perepS = 0;
unsigned j = 0;
for (int i = 0; i <8; i + +)
{
point.b = (unsigned long) b [i] + (unsigned long) a [i] + perepS;
rez [j] = point.a [0];
perepS = point.a [1];
j + +;
}
rez [j] = perepS;
}
// ---------------------------------------- ------------------------ ModN (unsigned a [16], ...