All Projects → songgeng87 → Sm9_free

songgeng87 / Sm9_free

Licence: bsd-2-clause
基于Miracl的国密算法SM9实现

Programming Languages

c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to Sm9 free

Xcode Starter Pack
My personal default xcconfig files and whatnot for a new project
Stars: ✭ 15 (-54.55%)
Mutual labels:  xcode
Xcodecompilationdatabase
Generate a Compilation Database from Xcode's build log - nothing more :).
Stars: ✭ 28 (-15.15%)
Mutual labels:  xcode
Mod Pbxproj
A python module to manipulate XCode projects
Stars: ✭ 959 (+2806.06%)
Mutual labels:  xcode
Refresher
DEPRECATED: Pull to refresh in Swift
Stars: ✭ 885 (+2581.82%)
Mutual labels:  xcode
Mvvm C Templates
Templates for MVVM-C architecture
Stars: ✭ 27 (-18.18%)
Mutual labels:  xcode
Xtream Iptv Player Reactnative
Stars: ✭ 30 (-9.09%)
Mutual labels:  xcode
Xcbt
⌛️xcbt shows Xcode build time of a specified project.
Stars: ✭ 14 (-57.58%)
Mutual labels:  xcode
Bfkit Swift
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.
Stars: ✭ 963 (+2818.18%)
Mutual labels:  xcode
Headfirstdesignpatternscpp
An implementation of examples from "Head First Design Patterns", written in C++.
Stars: ✭ 28 (-15.15%)
Mutual labels:  xcode
Swiftlyext
SwiftlyExt is a collection of useful extensions for Swift 3 standard classes and types 🚀
Stars: ✭ 31 (-6.06%)
Mutual labels:  xcode
Gitversioningonxcode
Pretty Xcode Git versioning for iOS & macOS applications
Stars: ✭ 15 (-54.55%)
Mutual labels:  xcode
Xcodecodesnippets
Code snippets for Xcode.
Stars: ✭ 27 (-18.18%)
Mutual labels:  xcode
Hmlldb
HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps.
Stars: ✭ 30 (-9.09%)
Mutual labels:  xcode
Awesome Swiftui
A collaborative list of awesome articles, talks, books, videos and code examples about SwiftUI.
Stars: ✭ 878 (+2560.61%)
Mutual labels:  xcode
Metro Lights
A dark Xcode theme inspired by City Lights for Atom.
Stars: ✭ 32 (-3.03%)
Mutual labels:  xcode
Swiftinfo
📊 Extract and analyze the evolution of an iOS app's code.
Stars: ✭ 880 (+2566.67%)
Mutual labels:  xcode
Coremlstyletransfer
A simple demo for Core ML and Style Transfer
Stars: ✭ 30 (-9.09%)
Mutual labels:  xcode
Isimulator
iSimulator is a GUI utility to control the Simulator, and manage the app installed on the simulator.
Stars: ✭ 963 (+2818.18%)
Mutual labels:  xcode
React Native Video Processing
Native Video editing/trimming/compressing 🎥 library for React-Native
Stars: ✭ 959 (+2806.06%)
Mutual labels:  xcode
Instories
iOS app for viewing Instagram stories anonymously.
Stars: ✭ 31 (-6.06%)
Mutual labels:  xcode

SM9_FREE

标识密码算法SM9(IBC)实现,包括密钥生成、签名验签、密钥交换和加解密等SM9标准中提到的所有功能。

该实现基于Miracl密码库

采用C语言编写,可支持X86、X86_64、ARM等多平台编译。

源码关系

Miracl密码库比较庞大,因此只截取出其中最核心的部分,包括大整数运算,Fp,Fp^2,Fp^4域计算以及Fp和Fp^2上椭圆曲线基础计算等功能。

依赖的所有Miracl密码库文件在文件夹 SM9_FREE/miracl 内。

Miracl密码库 基础之上,实现了满足SM9扩域需求的Fp^12和ate-pairing实现,最后在此之上完成了SM9的密钥生成、签名验签、密钥交换和加解密等功能。 所有和SM9相关的文件都在文件夹 SM9_FREE/sm9内。

SM9Test.c文件内是简单的测试用例,同时对性能做了简单的统计。

SM9编译测试

可以直接用XCODE进行编译测试

也可用gcc进行编译

make test

./test

SM9使用方法

#具体返回错误码等可参考sm9_algorithm.h文件

  1. 首先需要初始化参数(使用SM9 第五部分 指定的曲线类型和主密钥初始化系统):

SM9_Init(0,0,32,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );

  1. 如果想要使用签名部分

2.1 需要首先生成签名公私钥对:

SM9_MSK msk = SM9_MSK_New(32, cks); // 申明一个签名主密钥

SM9_MSPK mspk = SM9_MSPK_New(32); //申明一个主签名公钥

SM9_GenMSignPubKey(&msk, &mspk); // 生成主签名公钥

2.2 启动签名验签lib

gg = SM9_Set_Sign(mspk.x1, mspk.x2, mspk.y1, mspk.y2, NULL); // 启动签名lib

第二次启动时候可以使用上述生成的gg

SM9_Set_Sign(NULL, NULL, NULL, NULL, gg);

2.3 针对具体id生成签名私钥

SM9_PK pk = SM9_PK_New(5, id); // 申明一个签名公钥

SM9_SSK sk = SM9_SSK_New(32); // 申明一个签名私钥

SM9_GenSignSecKey(&sk, &pk, &msk); // 由公钥(id)生成签名私钥

2.4 完成签名

SM9_Sign sign = SM9_Sign_New(32); // 申明一个签名体

SM9_Signature(msg, 20, rand, &sk, &sign); //签名

2.5 验签部分

单独使用验签,同样需要先初始化参数

SM9_Init(0,0,32,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );

和启动签名验签lib

SM9_Set_Sign(NULL, NULL, NULL, NULL, gg);

随后可以根据用户id完成验签

SM9_Verify(msg, 20, &sign, &pk, NULL);

开源协议

本代码遵循BSD开源协议,欢迎大家使用

性能

在cpu i7 2.3G, 64位单线程环境下:

签名10000次大约耗时:120秒

验证10000次大约耗时:372秒

加密10000次大约耗时:130秒

解密10000次大约耗时:214秒

密钥交换20000次大约耗时:833秒

捐献

接受ETH捐献: ETH地址:0x36D112ad944c44Be528D5B799ECC131ffD3669BA

接受EOS捐献: EOS账号:jueduijuxing

所有收到的捐献将以徐峥、刘青云、周迅或张韶涵的名义在西部助建希望小学、水井等基础设施(不知以他人名义捐献是否妥当,如有不妥将删除)。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].