LCOV - code coverage report
Current view: top level - ballet/bn254 - fd_bn254_g2_inl.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 52 56 92.9 %
Date: 2026-11-26 02:16:43 Functions: 10 18 55.6 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_ballet_bn254_fd_bn254_g2_inl_h
       2             : #define HEADER_fd_src_ballet_bn254_fd_bn254_g2_inl_h
       3             : 
       4             : /* Small G2 helpers shared by fd_bn254_g2.c and fd_bn254_pairing.c. */
       5             : 
       6             : #include "./fd_bn254_field_inl.h"
       7             : 
       8             : static inline int
       9             : fd_bn254_g2_eq( fd_bn254_g2_t const * p,
      10         332 :                 fd_bn254_g2_t const * q ) {
      11         332 :   if( fd_bn254_g2_is_zero( p ) ) {
      12           0 :     return fd_bn254_g2_is_zero( q );
      13           0 :   }
      14         332 :   if( fd_bn254_g2_is_zero( q ) ) {
      15           0 :     return 0;
      16           0 :   }
      17             : 
      18         332 :   fd_bn254_fp2_t pz2[1], qz2[1];
      19         332 :   fd_bn254_fp2_t l[1], r[1];
      20             : 
      21         332 :   fd_bn254_fp2_sqr( pz2, &p->Z );
      22         332 :   fd_bn254_fp2_sqr( qz2, &q->Z );
      23             : 
      24         332 :   fd_bn254_fp2_mul( l, &p->X, qz2 );
      25         332 :   fd_bn254_fp2_mul( r, &q->X, pz2 );
      26         332 :   if( !fd_bn254_fp2_eq( l, r ) ) {
      27           8 :     return 0;
      28           8 :   }
      29             : 
      30         324 :   fd_bn254_fp2_mul( l, &p->Y, qz2 );
      31         324 :   fd_bn254_fp2_mul( l, l, &q->Z );
      32         324 :   fd_bn254_fp2_mul( r, &q->Y, pz2 );
      33         324 :   fd_bn254_fp2_mul( r, r, &p->Z );
      34         324 :   return fd_bn254_fp2_eq( l, r );
      35         332 : }
      36             : 
      37             : static inline fd_bn254_g2_t *
      38             : fd_bn254_g2_set( fd_bn254_g2_t *       r,
      39         972 :                  fd_bn254_g2_t const * p ) {
      40         972 :   fd_bn254_fp2_set( &r->X, &p->X );
      41         972 :   fd_bn254_fp2_set( &r->Y, &p->Y );
      42         972 :   fd_bn254_fp2_set( &r->Z, &p->Z );
      43         972 :   return r;
      44         972 : }
      45             : 
      46             : static inline fd_bn254_g2_t *
      47             : fd_bn254_g2_neg( fd_bn254_g2_t *       r,
      48         265 :                  fd_bn254_g2_t const * p ) {
      49         265 :   fd_bn254_fp2_set( &r->X, &p->X );
      50         265 :   fd_bn254_fp2_neg( &r->Y, &p->Y );
      51         265 :   fd_bn254_fp2_set( &r->Z, &p->Z );
      52         265 :   return r;
      53         265 : }
      54             : 
      55             : static inline fd_bn254_g2_t *
      56          39 : fd_bn254_g2_set_zero( fd_bn254_g2_t * r ) {
      57          39 :   fd_bn254_fp2_set_zero( &r->X );
      58          39 :   fd_bn254_fp2_set_zero( &r->Y );
      59          39 :   fd_bn254_fp2_set_zero( &r->Z );
      60          39 :   return r;
      61          39 : }
      62             : 
      63             : static inline fd_bn254_g2_t *
      64             : fd_bn254_g2_frob( fd_bn254_g2_t *       r,
      65         929 :                   fd_bn254_g2_t const * p ) {
      66         929 :   fd_bn254_fp2_conj( &r->X, &p->X );
      67         929 :   fd_bn254_fp2_mul ( &r->X, &r->X, &fd_bn254_const_frob_gamma1_mont[1] );
      68         929 :   fd_bn254_fp2_conj( &r->Y, &p->Y );
      69         929 :   fd_bn254_fp2_mul ( &r->Y, &r->Y, &fd_bn254_const_frob_gamma1_mont[2] );
      70         929 :   fd_bn254_fp2_conj( &r->Z, &p->Z );
      71         929 :   return r;
      72         929 : }
      73             : 
      74             : static inline fd_bn254_g2_t *
      75             : fd_bn254_g2_frob2( fd_bn254_g2_t *       r,
      76         597 :                    fd_bn254_g2_t const * p ) {
      77             :   /* X */
      78         597 :   fd_bn254_fp_mul( &r->X.el[0], &p->X.el[0], &fd_bn254_const_frob_gamma2_mont[1] );
      79         597 :   fd_bn254_fp_mul( &r->X.el[1], &p->X.el[1], &fd_bn254_const_frob_gamma2_mont[1] );
      80             :   /* Y */
      81         597 :   fd_bn254_fp_mul( &r->Y.el[0], &p->Y.el[0], &fd_bn254_const_frob_gamma2_mont[2] );
      82         597 :   fd_bn254_fp_mul( &r->Y.el[1], &p->Y.el[1], &fd_bn254_const_frob_gamma2_mont[2] );
      83             :   /* Z=1 */
      84         597 :   fd_bn254_fp2_set( &r->Z, &p->Z );
      85         597 :   return r;
      86         597 : }
      87             : 
      88             : #endif /* HEADER_fd_src_ballet_bn254_fd_bn254_g2_inl_h */

Generated by: LCOV version 1.14