openHiTLS API openHiTLS 0.1.0-Alpha1
crypt_eal_pkey.h
浏览该文件的文档.
1/*---------------------------------------------------------------------------------------------
2 * This file is part of the openHiTLS project.
3 * Copyright © 2023 Huawei Technologies Co.,Ltd. All rights reserved.
4 * Licensed under the openHiTLS Software license agreement 1.0. See LICENSE in the project root
5 * for license information.
6 *---------------------------------------------------------------------------------------------
7 */
8
15#ifndef CRYPT_EAL_PKEY_H
16#define CRYPT_EAL_PKEY_H
17
18#include <stdbool.h>
19#include <stdint.h>
20#include "crypt_algid.h"
21#include "crypt_types.h"
22#include "crypt_method.h"
23#include "crypt_eal_pkey.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif // __cplusplus
28
34typedef struct {
36 union {
43 }key;
45
51typedef struct {
53 union {
60 } key;
62
69typedef struct {
71 union {
76 } para;
78
84typedef struct EAL_PkeyCtx CRYPT_EAL_PkeyCtx;
85
96
97/* Pkey external interface */
108
120
132
140
152
164
176
187
199
211
223
235
252int32_t CRYPT_EAL_PkeySign(const CRYPT_EAL_PkeyCtx *pkey, CRYPT_MD_AlgId id, const uint8_t *data,
253 uint32_t dataLen, uint8_t *sign, uint32_t *signLen);
254
269int32_t CRYPT_EAL_PkeyVerify(const CRYPT_EAL_PkeyCtx *pkey, CRYPT_MD_AlgId id, const uint8_t *data,
270 uint32_t dataLen, const uint8_t *sign, uint32_t signLen);
271
289int32_t CRYPT_EAL_PkeySignData(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *hash, uint32_t hashLen,
290 uint8_t *sign, uint32_t *signLen);
291
307int32_t CRYPT_EAL_PkeyVerifyData(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *hash, uint32_t hashLen,
308 const uint8_t *sign, uint32_t signLen);
309
324int32_t CRYPT_EAL_PkeyEncrypt(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *data, uint32_t dataLen,
325 uint8_t *out, uint32_t *outLen);
326
340int32_t CRYPT_EAL_PkeyDecrypt(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *data, uint32_t dataLen,
341 uint8_t *out, uint32_t *outLen);
342
354
369 uint8_t *share, uint32_t *shareLen);
370
381
392
403
414
427int32_t CRYPT_EAL_PkeyCtrl(CRYPT_EAL_PkeyCtx *pkey, int32_t opt, void *val, uint32_t len);
428
438
448
459
472
484
495
505typedef bool (*CRYPT_EAL_Pct)(CRYPT_EAL_PkeyCtx *pkey);
506
507
518
519#ifdef __cplusplus
520}
521#endif // __cplusplus
522
523#endif // CRYPT_EAL_PKEY_H
CRYPT_PKEY_ParaId
Definition crypt_algid.h:164
CRYPT_MD_AlgId
Definition crypt_algid.h:59
CRYPT_PKEY_AlgId
Definition crypt_algid.h:102
int32_t CRYPT_EAL_PkeyGetPara(const CRYPT_EAL_PkeyCtx *pkey, CRYPT_EAL_PkeyPara *para)
Obtain the key parameter, the key parameter marked as "para" is applied for and released by the calle...
int32_t CRYPT_EAL_PkeySetPrv(CRYPT_EAL_PkeyCtx *pkey, const CRYPT_EAL_PkeyPrv *key)
Set the private key. The caller applies for and releases memory for the private key marked as "key".
int32_t CRYPT_EAL_PkeyGen(CRYPT_EAL_PkeyCtx *pkey)
Generate the key data.
int32_t CRYPT_EAL_PkeyDecrypt(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *data, uint32_t dataLen, uint8_t *out, uint32_t *outLen)
Decrypt the data.
int32_t CRYPT_EAL_PkeySignData(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *hash, uint32_t hashLen, uint8_t *sign, uint32_t *signLen)
Sign hash data
int32_t CRYPT_EAL_PkeyVerifyData(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *hash, uint32_t hashLen, const uint8_t *sign, uint32_t signLen)
Verify the signature of the hash data
void * CRYPT_EAL_PkeyGetExtData(const CRYPT_EAL_PkeyCtx *pkey)
Obtain the user's personal data.
uint32_t CRYPT_EAL_PkeyGetSignLen(const CRYPT_EAL_PkeyCtx *pkey)
Obtains the signature length of the key for signature, only support algorithm that can be signed.
int32_t CRYPT_EAL_PkeyComputeShareKey(const CRYPT_EAL_PkeyCtx *pkey, const CRYPT_EAL_PkeyCtx *pubKey, uint8_t *share, uint32_t *shareLen)
Compute the shared key.
int32_t CRYPT_EAL_PkeyCheck(const CRYPT_EAL_PkeyCtx *pkey)
Check the key pair consistency. only supports CRYPT_PKEY_DH.
CRYPT_EAL_PkeyCtx * CRYPT_EAL_PkeyDupCtx(const CRYPT_EAL_PkeyCtx *pkey)
Copy the Pkey context. After the duplication is complete, call the CRYPT_EAL_PkeyFreeCtx interface to...
uint32_t CRYPT_EAL_PkeyGetKeyBits(const CRYPT_EAL_PkeyCtx *pkey)
Obtain the number of bits in the key length.
bool(* CRYPT_EAL_Pct)(CRYPT_EAL_PkeyCtx *pkey)
Key pairing consistency test
Definition crypt_eal_pkey.h:505
int32_t CRYPT_EAL_PkeyCtrl(CRYPT_EAL_PkeyCtx *pkey, int32_t opt, void *val, uint32_t len)
Make specific option for setting/obtain, supported option can see the structure of CRYPT_PkeyCtrl.
CRYPT_PKEY_AlgId CRYPT_EAL_PkeyGetId(const CRYPT_EAL_PkeyCtx *pkey)
Obtain the key algorithm type.
int32_t CRYPT_EAL_PkeyCopyCtx(CRYPT_EAL_PkeyCtx *to, const CRYPT_EAL_PkeyCtx *from)
Copy the pkey context.
int32_t CRYPT_EAL_PkeyCmp(const CRYPT_EAL_PkeyCtx *a, const CRYPT_EAL_PkeyCtx *b)
Compare keys or parameters
uint32_t CRYPT_EAL_PkeyGetSecurityBits(const CRYPT_EAL_PkeyCtx *pkey)
Obtain the key security strength. Only supports CRYPT_PKEY_RSA and CRYPT_PKEY_ECDSA.
int32_t CRYPT_EAL_PkeySetExtData(CRYPT_EAL_PkeyCtx *pkey, void *data)
Set the user's personal data.
CRYPT_EAL_PkeyCtx * CRYPT_EAL_PkeyNewCtx(CRYPT_PKEY_AlgId id)
Create an asymmetric key pair structure.
struct EAL_PkeyCtx CRYPT_EAL_PkeyCtx
Definition crypt_eal_pkey.h:84
CRYPT_PKEY_ParaId CRYPT_EAL_PkeyGetParaId(const CRYPT_EAL_PkeyCtx *pkey)
Obtain the key algorithm parameter ID.
int32_t CRYPT_EAL_PkeyUpRef(CRYPT_EAL_PkeyCtx *pkey)
EAL layer reference counting auto-increment
int32_t CRYPT_EAL_PkeyPairCheck(CRYPT_EAL_PkeyCtx *pubKey, CRYPT_EAL_PkeyCtx *prvKey)
Check whether the public and private keys match.
uint32_t CRYPT_EAL_PkeyGetKeyLen(const CRYPT_EAL_PkeyCtx *pkey)
Obtain the number of bytes in the key length.
int32_t CRYPT_EAL_PkeySetPub(CRYPT_EAL_PkeyCtx *pkey, const CRYPT_EAL_PkeyPub *key)
Set the public key. The caller applies for and releases memory for the public key marked as "key".
int32_t CRYPT_EAL_PkeySetPara(CRYPT_EAL_PkeyCtx *pkey, const CRYPT_EAL_PkeyPara *para)
Set the key parameters, the key parameter marked as "para" is applied for and released by the caller.
int32_t CRYPT_EAL_PkeySetParaById(CRYPT_EAL_PkeyCtx *pkey, CRYPT_PKEY_ParaId id)
Set key parameters.
void CRYPT_EAL_PkeyFreeCtx(CRYPT_EAL_PkeyCtx *pkey)
Release the asymmetric key pair structure.
int32_t CRYPT_EAL_PkeyVerify(const CRYPT_EAL_PkeyCtx *pkey, CRYPT_MD_AlgId id, const uint8_t *data, uint32_t dataLen, const uint8_t *sign, uint32_t signLen)
Signature verification interface
int32_t CRYPT_EAL_PkeyEncrypt(const CRYPT_EAL_PkeyCtx *pkey, const uint8_t *data, uint32_t dataLen, uint8_t *out, uint32_t *outLen)
Encrypt data.
int32_t CRYPT_EAL_PkeySign(const CRYPT_EAL_PkeyCtx *pkey, CRYPT_MD_AlgId id, const uint8_t *data, uint32_t dataLen, uint8_t *sign, uint32_t *signLen)
Signature interface
bool CRYPT_EAL_PkeyIsValidAlgId(CRYPT_PKEY_AlgId id)
Check whether the id is valid asymmetric algorithm ID.
int32_t CRYPT_EAL_PkeyGetPrv(const CRYPT_EAL_PkeyCtx *pkey, CRYPT_EAL_PkeyPrv *key)
Obtain the private key. The caller applies for and releases memory for the private key marked as "key...
int32_t CRYPT_EAL_PkeyGetPub(const CRYPT_EAL_PkeyCtx *pkey, CRYPT_EAL_PkeyPub *key)
Obtain the public key. The caller applies for and releases memory for the public key marked as "key".
CRYPT_DsaPub dsaPub
Definition crypt_eal_pkey.h:38
CRYPT_DhPub dhPub
Definition crypt_eal_pkey.h:39
CRYPT_EccPub eccPub
Definition crypt_eal_pkey.h:40
CRYPT_PKEY_AlgId id
Definition crypt_eal_pkey.h:35
CRYPT_Curve25519Pub curve25519Pub
Definition crypt_eal_pkey.h:41
CRYPT_RsaPub rsaPub
Definition crypt_eal_pkey.h:37
CRYPT_Curve448Pub curve448Pub
Definition crypt_eal_pkey.h:42
Definition crypt_eal_pkey.h:34
CRYPT_EccPrv eccPrv
Definition crypt_eal_pkey.h:57
CRYPT_DhPrv dhPrv
Definition crypt_eal_pkey.h:56
CRYPT_Curve448Prv curve448Prv
Definition crypt_eal_pkey.h:59
CRYPT_Curve25519Prv curve25519Prv
Definition crypt_eal_pkey.h:58
CRYPT_RsaPrv rsaPrv
Definition crypt_eal_pkey.h:54
CRYPT_DsaPrv dsaPrv
Definition crypt_eal_pkey.h:55
CRYPT_PKEY_AlgId id
Definition crypt_eal_pkey.h:52
Definition crypt_eal_pkey.h:51
CRYPT_RsaPara rsaPara
Definition crypt_eal_pkey.h:72
CRYPT_PKEY_AlgId id
Definition crypt_eal_pkey.h:70
CRYPT_EccPara eccPara
Definition crypt_eal_pkey.h:75
CRYPT_DsaPara dsaPara
Definition crypt_eal_pkey.h:73
CRYPT_DhPara dhPara
Definition crypt_eal_pkey.h:74
Definition crypt_eal_pkey.h:69
Definition crypt_types.h:31
Definition crypt_types.h:81
Definition crypt_types.h:105
Definition crypt_types.h:183
Definition crypt_types.h:251
Definition crypt_types.h:262
Definition crypt_types.h:276