1 /* 2 * Copyright (c) 2022 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 HKS_OPENSSL_SM2_H 17 #define HKS_OPENSSL_SM2_H 18 19 #include <stdint.h> 20 21 #include "hks_crypto_hal.h" 22 #include "hks_type.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define SM2_C1_SIZE 65 29 #define SM2_C3_SIZE 32 30 #define SM2_KEYPAIR_CNT 3 31 32 #ifdef HKS_SUPPORT_SM2_C 33 #ifdef HKS_SUPPORT_SM2_GENERATE_KEY 34 int32_t HksOpensslSm2GenerateKey(const struct HksKeySpec *spec, struct HksBlob *key); 35 #endif 36 37 #ifdef HKS_SUPPORT_SM2_GET_PUBLIC_KEY 38 int32_t HksOpensslGetSm2PubKey(const struct HksBlob *input, struct HksBlob *output); 39 #endif 40 41 #ifdef HKS_SUPPORT_SM2_SIGN_VERIFY 42 int32_t HksOpensslSm2Verify(const struct HksBlob *key, const struct HksUsageSpec *usageSpec, 43 const struct HksBlob *message, const struct HksBlob *signature); 44 int32_t HksOpensslSm2Sign(const struct HksBlob *key, const struct HksUsageSpec *usageSpec, 45 const struct HksBlob *message, struct HksBlob *signature); 46 #endif 47 48 #ifdef HKS_SUPPORT_SM2_ENCRYPT_DECRYPT 49 int32_t HksOpensslSm2Encrypt(const struct HksBlob *keyPair, const struct HksUsageSpec *usageSpec, 50 const struct HksBlob *plainBlob, struct HksBlob *cipherBlob); 51 int32_t HksOpensslSm2Decrypt(const struct HksBlob *keyPair, const struct HksUsageSpec *usageSpec, 52 const struct HksBlob *cipherBlob, struct HksBlob *plainBlob); 53 #endif //HKS_SUPPORT_SM2_ENCRYPT_DECRYPT 54 #endif 55 #ifdef __cplusplus 56 } 57 #endif 58 59 #endif /* HKS_OPENSSL_SM2_H */ 60