2020-05-15 21:30:37 +02:00
|
|
|
|
|
|
|
const buildTaskManager = require("./taskmanager");
|
2020-06-16 16:45:32 +02:00
|
|
|
const binFileUtils = require("./binfileutils");
|
2020-05-15 21:30:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
This function creates a new section in the fdTo file with id idSection.
|
|
|
|
It multiplies the pooints in fdFrom by first, first*inc, first*inc^2, ....
|
|
|
|
nPoint Times.
|
|
|
|
It also updates the newChallangeHasher with the new points
|
|
|
|
*/
|
|
|
|
|
2020-06-16 16:45:32 +02:00
|
|
|
async function applyKeyToSection(fdOld, sections, fdNew, idSection, curve, groupName, first, inc, sectionName, verbose) {
|
|
|
|
const MAX_CHUNK_SIZE = 1 << 16;
|
|
|
|
const G = curve[groupName];
|
2020-05-15 21:30:37 +02:00
|
|
|
const sG = G.F.n8*2;
|
2020-06-16 16:45:32 +02:00
|
|
|
const nPoints = sections[idSection][0].size / sG;
|
2020-05-15 21:30:37 +02:00
|
|
|
|
2020-06-16 16:45:32 +02:00
|
|
|
await binFileUtils.startReadUniqueSection(fdOld, sections,idSection );
|
|
|
|
await binFileUtils.startWriteSection(fdNew, idSection);
|
2020-05-15 21:30:37 +02:00
|
|
|
|
|
|
|
let t = first;
|
2020-06-16 16:45:32 +02:00
|
|
|
for (let i=0; i<nPoints; i += MAX_CHUNK_SIZE) {
|
|
|
|
if (verbose) console.log(`Applying key: ${sectionName}: ${i}/${nPoints}`);
|
|
|
|
const n= Math.min(nPoints - i, MAX_CHUNK_SIZE);
|
|
|
|
let buff;
|
|
|
|
buff = await fdOld.read(n*sG);
|
|
|
|
buff = await G.batchApplyKey(buff, t, inc);
|
|
|
|
await fdNew.write(buff);
|
2020-05-15 21:30:37 +02:00
|
|
|
t = curve.Fr.mul(t, curve.Fr.pow(inc, n));
|
|
|
|
}
|
|
|
|
|
2020-06-16 16:45:32 +02:00
|
|
|
await binFileUtils.endWriteSection(fdNew);
|
|
|
|
await binFileUtils.endReadSection(fdOld);
|
2020-05-15 21:30:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-16 16:45:32 +02:00
|
|
|
async function applyKeyToBinFile(fdOld, fdNew, curve, groupName, nPoints, first, inc, sectionName, verbose) {
|
2020-05-15 21:30:37 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-16 16:45:32 +02:00
|
|
|
module.exports.applyKeyToBinFile = applyKeyToBinFile;
|
|
|
|
module.exports.applyKeyToSection = applyKeyToSection;
|