Added a new Attribute to store TPM key handle
[aaf/sshsm.git] / SoftHSMv2 / src / lib / HwInfra / HwInfra.h
1 /* Copyright 2018 Intel Corporation, Inc
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *       http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdio.h>
17 #include <sys/types.h>
18 #include <dirent.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include "hwpluginif.h"
23
24 #if defined(__cplusplus)
25 extern "C" {
26 #endif
27
28 #ifndef __SSHSM_HW_INFRA_UTIL_H__
29 #define __SSHSM_HW_INFRA_UTIL_H__
30
31 #define MAX_KEY_DIRS_SUPPORTED 64
32
33 typedef struct hwpluginentries_s {
34    char so_full_path[256+1];
35    char activate_dir_full_path[256+1];
36    int num_key_dirs;
37    char key_dir_full_path[MAX_KEY_DIRS_SUPPORTED][256+1];
38 }hwpluginentries_t;
39
40 int prepareHWPlugin();
41 int loadHWPlugin(char *parent_dir, char *pluginsubdir);
42 int HwPlugin_Initiate_Activate_and_load_keys( hwpluginentries_t *);
43 int load_hw_plugin_and_get_function_pointers(char *,
44               SSHSM_HW_FUNCTIONS_t *funcs);
45 int init_hw_plugin(SSHSM_HW_FUNCTIONS_t *funcs);
46 int activate_hw_plugin(hwpluginentries_t *entries, SSHSM_HW_FUNCTIONS_t *funcs);
47 int load_keys_in_hw_plugin(hwpluginentries_t *entries,
48                    SSHSM_HW_FUNCTIONS_t *funcs);
49 int get_all_file_contents(char *dirpath,  char starting_char,
50                   SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *c_buffers );
51
52 void free_buffers ( SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *c_buffers );
53 int program_pkcs11_info (char *dirpath, void *key_handle, SSHSM_HW_PLUGIN_IMPORT_PUBLIC_KEY_INFO_t* ik);
54 int PrepareKeyInSoftHSM(unsigned int slot_id,
55                unsigned char *upin, int upin_len,
56                unsigned char *key_id, int key_id_len,
57                unsigned char *key_label, void *key_handle,
58                SSHSM_HW_PLUGIN_IMPORT_PUBLIC_KEY_INFO_t* ik);
59
60 int HwInfraSignInit(void *keyHandle,  unsigned long mechanism,
61                  void* param, int paramLen, void **hwCryptoOpaque);
62 int HwInfraSign(void *keyHandle,  unsigned long mechanism,
63                  unsigned char *msg, int msg_len, void *hwCryptoOpaque,
64                  unsigned char *outsig,  int *outsiglen);
65 int HwInfraSignUpdate(void *keyHandle, unsigned long mechanism,
66                  unsigned char *msg, int msg_len, void *hwCryptoOpaque);
67 int HwInfraSignFinal(void *keyHandle,  unsigned long mechanism,
68                  void *hwCryptoOpaque,
69                  unsigned char *outsig,  int *outsiglen);
70 int HwInfraSignCleanup(void *keyHandle,  unsigned long mechanism,
71                        void *hwCryptoOpaque);
72
73
74 #define MAX_PARENT_PATH_NAME 256
75
76 #define LOG printf
77 #define SSHSM_HW_PLUGIN_ERROR_BASE (10000)
78
79 #define ENVIRONMENT_TOO_LONG (01)
80 #define PLUGIN_PATH_TOO_LONG (02)
81 #define PLUGIN_PATH_OPEN_ERROR (03)
82 #define INCOMPLETE_PLUGIN_DIR (04)
83 #define ALLOCATION_ERROR (05)
84 #define PLUGIN_DL_OPEN_ERROR (06)
85 #define PLUGIN_DL_SYM_ERROR (07)
86 #define PLUGIN_INIT_ERROR (10)
87 #define INVALID_KEY_ERROR (11)
88
89 #if defined(__cplusplus)
90 }
91 #endif
92
93
94 #endif /* __SSHSM_HW_INFRA_UTIL_H__ */
95
96