API参考
载入中...
搜索中...
未找到
app_utils.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_APP_UTILS_H
17#define HITLS_APP_UTILS_H
18#include <stddef.h>
19#include <stdint.h>
20#include "bsl_ui.h"
21#include "bsl_types.h"
22#include "crypt_eal_pkey.h"
23#include "app_conf.h"
24#include "app_provider.h"
25#include "app_sm.h"
26#include "hitls_csr_local.h"
27#include "bsl_pem_internal.h"
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#define APP_MAX_PASS_LENGTH 1024
33#define APP_MIN_PASS_LENGTH 1
34#define APP_FILE_MAX_SIZE_KB 256
35#define APP_FILE_MAX_SIZE (APP_FILE_MAX_SIZE_KB * 1024) // 256KB
36#define APP_HEX_TO_BYTE 2
37
38#define APP_MAX_PATH_LEN PATH_MAX
39
40#define DEFAULT_SALTLEN 16
41#define DEFAULT_ITCNT 2048
42
43#define MAX_DIGEST_SIZE (1024 * 8) // Indicates the length of a single digest during digest calculation.
44
58int32_t HITLS_APP_CheckPasswd(const uint8_t *password, const uint32_t passwordLen);
59
60int32_t HITLS_APP_Passwd(char *buf, int32_t bufMaxLen, int32_t flag);
61
62void HITLS_APP_PrintPassErrlog(void);
76int32_t HITLS_APP_ParsePasswd(const char *passArg, char **pass);
77
88int32_t HITLS_APP_GetPasswd(BSL_UI_ReadPwdParam *param, char **passin, uint32_t *passLen);
89
102CRYPT_EAL_PkeyCtx *HITLS_APP_LoadPubKey(const char *inFilePath, BSL_ParseFormat informat);
103
120CRYPT_EAL_PkeyCtx *HITLS_APP_ProviderLoadPrvKey(CRYPT_EAL_LibCtx *libCtx, const char *attrName,
121 const char *inFilePath, BSL_ParseFormat informat, char **passin);
122
136CRYPT_EAL_PkeyCtx *HITLS_APP_LoadPrvKey(const char *inFilePath, BSL_ParseFormat informat, char **passin);
137
154int32_t HITLS_APP_PrintPubKey(CRYPT_EAL_PkeyCtx *pkey, const char *outFilePath, BSL_ParseFormat outformat);
155
175int32_t HITLS_APP_PrintPrvKey(CRYPT_EAL_PkeyCtx *pkey, const char *outFilePath, BSL_ParseFormat outformat,
176 int32_t cipherAlgCid, char **passout);
177
178typedef struct {
179 const char *name;
180 BSL_ParseFormat outformat;
181 int32_t cipherAlgCid;
182 bool text;
183 bool noout;
185
186int32_t HITLS_APP_PrintPrvKeyByUio(BSL_UIO *uio, CRYPT_EAL_PkeyCtx *pkey, AppKeyPrintParam *printKeyParam,
187 char **passout);
188
200int32_t HITLS_APP_GetAndCheckCipherOpt(const char *name, int32_t *symId);
201
212HITLS_X509_Cert *HITLS_APP_LoadCert(const char *inPath, BSL_ParseFormat inform);
213
224HITLS_X509_Csr *HITLS_APP_LoadCsr(const char *inPath, BSL_ParseFormat inform);
225
236HITLS_X509_Crl *HITLS_APP_LoadCrl(const char *inPath, BSL_ParseFormat inform);
237
238int32_t HITLS_APP_GetAndCheckHashOpt(const char *name, int32_t *hashId);
239
240int32_t HITLS_APP_PrintText(const BSL_Buffer *csrBuf, const char *outFileName);
241
259int32_t HITLS_APP_ParseHex(const char *hexStr, bool expectPrefix, uint8_t **bytes, uint32_t *bytesLen);
260
261CRYPT_EAL_PkeyCtx *HITLS_APP_GenRsaPkeyCtx(uint32_t bits);
262
278int32_t HITLS_APP_HexToBytes(const char *hexStr, uint8_t *bytes, uint32_t *bytesLen);
279
280int32_t HITLS_APP_ReadData(const char *path, BSL_PEM_Symbol *symbol, char *fileName, BSL_Buffer *data);
281
301int32_t HITLS_APP_ReadFileOrStdin(uint8_t **buf, uint64_t *bufLen, const char *inFile,
302 uint32_t maxSize, const char *module);
303
304typedef struct {
305 int32_t randAlgId;
306 AppProvider *provider;
307#ifdef HITLS_APP_SM_MODE
308 HITLS_APP_SM_Param *smParam;
309#endif
311
312int32_t HITLS_APP_Init(AppInitParam *param);
313
314void HITLS_APP_Deinit(AppInitParam *param, int32_t ret);
315
316int32_t HITLS_APP_GetTime(int64_t *time);
317
318#ifdef __cplusplus
319}
320#endif
321#endif // HITLS_APP_UTILS_H
struct UIO_ControlBlock BSL_UIO
UIO module control structure
定义 bsl_uio.h:37
struct EAL_PkeyCtx CRYPT_EAL_PkeyCtx
定义 crypt_eal_pkey.h:108
定义 app_utils.h:304
定义 app_utils.h:178
定义 app_provider.h:25
定义 bsl_types.h:40
BSL_UI read pwd parameters
定义 bsl_ui.h:71