16#ifndef CRYPT_CURVE25519_H
17#define CRYPT_CURVE25519_H
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_CURVE25519
23#include "crypt_local_types.h"
24#include "bsl_params.h"
30#define CRYPT_CURVE25519_KEYLEN 32
31#define CRYPT_CURVE25519_SIGNLEN 64
33typedef struct CryptCurve25519Ctx CRYPT_CURVE25519_Ctx;
35#ifdef HITLS_CRYPTO_X25519
43CRYPT_CURVE25519_Ctx *CRYPT_X25519_NewCtx(
void);
54CRYPT_CURVE25519_Ctx *CRYPT_X25519_NewCtxEx(
void *libCtx);
57#ifdef HITLS_CRYPTO_ED25519
65CRYPT_CURVE25519_Ctx *CRYPT_ED25519_NewCtx(
void);
76CRYPT_CURVE25519_Ctx *CRYPT_ED25519_NewCtxEx(
void *libCtx);
88CRYPT_CURVE25519_Ctx *CRYPT_CURVE25519_DupCtx(CRYPT_CURVE25519_Ctx *ctx);
96void CRYPT_CURVE25519_FreeCtx(CRYPT_CURVE25519_Ctx *pkey);
112int32_t CRYPT_CURVE25519_Ctrl(CRYPT_CURVE25519_Ctx *pkey, int32_t opt,
void *val, uint32_t len);
125int32_t CRYPT_CURVE25519_SetPubKey(CRYPT_CURVE25519_Ctx *pkey,
const CRYPT_Curve25519Pub *pub);
139int32_t CRYPT_CURVE25519_GetPubKey(
const CRYPT_CURVE25519_Ctx *pkey,
CRYPT_Curve25519Pub *pub);
152int32_t CRYPT_CURVE25519_SetPrvKey(CRYPT_CURVE25519_Ctx *pkey,
const CRYPT_Curve25519Prv *prv);
166int32_t CRYPT_CURVE25519_GetPrvKey(
const CRYPT_CURVE25519_Ctx *pkey,
CRYPT_Curve25519Prv *prv);
168#ifdef HITLS_BSL_PARAMS
180int32_t CRYPT_CURVE25519_SetPubKeyEx(CRYPT_CURVE25519_Ctx *pkey,
const BSL_Param *para);
193int32_t CRYPT_CURVE25519_SetPrvKeyEx(CRYPT_CURVE25519_Ctx *pkey,
const BSL_Param *para);
207int32_t CRYPT_CURVE25519_GetPubKeyEx(
const CRYPT_CURVE25519_Ctx *pkey, BSL_Param *para);
221int32_t CRYPT_CURVE25519_GetPrvKeyEx(
const CRYPT_CURVE25519_Ctx *pkey, BSL_Param *para);
232int32_t CRYPT_CURVE25519_GetBits(
const CRYPT_CURVE25519_Ctx *pkey);
234#ifdef HITLS_CRYPTO_ED25519
255int32_t CRYPT_CURVE25519_Sign(CRYPT_CURVE25519_Ctx *pkey, int32_t algId,
const uint8_t *msg,
256 uint32_t msgLen, uint8_t *sign, uint32_t *signLen);
266int32_t CRYPT_CURVE25519_GetSignLen(
const CRYPT_CURVE25519_Ctx *pkey);
288int32_t CRYPT_CURVE25519_Verify(
const CRYPT_CURVE25519_Ctx *pkey, int32_t algId,
const uint8_t *msg,
289 uint32_t msgLen,
const uint8_t *sign, uint32_t signLen);
304int32_t CRYPT_ED25519_GenKey(CRYPT_CURVE25519_Ctx *pkey);
307#ifdef HITLS_CRYPTO_X25519
320int32_t CRYPT_CURVE25519_ComputeSharedKey(CRYPT_CURVE25519_Ctx *prvKey, CRYPT_CURVE25519_Ctx *pubKey,
321 uint8_t *sharedKey, uint32_t *shareKeyLen);
334int32_t CRYPT_X25519_GenKey(CRYPT_CURVE25519_Ctx *pkey);
337#ifdef HITLS_CRYPTO_CURVE25519_CMP
349int32_t CRYPT_CURVE25519_Cmp(
const CRYPT_CURVE25519_Ctx *a,
const CRYPT_CURVE25519_Ctx *b);
351#define CRYPT_CURVE25519_Cmp NULL
362int32_t CRYPT_CURVE25519_GetSecBits(
const CRYPT_CURVE25519_Ctx *ctx);
364#ifdef HITLS_CRYPTO_KEY_DECODE_CHAIN
372int32_t CRYPT_CURVE25519_Import(CRYPT_CURVE25519_Ctx *ctx,
const BSL_Param *params);
381int32_t CRYPT_CURVE25519_Export(
const CRYPT_CURVE25519_Ctx *ctx, BSL_Param *params);
384#ifdef HITLS_CRYPTO_ED25519_CHECK
397int32_t CRYPT_ED25519_Check(uint32_t checkType,
const CRYPT_CURVE25519_Ctx *pkey1,
const CRYPT_CURVE25519_Ctx *pkey2);
400#ifdef HITLS_CRYPTO_X25519_CHECK
412int32_t CRYPT_X25519_Check(uint32_t checkType,
const CRYPT_CURVE25519_Ctx *pkey1,
const CRYPT_CURVE25519_Ctx *pkey2);
CRYPT_Data CRYPT_Curve25519Prv
定义 crypt_types.h:310
CRYPT_Data CRYPT_Curve25519Pub
定义 crypt_types.h:449