KT24-1110_65E-HA-651B/include_lib/system/crypto_toolbox/ecdh.h
2024-11-10 18:44:17 +08:00

42 lines
1.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _ECDH_H_
#define _ECDH_H_
#include "bigint_impl.h"
#define ECDH_MEM_POOL_SIZE 0x750
typedef struct {
bigint *x;
bigint *y;
bigint *z;
int Z_is_one;
int Z_is_zero;
} EC_POINT;
struct ECDH_CTX_st {
BI_CTX ctx;
EC_POINT G;
EC_POINT PubKey;
bigint *ECDHKey;
bigint *PriKey;
};
typedef struct ECDH_CTX_st ECDH_CTX;
//In:Prikey 24byte
//Out:PubKeyx PubKeyy 24byte
void ecdh_Generate_PublicKey(ECDH_CTX *ecdh_ctx, const unsigned char *PriKey, unsigned char *PubKeyx, unsigned char *PubKeyy);
//In:PublicKeyBx PublicKeyBy 24byte
//Out:DHKey 24byte
void ecdh_Compute_DHKey(ECDH_CTX *ecdh_ctx, unsigned char *PublicKeyBx, unsigned char *PublicKeyBy, unsigned char *DHKey);
///由于计算和用于发送的buffer存在大小端相反问题所以再封装一层函数
void ecdh_PublicKey(ECDH_CTX *ecdh_ctx, const unsigned char *PriKey, unsigned char *PubKeyx, unsigned char *PubKeyy);
void ecdh_DHKey(ECDH_CTX *ecdh_ctx, unsigned char *PublicKeyBx, unsigned char *PublicKeyBy, unsigned char *DHKey);
//ECDH_CTX *ecdh_init(void);
void ecdh_init(ECDH_CTX *ec_ctx, char *bigint_mem_pool);
void ecdh_free(ECDH_CTX *ecdh);
#endif