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

          Line data    Source code
       1             : #if !FD_HAS_HOSTED
       2             : #error "This target requires FD_HAS_HOSTED"
       3             : #endif
       4             : 
       5             : #include <stdio.h>
       6             : #include <stdlib.h>
       7             : 
       8             : #include "../../util/fd_util.h"
       9             : #include "fd_secp256k1.h"
      10             : 
      11             : int
      12             : LLVMFuzzerInitialize( int  *   argc,
      13          18 :                       char *** argv ) {
      14             :   /* Set up shell without signal handlers */
      15          18 :   putenv( "FD_LOG_BACKTRACE=0" );
      16          18 :   fd_boot( argc, argv );
      17          18 :   atexit( fd_halt );
      18          18 :   return 0;
      19          18 : }
      20             : 
      21             : struct verification_test {
      22             :   uchar msg[ 32 ];
      23             :   uchar sig[ 64 ];
      24             :   uchar pub[ 64 ];
      25             : };
      26             : typedef struct verification_test verification_test_t;
      27             : 
      28             : int
      29             : LLVMFuzzerTestOneInput( uchar const * data,
      30             :                         ulong         size ) {
      31             :   if( FD_UNLIKELY( size<sizeof(verification_test_t) ) ) return -1;
      32             : 
      33             :   verification_test_t * const test = ( verification_test_t * const ) data;
      34             :   uchar _pub[ 64 ]; uchar * pub = _pub;
      35             : 
      36             :   for ( int recid=0; recid<=3; recid++ ) {
      37             :     void * res = fd_secp256k1_recover(pub, test->msg, test->sig, recid);
      38             :     if ( FD_UNLIKELY( res != NULL && !memcmp( pub, test->pub, 64UL ) ) ) {
      39             :       // was able to verify fuzz input
      40             :       __builtin_trap();
      41             :     }
      42             :   }
      43             : 
      44             :   return 0;
      45             : }

Generated by: LCOV version 1.14