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 30 #define HCF_OPENSSL_SUCCESS 1 /* openssl return 1: success */ 31 #define HCF_BITS_PER_BYTE 8 32 33 typedef enum { 34 UNINITIALIZED = 0, 35 INITIALIZED = 1, 36 READY = 2, 37 } CryptoStatus; 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 HcfResult GetOpensslCurveId(int32_t keyLen, int32_t *returnCurveId); 44 HcfResult GetOpensslDigestAlg(uint32_t alg, EVP_MD **digestAlg); 45 void HcfPrintOpensslError(void); 46 47 HcfResult GetOpensslPadding(int32_t padding, int32_t *opensslPadding); 48 49 int32_t GetRealPrimes(int32_t primesFlag); 50 51 bool IsBigEndian(void); 52 53 HcfResult BigIntegerToBigNum(const HcfBigInteger *src, BIGNUM **dest); 54 55 HcfResult BigNumToBigInteger(const BIGNUM *src, HcfBigInteger *dest); 56 57 HcfResult GetRsaSpecStringMd(const HcfAlgParaValue md, char **returnString); 58 59 HcfResult GetRsaSpecStringMGF(char **returnString); 60 61 #ifdef __cplusplus 62 } 63 #endif 64 65 #endif 66