add missing files, 2 stage batch pack

This commit is contained in:
cathugger 2019-01-20 00:52:33 +02:00
parent f944bb64a2
commit 8f248cbd14
No known key found for this signature in database
GPG key ID: 9BADDA2DAF6F01A8
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,26 @@
#include "fe25519.h"
// tmp MUST != out
// in MAY == out
void fe25519_batchinvert(fe25519 *out[],fe25519 tmp[],fe25519 * const in[], size_t num)
{
fe25519 acc;
fe25519 tmpacc;
size_t i;
fe25519_setint(&acc,1);
for (i = 0;i < num;++i) {
tmp[i] = acc;
fe25519_mul(&acc,&acc,in[i]);
}
fe25519_invert(&acc,&acc);
i = num;
while (i--) {
fe25519_mul(&tmpacc,&acc,in[i]);
fe25519_mul(out[i],&acc,&tmp[i]);
acc = tmpacc;
}
}

View file

@ -0,0 +1,24 @@
#include "fe25519.h"
#include "ge25519.h"
// assumes inz[] points to things in in[]
// NOTE: leaves in unfinished state
void ge25519_batchpack_destructive_1(bytes32 out[], ge25519_p3 in[], fe25519 *inz[], fe25519 tmp[], size_t num)
{
fe25519 ty;
fe25519_batchinvert(inz, tmp, inz, num);
for (size_t i = 0; i < num; ++i) {
fe25519_mul(&ty, &in[i].y, &in[i].z);
fe25519_pack(out[i], &ty);
}
}
void ge25519_batchpack_destructive_finish(bytes32 out, ge25519_p3 *unf)
{
fe25519 tx;
// z of unfinished is inverted
fe25519_mul(&tx, &unf->x, &unf->z);
out[31] ^= fe25519_getparity(&tx) << 7;
}