LCOV - code coverage report
Current view: top level - ballet/ed25519 - fuzz_ed25519_sigverify.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 23 23 100.0 %
Date: 2024-11-13 11:58:15 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #if !FD_HAS_HOSTED
       2             : #error "This target requires FD_HAS_HOSTED"
       3             : #endif
       4             : 
       5             : #include <assert.h>
       6             : #include <stdio.h>
       7             : #include <stdlib.h>
       8             : 
       9             : #include "../../util/fd_util.h"
      10             : #include "../../util/sanitize/fd_fuzz.h"
      11             : #include "fd_ed25519.h"
      12             : 
      13             : int
      14             : LLVMFuzzerInitialize( int  *   argc,
      15          18 :                       char *** argv ) {
      16             :   /* Set up shell without signal handlers */
      17          18 :   putenv( "FD_LOG_BACKTRACE=0" );
      18          18 :   fd_boot( argc, argv );
      19          18 :   atexit( fd_halt );
      20          18 :   return 0;
      21          18 : }
      22             : 
      23             : struct signature_test {
      24             :   uchar prv[ 32 ];
      25             :   uchar msg[ ];
      26             : };
      27             : typedef struct signature_test signature_test_t;
      28             : 
      29             : int
      30             : LLVMFuzzerTestOneInput( uchar const * data,
      31          12 :                         ulong         size ) {
      32          12 :   if( FD_UNLIKELY( size<32UL ) ) return -1;
      33             : 
      34          12 :   signature_test_t * const test = ( signature_test_t * const ) data;
      35          12 :   ulong sz = size-32UL;
      36             : 
      37          12 :   fd_sha512_t _sha[1];
      38          12 :   fd_sha512_t *sha = fd_sha512_join( fd_sha512_new( _sha ) );
      39             : 
      40          12 :   uchar pub[ 32 ];
      41          12 :   fd_ed25519_public_from_private( pub, test->prv, sha );
      42             : 
      43          12 :   uchar sig[ 64 ];
      44          12 :   void * sig_result = fd_ed25519_sign( sig, test->msg, sz, pub, test->prv, sha );
      45          12 :   int cmp = memcmp( ( char * ) sig, ( char * ) sig_result, 64UL );
      46          12 :   assert( cmp == 0 );
      47             : 
      48          12 :   int verify_result = fd_ed25519_verify( test->msg, sz, sig, pub, sha );
      49          12 :   assert( verify_result == FD_ED25519_SUCCESS );
      50             : 
      51          12 :   FD_FUZZ_MUST_BE_COVERED;
      52          12 :   return 0;
      53          12 : }

Generated by: LCOV version 1.14