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-01-19 05:27:37 Functions: 21 28 75.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      486627 : fd_bn254_fp_is_zero( fd_bn254_fp_t const * r ) {
      51      486627 :   return r->limbs[0] == 0UL
      52      486627 :       && r->limbs[1] == 0UL
      53      486627 :       && r->limbs[2] == 0UL
      54      486627 :       && r->limbs[3] == 0UL;
      55      486627 : }
      56             : 
      57             : static inline int
      58        3552 : fd_bn254_fp_is_one( fd_bn254_fp_t const * r ) {
      59        3552 :   return r->limbs[0] == fd_bn254_const_one_mont->limbs[0]
      60        3552 :       && r->limbs[1] == fd_bn254_const_one_mont->limbs[1]
      61        3552 :       && r->limbs[2] == fd_bn254_const_one_mont->limbs[2]
      62        3552 :       && r->limbs[3] == fd_bn254_const_one_mont->limbs[3];
      63        3552 : }
      64             : 
      65             : static inline fd_bn254_fp_t *
      66      512223 : fd_bn254_fp_set_zero( fd_bn254_fp_t * r ) {
      67      512223 :   r->limbs[0] = 0UL;
      68      512223 :   r->limbs[1] = 0UL;
      69      512223 :   r->limbs[2] = 0UL;
      70      512223 :   r->limbs[3] = 0UL;
      71      512223 :   return r;
      72      512223 : }
      73             : 
      74             : static inline fd_bn254_fp_t *
      75      117168 : fd_bn254_fp_set_one( fd_bn254_fp_t * r ) {
      76      117168 :   r->limbs[0] = fd_bn254_const_one_mont->limbs[0];
      77      117168 :   r->limbs[1] = fd_bn254_const_one_mont->limbs[1];
      78      117168 :   r->limbs[2] = fd_bn254_const_one_mont->limbs[2];
      79      117168 :   r->limbs[3] = fd_bn254_const_one_mont->limbs[3];
      80      117168 :   return r;
      81      117168 : }
      82             : 
      83             : /* Extension fields utilities */
      84             : 
      85             : static inline int
      86      116958 : fd_bn254_fp2_is_zero( fd_bn254_fp2_t const * a ) {
      87      116958 :   return fd_bn254_fp_is_zero( &a->el[0] )
      88      116958 :       && fd_bn254_fp_is_zero( &a->el[1] );
      89      116958 : }
      90             : 
      91             : static inline int
      92         390 : fd_bn254_fp2_is_one( fd_bn254_fp2_t const * a ) {
      93         390 :   return fd_bn254_fp_is_one ( &a->el[0] )
      94         390 :       && fd_bn254_fp_is_zero( &a->el[1] );
      95         390 : }
      96             : 
      97             : static inline fd_bn254_fp2_t *
      98      235137 : fd_bn254_fp2_set_zero( fd_bn254_fp2_t * r ) {
      99      235137 :   fd_bn254_fp_set_zero( &r->el[0] );
     100      235137 :   fd_bn254_fp_set_zero( &r->el[1] );
     101      235137 :   return r;
     102      235137 : }
     103             : 
     104             : static inline fd_bn254_fp2_t *
     105       41898 : fd_bn254_fp2_set_one( fd_bn254_fp2_t * r ) {
     106       41898 :   fd_bn254_fp_set_one ( &r->el[0] );
     107       41898 :   fd_bn254_fp_set_zero( &r->el[1] );
     108       41898 :   return r;
     109       41898 : }
     110             : 
     111             : /* Fp6 */
     112             : 
     113             : static inline int
     114         378 : fd_bn254_fp6_is_zero( fd_bn254_fp6_t const * a ) {
     115         378 :   return fd_bn254_fp2_is_zero( &a->el[0] )
     116         378 :       && fd_bn254_fp2_is_zero( &a->el[1] )
     117         378 :       && fd_bn254_fp2_is_zero( &a->el[2] );
     118         378 : }
     119             : 
     120             : static inline int
     121         390 : fd_bn254_fp6_is_one( fd_bn254_fp6_t const * a ) {
     122         390 :   return fd_bn254_fp2_is_one ( &a->el[0] )
     123         390 :       && fd_bn254_fp2_is_zero( &a->el[1] )
     124         390 :       && fd_bn254_fp2_is_zero( &a->el[2] );
     125         390 : }
     126             : 
     127             : static inline fd_bn254_fp6_t *
     128         774 : fd_bn254_fp6_set_zero( fd_bn254_fp6_t * r ) {
     129         774 :   fd_bn254_fp2_set_zero( &r->el[0] );
     130         774 :   fd_bn254_fp2_set_zero( &r->el[1] );
     131         774 :   fd_bn254_fp2_set_zero( &r->el[2] );
     132         774 :   return r;
     133         774 : }
     134             : 
     135             : static inline fd_bn254_fp6_t *
     136         774 : fd_bn254_fp6_set_one( fd_bn254_fp6_t * r ) {
     137         774 :   fd_bn254_fp2_set_one ( &r->el[0] );
     138         774 :   fd_bn254_fp2_set_zero( &r->el[1] );
     139         774 :   fd_bn254_fp2_set_zero( &r->el[2] );
     140         774 :   return r;
     141         774 : }
     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         390 : fd_bn254_fp12_is_one( fd_bn254_fp12_t const * a ) {
     153         390 :   return fd_bn254_fp6_is_one ( &a->el[0] )
     154         390 :       && fd_bn254_fp6_is_zero( &a->el[1] );
     155         390 : }
     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         774 : fd_bn254_fp12_set_one( fd_bn254_fp12_t * r ) {
     166         774 :   fd_bn254_fp6_set_one ( &r->el[0] );
     167         774 :   fd_bn254_fp6_set_zero( &r->el[1] );
     168         774 :   return r;
     169         774 : }
     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