Open xxxLingyyy opened 4 years ago
Hoping for advice( ・´ω`・ )
Hello,
It is your timing code that is the problem. It does not take 156ms on Ubuntu. See the bmark.c program for guidance. Replace in your program
tBegin = clock(); for (i = 0; i < 100; i++) { ecurve_mult(r, G, Pb);//Pb=r*G } tEnd = clock(); printf("点T1生成成功,时间为:%f ms", ((double)(tEnd - tBegin)) / 100);
replace with
....
int iterations=0;
double elapsed;
clock_t start=clock();
do {
ecurve_mult(r, G, Pb);//Pb=r*G
elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
iterations++;
} while (elapsed<MIN_TIME || iterations<MIN_ITERS);
elapsed=1000.0*elapsed/iterations;
printf(" %8.2lf ms per iteration\n",elapsed);
Good luck!
Mike
On Tue, Mar 24, 2020 at 9:10 AM xxxLingyyy notifications@github.com wrote:
I'm learning Miracl Library recently, and I have to say it's really friendly to me. These days, I'm testing running time of scalar multiplication on elliptic curves (y^2=x^3+7) with a C program. It takes 1.25ms on VS2019, 64bit, while 156.25ms on Ubuntu Subsystem. How could it be so diffrent? My simple source code is as follows: `#include
include
include
include"miracl.h"
include
char aa="0000000000000000000000000000000000000000"; char bb="0000000000000000000000000000000000000007"; char pp="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73"; char GGx="3B4C382CE37AA192A4019E763036F4F5DD4D7EBB"; char GGy="938CF935318FDCED6BC28286531733C3F03C4FEE"; char nn="00000000000000000001B8FA16DFAB9ACA16B6B3";
int main() {
int i = 0;
big a, b, p,Gx, Gy,n,k,r;
big x1, y1, x2, y2;
// FILE* fp;
// errno_t err;
epoint* G = NULL;//基点
epoint* Pb = NULL;//公钥点
epoint* T1 = NULL;//T1(x1,y1)=[k]G
epoint* T2 = NULL;//
char Hexstring1[65] = { 0 };
char Hexstring2[65] = { 0 };
char Hextemp[1024] = { 0 };
char Binarystring1[257] = { 0 };
char Binarystring2[257] = { 0 };
char Binarytemp[513] = { 0 };
char digest[33] = { 0 };
//char test[] = "abcdbcdecdefdefgefghfghighijhnomnopnopqanhdjiclsjfnbhxejjbsxnaka";
sha256 sh;
clock_t tBegin, tEnd;//标量乘
clock_t tBegin1, tEnd1;//加法
clock_t tBegin2, tEnd2;//哈希
miracl* mip = mirsys(1000, 16);
a = mirvar(0);
b = mirvar(0);
p = mirvar(0);//256bits
Gx = mirvar(0);
Gy = mirvar(0);
n = mirvar(0);
k = mirvar(0);
r = mirvar(0);
x1 = mirvar(0);
y1 = mirvar(0);
x2 = mirvar(0);
y2 = mirvar(0);
shs256_init(&sh);
// err = fopen_s(&fp,"abp.txt", "r+");
// if (fp == 0) {
// printf("�ļ���ʧ��");
// exit(1);
// }
mip->IOBASE = 16;
// cinnum(a, fp);
// cinnum(b, fp);
// cinnum(p, fp);
// cinnum(Gx, fp);
// cinnum(Gy, fp);
// cinnum(n, fp);
cinstr(a,aa);
cinstr(b,bb);
cinstr(p,pp);
cinstr(Gx,GGx);
cinstr(Gy,GGy);
cinstr(n,nn);
// fclose(fp);
/*printf("-----------参数生成-----------\n");
printf("参数a:");
cotnum(a, stdout);
printf("参数b:");
cotnum(b, stdout);
printf("有限域素数p:");
cotnum(p, stdout);
printf("基点横坐标Gx:");
cotnum(Gx, stdout);
printf("基点纵坐标Gy:");
cotnum(Gy, stdout);
printf("基点的阶n:");
cotnum(n, stdout);*/
bigrand(n, r);//随机生成私钥
/*printf("选取私钥数字r:");
cotnum(r, stdout);*/
ecurve_init(a, b, p, MR_PROJECTIVE);
G = epoint_init();
Pb = epoint_init();
T1 = epoint_init();
T2 = epoint_init();
if (epoint_set(Gx, Gy, 0, G)) {
printf("点G生成成功\n");
}
else {
printf("点G生成失败\n");
}
tBegin = clock();
for (i = 0; i < 100; i++) {
ecurve_mult(r, G, Pb);//Pb=r*G
}
tEnd = clock();
printf("点T1生成成功,时间为:%f ms", ((double)(tEnd - tBegin)) / 100);
/*printf("公钥Pb生成成功\n");
printf("--------------标量乘-哈希-点加-------------\n");
bigrand(n, k);
printf("选取随机数k:");
cotnum(k, stdout);
//标量乘运算时间
//tBegin = clock();
//for (; i < 100; i++) {
ecurve_mult(k, G, T1);//生成点T1坐标(x1,y1)=k*G
//}
//
//tEnd = clock();
//printf("点T1生成成功,时间为:%f ms",((double)(tEnd-tBegin))/100);
epoint_get(T1, x1, y1);//获取点x1,y1的坐标
cotstr(x1, Hexstring1);//存入十六进制字符串数组
cotstr(y1, Hexstring2);
// sprintf_s(Hextemp, 1024, "%s%s", Hexstring1, Hexstring2);
sprintf_s(Hextemp, "%s%s", Hexstring1, Hexstring2);
//清空数组
memset(Hexstring1, 0, sizeof(Hexstring1));
memset(Hexstring2, 0, sizeof(Hexstring2));
printf("\n当前十六进制x1|y1为:");
puts(Hextemp);
for (i = 0; Hextemp[i] != 0; i++) {
shs256_process(&sh, Hextemp[i]);
}
//哈希运行时间sha256
tBegin1 = clock();
for (i=0; i < 500; i++) {
shs256_hash(&sh, digest);
}
tEnd1 = clock();
printf("\n哈希结果为:\n");
puts(digest);
printf("哈希所用时间为:%f ms", ((double)(tEnd1 - tBegin1))/500);
//点T2生成
ecurve_mult(k, Pb, T2);//生成点T2坐标(x2,y2)=k*Pb
epoint_get(T2, x2, y2);//获取点T2的坐标
printf("\n\nT2的 x2:");
cotnum(x2, stdout);
printf("T2的 y2:");
cotnum(y2, stdout);
//点加运行时间
tBegin2 = clock();
for (i = 0; i < 100; i++) {
ecurve_add(T1, T2);//T2=T1+T2
}
tEnd2 = clock();
printf("\n点加所用时间为:%f ms", ((double)(tEnd2 - tBegin2)) / 100);
epoint_get(T2, x2, y2);
printf("\n点加后T2的 x2:");
cotnum(x2, stdout);
printf("点加后T2的 y2:");
cotnum(y2, stdout);*/
mirkill(a);
mirkill(b);
mirkill(p);
mirkill(n);
mirkill(Gx);
mirkill(Gy);
mirkill(r);
mirkill(k);
mirkill(x1);
mirkill(x2);
mirkill(y1);
mirkill(y2);
epoint_free(G);
epoint_free(Pb);
epoint_free(T1);
epoint_free(T2);
mirexit();
return 0;
}` Thanks
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/86, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU3ZDTLUIJZALLVRJDNJLLRJB2IXANCNFSM4LSPUPBA .
I'm learning Miracl Library recently, and I have to say it's really friendly to me. These days, I'm testing running time of scalar multiplication on elliptic curves (y^2=x^3+7) with a C program. It takes 1.25ms on VS2019, 64bit, while 156.25ms on Ubuntu Subsystem. How could it be so diffrent? My simple source code is as follows: `#include
include
include
include"miracl.h"
include
char aa="0000000000000000000000000000000000000000"; char bb="0000000000000000000000000000000000000007"; char pp="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73"; char GGx="3B4C382CE37AA192A4019E763036F4F5DD4D7EBB"; char GGy="938CF935318FDCED6BC28286531733C3F03C4FEE"; char nn="00000000000000000001B8FA16DFAB9ACA16B6B3";
int main() {
// fclose(fp);
}` Thanks