📄 config.c
字号:
{
printf("\nThis method can only be used with moduli whose length in\n");
printf("bits can be represented as %d*(step size)*2^n, for any value\n",utlen);
printf("of n. For example if you input a step size of 8, then \n");
printf("moduli of 256, 512, 1024 bits etc will use this fast code\n");
if (nofull) printf("(assuming a full-length base)\n");
if (port)
printf("In this case case a step size of about 4 is probably optimal\n");
else
{
printf("The best step size can be determined by experiment, but\n");
printf("larger step sizes generate more code. For the Pentium 8 is \n");
printf("about optimal. For the Pentium Pro/Pentium II 16 is better.\n");
if (!nofull) printf("If in doubt, set to 8\n");
}
step_size=0;
while (step_size<2 || step_size>16)
{
printf("Enter step size = ");
scanf("%d",&step_size);
getchar();
}
printf("\nTo create the file MRKCM.C you must next execute\n");
if (port) printf("MEX %d C MRKCM\n",step_size);
else
{
printf("MEX %d <file> MRKCM\n",step_size);
printf("where <file> is the name of the macro .mcs file (e.g. ms86)\n");
}
printf("\nSpecial routines for modular multiplication will now be\n");
printf("automatically be invoked when, for example, powmod() is called\n");
printf("\nRemember to use a full-width base in your programs\n");
printf("by calling mirsys(..,0) or mirsys(..,256) at the start of the program\n");
fprintf(fp,"#define MR_KCM %d\n",step_size);
fprintf(fpl,"mrkcm.c\n");
selected=1;
}
else
{
printf("\nDo you want to create a Comba fixed size modular\n");
printf("multiplier, for faster modular multiplication with\n");
printf("smaller moduli. Can generate a lot of code \n");
printf("Useful particularly for Elliptic Curve cryptosystems over GF(p).\n");
printf("\nAnswer (Y/N)?");
r=answer();
if (r)
{
step_size=0;
while (step_size<2 || step_size>32)
{
printf("Enter modulus size in bits = ");
scanf("%d",&nbits);
getchar();
if (nofull)
{
printf("Enter base size in bits = ");
scanf("%d",&userlen);
getchar();
}
else userlen=utlen;
step_size=nbits/userlen;
if ((nbits%userlen)!=0) step_size++;
}
if (!nofull && (nbits%utlen)==0)
{
printf("\nDo you wish to use a \"special\" fast method\n");
printf("for modular reduction, for a particular modulus\n");
printf("Two types are supported - Generalised Mersenne Primes\n");
printf("also known as Solinas primes\n");
printf("(many already supported - easy to add more - see mrcomba.tpl)\n");
printf("and Pseudo Mersenne Primes (automatically supported)\n");
printf("If in any doubt answer No (Y/N)?");
r=answer();
if (r)
{
special=1;
printf("\nIs your modulus a Generalized Mersenne Prime (Y/N)?");
r=answer();
if (r) special=1;
else
{
printf("\nIs your modulus a \"Pseudo Mersenne\" Prime of the form\n");
printf("2^%d-c where c fits in a single word (Y/N)?",nbits);
r=answer();
if (r) special=2;
}
}
}
printf("\nTo create the file MRCOMBA.C you must next execute\n");
if (port) printf("MEX %d C MRCOMBA\n",step_size);
else
{
printf("MEX %d <file> MRCOMBA\n",step_size);
printf("where <file> is the name of the macro .mcs file (e.g. ms86)\n");
}
fprintf(fp,"#define MR_COMBA %d\n",step_size);
if (special) fprintf(fp,"#define MR_SPECIAL\n");
if (special==1) fprintf(fp,"#define MR_GENERALIZED_MERSENNE\n");
if (special==2) fprintf(fp,"#define MR_PSEUDO_MERSENNE\n");
if (special) fprintf(fp,"#define MR_NO_LAZY_REDUCTION\n");
fprintf(fpl,"mrcomba.c\n");
printf("\nSpecial routines for modular multiplication will now \n");
printf("automatically be invoked for this modulus\n");
printf("\nRemember to use a full-width base in your programs\n");
printf("by calling mirsys(..,0) or mirsys(,..,256) at the start of the program\n");
selected=1;
}
}
if (double_type)
{
maxbase=0;
#ifdef __TURBOC__
if (!port && !selected)
{
printf("\nDoes your computer have a Pentium processor\n");
printf("and do you wish to exploit its built-in FP coprocessor\n");
printf("NOTE: this may not be optimal for Pentium Pro or Pentium II\n");
printf("Supported only for 80x86 processors, and Borland C Compilers\n");
printf("This is a little experimental - so use with care\n");
printf("Answer (Y/N)?");
r=answer();
if (r)
{
printf("Enter (maximum) modulus size in bits = ");
scanf("%d",&nbits);
getchar();
b=31;
do {
b--;
r=64-b-b;
s=1.0;
for (i=0;i<r;i++) s*=2.0;
s*=b;
} while (s<=2*nbits);
s=1; for (i=0;i<b;i++) s*=2;
printf("\nDo you wish to generate variable length looping code, or\n");
printf("fixed length unrolled code? The former can be used with any\n");
printf("modulus less than the maximum size specified above. The latter will\n");
printf("only work with a fixed modulus of that size, but is usually a bit\n");
printf("faster, although it can generate a *lot* of code for larger moduli.\n");
printf("\nAnswer Yes for looping code(Y/N)?");
r=answer();
if (r)
{
fprintf(fp,"#define MR_PENTIUM -%d\n",nbits/b+1);
fprintf(fpl,"mr87v.c\n");
printf("Make sure to compile and link into your program the module MR87V.C\n");
}
else
{
fprintf(fp,"#define MR_PENTIUM %d\n",nbits/b+1);
fprintf(fpl,"mr87f.c\n");
printf("Make sure to compile and link into your program the module MR87F.C\n");
}
printf("\nSpecial fast routines for modular multiplication will now be\n");
printf("automatically be invoked when, for example, powmod() is called\n");
printf("\nIt is *vital* to use the appropriate number base, so\n");
printf("you *must* now call mirsys(...,MAXBASE) at the start of your program\n");
fprintf(fp,"#define MAXBASE %lf\n",s);
maxbase=1;
}
}
#endif
if (!maxbase)
{
s=1.0;
for (i=0;i<dmant-1;i++) /* extra bit "spare" so that 2 can be added */
{
if (i+i+1>=lmant) break;
s*=2.0;
}
fprintf(fp,"#define MAXBASE %lf\n",s);
}
}
fprintf(fp,"#define MR_BITSINCHAR %d\n",bitsinchar);
printf("\nDo you want to save space by using a smaller but slightly slower \n");
printf("AES implementation. Default to No. (Y/N)?");
r=answer();
if (r)
{
fprintf(fp,"#define MR_SMALL_AES\n");
}
printf("\nDo you want to save space by using only affine coordinates \n");
printf("for elliptic curve cryptography. Default to No. (Y/N)?");
r=answer();
if (r)
{
fprintf(fp,"#define MR_AFFINE_ONLY\n");
}
printf("\nDo you want to save space by not using point compression \n");
printf("for EC(p) elliptic curve cryptography. Default to No. (Y/N)?");
r=answer();
if (r)
fprintf(fp,"#define MR_NOSUPPORT_COMPRESSION\n");
printf("\nDo you want to save space by not supporting special code \n");
printf("for EC double-addition, as required for ECDSA signature \n");
printf("verification, or any multi-addition of points. Default to No. (Y/N)?");
r=answer();
if (r)
fprintf(fp,"#define MR_NO_ECC_MULTIADD\n");
printf("\nDo you want to save RAM by using a smaller sliding window \n");
printf("(By default the window size is 5, this reduces it to 4) \n");
printf("for all elliptic curve cryptography. Default to No. (Y/N)?");
r=answer();
if (r)
fprintf(fp,"#define MR_SMALL_EWINDOW\n");
if (!special)
{
printf("\nDo you want to save some space by supressing Lazy Reduction? \n");
printf("(as used for ZZn2 arithmetic). Default to No. (Y/N)?");
r=answer();
if (r)
fprintf(fp,"#define MR_NO_LAZY_REDUCTION\n");
}
printf("\nDo you NOT want to use the built in random number generator?\n");
printf("Removing it saves space, and maybe you have your own source\n");
printf("of randomness? Default to No. (Y/N)?");
r=answer();
if (r)
fprintf(fp,"#define MR_NO_RAND\n");
sb=0;
if (!nofull && ab)
{
printf("\nDo you want to save space by only using a simple number base?\n");
printf("(the number base in mirsys(.) must be 0 or must divide 2^U\n");
printf("exactly, where U is number of bits in the underlying type)\n");
printf("NOTE: no number base changes possible\n");
printf("Default to No. (Y/N)?");
r=answer();
if (r)
{
sb=1;
fprintf(fp,"#define MR_SIMPLE_BASE\n");
}
}
if (sb)
{
printf("\nDo you want to save space by only using simple I/O? \n");
printf("(Input from ROM, and Input/Output as binary bytes only) \n");
printf("(However crude HEX-only output is supported) \n");
printf("Default to No. (Y/N)?");
r=answer();
if (r)
fprintf(fp,"#define MR_SIMPLE_IO\n");
}
if (!double_type)
{
printf("\nDo you want to save space by NOT supporting KOBLITZ curves \n");
printf("for EC(2^m) elliptic curve cryptography. Default to No. (Y/N)?");
r=answer();
if (r)
fprintf(fp,"#define MR_NOKOBLITZ\n");
printf("\nDo you want to save space by NOT supporting SUPERSINGULAR curves \n");
printf("for EC(2^m) elliptic curve cryptography. Default to No. (Y/N)?");
r=answer();
if (r)
{
fprintf(fp,"#define MR_NO_SS\n");
}
}
printf("\nDo you want to enable a Double Precision big type. See doubig.txt\n");
printf("for more information. Default to No. (Y/N)?");
r=answer();
if (r)
{
fprintf(fp,"#define MR_MR_DOUBLE_BIG\n");
}
if (!port)
{
if (!dlong) printf("\nYou must now provide an assembly language file mrmuldv.c,\n");
else printf("\nYou must now provide an assembly or C file mrmuldv.c,\n");
if (!nofull)
printf("containing implementations of muldiv(), muldvd(), muldvd2() and muldvm()\n");
else
{
printf("containing an implementation of muldiv()\n");
if (rounding) printf("..and imuldiv()\n");
}
if (!dlong)
printf("Check mrmuldv.any - an assembly language version may be\n");
else
printf("Check mrmuldv.any - a C or assembly language version is\n");
printf("there already\n");
fprintf(fpl,"mrmuldv.c\n");
}
printf("\nA file mirdef.tst has been generated. If you are happy with it,\n");
printf("rename it to mirdef.h and use for compiling the MIRACL library.\n");
printf("A file miracl.lst has been generated that includes all the \n");
printf("files to be included in this build of the MIRACL library.\n");
fprintf(fpl,"\nCompile the above with -O2 optimization\n");
if (threaded)
fprintf(fpl,"Also use appropriate flag for multi-threaded compilation\n");
if (!port)
{
fprintf(fpl,"Note that mrmuldv.c file may be pure assembly, so may \n");
fprintf(fpl,"be renamed to mrmuldv.asm or mrmuldv.s, and assembled \n");
fprintf(fpl,"rather than compiled\n");
}
fclose(fp);
fclose(fpl);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -