80 uint16_t s = (t-1)/160;
82 uint16_t h = t - (160*s);
84 uint16_t hbytes = (h / 8) + (h%8 != 0);
88 uint8_t * Wprime = calloc(s*20+hbytes,
sizeof(uint8_t));
96 sha1(H, seed_bin, 160);
98 memcpy(Wprime, H+(20-hbytes), hbytes);
138 sha1(H, seed_bin, 160);
139 memcpy(Wprime+i*20+hbytes, H, 20);
145 unsigned char Wprime_hex[2*(s*20+hbytes)+1];
146 bin2hex(Wprime, s*20+hbytes, Wprime_hex);
182 number_set_str(bound_h,
"ffffffffffffffffffffffffffffffffffffffff", 16);
183 number_set_str(bound_l,
"1000000000000000000000000000000000000000", 16);
208 uint16_t s = (t-1)/160;
210 uint16_t h = t - (160*s);
212 uint16_t hbytes = (h / 8) + (h%8 != 0);
215 uint8_t * Wprime = calloc(s*20+hbytes,
sizeof(uint8_t));
231 uint8_t seed_bin[20];
234 sha1(H, seed_bin, 160);
236 memcpy(Wprime, H+(20-hbytes), hbytes);
274 sha1(H, seed_bin, 160);
275 memcpy(Wprime+i*20+hbytes, H, 20);
279 unsigned char Wprime_hex[2*(s*20+hbytes)+1];
280 bin2hex(Wprime, s*20+hbytes, Wprime_hex);
311 strcpy(seed_res, seed_hex);
343 const bool is_reduced,
const uint8_t base,
field_srcptr k, uint8_t stack)
509 MPHELL_ASSERT_ALWAYS(
field_elt_cmp(P1->
x, P1->
t, k)==0,
"The point P1 is not a point in a system of Extended Homogenous Projective coordinates");
510 MPHELL_ASSERT_ALWAYS(
field_elt_cmp(P2->
x, P2->
t, k)==0,
"The point P2 is not a point in a system of Extended Homogenous Projective coordinates");
539 MPHELL_ASSERT_ALWAYS(
field_elt_cmp(u, v, k)==0,
"The point P1 is not a point in a system of Extended Homogenous Projective coordinates");
542 MPHELL_ASSERT_ALWAYS(
field_elt_cmp(u, v, k)==0,
"The point P2 is not a point in a system of Extended Homogenous Projective coordinates");
674 field_elt x12, y12, z12, x1y1, f1, f2, temp1;
fp_elt * field_elt
Generic field element.
static bool field_elt_iszero(fe_srcptr src, field_srcptr k)
Test if src is zero.
static void field_elt_mul(fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k, uint8_t stack)
Set dst <- src1 * src2, if Montgomery arithmetic is used, the Montgomery multiplication will be used ...
void drbg_incr_data(uint8_t *data, const uint16_t data_len)
Increment data (Set data to data + 1 where data is an array of data_len bytes)
Declaration of sha1 functions.
uint16_t number_log2(number_srcptr src)
Calculate log2(src), which is the binary size of src.
Define an elliptic curve point.
uint32_t hex2bin(const char *in, unsigned char *out)
Convert an hexadecimal string into a binary string.
static void field_elt_inc(fe_ptr dst, fe_srcptr src, field_srcptr k)
Set dst <- src + 1.
void jacobi_quartic_point_set_neutral(ec_point_ptr dst, ec_curve_srcptr E, uint8_t stack)
Set dst to the neutral element: (0,1,0,1).
uint8_t bits_to_nblock(const uint16_t nbits)
Return the number of blocks required to store a nbits number.
void field_elt_sqrt(fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
Set dst <- src^(1/2)
void jacobi_quartic_point_get_y_affine(field_elt y, ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Convert P->y to its affine representation.
bool jacobi_quartic_point_are_equal(ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Test if P1 and P2 are equal on E.
bool field_elt_isone(fe_srcptr src, field_srcptr k)
Test if src is one.
void number_random1(number_ptr dst, number_srcptr bound, uint8_t stack)
Set dst to a random number_ptr between 0 and bound, the random process is chosen at the MPHELL initia...
bool jacobi_quartic_point_is_neutral(ec_point_srcptr P, ec_curve_srcptr E)
Test if P is the neutral element.
void field_elt_set_one(fe_ptr dst, field_srcptr k)
Set dst to one (or its Montgomery form if Montgomery arithmetic is used)
Declaration of ECC functions.
void field_elt_copy(fe_ptr dst, fe_srcptr src, field_srcptr k)
Copy src into dst, src and dst must belong to the same field.
void jacobi_quartic_point_dbl_dedicated(ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E, uint8_t stack)
Set P3 to 2*P1, using dedicated formulae (not protected against SPA, but faster)
bool field_elt_issquare(fe_srcptr src, field_srcptr k, uint8_t stack)
Test if src is a square using the Lengendre symbol.
void jacobi_quartic_point_set_aff_str(ec_point_ptr P, const char *str_x, const char *str_y, const bool is_reduced, const uint8_t base, field_srcptr k, uint8_t stack)
Set dest to the affine point (str_x,str_y)
const fp_elt * fe_srcptr
Pointer on a field element, the field element cannot be modified through this pointer.
void jacobi_quartic_compute_disc(ec_curve E, uint8_t stack)
Set the discriminant of E: disc = (2^8).(a^2 - 1)^2.
int8_t field_elt_cmp(fe_srcptr src1, fe_srcptr src2, field_srcptr k)
Compare src1 and src2.
void number_tmp_free(number *t, const uint8_t size, uint8_t stack)
Free a temporary number.
void jacobi_quartic_point_norm(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Convert a point in extented projective coordinate (X,Y,T,Z) to an affine point (x,...
void jacobi_quartic_point_set_aff(ec_point_ptr P, fe_srcptr x, fe_srcptr y, field_srcptr k, uint8_t stack)
Set dest to the affine point (x,y)
void jacobi_quartic_point_random(ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Create a random point P on the elliptic curve E.
fp_elt * fe_ptr
Pointer on a field element.
void field_elt_inv(fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
Set dst <- src^(-1)
bool jacobi_quartic_belongs(ec_point_srcptr P, ec_curve_srcptr E, uint8_t stack)
Test if P belongs to E.
void ec_point_copy(ec_point_ptr P3, ec_point_srcptr P, field_srcptr k)
Copy P into P3.
static void field_elt_mul2(fe_ptr dst, fe_srcptr src, field_srcptr k)
Set dst <- 2 * src.
void jacobi_quartic_curve_random_generation(fe_ptr a, char *seed_res, field_srcptr k, uint8_t stack)
Generate a 160 bits seed and coefficients a and b defining a Weiestrass elliptic curve....
void number_set_str(number_ptr dst, const char *str, const uint8_t base)
Set dst to str.
void number_tmp_alloc(number *t, const uint8_t size, uint8_t stack)
Allocate a temporary number.
static void field_elt_neg(fe_ptr dst, fe_srcptr src, field_srcptr k)
Set dst <- (-src)
int8_t number_cmp(number_srcptr src1, number_srcptr src2)
Compare src1 and src2.
Define an elliptic curve.
void field_elt_set_str(fe_ptr dst, const char *str, const uint8_t base, const bool isreduced, field_srcptr k, uint8_t stack)
Set dst to str, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
static void field_elt_sqr(fe_ptr dst, fe_srcptr src, field_srcptr k, uint8_t stack)
Set dst <- src^2.
bool jacobi_quartic_verify_random_generation(ec_curve E, const char *seed, uint8_t stack)
Test if E if generated from the seed "seed".
Primary field parameters.
Declaration of the Deterministic Random Bit Generator internal functions.
void field_elt_set_ui(fe_ptr dst, const block src, const bool isreduced, field_srcptr k, uint8_t stack)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void jacobi_quartic_point_add_unified(ec_point_ptr P3, ec_point_srcptr P1, ec_point_srcptr P2, ec_curve_srcptr E, uint8_t stack)
Set P3 to P1 + P2 using extended projective coordinate (T=(X^2)/Z), and unified formulae (protection ...
void jacobi_quartic_point_neg(ec_point_ptr P3, ec_point_srcptr P1, ec_curve_srcptr E)
Set P3 to -P1.
static void field_elt_sub(fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
Set dst <- src1 - src2.
static void field_elt_relax_pool_elt(field_elt *dst, field_ptr k, uint8_t stack)
Relax an initialised field element from the pool.
static void field_elt_add(fe_ptr dst, fe_srcptr src1, fe_srcptr src2, field_srcptr k)
Set dst <- src1 + src2.
static void field_elt_get_pool_elt(field_elt *dst, field_ptr k, uint8_t stack)
Get an initialised field element from the pool.
Quadratic extension field structure.
void number_str(char **str, number_srcptr src, const uint8_t base)
Converts src to string format in base specified by base.
void field_elt_random(fe_ptr dst, field_srcptr k, uint8_t stack)
Set dst to a random element of k, the random process is chosen at the MHELL initialisation.
void field_elt_set_number(fe_ptr dst, const bool isreduced, field_srcptr k, uint8_t stack, const uint32_t n,...)
Set dst to src, if Montgomery arithmetic is used, is_reduced == false -> transform dst into its Montg...
void jacobi_quartic_point_get_x_affine(field_elt x, ec_point_ptr P, ec_curve_srcptr E, uint8_t stack)
Convert P->x to its affine representation.