/ include / lsplugin / mkobject.h
mkobject.h
 1  /*
 2   * SPDX-FileCopyrightText: 2023-2024 Le'Sec Plugin collective
 3   *
 4   * SPDX-License-Identifier: LGPL-3.0-or-later
 5   */
 6  
 7  #ifndef LSPLUGIN_MKOBJECT_H
 8  # define LSPLUGIN_MKOBJECT_H
 9  
10  # include <lscrypto/key.h>
11  # include <lsplugin/mkoperator.h>
12  
13  /*
14   * For the moment, this plugin implementation only handles one object class,
15   * the key, so that's what is implemented below.  This will probably change
16   * in the future, as other object classes appear.
17   */
18  
19  /* ------------------------------------------------------------------------- */
20  
21  /*
22   * The key constructors and extractor as well as the key operator descriptor
23   * are a bit special,  and could fit in ltc-operator.h just as well as here.
24   * However, considering they normally are object associated operators, this
25   * ends up being the better fit...
26   * The key operator descriptor is very much alike the self-standing operator
27   * descriptors, though, and reuse the same function implementations for all
28   * performing functions.
29   */
30  
31  # define LSplugin_key_generator_FUNCTIONS()                             \
32    LE_STATUS (*lsp_generate_key_data)(LSC_key_generator_t *lsp_op)
33  
34  # define LSplugin_key_constructor_FUNCTIONS()                           \
35    LE_STATUS (*lsp_construct_key_data)(LSC_key_constructor_t *lsp_op)
36  
37  # define LSplugin_key_extractor_FUNCTIONS()                             \
38    LE_STATUS (*lsp_extract_key_data)(LSC_key_extractor_t *lsp_op)
39  
40  LSplugin_OPERATOR_DESC(key_generator, key_generation);
41  LSplugin_OPERATOR_DESC(key_constructor, key_construction);
42  LSplugin_OPERATOR_DESC(key_extractor, key_extraction);
43  
44  LE_STATUS LSplugin_key_generator_dispatch(LSC_key_generator_t *lsp_op, int lsp_num, ...);
45  LE_STATUS LSplugin_destroy_key_generator(LSC_key_generator_t *lsp_op);
46  LE_STATUS LSplugin_key_constructor_dispatch(LSC_key_constructor_t *lsp_op, int lsp_num, ...);
47  LE_STATUS LSplugin_destroy_key_constructor(LSC_key_constructor_t *lsp_op);
48  LE_STATUS LSplugin_key_extractor_dispatch(LSC_key_extractor_t *lsp_op, int lsp_num, ...);
49  LE_STATUS LSplugin_destroy_key_extractor(LSC_key_extractor_t *lsp_op);
50  
51  typedef struct LSplugin_key_desc_st LSplugin_key_desc_t;
52  struct LSplugin_key_desc_st {
53    const char *lsp_docstring;
54    const char *lsp_id;
55    const void *lsp_priv_desc;
56    LE_STATUS (*lsp_setup_key_data)(LSC_key_t *lsp_data, const void *lsp_priv_desc);
57    LE_STATUS (*lsp_clean_key_data)(LSC_key_t *lsp_data);
58    const int *lsp_dispatch_cmds;
59    LE_STATUS (*lsp_get_key_size)(LSC_key_t *lsp_data, size_t *lsp_keysize);
60    const LSplugin_key_generator_desc_t *lsp_generator_desc;
61    const LSplugin_key_constructor_desc_t *lsp_constructor_desc;
62    const LSplugin_key_extractor_desc_t *lsp_extractor_desc;
63    const LSplugin_encryptor_desc_t *lsp_encryptor_desc;
64    const LSplugin_decryptor_desc_t *lsp_decryptor_desc;
65    const LSplugin_signer_desc_t *lsp_signer_desc;
66    const LSplugin_verifier_desc_t *lsp_verifier_desc;
67    const LSplugin_derivator_desc_t *lsp_derivator_desc;
68    const LSplugin_mac_desc_t *lsp_mac_desc;
69    const LSplugin_encapsulator_desc_t *lsp_encapsulator_desc;
70    const LSplugin_decapsulator_desc_t *lsp_decapsulator_desc;
71  };
72  
73  LE_STATUS LSplugin_key_dispatch(LSC_key_t *lsp_key, int lsp_num, ...);
74  LE_STATUS LSplugin_destroy_key(LSC_key_t *lsp_key);
75  
76  /*
77   * Helpers
78   */
79  
80  const char *LSplugin_get_key_id(LSC_key_t *key);
81  
82  #endif