1 /* 2 * Copyright (c) 2020 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_H__ 17 #define __AUTH_INFO_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 struct auth_info_message { 27 struct uint8_buff cipher; 28 }; 29 30 struct auth_info_cache { 31 int32_t user_type; 32 struct hc_auth_id auth_id; 33 struct ltpk ltpk; 34 }; 35 36 struct exchange_auth_data { 37 struct hc_auth_id auth_id; 38 struct ltpk ltpk; 39 }; 40 41 typedef struct auth_info_message add_request_data; 42 typedef struct auth_info_message add_response_data; 43 44 typedef struct auth_info_message exchange_request_data; 45 typedef struct auth_info_message exchange_response_data; 46 47 typedef struct auth_info_message remove_request_data; 48 typedef struct auth_info_message remove_response_data; 49 50 #if !(defined(_CUT_PAKE_) || defined(_CUT_PAKE_SERVER_)) 51 const struct pake_session_key *get_pake_session_key(const struct hichain *hichain); 52 const struct challenge *get_pake_self_challenge(const struct hichain *hichain); 53 const struct challenge *get_pake_peer_challenge(const struct hichain *hichain); 54 const struct hc_auth_id *get_pake_self_auth_id(const struct hichain *hichain); 55 #endif /* _CUT_XXX_ */ 56 #if !(defined(_CUT_STS_) || defined(_CUT_STS_SERVER_)) 57 const struct sts_session_key *get_sts_session_key(const struct hichain *hichain); 58 #endif /* _CUT_XXX_ */ 59 int32_t encrypt_payload(const struct var_buffer *key, const struct uint8_buff *plain, 60 const char *aad, struct uint8_buff *payload); 61 int32_t decrypt_payload(const struct var_buffer *key, const struct uint8_buff *payload, 62 const char *aad, struct uint8_buff *plain); 63 struct auth_info_message *malloc_auth_info_msg(uint32_t size); 64 void free_auth_info_msg(struct auth_info_message *data); 65 int32_t save_auth_info(const struct hichain *hichain, int32_t pair_type, struct auth_info_cache *cache); 66 struct auth_info_cache *build_auth_client_info(struct hc_auth_id auth_id, int32_t user_type); 67 void destroy_auth_client(struct auth_info_cache *auth_info); 68 69 #endif /* __AUTH_INFO_H__ */ 70