Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/modules/multiset/main_impl.h
Show All 14 Lines | |||||
#include "group.h" | #include "group.h" | ||||
/** Converts a group element (Jacobian) to a multiset. | /** Converts a group element (Jacobian) to a multiset. | ||||
* Requires the field elements to be normalized | * Requires the field elements to be normalized | ||||
* Infinite uses special value, z = 0 | * Infinite uses special value, z = 0 | ||||
*/ | */ | ||||
static void multiset_from_gej_var(secp256k1_multiset *target, const secp256k1_gej *input) { | static void multiset_from_gej_var(secp256k1_multiset *target, const secp256k1_gej *input) { | ||||
if (input->infinity) { | if (input->infinity) { | ||||
memset(&target->d, 0, sizeof(target->d)); | memset(&target->data, 0, sizeof(target->data)); | ||||
} else { | } else { | ||||
secp256k1_fe_get_b32(target->d, &input->x); | secp256k1_fe_get_b32(target->data, &input->x); | ||||
secp256k1_fe_get_b32(target->d+32, &input->y); | secp256k1_fe_get_b32(target->data+32, &input->y); | ||||
secp256k1_fe_get_b32(target->d+64, &input->z); | secp256k1_fe_get_b32(target->data+64, &input->z); | ||||
} | } | ||||
} | } | ||||
/** Converts a multiset to group element (Jacobian) | /** Converts a multiset to group element (Jacobian) | ||||
* Infinite uses special value, z = 0 | * Infinite uses special value, z = 0 | ||||
*/ | */ | ||||
static void gej_from_multiset_var(secp256k1_gej *target, const secp256k1_multiset *input) { | static void gej_from_multiset_var(secp256k1_gej *target, const secp256k1_multiset *input) { | ||||
secp256k1_fe_set_b32(&target->x, input->d); | secp256k1_fe_set_b32(&target->x, input->data); | ||||
secp256k1_fe_set_b32(&target->y, input->d+32); | secp256k1_fe_set_b32(&target->y, input->data+32); | ||||
secp256k1_fe_set_b32(&target->z, input->d+64); | secp256k1_fe_set_b32(&target->z, input->data+64); | ||||
target->infinity = secp256k1_fe_is_zero(&target->z) ? 1 : 0; | target->infinity = secp256k1_fe_is_zero(&target->z) ? 1 : 0; | ||||
} | } | ||||
/** Converts a data element to a group element (affine) | /** Converts a data element to a group element (affine) | ||||
* | * | ||||
* We use trial-and-rehash which is fast but non-constant time. | * We use trial-and-rehash which is fast but non-constant time. | ||||
* Though constant time algo's exist we are not concerned with timing attacks | * Though constant time algo's exist we are not concerned with timing attacks | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | static int multiset_add_remove(const secp256k1_context* ctx, secp256k1_multiset *multiset, const unsigned char *input, size_t inputLen, int remove) { | ||||
VERIFY_CHECK(ctx != NULL); | VERIFY_CHECK(ctx != NULL); | ||||
ARG_CHECK(multiset != NULL); | ARG_CHECK(multiset != NULL); | ||||
ARG_CHECK(input != NULL); | ARG_CHECK(input != NULL); | ||||
gej_from_multiset_var(&source, multiset); | gej_from_multiset_var(&source, multiset); | ||||
ge_from_data_var(&newelm, input, inputLen, remove); | ge_from_data_var(&newelm, input, inputLen, remove); | ||||
secp256k1_gej_clear(&target); | |||||
secp256k1_gej_add_ge_var(&target, &source, &newelm, NULL); | secp256k1_gej_add_ge_var(&target, &source, &newelm, NULL); | ||||
secp256k1_fe_normalize(&target.x); | secp256k1_fe_normalize(&target.x); | ||||
secp256k1_fe_normalize(&target.y); | secp256k1_fe_normalize(&target.y); | ||||
secp256k1_fe_normalize(&target.z); | secp256k1_fe_normalize(&target.z); | ||||
multiset_from_gej_var(multiset, &target); | multiset_from_gej_var(multiset, &target); | ||||
return 1; | return 1; | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |