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 ISO_PROTOCOL_COMMON_H 17 #define ISO_PROTOCOL_COMMON_H 18 19 #include "alg_defs.h" 20 #include "string_util.h" 21 22 #define GENERATE_SESSION_KEY_STR "hichain_iso_session_key" 23 24 #define RAND_BYTE_LEN 16 25 #define PSK_LEN 32 26 #define ISO_SESSION_KEY_LEN 32 27 28 typedef struct IsoBaseParamsT { 29 Uint8Buff randSelf; 30 Uint8Buff randPeer; 31 Uint8Buff authIdSelf; // need malloc by caller 32 Uint8Buff authIdPeer; // need malloc by caller 33 Uint8Buff sessionKey; 34 uint8_t psk[PSK_LEN]; 35 const AlgLoader *loader; 36 } IsoBaseParams; 37 38 int32_t InitIsoBaseParams(IsoBaseParams *params); 39 void DestroyIsoBaseParams(IsoBaseParams *params); 40 41 int IsoClientGenRandom(IsoBaseParams *params); 42 int IsoClientCheckAndGenToken(IsoBaseParams *params, const Uint8Buff *peerToken, Uint8Buff *selfToken); 43 int IsoClientGenSessionKey(IsoBaseParams *params, int returnResult, const uint8_t *hmac, uint32_t hmacLen); 44 45 int IsoServerGenRandomAndToken(IsoBaseParams *params, Uint8Buff *selfTokenBuf); 46 int IsoServerGenSessionKeyAndCalToken(IsoBaseParams *params, const Uint8Buff *tokenFromPeer, Uint8Buff *tokenToPeer); 47 48 #endif