API参考
载入中...
搜索中...
未找到
auth_otp.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 AUTH_OTP_H
17#define AUTH_OTP_H
18
19#include <stdint.h>
20#include "bsl_params.h"
21#include "bsl_obj.h"
22#include "crypt_types.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
34
35typedef enum {
36 HITLS_AUTH_OTP_HOTP = 1,
37 HITLS_AUTH_OTP_TOTP = 2,
38} HITLS_AUTH_OtpType;
39
40/* Commands for parameter operations and retrieval */
41typedef enum {
42 HITLS_AUTH_OTP_SET_CTX_DIGITS = 1,
43 HITLS_AUTH_OTP_SET_CTX_HASHALGID = 2,
44 HITLS_AUTH_OTP_SET_CTX_TOTP_TIMESTEPSIZE = 3,
45 HITLS_AUTH_OTP_SET_CTX_TOTP_STARTOFFSET = 4,
46 HITLS_AUTH_OTP_SET_CTX_TOTP_VALIDWINDOW = 5,
47 HITLS_AUTH_OTP_GET_CTX_PROTOCOLTYPE = 6,
48 HITLS_AUTH_OTP_GET_CTX_KEY = 7,
49 HITLS_AUTH_OTP_GET_CTX_DIGITS = 8,
50 HITLS_AUTH_OTP_GET_CTX_HASHALGID = 9,
51 HITLS_AUTH_OTP_GET_CTX_TOTP_TIMESTEPSIZE = 10,
52 HITLS_AUTH_OTP_GET_CTX_TOTP_STARTOFFSET = 11,
53 HITLS_AUTH_OTP_GET_CTX_TOTP_VALIDWINDOW = 12,
54} HITLS_AUTH_OtpCmd;
55
56/* HMAC hashing algorithm used in TOTP. */
57typedef enum {
58 HITLS_AUTH_OTP_CRYPTO_SHA1 = BSL_CID_HMAC_SHA1,
59 HITLS_AUTH_OTP_CRYPTO_SHA256 = BSL_CID_HMAC_SHA256,
60 HITLS_AUTH_OTP_CRYPTO_SHA512 = BSL_CID_HMAC_SHA512
61} HITLS_AUTH_OtpCryptAlgId;
62
63typedef enum {
64 HITLS_AUTH_OTP_RANDOM_CB = 1,
65 HITLS_AUTH_OTP_HMAC_CB = 2,
66} HITLS_AUTH_OtpCryptCbType;
67
85typedef int32_t (*HITLS_AUTH_OtpHmac)(void *libCtx, const char *attrName, int32_t algId, const uint8_t *key,
86 uint32_t keyLen, const uint8_t *input, uint32_t inputLen, uint8_t *hmac,
87 uint32_t *hmacLen);
88
99typedef int32_t (*HITLS_AUTH_OtpRandom)(uint8_t *buffer, uint32_t bufferLen);
100
109HITLS_AUTH_OtpCtx *HITLS_AUTH_OtpNewCtx(int32_t protocolType);
110
121HITLS_AUTH_OtpCtx *HITLS_AUTH_ProviderOtpNewCtx(CRYPT_EAL_LibCtx *libCtx, int32_t protocolType, const char *attrName);
122
130
143int32_t HITLS_AUTH_OtpSetCryptCb(HITLS_AUTH_OtpCtx *ctx, int32_t cbType, void *cryptCb);
144
156int32_t HITLS_AUTH_OtpInit(HITLS_AUTH_OtpCtx *ctx, uint8_t *key, uint32_t keyLen);
157
170int32_t HITLS_AUTH_OtpGen(HITLS_AUTH_OtpCtx *ctx, const BSL_Param *param, char *otp, uint32_t *otpLen);
171
187int32_t HITLS_AUTH_OtpValidate(HITLS_AUTH_OtpCtx *ctx, const BSL_Param *param, const char *otp, const uint32_t otpLen,
188 uint64_t *matched);
189
202int32_t HITLS_AUTH_OtpCtxCtrl(HITLS_AUTH_OtpCtx *ctx, int32_t cmd, void *param, uint32_t paramLen);
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif // AUTH_OTP_H
int32_t HITLS_AUTH_OtpGen(HITLS_AUTH_OtpCtx *ctx, const BSL_Param *param, char *otp, uint32_t *otpLen)
Generate an OTP.
定义 otp.c:162
HITLS_AUTH_OtpCtx * HITLS_AUTH_ProviderOtpNewCtx(CRYPT_EAL_LibCtx *libCtx, int32_t protocolType, const char *attrName)
Create a new OTP context object with provider, all library callbacks by default are set when created.
定义 otp_util.c:234
int32_t HITLS_AUTH_OtpValidate(HITLS_AUTH_OtpCtx *ctx, const BSL_Param *param, const char *otp, const uint32_t otpLen, uint64_t *matched)
Validate the OTP.
定义 otp.c:236
void HITLS_AUTH_OtpFreeCtx(HITLS_AUTH_OtpCtx *ctx)
Free a OTP context object.
定义 otp_util.c:287
int32_t(* HITLS_AUTH_OtpHmac)(void *libCtx, const char *attrName, int32_t algId, const uint8_t *key, uint32_t keyLen, const uint8_t *input, uint32_t inputLen, uint8_t *hmac, uint32_t *hmacLen)
Compute HMAC of the key and input data.
定义 auth_otp.h:85
int32_t HITLS_AUTH_OtpInit(HITLS_AUTH_OtpCtx *ctx, uint8_t *key, uint32_t keyLen)
Set or generate a random OTP key.
定义 otp.c:28
int32_t HITLS_AUTH_OtpSetCryptCb(HITLS_AUTH_OtpCtx *ctx, int32_t cbType, void *cryptCb)
Set cryptographic callback functions for the context. When setting callbacks, the input callbacks wil...
定义 otp_util.c:307
int32_t(* HITLS_AUTH_OtpRandom)(uint8_t *buffer, uint32_t bufferLen)
Generate random bytes.
定义 auth_otp.h:99
HITLS_AUTH_OtpCtx * HITLS_AUTH_OtpNewCtx(int32_t protocolType)
Create a new OTP context object, all library callbacks by default are set when created.
定义 otp_util.c:230
int32_t HITLS_AUTH_OtpCtxCtrl(HITLS_AUTH_OtpCtx *ctx, int32_t cmd, void *param, uint32_t paramLen)
Control interface for getting/setting various parameters in OTP Ctx.
定义 otp_util.c:184
struct Otp_Ctx HITLS_AUTH_OtpCtx
定义 auth_otp.h:33
定义 otp.h:48