1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
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 #ifndef AUTH_INFO_TEST_H
17 #define AUTH_INFO_TEST_H
18 
19 #include "hichain.h"
20 #include "distribution.h"
21 
22 /* auth_info exchange data len */
23 #define HC_AUTH_REQUEST_LEN  350
24 #define HC_AUTH_RESPONSE_LEN 256
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 struct auth_info_message {
31     struct uint8_buff cipher;
32 };
33 
34 struct auth_info_cache {
35     int32_t user_type;
36     struct hc_auth_id auth_id;
37     struct ltpk ltpk;
38 };
39 
40 struct exchange_auth_data {
41     struct hc_auth_id auth_id;
42     struct ltpk ltpk;
43 };
44 
45 typedef struct auth_info_message add_request_data;
46 typedef struct auth_info_message add_response_data;
47 
48 typedef struct auth_info_message exchange_request_data;
49 typedef struct auth_info_message exchange_response_data;
50 
51 typedef struct auth_info_message remove_request_data;
52 typedef struct auth_info_message remove_response_data;
53 
54 #if !(defined(_CUT_PAKE_) || defined(_CUT_PAKE_SERVER_))
55 const struct pake_session_key *get_pake_session_key(const struct hichain *hichain);
56 const struct challenge *get_pake_self_challenge(const struct hichain *hichain);
57 const struct challenge *get_pake_peer_challenge(const struct hichain *hichain);
58 const struct hc_auth_id *get_pake_self_auth_id(const struct hichain *hichain);
59 #endif /* _CUT_XXX_ */
60 #if !(defined(_CUT_STS_) || defined(_CUT_STS_SERVER_))
61 const struct sts_session_key *get_sts_session_key(const struct hichain *hichain);
62 #endif /* _CUT_XXX_ */
63 int32_t encrypt_payload(const struct var_buffer *key, const struct uint8_buff *plain,
64     const char *aad, struct uint8_buff *payload);
65 int32_t decrypt_payload(const struct var_buffer *key, const struct uint8_buff *payload,
66     const char *aad, struct uint8_buff *plain);
67 struct auth_info_message *malloc_auth_info_msg(uint32_t size);
68 void free_auth_info_msg(struct auth_info_message *data);
69 int32_t save_auth_info(const struct hichain *hichain, int32_t pair_type, struct auth_info_cache *cache);
70 struct auth_info_cache *build_auth_client_info(struct hc_auth_id auth_id, int32_t user_type);
71 void destroy_auth_client(struct auth_info_cache *auth_info);
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif