使用 VS 2019 編譯開源軟件 MIRACL (1)

          Cryptographic SDK 是一個開源的密碼學和多精度整數及有理數運算軟件,開發語言爲ANSI C。它在Github 上的鏈接是:https://github.com/miracl/MIRACL  。注意如果用於商業用途,需要向開發方購買許可證。本文將介紹如何將其源碼編譯爲庫文件,這裏使用的操作系統是 64位 Windows 10,編譯工具是 Visual Studio 2019 社區版(包含 Microsoft Visual C++ 2019)。編譯 32 位靜態庫的過程如下:
        1) 在 D:\tmp 目錄下執行命令:git clone https://github.com/miracl/MIRACL.git
        2) 創建 D:\tmp\miracl_config 子目錄,將 D:\tmp\MIRACL\config.c 拷貝到該子目錄下。config.c 是 MIRACL 自帶的一個獨立程序,用途是通過向用戶提問,收集用戶答案,根據用戶回答生成必要的頭文件和待編譯源文件名稱列表。稍後將做詳細介紹。
        3) 將 config.c 編譯爲可執行程序。方法是啓動 VS 2019 x86 命令行工具,如下圖:

        進入子目錄 D:\tmp\miracl_config,執行命令
cl config.c
        這樣就生成了config.obj 和config.exe 文件。運行 config.exe,該程序將會提出一系列的問題,用戶應該根據本機實際情況進行回答。
        對於提出的問題:Now enter number of bits in underlying type=
本文中的回答是 32 。
        對於提出的問題:Do you want a C-only version of MIRACL (Y/N)?
本文中的回答是Y。即在這裏只編譯 C 語言版本的庫。如果要編譯與 C++ 有關的部分,應當回答 N 。
        對於提出的問題:Do you want to compile MIRACL as a C++ library, rather than a C library?
本文中的回答是N。如果要編譯與 C++ 有關的部分,應當回答 Y 。
        對於其他問題,儘量按照 Default 建議的值來設置。

        本文中遇到的全部提問及相應回答詳情如下(僅供參考):

D:\tmp\miracl_config>config
This program attempts to generate a mirdef.h file from your
responses to some simple questions, and by some internal tests
of its own.

The most fundamental decision is that of the 'underlying type'
that is the C data type to be used to store each digit of a
big number. You input the number of bits in this type, and
this program finds a suitable candidate (usually short, int or
long). Typical values would be 16, 32 or perhaps 64.
The bigger the better, but a good starting point would be to
enter the native wordlength of your computer

For your information:-
The size of a char  is 8 bits
The size of a short is 16 bits
The size of an int  is 32 bits
The size of a long  is 32 bits
The size of a double is 64 bits, its mantissa is 53 bits
The size of a long double is 64 bits, its mantissa is 53 bits

    Little-endian processor detected

A double can be used as the underlying type. In rare circumstances
 this may be optimal. NOT recommended!

Do you wish to use a double as the underlying type? (Y/N)?N

Now enter number of bits in underlying type= 32

    underlying type is an int
    32 bit unsigned type is an unsigned int

Does compiler support a 64 bit integer type? (Y/N)?Y
Is it called long long? (Y/N)?Y
    double length type is a long long
    64 bit unsigned type is an unsigned long long

For very constrained environments it is possible to build a version of MIRACL
which does not require a heap. Not recommended for beginners.
Some routines are not available in this mode and the max length of Big
variables is fixed at compile time
Do you want a no-heap version of the MIRACL C library? (Y/N)? N

Do you want a C-only version of MIRACL (Y/N)?Y

Do you want support for flash arithmetic? (Y/N)?Y
Do you want stripped-down version (smaller - no error messages) (Y/N)?N
Do you want multi-threaded version of MIRACL
Not recommended for program development - read the manual (Y/N)?N
Does your development environment support standard screen/keyboard I/O?
(It doesn't for example in MS Windows, and embedded applications)
If in doubt, answer Yes (Y/N)?N
Does your development environment support standard file I/O?
(It doesn't for example in an embedded application)
If in doubt, answer Yes (Y/N)?Y


Do you for some reason NOT want to use a full-width number base?

You may not if your processor instruction set does not support
32-bit UNSIGNED multiply and divide instructions.
If NOT then a full-width number base will be difficult and
slow to implement, which is a pity, because its normally faster
If for some other reason you don't want to use a full-width
number base, (abnormal handling of integer overflow or no muldvd()
/muldvd2()/muldvm() available?), answer Yes
If in doubt answer No

Answer (Y/N)?N

Always using a power-of-2 (or 0) as a number base reduces code space
and will also be a little faster. This is recommended.

Will all of your programs use a power-of-2 as a number base (Y/N)?Y

Do you want to create a Comba fixed size multiplier
for binary polynomial multiplication. This requires that
your processor supports a special binary multiplication instruction
which it almost certainly does not....
Useful particularly for Elliptic Curve cryptosystems over GF(2^m).

Default to No. Answer (Y/N)?N

Do you wish to use the Karatsuba/Comba/Montgomery method
for modular arithmetic - as used by exponentiation
cryptosystems like RSA.
This method may be faster than the standard method when
using larger moduli, or if your processor has no
unsigned integer multiply/divide instruction in its
instruction set. This is true of some popular RISC computers

Answer (Y/N)?N

Do you want to create a Comba fixed size modular
multiplier, for faster modular multiplication with
smaller moduli. Can generate a lot of code
Useful particularly for Elliptic Curve cryptosystems over GF(p).

Answer (Y/N)?N

Do you want to save space by using a smaller but slightly slower
AES implementation. Default to No. (Y/N)?N

Do you want to use Edwards paramaterization of elliptic curves over Fp
This is faster for basic Elliptic Curve cryptography (but does not support
Pairing-based Cryptography and some applications). Default to No. (Y/N)?N

Do you want to save space by using only affine coordinates
for elliptic curve cryptography. Default to No. (Y/N)?N

Do you want to save space by not using point compression
for EC(p) elliptic curve cryptography. Default to No. (Y/N)?N

Do you want to save space by not supporting special code
for EC double-addition, as required for ECDSA signature
verification, or any multi-addition of points. Default to No. (Y/N)?N

Do you want to save RAM by using a smaller sliding window
for all elliptic curve cryptography. Default to No. (Y/N)?N

Do you want to save some space by supressing Lazy Reduction?
(as used for ZZn2 arithmetic). Default to No. (Y/N)?N

Do you NOT want to use the built in random number generator?
Removing it saves space, and maybe you have your own source
of randomness? Default to No. (Y/N)?N

Do you want to save space by only using a simple number base?
(the number base in mirsys(.) must be 0 or must divide 2^U
exactly, where U is number of bits in the underlying type)
NOTE: no number base changes possible
Default to No. (Y/N)?N

Do you want to save space by NOT supporting KOBLITZ curves
for EC(2^m) elliptic curve cryptography. Default to No. (Y/N)?N

Do you want to save space by NOT supporting SUPERSINGULAR curves
for EC(2^m) elliptic curve cryptography. Default to No. (Y/N)?N

Do you want to enable a Double Precision big type. See doubig.txt
for more information. Default to No. (Y/N)?N

Do you want to compile MIRACL as a C++ library, rather than a C library?
Default to No. (Y/N)?N

Do you want to avoid the use of compiler intrinsics?
Default to No. (Y/N)?N

A file mirdef.tst has been generated. If you are happy with it,
rename it to mirdef.h and use for compiling the MIRACL library.
A file miracl.lst has been generated that includes all the
files to be included in this build of the MIRACL library.

        最後顯示的提示語告訴我們:生成了mirdef.tst 文件和 miracl.lst 兩個文件。我們可以用文本編輯器打開並查看它們的內容。mirdef.tst 實際上是一個頭文件,miracl.lst 文件內容是一個待編譯 C 源程序文件名列表。到此時,我們就準備好了將要編譯的文件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章