forked from lthn/blockchain
crypto: ge_cached_to_p2 implemented
This commit is contained in:
parent
2ca7c556d9
commit
f2e58daa8c
2 changed files with 19 additions and 13 deletions
|
|
@ -325,7 +325,7 @@ Preconditions:
|
|||
|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;
|
||||
|
|
@ -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 */
|
||||
|
||||
/*
|
||||
|
|
@ -970,7 +960,7 @@ Postconditions:
|
|||
|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];
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 *);
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue