1 /* 2 * Copyright (c) 2022-2023 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 #ifndef __HVB_SM2_H__ 16 #define __HVB_SM2_H__ 17 18 #include <stdint.h> 19 20 #define SM2_VERIFY_OK 0 21 #define SM2_POINTER_NULL (-1) 22 #define SM2_PARAM_LEN_ERROR (-2) 23 #define SM2_PARAM_ERROR (-3) 24 #define SM2_COMPUTE_Z_ERROR (-4) 25 #define SM2_COMPUTE_DIGEST_ERROR (-5) 26 #define SM2_CHECK_RS_ERROR (-6) 27 #define SM2_R_NOT_INDOMAIN (-7) 28 #define SM2_S_NOT_INDOMAIN (-8) 29 #define SM2_R_ADD_S_ERROR (-9) 30 #define SM2_VERIFY_ERROR (-10) 31 #define SM2_HASH_INIT_ERROR (-11) 32 #define SM2_HASH_UPDATE_ERROR (-12) 33 #define SM2_HASH_FINALE_ERROR (-13) 34 #define SM2_MOD_ADD_ERROR (-14) 35 #define SM2_POINT_MUL_ADD_ERROR (-15) 36 #define SM2_KEY_LEN 32 37 38 struct sm2_pubkey { 39 uint8_t x[SM2_KEY_LEN]; 40 uint8_t y[SM2_KEY_LEN]; 41 }; 42 43 int sm2_digest_verify(const struct sm2_pubkey *pkey, const uint8_t *pdigest, uint32_t digestlen, 44 const uint8_t *psign, uint32_t signlen); 45 46 int hvb_sm2_verify(const struct sm2_pubkey *pkey, const uint8_t *pid, uint32_t idlen, 47 const uint8_t *pmsg, uint32_t msglen, const uint8_t *psign, uint32_t signlen); 48 #endif 49