crypto/fipsmodule/ec/gfp_p256.c
/* Point addition when b is known to be affine: r = a+b */
Point addition when b is known to be affine: r = a+b
Point addition when b is known to be affine : r = a + b
void GFp_nistz256_point_add_affine(P256_POINT *r, const P256_POINT *a,
                                   const P256_POINT_AFFINE *b) {
  BN_ULONG U2[P256_LIMBS], S2[P256_LIMBS];
  BN_ULONG Z1sqr[P256_LIMBS];
  BN_ULONG H[P256_LIMBS], R[P256_LIMBS];
  BN_ULONG Hsqr[P256_LIMBS];
  BN_ULONG Rsqr[P256_LIMBS];
  BN_ULONG Hcub[P256_LIMBS];
  BN_ULONG res_x[P256_LIMBS];
  BN_ULONG res_y[P256_LIMBS];
  BN_ULONG res_z[P256_LIMBS];
  const BN_ULONG *in1_x = a->X;
  const BN_ULONG *in1_y = a->Y;
  const BN_ULONG *in1_z = a->Z;
  const BN_ULONG *in2_x = b->X;
  const BN_ULONG *in2_y = b->Y;
  BN_ULONG in1infty = is_zero(a->Z);
  BN_ULONG in2infty = is_zero(b->X) & is_zero(b->Y);
  elem_sqr_mont(Z1sqr, in1_z);        
  elem_mul_mont(U2, in2_x, Z1sqr);    
  elem_sub(H, U2, in1_x);             
  elem_mul_mont(S2, Z1sqr, in1_z);    
  elem_mul_mont(res_z, H, in1_z);     
  elem_mul_mont(S2, S2, in2_y);       
  elem_sub(R, S2, in1_y);             
  elem_sqr_mont(Hsqr, H);             
  elem_sqr_mont(Rsqr, R);             
  elem_mul_mont(Hcub, Hsqr, H);       
  elem_mul_mont(U2, in1_x, Hsqr);     
  elem_mul_by_2(Hsqr, U2);            
  elem_sub(res_x, Rsqr, Hsqr);
  elem_sub(res_x, res_x, Hcub);
  elem_sub(H, U2, res_x);
  elem_mul_mont(S2, in1_y, Hcub);
  elem_mul_mont(H, H, R);
  elem_sub(res_y, H, S2);
  copy_conditional(res_x, in2_x, in1infty);
  copy_conditional(res_x, in1_x, in2infty);
  copy_conditional(res_y, in2_y, in1infty);
  copy_conditional(res_y, in1_y, in2infty);
  copy_conditional(res_z, ONE, in1infty);
  copy_conditional(res_z, in1_z, in2infty);
  limbs_copy(r->X, res_x, P256_LIMBS);
  limbs_copy(r->Y, res_y, P256_LIMBS);
  limbs_copy(r->Z, res_z, P256_LIMBS);
}
void GFp_nistz256_point_add_affine ( P256_POINT * r , const P256_POINT * a , const P256_POINT_AFFINE * b ) { BN_ULONG U2 [ P256_LIMBS ] , S2 [ P256_LIMBS ] ; BN_ULONG Z1sqr [ P256_LIMBS ] ; BN_ULONG H [ P256_LIMBS ] , R [ P256_LIMBS ] ; BN_ULONG Hsqr [ P256_LIMBS ] ; BN_ULONG Rsqr [ P256_LIMBS ] ; BN_ULONG Hcub [ P256_LIMBS ] ; BN_ULONG res_x [ P256_LIMBS ] ; BN_ULONG res_y [ P256_LIMBS ] ; BN_ULONG res_z [ P256_LIMBS ] ; const BN_ULONG * in1_x = a -> X ; const BN_ULONG * in1_y = a -> Y ; const BN_ULONG * in1_z = a -> Z ; const BN_ULONG * in2_x = b -> X ; const BN_ULONG * in2_y = b -> Y ; BN_ULONG in1infty = is_zero ( a -> Z ) ; BN_ULONG in2infty = is_zero ( b -> X ) & is_zero ( b -> Y ) ; elem_sqr_mont ( Z1sqr , in1_z ) ; elem_mul_mont ( U2 , in2_x , Z1sqr ) ; elem_sub ( H , U2 , in1_x ) ; elem_mul_mont ( S2 , Z1sqr , in1_z ) ; elem_mul_mont ( res_z , H , in1_z ) ; elem_mul_mont ( S2 , S2 , in2_y ) ; elem_sub ( R , S2 , in1_y ) ; elem_sqr_mont ( Hsqr , H ) ; elem_sqr_mont ( Rsqr , R ) ; elem_mul_mont ( Hcub , Hsqr , H ) ; elem_mul_mont ( U2 , in1_x , Hsqr ) ; elem_mul_by_2 ( Hsqr , U2 ) ; elem_sub ( res_x , Rsqr , Hsqr ) ; elem_sub ( res_x , res_x , Hcub ) ; elem_sub ( H , U2 , res_x ) ; elem_mul_mont ( S2 , in1_y , Hcub ) ; elem_mul_mont ( H , H , R ) ; elem_sub ( res_y , H , S2 ) ; copy_conditional ( res_x , in2_x , in1infty ) ; copy_conditional ( res_x , in1_x , in2infty ) ; copy_conditional ( res_y , in2_y , in1infty ) ; copy_conditional ( res_y , in1_y , in2infty ) ; copy_conditional ( res_z , ONE , in1infty ) ; copy_conditional ( res_z , in1_z , in2infty ) ; limbs_copy ( r -> X , res_x , P256_LIMBS ) ; limbs_copy ( r -> Y , res_y , P256_LIMBS ) ; limbs_copy ( r -> Z , res_z , P256_LIMBS ) ; }
Point addition when b is known to be affine: r = a+b
Point addition when b is known to be affine : r = a + b
/* Z1^2 */ /* U2 = X2*Z1^2 */ /* H = U2 - U1 */ /* S2 = Z1^3 */ /* Z3 = H*Z1*Z2 */ /* S2 = Y2*Z1^3 */ /* R = S2 - S1 */ /* H^2 */ /* R^2 */ /* H^3 */ /* U1*H^2 */ /* 2*U1*H^2 */