LCOV - code coverage report
Current view: top level - hal/ledger/src - endorsement.c (source / functions) Hit Total Coverage
Test: powHSM firmware Lines: 29 29 100.0 %
Date: 2025-10-30 06:27:42 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /**
       2             :  * The MIT License (MIT)
       3             :  *
       4             :  * Copyright (c) 2021 RSK Labs Ltd
       5             :  *
       6             :  * Permission is hereby granted, free of charge, to any person obtaining a copy
       7             :  * of this software and associated documentation files (the "Software"), to
       8             :  * deal in the Software without restriction, including without limitation the
       9             :  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
      10             :  * sell copies of the Software, and to permit persons to whom the Software is
      11             :  * furnished to do so, subject to the following conditions:
      12             :  *
      13             :  * The above copyright notice and this permission notice shall be included in
      14             :  * all copies or substantial portions of the Software.
      15             :  *
      16             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      17             :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      18             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      19             :  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      20             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      21             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
      22             :  * IN THE SOFTWARE.
      23             :  */
      24             : 
      25             : #include "os.h"
      26             : #include "hal/constants.h"
      27             : #include "hal/endorsement.h"
      28             : 
      29             : // Index of the ledger endorsement scheme
      30             : #define ENDORSEMENT_SCHEME_INDEX 2
      31             : 
      32             : static bool sign_performed;
      33             : 
      34          11 : bool endorsement_init() {
      35          11 :     sign_performed = false;
      36          11 :     return true;
      37             : }
      38             : 
      39           1 : uint8_t* endorsement_get_envelope() {
      40           1 :     return NULL;
      41             : }
      42             : 
      43           1 : size_t endorsement_get_envelope_length() {
      44           1 :     return 0;
      45             : }
      46             : 
      47           6 : bool endorsement_sign(uint8_t* msg,
      48             :                       size_t msg_size,
      49             :                       uint8_t* signature_out,
      50             :                       uint8_t* signature_out_length) {
      51             : 
      52           6 :     if (*signature_out_length < MAX_SIGNATURE_LENGTH) {
      53           1 :         return false;
      54             :     }
      55             : 
      56           5 :     *signature_out_length =
      57           5 :         os_endorsement_key2_derive_sign_data(msg, msg_size, signature_out);
      58             : 
      59           5 :     sign_performed = true;
      60           5 :     return true;
      61             : }
      62             : 
      63           3 : bool endorsement_get_code_hash(uint8_t* code_hash_out,
      64             :                                uint8_t* code_hash_out_length) {
      65           3 :     if (!sign_performed) {
      66           1 :         return false;
      67             :     }
      68             : 
      69           2 :     if (*code_hash_out_length < HASH_LENGTH) {
      70           1 :         return false;
      71             :     }
      72             : 
      73           1 :     *code_hash_out_length = os_endorsement_get_code_hash(code_hash_out);
      74           1 :     return true;
      75             : }
      76             : 
      77           3 : bool endorsement_get_public_key(uint8_t* public_key_out,
      78             :                                 uint8_t* public_key_out_length) {
      79           3 :     if (!sign_performed) {
      80           1 :         return false;
      81             :     }
      82             : 
      83           2 :     if (*public_key_out_length < PUBKEY_UNCMP_LENGTH) {
      84           1 :         return false;
      85             :     }
      86             : 
      87           1 :     *public_key_out_length =
      88           1 :         os_endorsement_get_public_key(ENDORSEMENT_SCHEME_INDEX, public_key_out);
      89           1 :     return true;
      90             : }

Generated by: LCOV version 1.16