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_PARAMS_PARSER_H 17 #define HCF_PARAMS_PARSER_H 18 19 #include <stdint.h> 20 #include "result.h" 21 22 typedef enum { 23 HCF_ALG_TYPE = 1, 24 HCF_ALG_KEY_TYPE, 25 HCF_ALG_MODE, 26 HCF_ALG_PADDING_TYPE, 27 HCF_ALG_PRIMES, 28 HCF_ALG_DIGEST, 29 HCF_ALG_MGF1_DIGEST, 30 } HCF_ALG_PARA_TYPE; 31 32 typedef enum { 33 HCF_ALG_AES = 1, 34 HCF_ALG_DES, 35 HCF_ALG_RSA, 36 HCF_ALG_ECC, 37 } HCF_ALG_VALUE; 38 39 typedef enum { 40 HCF_ALG_ECC_224 = 1, 41 HCF_ALG_ECC_256, 42 HCF_ALG_ECC_384, 43 HCF_ALG_ECC_521, 44 45 HCF_ALG_AES_128, 46 HCF_ALG_AES_192, 47 HCF_ALG_AES_256, 48 HCF_ALG_3DES_192, 49 50 HCF_ALG_MODE_NONE, 51 HCF_ALG_MODE_ECB, 52 HCF_ALG_MODE_CBC, 53 HCF_ALG_MODE_CTR, 54 HCF_ALG_MODE_OFB, 55 HCF_ALG_MODE_CFB, 56 HCF_ALG_MODE_CFB1, 57 HCF_ALG_MODE_CFB8, 58 HCF_ALG_MODE_CFB64, 59 HCF_ALG_MODE_CFB128, 60 HCF_ALG_MODE_CCM, 61 HCF_ALG_MODE_GCM, 62 63 HCF_ALG_NOPADDING, 64 HCF_ALG_PADDING_PKCS5, 65 HCF_ALG_PADDING_PKCS7, 66 67 // rsa keysize 68 HCF_OPENSSL_RSA_512, 69 HCF_OPENSSL_RSA_768, 70 HCF_OPENSSL_RSA_1024, 71 HCF_OPENSSL_RSA_2048, 72 HCF_OPENSSL_RSA_3072, 73 HCF_OPENSSL_RSA_4096, 74 HCF_OPENSSL_RSA_8192, 75 76 // rsa cipher padding, 77 HCF_OPENSSL_RSA_PKCS1_PADDING, 78 HCF_OPENSSL_RSA_PKCS1_OAEP_PADDING, 79 HCF_OPENSSL_RSA_PSS_PADDING, 80 81 // digest 82 HCF_OPENSSL_DIGEST_NONE, 83 HCF_OPENSSL_DIGEST_MD5, 84 HCF_OPENSSL_DIGEST_SHA1, 85 HCF_OPENSSL_DIGEST_SHA224, 86 HCF_OPENSSL_DIGEST_SHA256, 87 HCF_OPENSSL_DIGEST_SHA384, 88 HCF_OPENSSL_DIGEST_SHA512, 89 90 // primes 91 HCF_OPENSSL_PRIMES_2, 92 HCF_OPENSSL_PRIMES_3, 93 HCF_OPENSSL_PRIMES_4, 94 HCF_OPENSSL_PRIMES_5, 95 } HCF_ALG_PARA_VALUE; 96 97 typedef struct { 98 const char* tag; 99 HCF_ALG_PARA_TYPE paraType; 100 HCF_ALG_PARA_VALUE paraValue; 101 } HcfParaConfig; 102 103 typedef struct { 104 HCF_ALG_VALUE algo; 105 HCF_ALG_PARA_VALUE keySize; 106 HCF_ALG_PARA_VALUE mode; 107 HCF_ALG_PARA_VALUE paddingMode; 108 HCF_ALG_PARA_VALUE md; 109 HCF_ALG_PARA_VALUE mgf1md; 110 } CipherAttr; 111 112 typedef struct { 113 HCF_ALG_VALUE algo; // algType 114 int32_t bits; // keyLen 115 int32_t primes; // number of primes 116 } HcfAsyKeyGenParams; 117 118 typedef struct { 119 HCF_ALG_VALUE algo; // algType 120 HCF_ALG_PARA_VALUE keyLen; 121 HCF_ALG_PARA_VALUE padding; 122 HCF_ALG_PARA_VALUE md; 123 HCF_ALG_PARA_VALUE mgf1md; 124 } HcfSignatureParams; 125 126 typedef struct { 127 HCF_ALG_VALUE algo; 128 HCF_ALG_PARA_VALUE keyLen; 129 } HcfKeyAgreementParams; 130 131 typedef HcfResult (*SetParameterFunc) (const HcfParaConfig* config, void *params); 132 133 #ifdef __cplusplus 134 extern "C" { 135 #endif 136 137 HcfResult ParseAndSetParameter(const char *paramsStr, void *params, SetParameterFunc setFunc); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 #endif 143