#include "platform.h"
#include "gnunet_common.h"
#include <gcrypt.h>
#include <sodium.h>
#include "gnunet_util_lib.h"
#include "benchmark.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <gmp.h>
#include <limits.h>
Go to the source code of this file.
Macros | |
#define | P_BITS (256) |
#define | P_BYTES ((P_BITS + CHAR_BIT - 1) / CHAR_BIT) |
#define | P_LIMBS ((P_BITS + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS) |
Functions | |
static void | decode_bytes (mp_limb_t *number, const uint8_t *bytes) |
This function decodes the byte buffer into the MPI limb. More... | |
static void | encode_bytes (uint8_t *bytes, mp_limb_t *number) |
This function encodes the MPI limb into a byte buffer. More... | |
void | GNUNET_CRYPTO_ecdhe_elligator_initialize (void) |
void | __attribute__ ((constructor)) |
Initialize elligator scratch space. More... | |
static void | least_square_root (mp_limb_t *root, const mp_limb_t *number, mp_limb_t *scratch_space) |
Calculates the root of a given number. More... | |
bool | GNUNET_CRYPTO_ecdhe_elligator_encoding (uint8_t random_tweak, struct GNUNET_CRYPTO_ElligatorRepresentative *r, const struct GNUNET_CRYPTO_EcdhePublicKey *pub) |
Encodes a point on Curve25519 to a an element of the underlying finite field. More... | |
static bool | elligator_direct_map (uint8_t *point, bool *high_y, uint8_t *representative) |
Takes a number of the underlying finite field of Curve25519 and projects it into a valid point on that curve. More... | |
void | GNUNET_CRYPTO_ecdhe_elligator_decoding (struct GNUNET_CRYPTO_EcdhePublicKey *point, bool *high_y, const struct GNUNET_CRYPTO_ElligatorRepresentative *representative) |
Clears the most significant bit and second most significant bit of the serialized representaive before applying elligator direct map. More... | |
static bool | convert_from_ed_to_curve (uint8_t *point, const uint8_t *source) |
Takes a number of the underlying finite field of Curve25519 and projects it into a valid point on that curve. More... | |
static enum GNUNET_GenericReturnValue | elligator_generate_public_key (const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *pub) |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand (uint8_t random_tweak, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk, struct GNUNET_CRYPTO_EcdhePublicKey *pk, struct GNUNET_CRYPTO_ElligatorRepresentative *repr) |
Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_ecdhe_elligator_key_get_public (const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk, struct GNUNET_CRYPTO_EcdhePublicKey *pk, struct GNUNET_CRYPTO_ElligatorRepresentative *repr) |
Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point. More... | |
void | GNUNET_CRYPTO_ecdhe_elligator_key_create (struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk) |
Generates a private key for Curve25519. More... | |
Variables | |
static const uint8_t | lookupTable [8][crypto_scalarmult_SCALARBYTES] |
static const unsigned char | p_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | negative_1_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | negative_2_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | divide_negative_1_2_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | divide_plus_p_3_8_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | divide_minus_p_1_2_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | square_root_negative_1_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | A_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | negative_A_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | u_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | inverted_u_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static const unsigned char | d_bytes [(((256)+CHAR_BIT - 1)/CHAR_BIT)] |
static mp_limb_t | p [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | negative_1 [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | negative_2 [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | divide_negative_1_2 [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | divide_plus_p_3_8 [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | divide_minus_p_1_2 [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | square_root_negative_1 [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | A [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | negative_A [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | u [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | inverted_u [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_limb_t | d [(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)] |
static mp_size_t | scratch_space_length |
#define P_BITS (256) |
Definition at line 92 of file crypto_elligator.c.
#define P_BYTES ((P_BITS + CHAR_BIT - 1) / CHAR_BIT) |
Definition at line 93 of file crypto_elligator.c.
#define P_LIMBS ((P_BITS + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS) |
Definition at line 94 of file crypto_elligator.c.
|
static |
This function decodes the byte buffer into the MPI limb.
number | decoded number |
bytes | input bytes to decode into number |
Definition at line 205 of file crypto_elligator.c.
References number, P_BYTES, and P_LIMBS.
Referenced by __attribute__(), convert_from_ed_to_curve(), elligator_direct_map(), and GNUNET_CRYPTO_ecdhe_elligator_encoding().
|
static |
This function encodes the MPI limb into a byte buffer.
bytes | output bytes |
number | number to encode |
Definition at line 225 of file crypto_elligator.c.
References number, P_BYTES, and P_LIMBS.
Referenced by convert_from_ed_to_curve(), elligator_direct_map(), and GNUNET_CRYPTO_ecdhe_elligator_encoding().
void GNUNET_CRYPTO_ecdhe_elligator_initialize | ( | void | ) |
void __attribute__ | ( | (constructor) | ) |
Initialize elligator scratch space.
Definition at line 239 of file crypto_elligator.c.
References A, A_bytes, d, d_bytes, decode_bytes(), divide_minus_p_1_2, divide_minus_p_1_2_bytes, divide_negative_1_2, divide_negative_1_2_bytes, divide_plus_p_3_8, divide_plus_p_3_8_bytes, initialized, inverted_u, inverted_u_bytes, negative_1, negative_1_bytes, negative_2, negative_2_bytes, negative_A, negative_A_bytes, p, P_BITS, p_bytes, P_LIMBS, scratch_space_length, square_root_negative_1, square_root_negative_1_bytes, u, and u_bytes.
|
static |
Calculates the root of a given number.
Returns trash if the number is a quadratic non-residue.
root | storage for calculated root |
number | value for which the root is calculated |
scratch_space | buffer for calculation |
Definition at line 320 of file crypto_elligator.c.
References divide_minus_p_1_2, divide_plus_p_3_8, number, p, P_BITS, P_LIMBS, and square_root_negative_1.
Referenced by GNUNET_CRYPTO_ecdhe_elligator_encoding().
|
static |
Takes a number of the underlying finite field of Curve25519 and projects it into a valid point on that curve.
This function works deterministically. This step is also known as elligators "decoding" step. Taken from https://github.com/Kleshni/Elligator-2/blob/master/main.c.
point | storage for calculated point on Curve25519 |
high_y | The 'high_y' argument of the corresponding GNUNET_CRYPTO_ecdhe_elligator_encoding call |
representative | Given representative |
Definition at line 447 of file crypto_elligator.c.
References A, decode_bytes(), divide_minus_p_1_2, encode_bytes(), negative_2, negative_A, p, P_BITS, P_LIMBS, result, scratch_space_length, and u.
Referenced by GNUNET_CRYPTO_ecdhe_elligator_decoding().
|
static |
Takes a number of the underlying finite field of Curve25519 and projects it into a valid point on that curve.
This function works deterministically. This step is also known as elligators "decoding" step. Taken from https://github.com/Kleshni/Elligator-2/blob/master/main.c.
point | storage for calculated point on Curve25519 |
source | Ed25519 curve point |
Definition at line 542 of file crypto_elligator.c.
References d, decode_bytes(), divide_minus_p_1_2, divide_negative_1_2, encode_bytes(), negative_1, negative_2, p, P_BITS, P_BYTES, P_LIMBS, result, scratch_space_length, and source.
Referenced by elligator_generate_public_key().
|
static |
Definition at line 609 of file crypto_elligator.c.
References convert_from_ed_to_curve(), GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, lookupTable, pk, pub, and GNUNET_CRYPTO_EddsaPublicKey::q_y.
Referenced by GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand().
|
static |
Definition at line 42 of file crypto_elligator.c.
Referenced by elligator_generate_public_key().
|
static |
Definition at line 98 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 105 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 112 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 119 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 126 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 133 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 140 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 147 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 154 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 161 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 168 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 175 of file crypto_elligator.c.
Referenced by __attribute__().
|
static |
Definition at line 182 of file crypto_elligator.c.
Referenced by __attribute__(), convert_from_ed_to_curve(), elligator_direct_map(), GNUNET_CRYPTO_ecdhe_elligator_encoding(), and least_square_root().
|
static |
Definition at line 183 of file crypto_elligator.c.
Referenced by __attribute__(), and convert_from_ed_to_curve().
|
static |
Definition at line 184 of file crypto_elligator.c.
Referenced by __attribute__(), convert_from_ed_to_curve(), elligator_direct_map(), and GNUNET_CRYPTO_ecdhe_elligator_encoding().
|
static |
Definition at line 185 of file crypto_elligator.c.
Referenced by __attribute__(), and convert_from_ed_to_curve().
|
static |
Definition at line 186 of file crypto_elligator.c.
Referenced by __attribute__(), and least_square_root().
|
static |
Definition at line 187 of file crypto_elligator.c.
Referenced by __attribute__(), convert_from_ed_to_curve(), elligator_direct_map(), and least_square_root().
|
static |
Definition at line 188 of file crypto_elligator.c.
Referenced by __attribute__(), and least_square_root().
|
static |
Definition at line 189 of file crypto_elligator.c.
Referenced by __attribute__(), elligator_direct_map(), and GNUNET_CRYPTO_ecdhe_elligator_encoding().
|
static |
Definition at line 190 of file crypto_elligator.c.
Referenced by __attribute__(), and elligator_direct_map().
|
static |
Definition at line 191 of file crypto_elligator.c.
Referenced by __attribute__(), _nss_gns_gethostbyname2_r(), bind_abstime(), bind_nbotime(), bind_u16(), bind_u32(), bind_u64(), compute_scalar_product(), elligator_direct_map(), encrypt_fair(), extract_abs_time(), extract_abs_time_nbo(), extract_uint16(), extract_uint32(), extract_uint64(), GDS_u_connect(), GDS_u_drop(), GDS_u_hold(), GDS_u_send(), GDS_u_try_connect(), getopt_set_keywords(), gns_resolve_name(), GNUNET_uri_parse(), load_underlay(), qconv_abs_time(), qconv_rel_time(), shutdown_task(), u_address_add(), and update_network_size_estimate().
|
static |
Definition at line 192 of file crypto_elligator.c.
Referenced by __attribute__(), and GNUNET_CRYPTO_ecdhe_elligator_encoding().
|
static |
Definition at line 193 of file crypto_elligator.c.
Referenced by __attribute__(), compute_lagrange_coefficient(), convert_from_ed_to_curve(), decode_private_ecdsa_key(), decrypt_new_element(), diff_create(), feed_buffer_to_gst(), GCCH_handle_channel_plaintext_data(), get_app(), get_audiobin(), get_coder(), get_delay_randomization(), gg_load_configuration(), gg_setup_gst_bus(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_FS_indexing_init(), GNUNET_hton_double(), GNUNET_memcmp_ct_(), GNUNET_ntoh_double(), gnunet_read(), GNUNET_TIME_randomize(), insert_decrypt_element(), insert_round1_element(), insert_round2_element(), keygen_reveal_get_enc_preshare(), keygen_reveal_get_exp_coeff(), keygen_reveal_get_exp_preshare(), keygen_round1_new_element(), keygen_round2_new_element(), num_to_regex(), on_appsink_new_sample(), and state_changed_cb().
|
static |
Definition at line 195 of file crypto_elligator.c.
Referenced by __attribute__(), convert_from_ed_to_curve(), elligator_direct_map(), and GNUNET_CRYPTO_ecdhe_elligator_encoding().