digest.h
1 // SPDX-FileCopyrightText: 2024-2025 Le'Sec Core collective 2 // 3 // SPDX-License-Identifier: LGPL-3.0-or-later 4 5 #ifndef LSC_DIGEST_H 6 # define LSC_DIGEST_H 7 8 # include <lscore/operation.h> 9 # include <lscrypto/op-functions.h> 10 # include <lscrypto/types.h> 11 12 # ifdef __cplusplus 13 extern "C" { 14 # endif 15 16 // Produces the following symbols: 17 // 18 // LSC_digester_st 19 // LSC_digester_t 20 // LSC_digester_dispatch_fn 21 // LSC_digester_destroy_fn 22 // LSC_new_digester() 23 // LSC_free_digester() 24 LSC_IMPL_BASIC_OPERATION_CLASS(digester, digestion); 25 26 // Implementors should use the following bread and butter code factories 27 // in their digester dispatch function: 28 // 29 // switch (num) { 30 // LSC_DIGESTER_TYPE_BASE_DISPATCHES("{typename}", {key-var}, 31 // {status-var}, {va_list-var}, 32 // {cmds-var}); 33 // ... 34 # define LSC_DIGESTER_TYPE_BASE_COMMANDS() \ 35 LSC_OPERATION_TYPE_BASE_COMMANDS(digester) 36 # define LSC_DIGESTER_TYPE_BASE_DISPATCHES(lsc_id, lsc_obj, lsc_status, \ 37 lsc_valist, lsc_cmds) \ 38 LSC_OPERATION_TYPE_BASE_DISPATCHES(digester, lsc_id, lsc_obj, \ 39 lsc_status, lsc_valist, lsc_cmds) 40 41 // Size functions. These are slightly different from the ones defined 42 // by op-functions.h macros, as verification doesn't really produce any 43 // output, apart from a _Bool, but also takes two inputs, the message and 44 // the digest to verify against. 45 // 46 // LSC_NR_operation_output_size is re-used for the digest size, as that 47 // corresponds to the digest operation output. 48 // 49 // LSC_get_digester_input_size() 50 // LSC_get_digester_digest_size() 51 enum { 52 LSC_NR_get_digester_input_size = (0 + LSC_NR__crypto_op_class_start), 53 LSC_NR_get_digester_digest_size = (1 + LSC_NR__crypto_op_class_start) 54 }; 55 LSC_CRYPTO_OP_SIZE_FUNCTION(digester, input); 56 LSC_CRYPTO_OP_SIZE_FUNCTION(digester, digest); 57 # define LSC_DIGESTER_SIZE_COMMANDS() \ 58 LSC_CRYPTO_OP_SIZE_COMMAND(digester, input), \ 59 LSC_CRYPTO_OP_SIZE_COMMAND(digester, digest) 60 61 // Produces the following function: 62 // 63 // LSC_perform_digestion_once(): 64 LSC_CRYPTO_OP_ONESHOT_FUNCTIONS(digester, digestion); 65 66 // Produces the following function: 67 // 68 // LSC_start_digestion(): 69 // LSC_stop_digestion(): 70 // LSC_accumulate_digestion_input(): 71 // LSC_extract_digestion_output(): 72 // LSC_finalize_digestion(): 73 LSC_CRYPTO_OP_BASE_FUNCTIONS(digester, digestion); 74 LSC_CRYPTO_OP_ACCUMULATE_FUNCTION(digester, digestion); 75 LSC_CRYPTO_OP_EXTRACT_FUNCTION(digester, digestion); 76 LSC_CRYPTO_OP_FINALIZE_FUNCTIONS(digester, digestion); 77 78 // Registration functions 79 LSC_OPERATION_CLASS_REGISTRATION_FUNCTIONS(digester); 80 81 # ifdef __cplusplus 82 } 83 # endif 84 85 #endif