Skip to content

Commit

Permalink
Add sm2_encrypt_pre_compute
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Apr 25, 2024
1 parent f0859a1 commit 3f1fdc1
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 94 deletions.
35 changes: 27 additions & 8 deletions include/gmssl/sm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,36 @@ _gmssl_export int sm2_ecdh(const SM2_KEY *key, const uint8_t *peer_public, size_


typedef struct {
SM2_KEY sm2_key;
uint8_t buf[SM2_MAX_CIPHERTEXT_SIZE];
sm2_z256_t k;
SM2_POINT C1;
} SM2_ENC_PRE_COMP;

#define SM2_ENC_PRE_COMP_NUM 8
int sm2_encrypt_pre_compute(SM2_ENC_PRE_COMP pre_comp[SM2_ENC_PRE_COMP_NUM]);
int sm2_do_encrypt_ex(const SM2_KEY *key, const SM2_ENC_PRE_COMP *pre_comp,
const uint8_t *in, size_t inlen, SM2_CIPHERTEXT *out);

typedef struct {
SM2_ENC_PRE_COMP pre_comp[SM2_ENC_PRE_COMP_NUM];
size_t pre_comp_num;
uint8_t buf[SM2_MAX_PLAINTEXT_SIZE];
size_t buf_size;
} SM2_ENC_CTX;

_gmssl_export int sm2_encrypt_init(SM2_ENC_CTX *ctx, const SM2_KEY *sm2_key);
_gmssl_export int sm2_encrypt_update(SM2_ENC_CTX *ctx, const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen);
_gmssl_export int sm2_encrypt_finish(SM2_ENC_CTX *ctx, const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen);
_gmssl_export int sm2_decrypt_init(SM2_ENC_CTX *ctx, const SM2_KEY *sm2_key);
_gmssl_export int sm2_decrypt_update(SM2_ENC_CTX *ctx, const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen);
_gmssl_export int sm2_decrypt_finish(SM2_ENC_CTX *ctx, const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen);
_gmssl_export int sm2_encrypt_init(SM2_ENC_CTX *ctx);
_gmssl_export int sm2_encrypt_update(SM2_ENC_CTX *ctx, const uint8_t *in, size_t inlen);
_gmssl_export int sm2_encrypt_finish(SM2_ENC_CTX *ctx, const SM2_KEY *public_key, uint8_t *out, size_t *outlen);
_gmssl_export int sm2_encrypt_reset(SM2_ENC_CTX *ctx);

typedef struct {
uint8_t buf[SM2_MAX_CIPHERTEXT_SIZE];
size_t buf_size;
} SM2_DEC_CTX;

_gmssl_export int sm2_decrypt_init(SM2_DEC_CTX *ctx);
_gmssl_export int sm2_decrypt_update(SM2_DEC_CTX *ctx, const uint8_t *in, size_t inlen);
_gmssl_export int sm2_decrypt_finish(SM2_DEC_CTX *ctx, const SM2_KEY *key, uint8_t *out, size_t *outlen);
_gmssl_export int sm2_decrypt_reset(SM2_DEC_CTX *ctx);


#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 3f1fdc1

Please sign in to comment.