资源简介
SM2.rar
代码片段和文件信息
// \file:sm2.c
//SM2 Algorithm
//2011-11-10
//author:goldboar
//email:goldboar@163.com
//depending:opnessl library
//SM2 Standards: http://www.oscca.gov.cn/News/201012/News_1197.htm
#include
#include
#include
#include
#include
#include
#include
#include “kdf.h“
#include “sm2.h“
#define NID_X9_62_prime_field 406
static void BNPrintf(BIGNUM* bn)
{
char *p=NULL;
p=BN_bn2hex(bn);
printf(“%s“p);
OPENSSL_free(p);
}
static int sm2_sign_setup(EC_KEY *eckey BN_CTX *ctx_in BIGNUM **kp BIGNUM **rp)
{
BN_CTX *ctx = NULL;
BIGNUM *k = NULL *r = NULL *order = NULL *X = NULL;
EC_POINT *tmp_point=NULL;
const EC_GROUP *group;
int ret = 0;
if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL)
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if (ctx_in == NULL)
{
if ((ctx = BN_CTX_new()) == NULL)
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUPERR_R_MALLOC_FAILURE);
return 0;
}
}
else
ctx = ctx_in;
k = BN_new(); /* this value is later returned in *kp */
r = BN_new(); /* this value is later returned in *rp */
order = BN_new();
X = BN_new();
if (!k || !r || !order || !X)
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ERR_R_MALLOC_FAILURE);
goto err;
}
if ((tmp_point = EC_POINT_new(group)) == NULL)
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ERR_R_EC_LIB);
goto err;
}
if (!EC_GROUP_get_order(group order ctx))
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ERR_R_EC_LIB);
goto err;
}
do
{
/* get random k */
do
if (!BN_rand_range(k order))
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED);
goto err;
}
while (BN_is_zero(k));
/* compute r the x-coordinate of generator * k */
if (!EC_POINT_mul(group tmp_point k NULL NULL ctx))
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ERR_R_EC_LIB);
goto err;
}
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field)
{
if (!EC_POINT_get_affine_coordinates_GFp(group
tmp_point X NULL ctx))
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUPERR_R_EC_LIB);
goto err;
}
}
else /* NID_X9_62_characteristic_two_field */
{
if (!EC_POINT_get_affine_coordinates_GF2m(group
tmp_point X NULL ctx))
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUPERR_R_EC_LIB);
goto err;
}
}
if (!BN_nnmod(r X order ctx))
{
ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ERR_R_BN_LIB);
goto err;
}
}
while (BN_is_zero(r));
/* compute the inverse of k */
// if (!BN_mod_inverse(k k order ctx))
// {
// ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP ERR_R_BN_LIB);
// goto err;
// }
/* clear old values if necessary */
if (*rp != NULL)
BN_clear_free(*rp);
if (*kp != NULL)
BN_clear_free(*kp);
/* save the pre-com
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 19188 2016-04-21 00:45 SM2\sm2.c
文件 909 2011-11-10 18:12 SM2\sm2.h
文件 13436 2017-11-28 09:45 SM2\sm2_custom.cpp
文件 2958 2016-05-05 09:51 SM2\sm2_custom.h
文件 14333 2017-11-27 17:14 SM2\sm3.cpp
文件 4578 2017-11-27 17:14 SM2\sm3.h
目录 0 2017-11-28 14:01 SM2
----------- --------- ---------- ----- ----
55402 7
- 上一篇:大唐杯练习题.doc
- 下一篇:解析ARP数据包报告
相关资源
- Chrome插件百度网盘助手0.8.4_0.crx
- max4.0发布接口.rar
- zengerzheng_1516997.zip
- 20161102204738355.rar
- s54jmr.doc
- 交通灯两路.rar
- .net全套就业班视频教程.txt
- bao.zip
- 自然语言处理.docx
- ue.js2.5+cube-ui重构饿了么App.txt
- 二次解析源码带后台广告位.zip
- 文档操作.exe
- MB_Client_Four_Connections.rar
- MB_Client_Two_Connections.rar
- 安卓开发环境集成版.txt
- VMwareESXi5.1.0.txt
- CK.txt
- Dogsvs.Cats.txt
- 数据挖掘综述_王梦雪-副本.pdf
- 20100319172412452.doc
- ArcGISAPI4.X-Echarts4-三维.zip
- 加载百度地图.zip
- SecureCRT.exe
- 《数字信号处理》课后习题.zip
- 朴素贝叶斯分类器对西瓜数据3.0的应
- 国产木马冰河2.2的控制端2008.6.12更新
- hxdef100r.zip
- Ymodem升级工具(修复版).rar
- 精髓.rar
- 某软敏捷开发框架专业版V7.0.3.txt
评论
共有 条评论