-
-
Save CodesInChaos/ef914909941ce7caf514 to your computer and use it in GitHub Desktop.
Computes the Ed25519 Base lookup table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ge_cached_to_precomp(out GroupElementPreComp preComp, ref GroupElementCached cached) | |
{ | |
FieldElement invDenominator; | |
FieldOperations.fe_invert(out invDenominator, ref cached.Z); | |
FieldOperations.fe_mul(out preComp.yminusx, ref cached.YminusX, ref invDenominator); | |
FieldOperations.fe_mul(out preComp.yplusx, ref cached.YplusX, ref invDenominator); | |
FieldOperations.fe_mul(out preComp.xy2d, ref cached.T2d, ref invDenominator); | |
} | |
private static GroupElementPreComp[] ComputeLine(ref GroupElementCached b) | |
{ | |
var result = new GroupElementPreComp[8]; | |
GroupElementP3 p3; | |
GroupOperations.ge_p3_0(out p3); | |
for (int j = 0; j < 8; j++) | |
{ | |
GroupElementP1P1 p1p1; | |
GroupElementCached cached; | |
GroupOperations.ge_add(out p1p1, ref p3, ref b); | |
GroupOperations.ge_p1p1_to_p3(out p3, ref p1p1); | |
GroupOperations.ge_p3_to_cached(out cached, ref p3); | |
ge_cached_to_precomp(out result[j], ref cached); | |
} | |
return result; | |
} | |
internal static GroupElementPreComp[][] ComputeTable(ref GroupElementCached b) | |
{ | |
var result = new GroupElementPreComp[32][]; | |
GroupElementP3 p3; | |
GroupElementP2 p2; | |
GroupElementP1P1 p1p1; | |
GroupElementCached cached; | |
GroupOperations.ge_p3_0(out p3); | |
GroupOperations.ge_add(out p1p1, ref p3, ref b); | |
GroupOperations.ge_p1p1_to_p3(out p3, ref p1p1); | |
for (int i = 0; i < 32; i++) | |
{ | |
GroupOperations.ge_p3_to_cached(out cached, ref p3); | |
result[i] = ComputeLine(ref cached); | |
GroupOperations.ge_p3_to_p2(out p2, ref p3); | |
for (int k = 0; k < 7; k++) | |
{ | |
GroupOperations.ge_p2_dbl(out p1p1, ref p2); | |
GroupOperations.ge_p1p1_to_p2(out p2, ref p1p1); | |
} | |
GroupOperations.ge_p2_dbl(out p1p1, ref p2); | |
GroupOperations.ge_p1p1_to_p3(out p3, ref p1p1); | |
} | |
return result; | |
} | |
internal static GroupElementPreComp[][] ComputeTable() | |
{ | |
GroupElementCached cached; | |
cached.YplusX = new FieldElement(25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605); | |
cached.YminusX = new FieldElement(-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378); | |
cached.T2d = new FieldElement(-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546); | |
FieldOperations.fe_1(out cached.Z); | |
var result = ComputeTable(ref cached); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment