Remove unused macros

Remove fp_ fn_ macros can reduce the API size. Another reason is that some macros such as fp_equ, fn_equ, can not return correct result on `a` and `a + modulus`
This commit is contained in:
Zhi Guan
2024-04-13 18:41:19 +08:00
parent 0daba2e61d
commit e9d61cb1f4
5 changed files with 23 additions and 562 deletions

View File

@@ -59,7 +59,7 @@ int sm9_sign_master_key_to_der(const SM9_SIGN_MASTER_KEY *msk, uint8_t **out, si
uint8_t Ppubs[1 + 32 * 4];
size_t len = 0;
sm9_z256_fn_to_bytes(msk->ks, ks);
sm9_z256_to_bytes(msk->ks, ks);
sm9_z256_twist_point_to_uncompressed_octets(&msk->Ppubs, Ppubs);
if (asn1_integer_to_der(ks, sizeof(ks), NULL, &len) != 1
@@ -206,7 +206,7 @@ int sm9_enc_master_key_to_der(const SM9_ENC_MASTER_KEY *msk, uint8_t **out, size
uint8_t Ppube[1 + 32 * 2];
size_t len = 0;
sm9_z256_fn_to_bytes(msk->ke, ke);
sm9_z256_to_bytes(msk->ke, ke);
sm9_z256_point_to_uncompressed_octets(&msk->Ppube, Ppube);
if (asn1_integer_to_der(ke, sizeof(ke), NULL, &len) != 1
@@ -383,7 +383,7 @@ int sm9_sign_master_key_extract_key(SM9_SIGN_MASTER_KEY *msk, const char *id, si
// t1 = H1(ID || hid, N) + ks
sm9_z256_hash1(t, id, idlen, SM9_HID_SIGN);
sm9_z256_fn_add(t, t, msk->ks);
if (sm9_z256_fn_is_zero(t)) {
if (sm9_z256_is_zero(t)) {
// 这是一个严重问题意味着整个msk都需要作废了
error_print();
return -1;
@@ -408,7 +408,7 @@ int sm9_enc_master_key_extract_key(SM9_ENC_MASTER_KEY *msk, const char *id, size
// t1 = H1(ID || hid, N) + ke
sm9_z256_hash1(t, id, idlen, SM9_HID_ENC);
sm9_z256_fn_add(t, t, msk->ke);
if (sm9_z256_fn_is_zero(t)) {
if (sm9_z256_is_zero(t)) {
error_print();
return -1;
}
@@ -432,7 +432,7 @@ int sm9_exch_master_key_extract_key(SM9_EXCH_MASTER_KEY *msk, const char *id, si
// t1 = H1(ID || hid, N) + ke
sm9_z256_hash1(t, id, idlen, SM9_HID_EXCH);
sm9_z256_fn_add(t, t, msk->ke);
if (sm9_z256_fn_is_zero(t)) {
if (sm9_z256_is_zero(t)) {
error_print();
return -1;
}
@@ -1075,7 +1075,7 @@ int sm9_sign_master_key_print(FILE *fp, int fmt, int ind, const char *label, con
{
format_print(fp, fmt, ind, "%s\n", label);
ind += 4;
sm9_z256_fn_print(fp, fmt, ind, "ks", msk->ks);
sm9_z256_print(fp, fmt, ind, "ks", msk->ks);
sm9_z256_twist_point_print(fp, fmt, ind, "Ppubs", &msk->Ppubs);
return 1;
}
@@ -1101,7 +1101,7 @@ int sm9_enc_master_key_print(FILE *fp, int fmt, int ind, const char *label, cons
{
format_print(fp, fmt, ind, "%s\n", label);
ind += 4;
sm9_z256_fn_print(fp, fmt, ind, "ke", msk->ke);
sm9_z256_print(fp, fmt, ind, "ke", msk->ke);
sm9_z256_point_print(fp, fmt, ind, "Ppube", &msk->Ppube);
return 1;
}

View File

@@ -31,7 +31,7 @@ int sm9_signature_to_der(const SM9_SIGNATURE *sig, uint8_t **out, size_t *outlen
uint8_t Sbuf[65];
size_t len = 0;
sm9_z256_fn_to_bytes(sig->h, hbuf);
sm9_z256_to_bytes(sig->h, hbuf);
sm9_z256_point_to_uncompressed_octets(&sig->S, Sbuf);
if (asn1_octet_string_to_der(hbuf, sizeof(hbuf), NULL, &len) != 1
@@ -145,7 +145,7 @@ int sm9_do_sign(const SM9_SIGN_KEY *key, const SM3_CTX *sm3_ctx, SM9_SIGNATURE *
// A5: l = (r - h) mod N, if l = 0, goto A2
sm9_z256_fn_sub(r, r, sig->h);
} while (sm9_z256_fn_is_zero(r));
} while (sm9_z256_is_zero(r));
// A6: S = l * dsA
sm9_z256_point_mul(&sig->S, r, &key->ds);
@@ -241,7 +241,7 @@ int sm9_do_verify(const SM9_SIGN_MASTER_KEY *mpk, const char *id, size_t idlen,
sm3_update(&tmp_ctx, ct2, sizeof(ct2));
sm3_finish(&tmp_ctx, Ha + 32);
sm9_z256_fn_from_hash(h2, Ha);
if (sm9_z256_fn_equ(h2, sig->h) != 1) {
if (sm9_z256_equ(h2, sig->h) != 1) {
return 0;
}