LCOV - code coverage report
Current view: top level - ballet/lthash - fd_lthash.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 17 32 53.1 %
Date: 2026-08-11 04:50:19 Functions: 12 1002 1.2 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_ballet_lthash_fd_lthash_h
       2             : #define HEADER_fd_src_ballet_lthash_fd_lthash_h
       3             : 
       4             : /* LtHash provides APIs for lattice-based incremental hash based on blake3.
       5             :    https://eprint.iacr.org/2019/227
       6             : */
       7             : 
       8             : #include "../blake3/fd_blake3.h"
       9             : 
      10             : #define FD_LTHASH_ALIGN       (64UL) /* sufficient for AVX512 */
      11       27372 : #define FD_LTHASH_LEN_BYTES (2048UL)
      12  1754036375 : #define FD_LTHASH_LEN_ELEMS (1024UL)
      13             : 
      14             : union __attribute__((aligned(FD_LTHASH_ALIGN))) fd_lthash_value {
      15             :   uchar  bytes[FD_LTHASH_LEN_BYTES];
      16             :   ushort words[FD_LTHASH_LEN_ELEMS];
      17             : };
      18             : typedef union fd_lthash_value fd_lthash_value_t;
      19             : 
      20             : FD_PROTOTYPES_BEGIN
      21             : 
      22             : static inline fd_lthash_value_t *
      23             : fd_lthash_fini( fd_blake3_t * sha,
      24           0 :                 fd_lthash_value_t * hash ) {
      25           0 :   return fd_blake3_fini_2048( sha, hash->bytes );
      26           0 : }
      27             : 
      28             : static inline fd_lthash_value_t *
      29       27333 : fd_lthash_zero( fd_lthash_value_t * r ) {
      30       27333 :   return fd_memset( r->bytes, 0, FD_LTHASH_LEN_BYTES );
      31       27333 : }
      32             : 
      33             : static inline int
      34           0 : fd_lthash_is_zero( fd_lthash_value_t const * r ) {
      35           0 :   for ( ulong i=0; i<FD_LTHASH_LEN_ELEMS; i++ ) {
      36           0 :     if( r->words[i] != 0 ) {
      37           0 :       return 0; /* not zero */
      38           0 :     }
      39           0 :   }
      40           0 : 
      41           0 :   return 1;
      42           0 : }
      43             : 
      44             : static inline int
      45             : fd_lthash_eq( fd_lthash_value_t const * a,
      46           0 :               fd_lthash_value_t const * b ) {
      47           0 :   return fd_memeq( a->bytes, b->bytes, FD_LTHASH_LEN_BYTES );
      48           0 : }
      49             : 
      50             : static inline fd_lthash_value_t *
      51             : fd_lthash_add( fd_lthash_value_t * restrict       r,
      52     1697596 :                fd_lthash_value_t const * restrict a ) {
      53  1740035900 :   for ( ulong i=0; i<FD_LTHASH_LEN_ELEMS; i++ ) {
      54  1738338304 :     r->words[i] = (ushort)( r->words[i] + a->words[i] );
      55  1738338304 :   }
      56     1697596 :   return r;
      57     1697596 : }
      58             : 
      59             : static inline fd_lthash_value_t *
      60             : fd_lthash_sub( fd_lthash_value_t * restrict       r,
      61       13659 :                fd_lthash_value_t const * restrict a ) {
      62    14000475 :   for ( ulong i=0; i<FD_LTHASH_LEN_ELEMS; i++ ) {
      63    13986816 :     r->words[i] = (ushort)( r->words[i] - a->words[i] );
      64    13986816 :   }
      65       13659 :   return r;
      66       13659 : }
      67             : 
      68             : FD_PROTOTYPES_END
      69             : 
      70             : #endif /* HEADER_fd_src_ballet_lthash_fd_lthash_h */

Generated by: LCOV version 1.14