Skip to content

Commit

Permalink
crypto: ge_cached_to_p2 implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
sowle committed Dec 27, 2021
1 parent 2ca7c55 commit f2e58da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/crypto/crypto-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ return 0 if f is in {0,2,4,...,q-1}
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*/

static int fe_isnegative(const fe f) {
int fe_isnegative(const fe f) {
unsigned char s[32];
fe_tobytes(s, f);
return s[0] & 1;
Expand All @@ -342,16 +342,6 @@ int fe_isnonzero(const fe f) {
s[27] | s[28] | s[29] | s[30] | s[31]) - 1) >> 8) + 1;
}

int fe_cmp(const fe a, const fe b)
{
for (size_t i = 9; i != SIZE_MAX; --i)
{
if ((const uint32_t)a[i] < (const uint32_t)b[i]) return -1;
if ((const uint32_t)a[i] > (const uint32_t)b[i]) return 1;
}
return 0;
}

/* From fe_mul.c */

/*
Expand Down Expand Up @@ -970,7 +960,7 @@ Can overlap h with f or g.
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*/

static void fe_sub(fe h, const fe f, const fe g) {
void fe_sub(fe h, const fe f, const fe g) {
int32_t f0 = f[0];
int32_t f1 = f[1];
int32_t f2 = f[2];
Expand Down Expand Up @@ -4310,3 +4300,17 @@ void ge_scalarmult_vartime_p3_v2(ge_p3 *r, const unsigned char *a, const ge_p3 *
ge_p1p1_to_p3(r, &t);
}
}


void ge_cached_to_p2(ge_p2 *r, const ge_cached *c)
{
static const fe inv2 = { 10, 0, 0, 0, 0, 0, 0, 0, 0, -16777216 };

fe_sub(r->X, c->YplusX, c->YminusX);
fe_mul(r->X, r->X, inv2);

fe_add(r->Y, c->YplusX, c->YminusX);
fe_mul(r->Y, r->Y, inv2);

fe_copy(r->Z, c->Z);
}
4 changes: 3 additions & 1 deletion src/crypto/crypto-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *);
void ge_p2_to_p3(ge_p3 *r, const ge_p2 *t);
void ge_bytes_hash_to_ec(ge_p3 *, const void *, size_t);
void ge_bytes_hash_to_ec_32(ge_p3 *, const unsigned char *);
void ge_cached_to_p2(ge_p2 *r, const ge_cached *c);

void ge_p3_0(ge_p3 *h);
void ge_sub(ge_p1p1 *, const ge_p3 *, const ge_cached *);
Expand Down Expand Up @@ -138,8 +139,9 @@ void sc_invert(unsigned char*, const unsigned char*);

void fe_sq(fe h, const fe f);
int fe_isnonzero(const fe f);
int fe_cmp(const fe a, const fe b);
void fe_sub(fe h, const fe f, const fe g);
void fe_mul(fe, const fe, const fe);
void fe_frombytes(fe h, const unsigned char *s);
void fe_invert(fe out, const fe z);
void fe_tobytes(unsigned char *s, const fe h);
int fe_isnegative(const fe f);

0 comments on commit f2e58da

Please sign in to comment.