diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c index 29822831..86940589 100644 --- a/src/crypto/crypto-ops.c +++ b/src/crypto/crypto-ops.c @@ -30,6 +30,7 @@ #include #include "warnings.h" #include "crypto-ops.h" +#include "hash-ops.h" // for cn_fast_hash DISABLE_VS_WARNINGS(4146 4244) @@ -3724,3 +3725,18 @@ void sc_invert(unsigned char* out, const unsigned char* z) sc_mul(out, out, out); 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 +void ge_bytes_hash_to_ec(ge_p3 *res, const unsigned char *ge_bytes) +{ + unsigned char h[HASH_SIZE]; + ge_p2 point; + ge_p1p1 point2; + + cn_fast_hash(ge_bytes, 32, h); + ge_fromfe_frombytes_vartime(&point, &h[0]); + ge_mul8(&point2, &point); + ge_p1p1_to_p3(res, &point2); +} diff --git a/src/crypto/crypto-ops.h b/src/crypto/crypto-ops.h index f94d5f86..07122772 100644 --- a/src/crypto/crypto-ops.h +++ b/src/crypto/crypto-ops.h @@ -105,6 +105,8 @@ void ge_scalarmult_p3(ge_p3 *, const unsigned char *, const ge_p3 *); void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp); void ge_mul8(ge_p1p1 *, const ge_p2 *); void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *); +void ge_bytes_hash_to_ec(ge_p3 *, const unsigned char *); + void ge_p3_0(ge_p3 *h); void ge_sub(ge_p1p1 *, const ge_p3 *, const ge_cached *); diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index ec93366d..8c51959f 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -303,11 +303,13 @@ namespace crypto { PUSH_VS_WARNINGS DISABLE_VS_WARNINGS(4200) -struct rs_comm_entry -{ - ec_point a, b; -}; - struct rs_comm { + struct rs_comm_entry + { + ec_point a, b; + }; + + struct rs_comm + { hash h; struct rs_comm_entry ab[]; }; @@ -422,4 +424,5 @@ POP_VS_WARNINGS sc_sub(&h, &h, &sum); return sc_isnonzero(&h) == 0; } -} + +} // namespace crypto