Modify TPM2 Plugin codes
[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
28     unsigned char *msg;
29     int msg_len;
30     unsigned char *sig;
31     int *sig_len;
32
33     SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *activate_in_info;
34     activate_in_info = malloc(sizeof(SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t));
35     SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *loadkey_in_info;
36     loadkey_in_info = malloc(sizeof(SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t));
37     loadkey_in_info->num_buffers = 2;
38     unsigned char *str ="abcde";
39     //loadkey_in_info->buffer_info[0]->buffer = str;
40     //loadkey_in_info->buffer_info[0]->length_of_buffer = 5;
41     //loadkey_in_info->buffer_info[1]->buffer = str;
42     //loadkey_in_info->buffer_info[1]->length_of_buffer = 5;
43
44     void **keyHandle;
45
46     printf("---------------------------------------------\n");
47     printf("Test app calling tpm2_plugin APIs\n");
48
49     printf("---------------------------------------------\n");
50     tpm2_plugin_init();
51
52     printf("---------------------------------------------\n");
53     tpm2_plugin_uninit();
54
55     printf("---------------------------------------------\n");
56     tpm2_plugin_activate(activate_in_info);
57
58     printf("---------------------------------------------\n");
59     tpm2_plugin_rsa_sign_init(keyHandle_sign, mechanism, param, len);
60
61     printf("---------------------------------------------\n");
62     tpm2_plugin_load_key(loadkey_in_info, keyHandle);
63
64     printf("---------------------------------------------\n");
65     tpm2_plugin_rsa_sign(keyHandle_sign, mechanism, msg, msg_len, sig, sig_len);
66
67 }