LCOV - code coverage report
Current view: top level - ballet/bn254 - fd_bn254_g2_inl.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 50 54 92.6 %
Date: 2026-10-18 04:43:39 Functions: 11 18 61.1 %

          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        1206 :                 fd_bn254_g2_t const * q ) {
      11        1206 :   if( fd_bn254_g2_is_zero( p ) ) {
      12          12 :     return fd_bn254_g2_is_zero( q );
      13          12 :   }
      14        1194 :   if( fd_bn254_g2_is_zero( q ) ) {
      15           0 :     return 0;
      16           0 :   }
      17             : 
      18        1194 :   fd_bn254_fp2_t pz2[1], qz2[1];
      19        1194 :   fd_bn254_fp2_t l[1], r[1];
      20             : 
      21        1194 :   fd_bn254_fp2_sqr( pz2, &p->Z );
      22        1194 :   fd_bn254_fp2_sqr( qz2, &q->Z );
      23             : 
      24        1194 :   fd_bn254_fp2_mul( l, &p->X, qz2 );
      25        1194 :   fd_bn254_fp2_mul( r, &q->X, pz2 );
      26        1194 :   if( !fd_bn254_fp2_eq( l, r ) ) {
      27           0 :     return 0;
      28           0 :   }
      29             : 
      30        1194 :   fd_bn254_fp2_mul( l, &p->Y, qz2 );
      31        1194 :   fd_bn254_fp2_mul( l, l, &q->Z );
      32        1194 :   fd_bn254_fp2_mul( r, &q->Y, pz2 );
      33        1194 :   fd_bn254_fp2_mul( r, r, &p->Z );
      34        1194 :   return fd_bn254_fp2_eq( l, r );
      35        1194 : }
      36             : 
      37             : static inline fd_bn254_g2_t *
      38             : fd_bn254_g2_set( fd_bn254_g2_t *       r,
      39       33972 :                  fd_bn254_g2_t const * p ) {
      40       33972 :   fd_bn254_fp2_set( &r->X, &p->X );
      41       33972 :   fd_bn254_fp2_set( &r->Y, &p->Y );
      42       33972 :   fd_bn254_fp2_set( &r->Z, &p->Z );
      43       33972 :   return r;
      44       33972 : }
      45             : 
      46             : static inline fd_bn254_g2_t *
      47             : fd_bn254_g2_neg( fd_bn254_g2_t *       r,
      48         876 :                  fd_bn254_g2_t const * p ) {
      49         876 :   fd_bn254_fp2_set( &r->X, &p->X );
      50         876 :   fd_bn254_fp2_neg( &r->Y, &p->Y );
      51         876 :   fd_bn254_fp2_set( &r->Z, &p->Z );
      52         876 :   return r;
      53         876 : }
      54             : 
      55             : static inline fd_bn254_g2_t *
      56          87 : fd_bn254_g2_set_zero( fd_bn254_g2_t * r ) {
      57             :   // fd_bn254_fp2_set_zero( &r->X );
      58             :   // fd_bn254_fp2_set_zero( &r->Y );
      59          87 :   fd_bn254_fp2_set_zero( &r->Z );
      60          87 :   return r;
      61          87 : }
      62             : 
      63             : static inline fd_bn254_g2_t *
      64             : fd_bn254_g2_frob( fd_bn254_g2_t *       r,
      65        3288 :                   fd_bn254_g2_t const * p ) {
      66        3288 :   fd_bn254_fp2_conj( &r->X, &p->X );
      67        3288 :   fd_bn254_fp2_mul ( &r->X, &r->X, &fd_bn254_const_frob_gamma1_mont[1] );
      68        3288 :   fd_bn254_fp2_conj( &r->Y, &p->Y );
      69        3288 :   fd_bn254_fp2_mul ( &r->Y, &r->Y, &fd_bn254_const_frob_gamma1_mont[2] );
      70        3288 :   fd_bn254_fp2_conj( &r->Z, &p->Z );
      71        3288 :   return r;
      72        3288 : }
      73             : 
      74             : static inline fd_bn254_g2_t *
      75             : fd_bn254_g2_frob2( fd_bn254_g2_t *       r,
      76        2082 :                    fd_bn254_g2_t const * p ) {
      77             :   /* X */
      78        2082 :   fd_bn254_fp_mul( &r->X.el[0], &p->X.el[0], &fd_bn254_const_frob_gamma2_mont[1] );
      79        2082 :   fd_bn254_fp_mul( &r->X.el[1], &p->X.el[1], &fd_bn254_const_frob_gamma2_mont[1] );
      80             :   /* Y */
      81        2082 :   fd_bn254_fp_mul( &r->Y.el[0], &p->Y.el[0], &fd_bn254_const_frob_gamma2_mont[2] );
      82        2082 :   fd_bn254_fp_mul( &r->Y.el[1], &p->Y.el[1], &fd_bn254_const_frob_gamma2_mont[2] );
      83             :   /* Z=1 */
      84        2082 :   fd_bn254_fp2_set( &r->Z, &p->Z );
      85        2082 :   return r;
      86        2082 : }
      87             : 
      88             : #endif /* HEADER_fd_src_ballet_bn254_fd_bn254_g2_inl_h */

Generated by: LCOV version 1.14