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 16 #ifndef HCF_OPENSSL_COMMON_H 17 #define HCF_OPENSSL_COMMON_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include <openssl/bn.h> 22 #include <openssl/ec.h> 23 #include <openssl/evp.h> 24 #include <openssl/rsa.h> 25 26 #include "big_integer.h" 27 #include "params_parser.h" 28 #include "result.h" 29 #include "utils.h" 30 31 #define HCF_OPENSSL_SUCCESS 1 /* openssl return 1: success */ 32 #define HCF_BITS_PER_BYTE 8 33 34 typedef enum { 35 UNINITIALIZED = 0, 36 INITIALIZED = 1, 37 READY = 2, 38 } CryptoStatus; 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 HcfResult GetCurveNameByCurveId(int32_t curveId, char **curveName); 45 HcfResult GetAlgNameByBits(int32_t keyLen, char **algName); 46 HcfResult GetOpensslCurveId(int32_t keyLen, int32_t *returnCurveId); 47 HcfResult GetOpensslDigestAlg(uint32_t alg, EVP_MD **digestAlg); 48 void HcfPrintOpensslError(void); 49 50 HcfResult GetOpensslPadding(int32_t padding, int32_t *opensslPadding); 51 52 int32_t GetRealPrimes(int32_t primesFlag); 53 54 bool IsBigEndian(void); 55 56 HcfResult BigIntegerToBigNum(const HcfBigInteger *src, BIGNUM **dest); 57 58 HcfResult BigNumToBigInteger(const BIGNUM *src, HcfBigInteger *dest); 59 60 HcfResult GetRsaSpecStringMd(const HcfAlgParaValue md, char **returnString); 61 62 HcfResult GetRsaSpecStringMGF(char **returnString); 63 64 HcfResult GetSm2SpecStringSm3(char **returnString); 65 66 HcfResult KeyDerive(EVP_PKEY *priKey, EVP_PKEY *pubKey, HcfBlob *returnSecret); 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #endif 73