• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef CRYPT_ENCODE_DECODE_KEY_H
17 #define CRYPT_ENCODE_DECODE_KEY_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_CODECSKEY
21 
22 #include "bsl_types.h"
23 #include "bsl_asn1.h"
24 #include "crypt_eal_pkey.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cpluscplus */
29 
30 #ifdef HITLS_CRYPTO_KEY_DECODE
31 
32 typedef struct {
33     BslCid keyType;
34     BSL_ASN1_Buffer keyParam;
35     BSL_ASN1_BitString pubKey;
36 } CRYPT_DECODE_SubPubkeyInfo;
37 
38 int32_t CRYPT_DECODE_SubPubkey(uint8_t *buff, uint32_t buffLen, BSL_ASN1_DecTemplCallBack keyInfoCb,
39     CRYPT_DECODE_SubPubkeyInfo *subPubkeyInfo, bool isComplete);
40 typedef struct {
41     int32_t version;
42     BslCid keyType;
43     BSL_ASN1_Buffer keyParam;
44     uint8_t *pkeyRawKey;
45     uint32_t pkeyRawKeyLen;
46     void *attrs; // HITLS_X509_Attrs *
47 } CRYPT_ENCODE_DECODE_Pk8PrikeyInfo;
48 
49 int32_t CRYPT_DECODE_Pkcs8Info(uint8_t *buff, uint32_t buffLen, BSL_ASN1_DecTemplCallBack keyInfoCb,
50     CRYPT_ENCODE_DECODE_Pk8PrikeyInfo *pk8PrikeyInfo);
51 
52 int32_t CRYPT_EAL_ParseRsaPssAlgParam(BSL_ASN1_Buffer *param, CRYPT_RSA_PssPara *para);
53 
54 int32_t CRYPT_EAL_PriKeyParseFile(BSL_ParseFormat format, int32_t type,
55     const char *path, const BSL_Buffer *pwd, CRYPT_EAL_PkeyCtx **ealPriKey);
56 #endif
57 
58 #ifdef HITLS_CRYPTO_KEY_ENCODE
59 
60 int32_t CRYPT_ENCODE_Pkcs8Info(CRYPT_ENCODE_DECODE_Pk8PrikeyInfo *pk8PrikeyInfo, BSL_Buffer *asn1);
61 
62 int32_t CRYPT_EAL_EncodePubKeyBuffInternal(CRYPT_EAL_PkeyCtx *ealPubKey,
63     BSL_ParseFormat format, int32_t type, bool isComplete, BSL_Buffer *encode);
64 
65 #ifdef HITLS_CRYPTO_RSA
66 int32_t CRYPT_EAL_EncodeRsaPssAlgParam(const CRYPT_RSA_PssPara *rsaPssParam, uint8_t **buf, uint32_t *bufLen);
67 #endif
68 
69 #endif // HITLS_CRYPTO_KEY_ENCODE
70 
71 #if defined(HITLS_CRYPTO_RSA) && defined(HITLS_CRYPTO_KEY_DECODE)
72 int32_t CRYPT_EAL_InitRsaPrv(const CRYPT_EAL_PkeyCtx *ealPriKey, CRYPT_PKEY_AlgId cid, CRYPT_EAL_PkeyPrv *rsaPrv);
73 void CRYPT_EAL_DeinitRsaPrv(CRYPT_EAL_PkeyPrv *rsaPrv);
74 int32_t CRYPT_EAL_GetRsaPssPara(CRYPT_EAL_PkeyCtx *ealPriKey, CRYPT_RSA_PssPara *rsaPssParam);
75 #endif
76 
77 #ifdef HITLS_PKI_PKCS12_PARSE
78 // parse PKCS7-EncryptData:only support PBES2 + PBKDF2.
79 int32_t CRYPT_EAL_ParseAsn1PKCS7EncryptedData(CRYPT_EAL_LibCtx *libCtx, const char *attrName, BSL_Buffer *encode,
80     const uint8_t *pwd, uint32_t pwdlen, BSL_Buffer *output);
81 #endif
82 
83 #ifdef HITLS_PKI_PKCS12_GEN
84 // encode PKCS7-EncryptData:only support PBES2 + PBKDF2.
85 int32_t CRYPT_EAL_EncodePKCS7EncryptDataBuff(CRYPT_EAL_LibCtx *libCtx, const char *attrName, BSL_Buffer *data,
86     const void *encodeParam, BSL_Buffer *encode);
87 #endif
88 
89 int32_t CRYPT_EAL_GetEncodeFormat(const char *format);
90 
91 int32_t CRYPT_EAL_GetEncodeType(const char *type);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif // HITLS_CRYPTO_CODECSKEY
98 
99 #endif // CRYPT_ENCODE_DECODE_KEY_H
100