From 8063604b37bb9c4222f7a3210b2d569d20fa2e04 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 14 Jan 2021 23:45:47 +0300 Subject: [PATCH] crypto-ops: ge_p2_to_p3 implemented --- src/crypto/crypto-ops.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c index 86940589..dad60907 100644 --- a/src/crypto/crypto-ops.c +++ b/src/crypto/crypto-ops.c @@ -3726,9 +3726,28 @@ void sc_invert(unsigned char* out, const unsigned char* z) sc_mul(out, out, z); } -// res = Hp(ge_bytes) -// where Hp = 8 * ge_fromfe_frombytes_vartime(cn_fast_hash(ge_bytes)) -// In: ge_bytes -- points to 32 bytes data +/* + In: t (x, y, z) + Out: r (x, t, z, t) + + Note: expensive conversion because of fe_invert +*/ +void ge_p2_to_p3(ge_p3 *r, const ge_p2 *t) +{ + fe_copy(r->X, t->X); + fe_copy(r->Y, t->Y); + fe_copy(r->Z, t->Z); + fe_invert(r->T, t->Z); + fe_mul(r->T, r->T, t->Y); + fe_mul(r->T, r->T, t->X); +} + + +/* + In: ge_bytes -- points to 32 bytes of data + Out: res = Hp(ge_bytes) + where Hp = 8 * ge_fromfe_frombytes_vartime(cn_fast_hash(ge_bytes)) +*/ void ge_bytes_hash_to_ec(ge_p3 *res, const unsigned char *ge_bytes) { unsigned char h[HASH_SIZE]; @@ -3737,6 +3756,7 @@ void ge_bytes_hash_to_ec(ge_p3 *res, const unsigned char *ge_bytes) cn_fast_hash(ge_bytes, 32, h); ge_fromfe_frombytes_vartime(&point, &h[0]); + /*ge_p2_to_p3(res, &point); /* -- can be used to avoid multiplication by 8 for debugging */ ge_mul8(&point2, &point); ge_p1p1_to_p3(res, &point2); }