91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 21KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發布日期: 2024-01-28
  • 語言: C/C++
  • 標簽: 國密??SM2??SM3??openssl??

資源簡介

openssl庫,純C語言寫的SM2-SM3國密相關的內容,封裝加解密簽名驗簽等函數,可配合openssl動態庫內使用

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?

static?int?ec_field_inverse_mod_ord(const?EC_GROUP?*group?BIGNUM?*r
????????????????????????????????????const?BIGNUM?*x?BN_CTX?*ctx)
{
????BIGNUM?*e?=?NULL;
????BN_CTX?*new_ctx?=?NULL;
????int?ret?=?0;

????if?(group->mont_data?==?NULL)
????????return?0;

????if?(ctx?==?NULL?&&?(ctx?=?new_ctx?=?BN_CTX_secure_new())?==?NULL)
????????return?0;

????BN_CTX_start(ctx);
????if?((e?=?BN_CTX_get(ctx))?==?NULL)
????????goto?err;

????/*-
?????*?We?want?inverse?in?constant?time?therefore?we?utilize?the?fact
?????*?order?must?be?prime?and?use?Fermats?Little?Theorem?instead.
?????*/
????if?(!BN_set_word(e?2))
????????goto?err;
????if?(!BN_sub(e?group->order?e))
????????goto?err;
????/*-
?????*?Exponent?e?is?public.
?????*?No?need?for?scatter-gather?or?BN_FLG_CONSTTIME.
?????*/
????if?(!BN_mod_exp_mont(r?x?e?group->order?ctx?group->mont_data))
????????goto?err;

????ret?=?1;

?err:
????BN_CTX_end(ctx);
????BN_CTX_free(new_ctx);
????return?ret;
}

static?int?ec_group_do_inverse_ord(const?EC_GROUP?*group?BIGNUM?*res
const?BIGNUM?*x?BN_CTX?*ctx)
{
if?(group->meth->field_inverse_mod_ord?!=?NULL)
return?group->meth->field_inverse_mod_ord(group?res?x?ctx);
else
return?ec_field_inverse_mod_ord(group?res?x?ctx);
}

static?int?sm2_compute_z_digest(uint8_t?*out
?????????????????????????const?EVP_MD?*digest
?????????????????????????const?uint8_t?*id
?????????????????????????const?size_t?id_len
?????????????????????????const?EC_KEY?*key)
{
????int?rc?=?0;
????const?EC_GROUP?*group?=?EC_KEY_get0_group(key);
????BN_CTX?*ctx?=?NULL;
????EVP_MD_CTX?*hash?=?NULL;
????BIGNUM?*p?=?NULL;
????BIGNUM?*a?=?NULL;
????BIGNUM?*b?=?NULL;
????BIGNUM?*xG?=?NULL;
????BIGNUM?*yG?=?NULL;
????BIGNUM?*xA?=?NULL;
????BIGNUM?*yA?=?NULL;
????int?p_bytes?=?0;
????uint8_t?*buf?=?NULL;
????uint16_t?entl?=?0;
????uint8_t?e_byte?=?0;

????hash?=?EVP_MD_CTX_new();
????ctx?=?BN_CTX_new();
????if?(hash?==?NULL?||?ctx?==?NULL)?{
????????goto?done;
????}

????p?=?BN_CTX_get(ctx);
????a?=?BN_CTX_get(ctx);
????b?=?BN_CTX_get(ctx);
????xG?=?BN_CTX_get(ctx);
????yG?=?BN_CTX_get(ctx);
????xA?=?BN_CTX_get(ctx);
????yA?=?BN_CTX_get(ctx);

????if?(yA?==?NULL)?{
????????goto?done;
????}

????if?(!EVP_DigestInit(hash?digest))?{
????????goto?done;
????}

????/*?Z?=?h(ENTL?||?ID?||?a?||?b?||?xG?||?yG?||?xA?||?yA)?*/

????if?(id_len?>=?(UINT16_MAX?/?8))?{
????????/*?too?large?*/
????????goto?done;
????}

????entl?=?(uint16_t)(8?*?id_len);

????e_byte?=?entl?>>?8;
????if?(!EVP_DigestUpdate(hash?&e_byte?1))?{
????????goto?done;
????}
????e_byte?=?entl?&?0xFF;
????if?(!EVP_DigestUpdate(hash?

評論

共有 條評論