⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.c

📁 miracl大数库 miracl大数库 miracl大数库
💻 C
📖 第 1 页 / 共 3 页
字号:
        chosen=1;
      }
      if (!chosen && llsize>0 && dllen==llsize)
      {
           printf("    quad length type is a %s\n",longlong);
           fprintf(fp,"#define mr_qltype %s\n",longlong);
           chosen=1;
      }
      if (!chosen && qllen==2*bitsinchar*sizeof(long))
      {
        printf("\nDoes compiler support a %d bit integer type? (Y/N)?", 
              qllen);
        qlong=answer();
       
        if (qlong)
        {
            printf("Is it called long long? (Y/N)?");
            if (!answer())
            {
                printf("Enter its name : ");
                scanf("%s",longlong);
                getchar();
            }
            else strcpy(longlong,"long long");

            printf("    quad length type is a %s\n",longlong);
            fprintf(fp,"#define mr_qltype %s\n",longlong);
            chosen=1;
            if (64==qllen && !chosen64)
            { 
                printf("    64 bit unsigned type is an unsigned %s\n",longlong);
                fprintf(fp,"#define mr_unsign64 unsigned %s\n",longlong);
                chosen64=1;
            }
        }
        else
        {
            if (qllen==64) no64=1; /* there is no 64-bit type */
        }
      }
    }
    else qlong=1;


    if (!no64 && !chosen64)
    { /* Still no 64-bit type, but not ruled out either */
        printf("\nDoes compiler support a 64-bit integer type? (Y/N)?");
        dlong=answer();
       
        if (dlong)
        {
            printf("Is it called long long? (Y/N)?");
            if (!answer())
            {
                printf("Enter its name : ");
                scanf("%s",longlong);
                getchar();
            }
            else strcpy(longlong,"long long");

            printf("    64-bit type is a %s\n",longlong);
            fprintf(fp,"#define mr_unsign64 unsigned %s\n",longlong);
            chosen64=1;
        }
    }

    fpl=fopen("miracl.lst","wt");
    ab=0;
    static_build=0;
    if (!double_type)
    {
        printf("\nFor very constrained environments it is possible to build a version of MIRACL\n");
        printf("(for C only) which does not require a heap. Not recommended for beginners.\n");
        printf("Some routines are not available in this mode and the max length of Big\n");
        printf("variables is fixed at compile time\n");
        printf("Do you want a no-heap version of the MIRACL C library? (Y/N)? ");
        static_build=answer();
        if (static_build)
        {
            printf("Please enter the max size of your Big numbers in bits= ");
            scanf("%d",&nbits);
            getchar();
            maxsize=nbits/utlen;
            if ((nbits%utlen)!=0) maxsize++;
            fprintf(fp,"#define MR_STATIC %d\n",maxsize);
            fprintf(fp,"#define MR_ALWAYS_BINARY\n");
            ab=1;
        }
    }
    fprintf(fpl,"mrcore.c\n");
    fprintf(fpl,"mrarth0.c\n");
    fprintf(fpl,"mrarth1.c\n");
    fprintf(fpl,"mrarth2.c\n");
    fprintf(fpl,"mrsmall.c\n");
    fprintf(fpl,"mrio1.c\n");
    fprintf(fpl,"mrio2.c\n");
    fprintf(fpl,"mrgcd.c\n");
    fprintf(fpl,"mrjack.c\n");
    fprintf(fpl,"mrxgcd.c\n");
    fprintf(fpl,"mrarth3.c\n");
    fprintf(fpl,"mrbits.c\n");
    fprintf(fpl,"mrrand.c\n");
    fprintf(fpl,"mrprime.c\n");
    fprintf(fpl,"mrcrt.c\n");
    fprintf(fpl,"mrscrt.c\n");
    fprintf(fpl,"mrmonty.c\n");
    fprintf(fpl,"mrpower.c\n");
    fprintf(fpl,"mrsroot.c\n");
    fprintf(fpl,"mrcurve.c\n");
    fprintf(fpl,"mrlucas.c\n");
    fprintf(fpl,"mrshs.c\n");
    fprintf(fpl,"mrshs256.c\n");
    fprintf(fpl,"mraes.c\n");
    fprintf(fpl,"mrstrong.c\n");
    fprintf(fpl,"mrbrick.c\n");
    fprintf(fpl,"mrebrick.c\n");
    fprintf(fpl,"mrzzn2.c\n");
    fprintf(fpl,"mrzzn2b.c\n");
    fprintf(fpl,"mrzzn3.c\n");
    fprintf(fpl,"mrecn2.c\n");

    if (!static_build)
    {
        fprintf(fpl,"mrfast.c\n");
        fprintf(fpl,"mralloc.c\n");
    }
    if (chosen64) fprintf(fpl,"mrshs512.c\n");

    port=0;
    if (chosen)
    {
        printf("\nDo you want a C-only version of MIRACL (Y/N)?");
        port=answer();
        if (port) fprintf(fp,"#define MR_NOASM\n");
    }
    rounding=0;
    if (double_type)
    {
#ifdef __TURBOC__
        rounding=1;
#endif        
#ifdef _MSC_VER
        rounding=1;
#endif        
#ifdef __GNUC__
        rounding=1;
#endif        
        if (!rounding)
        {
          printf("It will help if rounding control can be exercised on doubles\n");
          printf("Can you implement this in mrarth1.c??  (Y/N)?");
          if (answer()) rounding=1;
        }
        if (rounding) 
        {
            fprintf(fp,"#define MR_FP_ROUNDING\n");
            magic=1.0;
            for (i=0;i<lmant-2;i++) magic*=2.0;
            magic+=2*magic;
            fprintf(fp,"#define MR_MAGIC %lf\n",magic);
        } 
    }

    printf("\nDo you want support for flash arithmetic? (Y/N)?");
    flsh=answer();
    if (flsh)
    { /* calculate size of mantissa in bits */
        eps=1.0;
        for (mant=0;;mant++)
        { /* IMPORTANT TO FOOL OPTIMIZER!!!!!! */
            x=1.0+eps;
            y=1.0;
            if (x==y) break;
            eps/=2.0;
        }
        mant--;
        fprintf(fp,"#define MR_FLASH %d\n",mant);  

        fprintf(fpl,"mrflash.c\n");
        fprintf(fpl,"mrfrnd.c\n");
        fprintf(fpl,"mrdouble.c\n");
        fprintf(fpl,"mrround.c\n");
        fprintf(fpl,"mrbuild.c\n");
        fprintf(fpl,"mrflsh1.c\n");
        fprintf(fpl,"mrpi.c\n");
        fprintf(fpl,"mrflsh2.c\n");
        fprintf(fpl,"mrflsh3.c\n");
        fprintf(fpl,"mrflsh4.c\n");

    }

    printf("Do you want stripped-down version (smaller - no error messages) (Y/N)?");
    stripped=answer();
    if (stripped) fprintf(fp,"#define MR_STRIPPED_DOWN\n");
    
     printf("Do you want multi-threaded version of MIRACL\n");
     printf("Not recommended for program development - read the manual (Y/N)?");
     threaded=answer();

     if (threaded)
     {
      printf("Do you want generic portable threading support (C only - No C++) (Y/N)?");
      choice=answer();
      if (choice) fprintf(fp,"#define MR_GENERIC_MT\n");
      if (!choice && !static_build) 
      {
          printf("Do you want multi-threaded support for C++ in MS Windows (Y/N)?");
          choice=answer();
          if (choice) fprintf(fp,"#define MR_WINDOWS_MT\n");
      }
      if (!choice && !static_build)
      {
          printf("Do you want multi-threaded support for C++ in Unix (Y/N)?");
          choice=answer();
          if (choice) fprintf(fp,"#define MR_UNIX_MT\n");
      }
      if (!choice && !static_build)
      {
          printf("Do you want multi-threaded support for C++ using openMP (Y/N)?");
          choice=answer();
          if (choice) fprintf(fp,"#define MR_OPENMP_MT\n");
      }
     }
    
    nio=1;
    printf("Does your development environment support standard screen/keyboard I/O?\n");
    printf("(It doesn't for example in MS Windows, and embedded applications)\n");
    printf("If in doubt, answer Yes (Y/N)?");
    standard=answer();
    if (!standard) fprintf(fp,"#define MR_NO_STANDARD_IO\n");
    else nio=0;

    printf("Does your development environment support standard file I/O?\n");
    printf("(It doesn't for example in an embedded application)\n");
    printf("If in doubt, answer Yes (Y/N)?");
    standard=answer();
    if (!standard) fprintf(fp,"#define MR_NO_FILE_IO\n");
    else nio=0;

    if (!static_build && !nofull)
    {
        printf("\n\nDo you for some reason NOT want to use a full-width number base?\n");
        printf("\nYou may not if your processor instruction set does not support\n");
        printf("%d-bit UNSIGNED multiply and divide instructions.\n",utlen);
        printf("If NOT then a full-width number base will be difficult and \n");
        printf("slow to implement, which is a pity, because its normally faster\n"); 
        printf("If for some other reason you don't want to use a full-width\n");
        printf("number base, (abnormal handling of integer overflow or no muldvd()\n");
        printf("/muldvd2()/muldvm() available?), answer Yes\n");
        printf("If in doubt answer No\n");
        printf("\nAnswer (Y/N)?");
        nofull=answer();
        if (nofull) 
        {
            printf("\nRemember to use mirsys(...,MAXBASE), or somesuch, in your programs\n");
            printf("as mirsys(...,0); will generate an 'Illegal Number base' error\n");
            fprintf(fp,"#define MR_NOFULLWIDTH\n");
        }
    }

    if (!static_build)
    {
     printf("\nAlways using a power-of-2 (or 0) as a number base reduces code space\n");
     printf("and will also be a little faster. This is recommended.\n"); 
     printf("\nWill all of your programs use a power-of-2 as a number base (Y/N)?");
     if (answer())
     {
         fprintf(fp,"#define MR_ALWAYS_BINARY\n");
         ab=1;
     }
    }

    selected=special=0;
    if (!nofull)
    {
     fprintf(fpl,"mrec2m.c\n");
     fprintf(fpl,"mrgf2m.c\n");

     printf("\nDo you want to create a Comba fixed size multiplier\n");
     printf("for binary polynomial multiplication. This requires that\n");
     printf("your processor supports a special binary multiplication instruction\n");
     printf("which it almost certainly does not....\n");
     printf("Useful particularly for Elliptic Curve cryptosystems over GF(2^m).\n");
     printf("\nDefault to No. Answer (Y/N)?");  
     r=answer();
     if (r)
     {
      step_size=0;
      while (step_size<2 || step_size>32)
      {
         printf("Enter field size in bits = ");
         scanf("%d",&nbits);
         getchar();
         step_size=nbits/utlen;
         if ((nbits%utlen)!=0) step_size++;
      }

      printf("\nTo create the file MRCOMBA2.C you must next execute\n");
      if (port) printf("MEX %d C MRCOMBA2\n",step_size);
      else
      {
       printf("MEX %d <file> MRCOMBA2\n",step_size);
       printf("where <file> is the name of the macro .mcs file (e.g. smartmips)\n");
      }

      fprintf(fp,"#define MR_COMBA2 %d\n",step_size);
      fprintf(fpl,"mrcomba2.c\n");

      printf("\nSpecial routines for polynomial multiplication will now \n");
      printf("automatically be invoked \n");
     }
     fprintf(fp,"#define MAXBASE ((mr_small)1<<(MIRACL-1))\n");
    }
    else
    {
     if (!double_type) fprintf(fp,"#define MAXBASE ((mr_small)1<<(MIRACL-2))\n");
    }

     
     printf("\nDo you wish to use the Karatsuba/Comba/Montgomery method\n");
     printf("for modular arithmetic - as used by exponentiation\n");
     printf("cryptosystems like RSA.\n"); 
     if (port)
     {
      printf("This method may be faster than the standard method when\n");
      printf("using larger moduli, or if your processor has no \n");
      printf("unsigned integer multiply/divide instruction in its\n");
      printf("instruction set. This is true of some popular RISC computers\n");
     }
     else
     {
      printf("This method is probably fastest om most processors which\n");
      printf("which support unsigned mul and a carry flag\n");
      printf("NOTE: your compiler must support in-line assembly,\n");
      printf("and you must be able to supply a suitable .mcs file\n");
      printf("like, for example, ms86.mcs for pentium processors\n");
     }
     printf("\nAnswer (Y/N)?");
     r=answer();
     if (r)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -