mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 00:46:17 +08:00
Update SM2 arithmetic implementations
Decouple API and implementations. SM2 arithmetic exposes 3 types: GF(p), GF(n), and Point.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
@@ -317,6 +317,8 @@ typedef struct {
|
||||
uint8_t ciphertext[SM2_MAX_PLAINTEXT_SIZE];
|
||||
} SM2_CIPHERTEXT;
|
||||
|
||||
int sm2_kdf(const uint8_t *in, size_t inlen, size_t outlen, uint8_t *out);
|
||||
|
||||
int sm2_do_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, SM2_CIPHERTEXT *out);
|
||||
int sm2_do_decrypt(const SM2_KEY *key, const SM2_CIPHERTEXT *in, uint8_t *out, size_t *outlen);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint64_t SM2_Z256[4];
|
||||
|
||||
void sm2_z256_copy(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_copy_conditional(uint64_t dst[4], const uint64_t src[4], uint64_t move);
|
||||
@@ -43,12 +44,25 @@ void sm2_z256_modp_mul_by_2(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_modp_mul_by_3(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_modp_div_by_2(uint64_t r[4], const uint64_t a[4]);
|
||||
|
||||
void sm2_z256_to_mont(const uint64_t a[4], uint64_t r[4]);
|
||||
void sm2_z256_from_mont(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_mont_mul(uint64_t r[4], const uint64_t a[4], const uint64_t b[4]);
|
||||
void sm2_z256_mont_sqr(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_mont_inv(uint64_t r[4], const uint64_t a[4]);
|
||||
int sm2_z256_mont_print(FILE *fp, int ind, int fmt, const char *label, const uint64_t a[4]);
|
||||
void sm2_z256_modp_to_mont(const uint64_t a[4], uint64_t r[4]);
|
||||
void sm2_z256_modp_from_mont(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_modp_mont_mul(uint64_t r[4], const uint64_t a[4], const uint64_t b[4]);
|
||||
void sm2_z256_modp_mont_sqr(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_modp_mont_exp(uint64_t r[4], const uint64_t a[4], const uint64_t e[4]);
|
||||
void sm2_z256_modp_mont_inv(uint64_t r[4], const uint64_t a[4]);
|
||||
int sm2_z256_modp_mont_print(FILE *fp, int ind, int fmt, const char *label, const uint64_t a[4]);
|
||||
|
||||
void sm2_z256_modn_add(uint64_t r[4], const uint64_t a[4], const uint64_t b[4]);
|
||||
void sm2_z256_modn_sub(uint64_t r[4], const uint64_t a[4], const uint64_t b[4]);
|
||||
void sm2_z256_modn_neg(uint64_t r[4], const uint64_t a[4]);
|
||||
|
||||
void sm2_z256_modn_to_mont(const uint64_t a[4], uint64_t r[4]);
|
||||
void sm2_z256_modn_from_mont(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_modn_mont_mul(uint64_t r[4], const uint64_t a[4], const uint64_t b[4]);
|
||||
void sm2_z256_modn_mont_sqr(uint64_t r[4], const uint64_t a[4]);
|
||||
void sm2_z256_modn_mont_exp(uint64_t r[4], const uint64_t a[4], const uint64_t e[4]);
|
||||
void sm2_z256_modn_mont_inv(uint64_t r[4], const uint64_t a[4]);
|
||||
int sm2_z256_modn_mont_print(FILE *fp, int ind, int fmt, const char *label, const uint64_t a[4]);
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user