Merge "Added 3 more TPM2 Plugin APIs"
[aaf/sshsm.git] / TPM2-Plugin / test / main.c
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 "tpm2_plugin_api.h"
18 //#include "plugin_register.h"
19 //#include "hwpluginif.h"
20
21 void main(void)
22 {
23     unsigned long mechanism =1;
24     void *param = NULL;
25     size_t len = 100;
26     void *keyHandle_sign = NULL;
27     unsigned long int hSession = 1;
28
29     unsigned char *msg;
30     int msg_len;
31     unsigned char *sig;
32     int *sig_len;
33
34     SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *activate_in_info;
35     activate_in_info = malloc(sizeof(SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t));
36     SSHSM_HW_PLUGIN_IMPORT_PUBLIC_KEY_INFO_t *importkey_info;
37     importkey_info = malloc(sizeof(SSHSM_HW_PLUGIN_IMPORT_PUBLIC_KEY_INFO_t));
38
39     SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *loadkey_in_info;
40     loadkey_in_info = malloc(sizeof(SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t));
41     loadkey_in_info->num_buffers = 2;
42     unsigned char *str ="abcde";
43     //loadkey_in_info->buffer_info[0]->buffer = str;
44     //loadkey_in_info->buffer_info[0]->length_of_buffer = 5;
45     //loadkey_in_info->buffer_info[1]->buffer = str;
46     //loadkey_in_info->buffer_info[1]->length_of_buffer = 5;
47
48     void **keyHandle;
49
50     printf("---------------------------------------------\n");
51     printf("Test app calling tpm2_plugin APIs\n");
52
53     printf("---------------------------------------------\n");
54     tpm2_plugin_init();
55
56     printf("---------------------------------------------\n");
57     tpm2_plugin_uninit();
58
59     printf("---------------------------------------------\n");
60     tpm2_plugin_activate(activate_in_info);
61
62     printf("---------------------------------------------\n");
63     tpm2_plugin_rsa_sign_init(keyHandle_sign, mechanism, param, len, (void *)hSession);
64
65     printf("---------------------------------------------\n");
66     tpm2_plugin_load_key(loadkey_in_info, keyHandle, importkey_info);
67
68     printf("---------------------------------------------\n");
69     tpm2_plugin_rsa_sign(keyHandle_sign, mechanism, msg, msg_len, (void *)hSession, sig, sig_len);
70
71 }