LCOV - code coverage report
Current view: top level - disco/keyguard - fd_keyguard_client.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 1 3 33.3 %
Date: 2025-09-19 04:41:14 Functions: 1 342 0.3 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_disco_keyguard_fd_keyguard_client_h
       2             : #define HEADER_fd_src_disco_keyguard_fd_keyguard_client_h
       3             : 
       4             : /* A simple blocking client to a remote signing server, based on a pair
       5             :    of (input, output) mcaches and data regions.
       6             : 
       7             :    For maximum security, the caller should ensure a few things before
       8             :    using,
       9             : 
      10             :     (a) The request mcache and data region are placed in a shared memory
      11             :         map that is accessible exclusively to the calling tile, and the
      12             :         keyguard tile.  The keyguard tile should map the memory as read
      13             :         only.
      14             : 
      15             :     (b) The response mcache and data region are placed in a shared
      16             :         memory map that is accessible exclusively to the calling tile,
      17             :         and the keyguard tile.  The calling tile should map the memory
      18             :         as read only.
      19             : 
      20             :     (c) No other data is placed in these shared memory maps, and no
      21             :         other tiles have access to them.
      22             : 
      23             :     (d) Each input/output mcache correspond to a single role, and the
      24             :         keyguard tile verifies that all incoming requests are
      25             :         specifically formatted for that role. */
      26             : 
      27             : #include "../../tango/fd_tango_base.h"
      28             : 
      29             : #define FD_KEYGUARD_CLIENT_ALIGN (128UL)
      30             : #define FD_KEYGUARD_CLIENT_FOOTPRINT (128UL)
      31             : 
      32             : struct __attribute__((aligned(FD_KEYGUARD_CLIENT_ALIGN))) fd_keyguard_client {
      33             :   fd_frag_meta_t * request;
      34             :   ulong            request_seq;
      35             :   ulong            request_depth;
      36             :   fd_wksp_t *      request_mem;
      37             :   ulong            request_chunk;
      38             :   ulong            request_chunk0;
      39             :   ulong            request_wmark;
      40             :   ulong            request_mtu;
      41             : 
      42             :   fd_frag_meta_t * response;
      43             :   ulong            response_seq;
      44             :   ulong            response_depth;
      45             :   fd_wksp_t *      response_mem;
      46             :   ulong            response_chunk0;
      47             :   ulong            response_wmark;
      48             : };
      49             : typedef struct fd_keyguard_client fd_keyguard_client_t;
      50             : 
      51             : FD_PROTOTYPES_BEGIN
      52             : 
      53             : void *
      54             : fd_keyguard_client_new( void *           shmem,
      55             :                         fd_frag_meta_t * request_mcache,
      56             :                         uchar *          request_dcache,
      57             :                         fd_frag_meta_t * response_mcache,
      58             :                         uchar *          response_dcache,
      59             :                         ulong            request_mtu );
      60             : 
      61             : static inline fd_keyguard_client_t *
      62          30 : fd_keyguard_client_join( void * shclient ) { return (fd_keyguard_client_t*)shclient; }
      63             : 
      64             : static inline void *
      65           0 : fd_keyguard_client_leave( fd_keyguard_client_t * client ) { return (void*)client; }
      66             : 
      67             : static inline void *
      68           0 : fd_keyguard_client_delete( void * shclient ) { return shclient; }
      69             : 
      70             : /* fd_keyguard_client_sign sends a remote signing request to the signing
      71             :     server, and blocks (spins) until the response is received.
      72             : 
      73             :     Signing is treated as infallible, and there are no error codes or
      74             :     results. If the remote signer is stuck or not running, this function
      75             :     will not timeout and instead hangs forever waiting for a response.
      76             :     This is currently by design.
      77             : 
      78             :     sign_data should be a pointer to a buffer, with length sign_data_len
      79             :     that will be signed.  The data should correspond to one of the
      80             :     roles described in fd_keyguard.h.  If the remote signing tile
      81             :     receives a malformed signing request, or one for a role that does
      82             :     not correspond to the role assigned to the receiving mcache, it
      83             :     will abort the whole program with a critical error.
      84             : 
      85             :     The response, a 64 byte signature, will be written into the signature
      86             :     buffer, which must be at least this size.
      87             : 
      88             :     sign_type is in FD_KEYGUARD_SIGN_TYPE_{...}. */
      89             : 
      90             : void
      91             : fd_keyguard_client_sign( fd_keyguard_client_t * client,
      92             :                          uchar *                signature,
      93             :                          uchar const *          sign_data,
      94             :                          ulong                  sign_data_len,
      95             :                          int                    sign_type );
      96             : 
      97             : FD_PROTOTYPES_END
      98             : 
      99             : #endif /* HEADER_fd_src_disco_keyguard_fd_keyguard_client_h */

Generated by: LCOV version 1.14