Tongsuo-Project / Tongsuo

铜锁/Tongsuo is a Modern Cryptographic Primitives and Protocols Library
https://www.tongsuo.net
Apache License 2.0
1.16k stars 186 forks source link

Cannot build the library with SM2 features enabled. #333

Open ElenaTyuleneva opened 1 year ago

ElenaTyuleneva commented 1 year ago

Hello! I'm struggling with the build of the BabaSSL library under Windows. I need the support of the following functions: _sm2_ciphertext_size sm2_encrypt sm2_plaintext_size sm2_decrypt sm2_compute_z_digest SM2_computekey

And I cannot identify the right version of BabaSSL to use (the one which has support for the specified algorithms). I can see, that these functions exist in BabaSSL8.3.1 (at least, I see them in the source code). I tried to build the library with the following commands:

perl Configure VC-WIN64A --prefix=<some_path_on_localdisk> --openssldir=<some_path_on_localdisk>\ssl enable-ntls enable-sm2 enable-sm3 enable-sm4
nmake
nmake install

The library was built successfully, but when I try to link it to my application, I can see linkage errors: image (there are the same errors for all other SM2 API)

Could you please help me to identify what I do wrong? (another version to use? another build command to execute?)

Thanks in advance, Elena

InfoHunter commented 1 year ago

The version 8.3.1 you have used is correct an it sees the building process was successful as well. The problem is that the functions you want to use are internal functions so they are not exported from the library. Instead, you need to use the EVP interface.

Here is an example on how to use SM2 for encryption/decryption: https://www.yuque.com/tsdoc/ts/zx1bok

For sm2_compute_z_digest and SM2_compute_key, I don't think there is a way to call them outside the library yet.

InfoHunter commented 1 year ago

Note: if you don't want to follow the normal sttyle (using EVP interface), you can always do some modification to your application and Tongsuo library to break the internal fence to use those sm2_ prefixed functions directly. You could probably refer to test/sm2_internal_test.c in branch 8.3-stable to find out how to do that.

ElenaTyuleneva commented 1 year ago

Thank you very much for the answer! I'll try to follow your instructions.