API参考
载入中...
搜索中...
未找到
hitls_cms_local.h
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 HITLS_CMS_LOCAL_H
17#define HITLS_CMS_LOCAL_H
18
19#include "hitls_build.h"
20#ifdef HITLS_PKI_CMS
21#include "hitls_x509_local.h"
22#include "crypt_eal_md.h"
23#include "hitls_cert_local.h"
24#include "hitls_pki_crl.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif /* __cplusplus */
29
30#ifdef HITLS_PKI_CMS_SIGNEDDATA
31
32#define HITLS_CMS_SIGNEDDATA_SIGNERINFO_V1 0x01
33#define HITLS_CMS_SIGNEDDATA_SIGNERINFO_V3 0x03
34
39typedef struct {
40 int32_t id;
41 BSL_Buffer param;
42 CRYPT_EAL_MdCtx *mdCtx;
43} CMS_AlgId;
44
49#define CMS_SignerInfos BslList
50
55typedef struct {
56 int32_t contentType;
57 BSL_Buffer content;
58} CMS_EncapContentInfo;
59
60#define HITLS_CMS_FLAG_GEN 0x01
61#define HITLS_CMS_FLAG_PARSE 0x02
62#define HITLS_CMS_FLAG_NO_SIGNEDATTR 0x08
63
68typedef struct _CMS_SignerInfo {
69 int32_t version;
70 BSL_ASN1_List *issuerName;
71 BSL_Buffer certSerialNum;
72 HITLS_X509_ExtSki subjectKeyId;
73 CMS_AlgId digestAlg;
74 HITLS_X509_Attrs *signedAttrs;
75 HITLS_X509_Asn1AlgId sigAlg;
76 HITLS_X509_Attrs *unsignedAttrs;
77 BSL_Buffer sigValue;
78 BSL_Buffer signData;
80 uint32_t flag;
81} CMS_SignerInfo;
82
83#define HITLS_CMS_UNINIT 0
84#define HITLS_CMS_SIGN_INIT 1
85#define HITLS_CMS_VERIFY_INIT 2
86#define HITLS_CMS_SIGN_FINISHED 3
87#define HITLS_CMS_VERIFY_FINISHED 4
92typedef struct {
93 int32_t version;
94 HITLS_X509_List *digestAlg;
95 CMS_EncapContentInfo encapCont;
96 HITLS_X509_List *certs;
97 HITLS_X509_List *crls;
98 CMS_SignerInfos *signerInfos;
99 uint32_t flag; // Used to mark signData parsing or generation, indicating resource release behavior.
100 uint8_t *initData;
101 bool detached;
102 uint32_t state;
103 HITLS_PKI_LibCtx *libCtx;
104 const char *attrName;
105} CMS_SignedData;
106
111typedef struct {
112 int32_t contentType;
113 BSL_Buffer content;
114} CMS_ContentInfo;
115
116typedef struct _HITLS_CMS {
117 int32_t dataType;
118 union {
119 CMS_SignedData *signedData;
120 } ctx;
121} HITLS_CMS;
122
129int32_t HITLS_CMS_ParseSignedData(HITLS_PKI_LibCtx *libCtx, const char *attrName, const BSL_Buffer *encode,
130 HITLS_CMS **signedData);
131
136CMS_SignerInfo *CMS_SignerInfoNew(uint32_t flag);
137
138void CMS_AlgIdFree(void *algId);
139
147int32_t HITLS_CMS_GenSignedDataBuff(int32_t format, HITLS_CMS *cms, BSL_Buffer *encode);
148
153void HITLS_CMS_SignerInfoFree(void *signerInfo);
154
158int32_t HITLS_CMS_AddMd(HITLS_X509_List *list, int32_t mdId);
159
163int32_t HITLS_CMS_SignedDataCtrl(HITLS_CMS *cms, int32_t cmd, void *val, uint32_t valLen);
164
168int32_t HITLS_CMS_AddCert(HITLS_X509_List **list, HITLS_X509_Cert *cert);
169
173int32_t HITLS_CMS_AddCrl(HITLS_X509_List **list, HITLS_X509_Crl *crl);
174
178int32_t HITLS_CMS_SignedDataInit(HITLS_CMS *cms, int32_t option, const BSL_Param *param);
179
183int32_t HITLS_CMS_SignedDataUpdate(HITLS_CMS *cms, const BSL_Buffer *input);
184
188int32_t HITLS_CMS_SignedDataFinal(HITLS_CMS *cms, const BSL_Param *param);
189
190#endif
191
192#ifdef HITLS_PKI_CMS_DATA
193// parse PKCS7-Data
194int32_t HITLS_CMS_ParseAsn1Data(BSL_Buffer *encode, BSL_Buffer *dataValue);
195#endif
196
197#ifdef HITLS_PKI_CMS_DIGESTINFO
198
199// parse PKCS7-DigestInfo:only support hash.
200int32_t HITLS_CMS_ParseDigestInfo(BSL_Buffer *encode, BslCid *cid, BSL_Buffer *digest);
201
202// encode PKCS7-DigestInfo:only support hash.
203int32_t HITLS_CMS_EncodeDigestInfoBuff(BslCid cid, BSL_Buffer *in, BSL_Buffer *encode);
204
205#endif
206
220int32_t HITLS_CMS_GenBuff(int32_t format, HITLS_CMS *cms, const BSL_Param *optionalParam, BSL_Buffer *encode);
221
234int32_t HITLS_CMS_GenFile(int32_t format, HITLS_CMS *cms, const BSL_Param *optionalParam, const char *path);
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif // HITLS_PKI_CMS
241
242#endif // HITLS_CMS_LOCAL_H
BslCid
定义 bsl_obj.h:36
定义 bsl_types.h:40