LCOV - code coverage report
Current view: top level - ballet/bigint - fd_big_mod_exp.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 3 0.0 %
Date: 2026-10-22 18:10:43 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_ballet_bigint_fd_big_mod_exp_h
       2             : #define HEADER_fd_src_ballet_bigint_fd_big_mod_exp_h
       3             : 
       4             : /* fd_big_mod_exp.h provides big-integer modular exponentiation, the core
       5             :    computation behind the sol_big_mod_exp syscall (SIMD-0529):
       6             : 
       7             :      result = (base ^ exponent) mod modulus
       8             : 
       9             :    All operands (base, exponent, modulus) and the result are encoded as
      10             :    LITTLE-ENDIAN unsigned integers (note: this differs from EIP-198 and
      11             :    the legacy big-endian sol_big_mod_exp).  The modulus MUST be odd and
      12             :    greater than 1. */
      13             : 
      14             : #include "../fd_ballet_base.h"
      15             : 
      16             : /* The syscall caps each operand at 512 bytes. */
      17           0 : #define FD_BIG_MOD_EXP_MAX_BYTES (512UL)
      18             : 
      19           0 : #define FD_BIG_MOD_EXP_SUCCESS     ( 0) /* computed ok */
      20           0 : #define FD_BIG_MOD_EXP_ERR_MODULUS (-1) /* modulus even, zero, or one */
      21             : 
      22             : FD_PROTOTYPES_BEGIN
      23             : 
      24             : /* fd_big_mod_exp_modulus_is_valid returns 1 if the little-endian modulus
      25             :    in mod[0,mod_len) is odd and strictly greater than 1, otherwise 0.
      26             :    (SIMD-0529 requires the modulus to be odd and > 1; even, zero, and one
      27             :    moduli are rejected.) */
      28             : 
      29             : FD_FN_PURE int
      30             : fd_big_mod_exp_modulus_is_valid( uchar const * mod,
      31             :                                  ulong         mod_len );
      32             : 
      33             : /* fd_big_mod_exp computes out := (base ^ exponent) mod modulus.
      34             : 
      35             :    base[0,base_len), exp[0,exp_len), mod[0,mod_len) are the little-endian
      36             :    operands; out receives exactly mod_len little-endian bytes (the result,
      37             :    trailing-zero padded).  base_len, exp_len, mod_len must each be in
      38             :    [0,FD_BIG_MOD_EXP_MAX_BYTES] (mod_len must be >0 for a meaningful
      39             :    result).  out MAY alias any input.
      40             : 
      41             :    Returns FD_BIG_MOD_EXP_SUCCESS on success.  Returns
      42             :    FD_BIG_MOD_EXP_ERR_MODULUS (without writing out) if the modulus is not
      43             :    odd and > 1.
      44             : 
      45             :    Requires an s2n-bignum build (FD_HAS_S2NBIGNUM). */
      46             : 
      47             : int
      48             : fd_big_mod_exp( uchar *       out,
      49             :                 uchar const * base, ulong base_len,
      50             :                 uchar const * exp,  ulong exp_len,
      51             :                 uchar const * mod,  ulong mod_len );
      52             : 
      53             : FD_PROTOTYPES_END
      54             : 
      55             : #endif /* HEADER_fd_src_ballet_bigint_fd_big_mod_exp_h */

Generated by: LCOV version 1.14