LCOV - code coverage report
Current view: top level - ballet/bn254 - fd_bn254_internal.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 75 75 100.0 %
Date: 2026-03-19 18:19:27 Functions: 14 28 50.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_ballet_bn254_fd_bn254_internal_h
       2             : #define HEADER_fd_src_ballet_bn254_fd_bn254_internal_h
       3             : 
       4             : #include "./fd_bn254.h"
       5             : 
       6             : /* Base field */
       7             : 
       8             : typedef fd_uint256_t fd_bn254_fp_t;
       9             : 
      10             : /* Extension fields */
      11             : 
      12             : struct FD_ALIGNED fd_bn254_fp2 {
      13             :   fd_bn254_fp_t el[2];
      14             : };
      15             : typedef struct fd_bn254_fp2 fd_bn254_fp2_t;
      16             : 
      17             : struct FD_ALIGNED fd_bn254_fp6 {
      18             :   fd_bn254_fp2_t el[3];
      19             : };
      20             : typedef struct fd_bn254_fp6 fd_bn254_fp6_t;
      21             : 
      22             : struct FD_ALIGNED fd_bn254_fp12 {
      23             :   fd_bn254_fp6_t el[2];
      24             : };
      25             : typedef struct fd_bn254_fp12 fd_bn254_fp12_t;
      26             : 
      27             : /* Point on G1, Jacobian coordinates */
      28             : struct FD_ALIGNED fd_bn254_g1 {
      29             :   fd_bn254_fp_t X;
      30             :   fd_bn254_fp_t Y;
      31             :   fd_bn254_fp_t Z;
      32             : };
      33             : typedef struct fd_bn254_g1 fd_bn254_g1_t;
      34             : 
      35             : /* Point on G2, Jacobian coordinates */
      36             : struct FD_ALIGNED fd_bn254_g2 {
      37             :   fd_bn254_fp2_t X;
      38             :   fd_bn254_fp2_t Y;
      39             :   fd_bn254_fp2_t Z;
      40             : };
      41             : typedef struct fd_bn254_g2 fd_bn254_g2_t;
      42             : 
      43             : /* Field utilities */
      44             : 
      45             : /* const 1. Montgomery.
      46             :    0x0e0a77c19a07df2f666ea36f7879462c0a78eb28f5c70b3dd35d438dc58f0d9d */
      47             : extern const fd_bn254_fp_t fd_bn254_const_one_mont[1];
      48             : 
      49             : static inline int
      50       60357 : fd_bn254_fp_is_zero( fd_bn254_fp_t const * r ) {
      51       60357 :   return r->limbs[0] == 0UL
      52       60357 :       && r->limbs[1] == 0UL
      53       60357 :       && r->limbs[2] == 0UL
      54       60357 :       && r->limbs[3] == 0UL;
      55       60357 : }
      56             : 
      57             : static inline int
      58         319 : fd_bn254_fp_is_one( fd_bn254_fp_t const * r ) {
      59         319 :   return r->limbs[0] == fd_bn254_const_one_mont->limbs[0]
      60         319 :       && r->limbs[1] == fd_bn254_const_one_mont->limbs[1]
      61         319 :       && r->limbs[2] == fd_bn254_const_one_mont->limbs[2]
      62         319 :       && r->limbs[3] == fd_bn254_const_one_mont->limbs[3];
      63         319 : }
      64             : 
      65             : static inline fd_bn254_fp_t *
      66       50248 : fd_bn254_fp_set_zero( fd_bn254_fp_t * r ) {
      67       50248 :   r->limbs[0] = 0UL;
      68       50248 :   r->limbs[1] = 0UL;
      69       50248 :   r->limbs[2] = 0UL;
      70       50248 :   r->limbs[3] = 0UL;
      71       50248 :   return r;
      72       50248 : }
      73             : 
      74             : static inline fd_bn254_fp_t *
      75        4280 : fd_bn254_fp_set_one( fd_bn254_fp_t * r ) {
      76        4280 :   r->limbs[0] = fd_bn254_const_one_mont->limbs[0];
      77        4280 :   r->limbs[1] = fd_bn254_const_one_mont->limbs[1];
      78        4280 :   r->limbs[2] = fd_bn254_const_one_mont->limbs[2];
      79        4280 :   r->limbs[3] = fd_bn254_const_one_mont->limbs[3];
      80        4280 :   return r;
      81        4280 : }
      82             : 
      83             : /* Extension fields utilities */
      84             : 
      85             : static inline int
      86       14963 : fd_bn254_fp2_is_zero( fd_bn254_fp2_t const * a ) {
      87       14963 :   return fd_bn254_fp_is_zero( &a->el[0] )
      88       14963 :       && fd_bn254_fp_is_zero( &a->el[1] );
      89       14963 : }
      90             : 
      91             : static inline int
      92          91 : fd_bn254_fp2_is_one( fd_bn254_fp2_t const * a ) {
      93          91 :   return fd_bn254_fp_is_one ( &a->el[0] )
      94          91 :       && fd_bn254_fp_is_zero( &a->el[1] );
      95          91 : }
      96             : 
      97             : static inline fd_bn254_fp2_t *
      98       24239 : fd_bn254_fp2_set_zero( fd_bn254_fp2_t * r ) {
      99       24239 :   fd_bn254_fp_set_zero( &r->el[0] );
     100       24239 :   fd_bn254_fp_set_zero( &r->el[1] );
     101       24239 :   return r;
     102       24239 : }
     103             : 
     104             : static inline fd_bn254_fp2_t *
     105        1312 : fd_bn254_fp2_set_one( fd_bn254_fp2_t * r ) {
     106        1312 :   fd_bn254_fp_set_one ( &r->el[0] );
     107        1312 :   fd_bn254_fp_set_zero( &r->el[1] );
     108        1312 :   return r;
     109        1312 : }
     110             : 
     111             : /* Fp6 */
     112             : 
     113             : static inline int
     114          52 : fd_bn254_fp6_is_zero( fd_bn254_fp6_t const * a ) {
     115          52 :   return fd_bn254_fp2_is_zero( &a->el[0] )
     116          52 :       && fd_bn254_fp2_is_zero( &a->el[1] )
     117          52 :       && fd_bn254_fp2_is_zero( &a->el[2] );
     118          52 : }
     119             : 
     120             : static inline int
     121          91 : fd_bn254_fp6_is_one( fd_bn254_fp6_t const * a ) {
     122          91 :   return fd_bn254_fp2_is_one ( &a->el[0] )
     123          91 :       && fd_bn254_fp2_is_zero( &a->el[1] )
     124          91 :       && fd_bn254_fp2_is_zero( &a->el[2] );
     125          91 : }
     126             : 
     127             : static inline fd_bn254_fp6_t *
     128         529 : fd_bn254_fp6_set_zero( fd_bn254_fp6_t * r ) {
     129         529 :   fd_bn254_fp2_set_zero( &r->el[0] );
     130         529 :   fd_bn254_fp2_set_zero( &r->el[1] );
     131         529 :   fd_bn254_fp2_set_zero( &r->el[2] );
     132         529 :   return r;
     133         529 : }
     134             : 
     135             : static inline fd_bn254_fp6_t *
     136         530 : fd_bn254_fp6_set_one( fd_bn254_fp6_t * r ) {
     137         530 :   fd_bn254_fp2_set_one ( &r->el[0] );
     138         530 :   fd_bn254_fp2_set_zero( &r->el[1] );
     139         530 :   fd_bn254_fp2_set_zero( &r->el[2] );
     140         530 :   return r;
     141         530 : }
     142             : 
     143             : /* Fp12 */
     144             : 
     145             : // static inline int
     146             : // fd_bn254_fp12_is_zero( fd_bn254_fp12_t const * a ) {
     147             : //   return fd_bn254_fp6_is_zero( &a->el[0] )
     148             : //       && fd_bn254_fp6_is_zero( &a->el[1] );
     149             : // }
     150             : 
     151             : static inline int
     152          91 : fd_bn254_fp12_is_one( fd_bn254_fp12_t const * a ) {
     153          91 :   return fd_bn254_fp6_is_one ( &a->el[0] )
     154          91 :       && fd_bn254_fp6_is_zero( &a->el[1] );
     155          91 : }
     156             : 
     157             : // static inline fd_bn254_fp12_t *
     158             : // fd_bn254_fp12_set_zero( fd_bn254_fp12_t * r ) {
     159             : //   fd_bn254_fp6_set_zero( &r->el[0] );
     160             : //   fd_bn254_fp6_set_zero( &r->el[1] );
     161             : //   return r;
     162             : // }
     163             : 
     164             : static inline fd_bn254_fp12_t *
     165         530 : fd_bn254_fp12_set_one( fd_bn254_fp12_t * r ) {
     166         530 :   fd_bn254_fp6_set_one ( &r->el[0] );
     167         530 :   fd_bn254_fp6_set_zero( &r->el[1] );
     168         530 :   return r;
     169         530 : }
     170             : 
     171             : fd_bn254_fp12_t *
     172             : fd_bn254_fp12_mul( fd_bn254_fp12_t * r,
     173             :                    fd_bn254_fp12_t const * a,
     174             :                    fd_bn254_fp12_t const * b );
     175             : 
     176             : fd_bn254_fp12_t *
     177             : fd_bn254_fp12_inv( fd_bn254_fp12_t * r,
     178             :                    fd_bn254_fp12_t const * a );
     179             : 
     180             : fd_bn254_fp12_t *
     181             : fd_bn254_final_exp( fd_bn254_fp12_t *       r,
     182             :                     fd_bn254_fp12_t * const x );
     183             : 
     184             : fd_bn254_fp12_t *
     185             : fd_bn254_miller_loop( fd_bn254_fp12_t *   r,
     186             :                       fd_bn254_g1_t const p[],
     187             :                       fd_bn254_g2_t const q[],
     188             :                       ulong               sz );
     189             : 
     190             : #endif /* HEADER_fd_src_ballet_bn254_fd_bn254_internal_h */

Generated by: LCOV version 1.14