void set_identity_tw_extensible(struct tw_extensible_t* a) { p448_set_ui(&a->x, 0); p448_set_ui(&a->y, 1); p448_set_ui(&a->z, 1); p448_set_ui(&a->t, 0); p448_set_ui(&a->u, 0); }
void deserialize_montgomery(struct montgomery_t* a, const struct p448_t* sbz) { p448_sqr(&a->z0, sbz); p448_set_ui(&a->xd, 1); p448_set_ui(&a->zd, 0); p448_set_ui(&a->xa, 1); p448_copy(&a->za, &a->z0); }
void set_identity_affine ( struct affine_t* a ) { p448_set_ui( &a->x, 0 ); p448_set_ui( &a->y, 1 ); }
void twist_even(struct tw_extensible_t* b, const struct extensible_t* a) { mask_t L0, L1; p448_sqr(&b->y, &a->z); p448_sqr(&b->z, &a->x); p448_sub(&b->u, &b->y, &b->z); p448_bias(&b->u, 2); p448_weak_reduce(&b->u); p448_sub(&b->z, &a->z, &a->x); p448_bias(&b->z, 2); p448_weak_reduce(&b->z); p448_mul(&b->y, &b->z, &a->y); p448_sub(&b->z, &a->z, &a->y); p448_bias(&b->z, 2); p448_weak_reduce(&b->z); p448_mul(&b->x, &b->z, &b->y); p448_mul(&b->t, &b->x, &b->u); p448_mul(&b->y, &b->x, &b->t); p448_isr(&b->t, &b->y); p448_mul(&b->u, &b->x, &b->t); p448_sqr(&b->x, &b->t); p448_mul(&b->t, &b->y, &b->x); p448_mul(&b->x, &a->x, &b->u); p448_mul(&b->y, &a->y, &b->u); L1 = p448_is_zero(&b->z); L0 = -L1; p448_addw(&b->y, L0); p448_weak_reduce(&b->y); p448_set_ui(&b->z, 1); p448_copy(&b->t, &b->x); p448_copy(&b->u, &b->y); }
void convert_affine_to_extensible(struct extensible_t* b, const struct affine_t* a) { p448_copy(&b->x, &a->x); p448_copy(&b->y, &a->y); p448_set_ui(&b->z, 1); p448_copy(&b->t, &a->x); p448_copy(&b->u, &a->y); }
void convert_tw_niels_to_tw_extensible(struct tw_extensible_t* e, const struct tw_niels_t* d) { p448_add(&e->y, &d->b, &d->a); p448_weak_reduce(&e->y); p448_sub(&e->x, &d->b, &d->a); p448_bias(&e->x, 2); p448_weak_reduce(&e->x); p448_set_ui(&e->z, 1); p448_copy(&e->t, &e->x); p448_copy(&e->u, &e->y); }
void test_only_twist ( struct tw_extensible_t* b, const struct extensible_t* a ) { mask_t L2, L3; struct p448_t L0, L1; p448_sqr ( &b->u, &a->z ); p448_sqr ( &b->y, &a->x ); p448_sub ( &b->z, &b->u, &b->y ); p448_bias ( &b->z, 2 ); p448_add ( &b->y, &b->z, &b->z ); p448_add ( &b->u, &b->y, &b->y ); IF32( p448_weak_reduce( &b->u ) ); p448_sub ( &b->y, &a->z, &a->x ); p448_bias ( &b->y, 2 ); IF32( p448_weak_reduce( &b->y ) ); p448_mul ( &b->x, &b->y, &a->y ); p448_sub ( &b->z, &a->z, &a->y ); p448_bias ( &b->z, 2 ); IF32( p448_weak_reduce( &b->z ) ); p448_mul ( &b->t, &b->z, &b->x ); p448_mul ( &L1, &b->t, &b->u ); p448_mul ( &b->x, &b->t, &L1 ); p448_isr ( &L0, &b->x ); p448_mul ( &b->u, &b->t, &L0 ); p448_sqr ( &L1, &L0 ); p448_mul ( &b->t, &b->x, &L1 ); p448_add ( &L1, &a->y, &a->x ); IF32( p448_weak_reduce( &L1 ) ); p448_sub ( &L0, &a->x, &a->y ); p448_bias ( &L0, 2 ); IF32( p448_weak_reduce( &L0 ) ); p448_mul ( &b->x, &b->t, &L0 ); p448_add ( &L0, &b->x, &L1 ); p448_sub ( &b->t, &L1, &b->x ); p448_bias ( &b->t, 2 ); IF32( p448_weak_reduce( &b->t ) ); p448_mul ( &b->x, &L0, &b->u ); L2 = p448_is_zero( &b->y ); L3 = - L2; p448_addw ( &b->x, L3 ); p448_weak_reduce( &b->x ); p448_mul ( &b->y, &b->t, &b->u ); L2 = p448_is_zero( &b->z ); L3 = - L2; p448_addw ( &b->y, L3 ); p448_weak_reduce( &b->y ); L3 = p448_is_zero( &a->y ); L2 = L3 + 1; p448_set_ui( &b->z, L2 ); p448_copy ( &b->t, &b->x ); p448_copy ( &b->u, &b->y ); }
mask_t deserialize_and_twist_approx ( struct tw_extensible_t* a, const struct p448_t* sdm1, const struct p448_t* sz ) { struct p448_t L0, L1; p448_sqr ( &a->z, sz ); p448_copy ( &a->y, &a->z ); p448_addw ( &a->y, 1 ); p448_sqr ( &a->x, &a->y ); p448_mulw ( &a->y, &a->x, 39082 ); p448_neg ( &a->x, &a->y ); p448_add ( &a->y, &a->z, &a->z ); p448_bias ( &a->y, 1 ); p448_add ( &a->u, &a->y, &a->y ); p448_add ( &a->y, &a->u, &a->x ); IF32( p448_weak_reduce( &a->y ) ); p448_sqr ( &a->x, &a->z ); p448_subw ( &a->x, 1 ); p448_neg ( &a->u, &a->x ); p448_bias ( &a->u, 2 ); IF32( p448_weak_reduce( &a->u ) ); p448_mul ( &a->x, sdm1, &a->u ); p448_mul ( &L0, &a->x, &a->y ); p448_mul ( &a->t, &L0, &a->y ); p448_mul ( &a->u, &a->x, &a->t ); p448_mul ( &a->t, &a->u, &L0 ); p448_mul ( &a->y, &a->x, &a->t ); p448_isr ( &L0, &a->y ); p448_mul ( &a->y, &a->u, &L0 ); p448_sqr ( &L1, &L0 ); p448_mul ( &a->u, &a->t, &L1 ); p448_mul ( &a->t, &a->x, &a->u ); p448_add ( &a->x, sz, sz ); p448_mul ( &L0, &a->u, &a->x ); p448_copy ( &a->x, &a->z ); p448_subw ( &a->x, 1 ); p448_neg ( &L1, &a->x ); p448_bias ( &L1, 2 ); IF32( p448_weak_reduce( &L1 ) ); p448_mul ( &a->x, &L1, &L0 ); p448_mul ( &L0, &a->u, &a->y ); p448_addw ( &a->z, 1 ); p448_mul ( &a->y, &a->z, &L0 ); p448_subw ( &a->t, 1 ); p448_bias ( &a->t, 1 ); mask_t ret = p448_is_zero( &a->t ); p448_set_ui( &a->z, 1 ); p448_copy ( &a->t, &a->x ); p448_copy ( &a->u, &a->y ); return ret; }
void convert_tw_affine_to_tw_pniels(struct tw_pniels_t* b, const struct tw_affine_t* a) { p448_sub(&b->n.a, &a->y, &a->x); p448_bias(&b->n.a, 2); p448_weak_reduce(&b->n.a); p448_add(&b->n.b, &a->x, &a->y); p448_weak_reduce(&b->n.b); p448_mul(&b->n.c, &a->y, &a->x); p448_mulw(&b->z, &b->n.c, 78164); p448_neg(&b->n.c, &b->z); p448_bias(&b->n.c, 2); p448_weak_reduce(&b->n.c); p448_set_ui(&b->z, 2); }
void test_only_twist(struct tw_extensible_t* b, const struct extensible_t* a) { mask_t L0, L1; struct p448_t L2, L3; p448_sqr(&b->u, &a->z); p448_sqr(&b->y, &a->x); p448_sub(&b->z, &b->u, &b->y); p448_bias(&b->z, 2); p448_add(&b->y, &b->z, &b->z); p448_add(&b->u, &b->y, &b->y); p448_sub(&b->y, &a->z, &a->x); p448_bias(&b->y, 2); p448_mul(&b->x, &b->y, &a->y); p448_sub(&b->z, &a->z, &a->y); p448_bias(&b->z, 2); p448_mul(&b->t, &b->z, &b->x); p448_mul(&L3, &b->t, &b->u); p448_mul(&b->x, &b->t, &L3); p448_isr(&L2, &b->x); p448_mul(&b->u, &b->t, &L2); p448_sqr(&L3, &L2); p448_mul(&b->t, &b->x, &L3); p448_add(&L3, &a->y, &a->x); p448_sub(&L2, &a->x, &a->y); p448_bias(&L2, 2); p448_mul(&b->x, &b->t, &L2); p448_add(&L2, &b->x, &L3); p448_sub(&b->t, &L3, &b->x); p448_bias(&b->t, 2); p448_mul(&b->x, &L2, &b->u); L0 = p448_is_zero(&b->y); L1 = -L0; p448_addw(&b->x, L1); p448_weak_reduce(&b->x); p448_mul(&b->y, &b->t, &b->u); L0 = p448_is_zero(&b->z); L1 = -L0; p448_addw(&b->y, L1); p448_weak_reduce(&b->y); L1 = p448_is_zero(&a->y); L0 = L1 + 1; p448_set_ui(&b->z, L0); p448_copy(&b->t, &b->x); p448_copy(&b->u, &b->y); }